33import matplotlib .pyplot as plt
44import shutil
55import unittest
6- import os
76import shutil
8- from os import path
97import shutil
108from pathlib import Path
11- from prose import Telescope , blocks , load
9+ from prose import Telescope , blocks
1210from prose .reports import Report , Summary
13- from prose .utils import register
11+ from prose .utils import register_args
12+ from prose .tess import TFOPObservation
1413
1514
1615RAW = Path ("synthetic_dataset" )
17- REDUCED = "synthetic_dataset"
16+ REDUCED = "test/ synthetic_dataset"
1817PHOT = "/Users/lgrcia/data/test_data_prose/Io_2021-11-28_TOI-4508.01_g'.phot"
19- OBS = Observation (PHOT )
2018
2119# Removing existing folders
2220if RAW .exists ():
3129
3230class TestReport (unittest .TestCase ):
3331
32+ OBS = Observation (PHOT )
33+
3434 def test_summary_report (self ):
3535
3636 # The summary template
37- summary = Summary (OBS )
37+ summary = Summary (self . OBS )
3838
3939 # The report
4040 report = Report ([summary ])
@@ -51,7 +51,7 @@ def test_fits_manager(self):
5151 fm = FitsManager (destination )
5252 result_file = TEST_FODLER / "test_fits_manager.txt"
5353 file = open (result_file , "w" )
54- file .write (fm .print ( repr = True ))
54+ file .write (fm .__repr__ ( ))
5555 file .close ()
5656
5757 def test_files (self ):
@@ -62,12 +62,12 @@ def test_files(self):
6262 fm = FitsManager (destination )
6363 result_file = TEST_FODLER / "test_fm_files.txt"
6464 file = open (result_file , "w" )
65- file .write ("\n " .join (fm .files (imtype = "dark" , exposure = 8 , exposure_tolerance = 1 ) ))
65+ file .write ("\n " .join (fm .files (type = "dark" , exposure = 8 , tolerance = 1 , path = True ). path . values ))
6666 file .close ()
6767
6868class TestReduction (unittest .TestCase ):
6969
70- def test_OLD_reduction (self ):
70+ def test_pipeline_reduction (self ):
7171
7272 # generate dataset
7373 import numpy as np
@@ -84,9 +84,9 @@ def test_OLD_reduction(self):
8484 })
8585
8686 fm = FitsManager (RAW , depth = 2 )
87- destination = fm .obs_name
88- calib = Calibration (** fm .observation_files (0 ), overwrite = True )
89- calib .run (fm .images , TEST_FODLER / destination )
87+ destination = fm .label ( 1 )
88+ calib = Calibration (** fm .observation_files (1 ), overwrite = True )
89+ calib .run (fm .all_images , TEST_FODLER / destination )
9090
9191 photometry = AperturePhotometry (
9292 files = calib .images ,
@@ -95,7 +95,7 @@ def test_OLD_reduction(self):
9595 )
9696 photometry .run (calib .phot )
9797
98- o = load (calib .phot )
98+ o = Observation (calib .phot )
9999 o .target = 0
100100 o .broeg2005 ()
101101 o .plot ()
@@ -108,7 +108,7 @@ def test_OLD_reduction(self):
108108
109109 shutil .rmtree (RAW )
110110
111- def test_OLD_empty_calibration (self ):
111+ def test_pipeline_empty_calibration (self ):
112112
113113 # generate dataset
114114 import numpy as np
@@ -125,143 +125,124 @@ def test_OLD_empty_calibration(self):
125125 })
126126
127127 fm = FitsManager (RAW , depth = 2 )
128- destination = fm .obs_name
128+ destination = fm .label ( 1 )
129129 calib = Calibration (bias = [], darks = [], flats = [], overwrite = True )
130- calib .run (fm .images , TEST_FODLER / destination )
130+ calib .run (fm .all_images , TEST_FODLER / destination )
131+
132+
133+ class TestTFOPObservation (unittest .TestCase ):
134+
135+ OBS = TFOPObservation (PHOT )
136+
137+ def __init__ (self , * args , ** kwargs ):
138+ unittest .TestCase .__init__ (self , * args , ** kwargs )
139+
140+ def test_tess_ids (self ):
141+ result_file = TEST_FODLER / "tess-properties.txt"
142+ file = open (result_file , "w" )
143+ assert self .OBS .tic_id == '170789802' , "wrong tic id"
144+ assert self .OBS .gaia_from_toi == "4877792060261482752" , "Wrong gaia from TOI"
145+ file .write (f"- TIC-id: { self .OBS .tic_id } \n " )
146+ file .write (f"- Gaia from TOI: { self .OBS .gaia_from_toi } \n " )
147+ file .write (f"- TOI-label: { self .OBS .tfop_prefix } \n " )
148+
149+ def test_gaia_from_toi (self ):
150+ assert self .OBS .gaia_from_toi == "4877792060261482752" , "Wrong gaia from TOI"
151+
131152
132153class TestObservation (unittest .TestCase ):
133154
155+ OBS = Observation (PHOT )
156+
134157 def __init__ (self , * args , ** kwargs ):
135158 unittest .TestCase .__init__ (self , * args , ** kwargs )
136159
137160 def test_properties (self ):
138161 result_file = TEST_FODLER / "properties.txt"
139162 file = open (result_file , "w" )
140- file .write (f"- simbad: { OBS .simbad } \n " )
141- file .write (f"- label: { OBS .label } \n " )
142- file .write (f"- date: { OBS .date } \n " )
143- file .write (f"- night_date: { OBS .night_date } \n " )
144- file .write (f"- telescope_name: { OBS .stack .telescope .name } \n " )
145- file .write (f"- xlabel: { OBS .xlabel } \n " )
146-
147- def test_tess_ids (self ):
148- result_file = TEST_FODLER / "tess-properties.txt"
149- file = open (result_file , "w" )
150- assert OBS .tic_id == '170789802' , "wrong tic id"
151- assert OBS .gaia_from_toi == "4877792060261482752" , "Wrong gaia from TOI"
152- file .write (f"- TIC-id: { OBS .tic_id } \n " )
153- file .write (f"- Gaia from TOI: { OBS .gaia_from_toi } \n " )
154- file .write (f"- TOI-label: { OBS .tfop_prefix } \n " )
163+ file .write (f"- simbad: { self .OBS .simbad } \n " )
164+ file .write (f"- label: { self .OBS .label } \n " )
165+ file .write (f"- date: { self .OBS .date } \n " )
166+ file .write (f"- night_date: { self .OBS .night_date } \n " )
167+ file .write (f"- telescope_name: { self .OBS .stack .telescope .name } \n " )
168+ file .write (f"- xlabel: { self .OBS .xlabel } \n " )
155169
156170 def test_set_gaia_target (self ):
157171 result_file = TEST_FODLER / "test_set_gaia_target.png"
158172 gaia = "Gaia DR2 4877792060261482752"
159- OBS .set_catalog_target ("gaia" , gaia )
160- OBS .target = 18
161- OBS .stack .show_cutout (OBS .target )
162- OBS .stack .plot_catalog ('gaia' , label = True )
173+ self .OBS .set_catalog_target ("gaia" , gaia )
174+ self .OBS .stack .show_cutout (self .OBS .target )
175+ self .OBS .stack .plot_catalog ('gaia' , label = True )
163176 plt .title (f"expected { gaia } " )
164177 plt .savefig (result_file )
165178 plt .close ()
166179
167180 def test_diff (self ):
168181 result_file = TEST_FODLER / "test_diff.png"
169- OBS .target = 18
170- OBS .broeg2005 ()
171- OBS .plot ()
182+ self . OBS .target = 18
183+ self . OBS .broeg2005 ()
184+ self . OBS .plot ()
172185 plt .savefig (result_file )
173186 plt .close ()
174187
175188 def test_plot (self ):
176189 result_file = TEST_FODLER / "test_plot.png"
177- OBS .plot ()
190+ self . OBS .plot ()
178191 plt .savefig (result_file )
179192 plt .close ()
180193
181194 def test_plot_systeamtics (self ):
182195 result_file = TEST_FODLER / "test_systematics.png"
183- OBS .plot_systematics ()
196+ self . OBS .plot_systematics ()
184197 plt .savefig (result_file )
185198 plt .close ()
186199
187200 def test_plot_comps_lcs (self ):
188201 result_file = TEST_FODLER / "test_plot_comps_lcs.png"
189- OBS .plot_comps_lcs ()
202+ self . OBS .plot_comps_lcs ()
190203 plt .savefig (result_file )
191204 plt .close ()
192205
193206 def test_show_stars (self ):
194207 result_file = TEST_FODLER / "test_show_stars.png"
195- OBS .show_stars ()
208+ self . OBS .show_stars ()
196209 plt .savefig (result_file )
197210 plt .close ()
198211
199212 def test_plot_psf_model (self ):
200213 result_file = TEST_FODLER / "test_plot_psf_model_target.png"
201- OBS .plot_psf_model ()
214+ self . OBS .plot_psf_model ()
202215 plt .savefig (result_file )
203216 plt .close ()
204217 result_file = TEST_FODLER / "test_plot_psf_model_other_star.png"
205- OBS .plot_psf_model (star = 110 , model = blocks .Moffat2D )
218+ self . OBS .plot_psf_model (star = 110 , model = blocks .Moffat2D )
206219 plt .savefig (result_file )
207220 plt .close ()
208221
209222 def test_noise_stats (self ):
210223 result_file = TEST_FODLER / "noise_stats.txt"
211224 file = open (result_file , "w" )
212- noise = OBS .noise_stats (verbose = False )
225+ noise = self . OBS .noise_stats (verbose = False )
213226 file .write (f"white (pont2006)\t { noise ['pont_white' ]:.3e} \n "
214227 f"red (pont2006)\t { noise ['pont_red' ]:.3e} \n "
215228 f"white (binned)\t \t { noise ['binned_white' ]:.3e} \n " )
216229
217- def test_gaia_from_toi (self ):
218- assert OBS .gaia_from_toi == "4877792060261482752" , "Wrong gaia from TOI"
219-
220230 def test_plate_solve (self ):
221231 result_file = TEST_FODLER / "test_plate_solve.png"
222- OBS .plate_solve ()
223- OBS .query_catalog ('gaia' )
224- gaias = OBS .stack .catalogs ["gaia" ][["x" , "y" ]].values
225- OBS .stack .show (frame = True )
232+ self . OBS .plate_solve ()
233+ self . OBS .query_catalog ('gaia' )
234+ gaias = self . OBS .stack .catalogs ["gaia" ][["x" , "y" ]].values
235+ self . OBS .stack .show (frame = True )
226236 viz .plot_marks (* gaias .T , color = "y" )
227237 plt .savefig (result_file )
228238 plt .close ()
229239
240+
241+ class TestArgsRegistration (unittest .TestCase ):
242+
243+ def __init__ (self , * args , ** kwargs ):
244+ unittest .TestCase .__init__ (self , * args , ** kwargs )
245+
246+
230247if __name__ == "__main__" :
231- unittest .main ()
232-
233- class Test :
234- def __init__ (self , a , b ):
235- register (locals ())
236- self .a = a
237-
238- t = Test (2 , 3 )
239- print ("{'a': 2, 'b': 3} {}" )
240- print (t .args , t .kwargs , "\n " )
241-
242- class Test :
243- def __init__ (self , a , b = 4 ):
244- register (locals ())
245- self .a = a
246-
247- t = Test (2 , 3 )
248- print ("{'a': 2} {'b': 3}" )
249- print (t .args , t .kwargs , "\n " )
250-
251- class Test :
252- def __init__ (self , a , * args ):
253- register (locals ())
254- self .a = a
255-
256- t = Test (2 , 5 )
257- print ("{'a': 2, '0': 5} {}" )
258- print (t .args , t .kwargs , "\n " )
259-
260- class Test :
261- def __init__ (self , a , ** kwargs ):
262- register (locals ())
263- self .a = a
264-
265- t = Test (2 , g = 5 )
266- print ("{'a': 2} {'g': 5}" )
267- print (t .args , t .kwargs , "\n " )
248+ unittest .main ()
0 commit comments