@@ -125,15 +125,10 @@ def save_sky_subtract_info( self, info ):
125125 for phrosty.imagesubtraction.sky_subtract().
126126 """
127127
128- try :
129- SNLogger .debug ( f"Saving sky_subtract info for path { info [0 ]} " )
130- self .skysub_img = info [0 ]
131- self .detmask_img = info [1 ]
132- self .skyrms = info [2 ]
133-
134- except :
135- if self .skysub_img is None or self .detmask_img is None or self .skyrms is None :
136- pipeline .failures ['skysub' ].append (f'{ self .image .band } { self .image .pointing } { self .image .sca } ' )
128+ SNLogger .debug ( f"Saving sky_subtract info for path { info [0 ]} " )
129+ self .skysub_img = info [0 ]
130+ self .detmask_img = info [1 ]
131+ self .skyrms = info [2 ]
137132
138133 def get_psf ( self , ra , dec ):
139134 """Get the at the right spot on the image.
@@ -177,8 +172,7 @@ def get_psf( self, ra, dec ):
177172 return None
178173
179174 def keep_psf_data ( self , psf_data ):
180- """Save PSF data to attribute. If self.get_psf() failed,
181- then the image is recorded as a failure.
175+ """Save PSF data to attribute.
182176
183177 Parameters
184178 ----------
@@ -189,9 +183,6 @@ def keep_psf_data( self, psf_data ):
189183
190184 self .psf_data = psf_data
191185
192- if self .psf_data is None :
193- pipeline .failures ['get_psf' ].append (f'{ self .image .band } { self .image .pointing } { self .image .sca } ' )
194-
195186 def free ( self ):
196187 """Try to free memory. More might be done here."""
197188 self .image .free ()
@@ -283,8 +274,17 @@ def __init__( self, diaobj, imgcol, band,
283274 self .template_images = [ PipelineImage ( i , self ) for i in template_images ]
284275
285276 # All of our failures.
286- self .failures = {'skysub' : [],
287- 'get_psf' : [],
277+ # LA NOTE: I want to add keys for when this fails in sky subtraction and PSF retrieval
278+ # as well. But that is slightly more involved because those things happen in
279+ # PipelineImage, not Pipeline. So, for now, anything that fails at 'make_lightcurve'
280+ # may have failed at earlier steps first. Also, source extractor doesn't fail on
281+ # an image full of NaNs for some reason. It just reports 0 sources. I would expect
282+ # that it should fail, here...
283+ self .failures = {'align_and_preconvolve' : [],
284+ 'find_decorrelation' : [],
285+ 'subtract' : [],
286+ 'variance' : [],
287+ 'apply_decorrelation' : [],
288288 'make_lightcurve' : [],
289289 'make_stamps' : []}
290290
@@ -344,9 +344,7 @@ def sky_sub_all_images( self ):
344344 all_imgs .extend ( self .template_images )
345345
346346 def log_error ( img , x ):
347-
348347 SNLogger .error ( f"Sky subtraction failure on { img .image .path } : { x } " )
349- self .failures ['skysub' ].append ( f'{ img .image .band } { img .image .pointing } { img .image .sca } ' )
350348
351349 if self .nprocs > 1 :
352350 with Pool ( self .nprocs ) as pool :
@@ -373,7 +371,6 @@ def get_psfs( self ):
373371
374372 def log_error ( img , x ):
375373 SNLogger .error ( f"get_psf failure on { img .image .path } : { x } " )
376- self .failures ['get_psf' ].append ( f'{ img .image .band } { img .image .pointing } { img .image .sca } ' )
377374
378375 if self .nprocs > 1 :
379376 with Pool ( self .nprocs ) as pool :
@@ -861,56 +858,80 @@ def log_fits_write_error( savepath, x ):
861858 for sci_image in self .science_images :
862859 SNLogger .info ( f"Processing { sci_image .image .name } minus { templ_image .image .name } " )
863860 sfftifier = None
861+ fail_info = {'science' : f'{ sci_image .image .band } { sci_image .image .pointing } { sci_image .image .sca } ' ,
862+ 'template' : f'{ templ_image .image .band } { templ_image .image .pointing } { templ_image .image .sca } '
863+ }
864+ i_failed = False
864865
865866 if 'align_and_preconvolve' in steps :
866867 SNLogger .info ( "...align_and_preconvolve" )
867868 with nvtx .annotate ( "align_and_pre_convolve" , color = 0x8888ff ):
868- sfftifier = self .align_and_pre_convolve ( templ_image , sci_image )
869+ try :
870+ sfftifier = self .align_and_pre_convolve ( templ_image , sci_image )
871+ except :
872+ i_failed = True
873+ self .failures ['align_and_preconvolve' ].append (fail_info )
869874
870- if 'subtract' in steps :
875+ if 'subtract' in steps and not i_failed :
871876 SNLogger .info ( "...subtract" )
872877 with nvtx .annotate ( "subtraction" , color = 0x44ccff ):
873- sfftifier .sfft_subtraction ()
878+ try :
879+ sfftifier .sfft_subtraction ()
880+ except :
881+ i_failed = True
882+ self .failures ['subtract' ].append (fail_info )
874883
875- if 'find_decorrelation' in steps :
884+ if 'find_decorrelation' in steps and not i_failed :
876885 SNLogger .info ( "...find_decorrelation" )
877886 with nvtx .annotate ( "find_decor" , color = 0xcc44ff ):
878- sfftifier .find_decorrelation ()
887+ try :
888+ sfftifier .find_decorrelation ()
889+ except :
890+ i_failed = True
891+ self .failures ['find_decorrelation' ].append (fail_info )
879892
880893 SNLogger .info ( "...generate variance image" )
881894 with nvtx .annotate ( "variance" , color = 0x44ccff ):
882- diff_var = sfftifier .create_variance_image ()
895+ try :
896+ diff_var = sfftifier .create_variance_image ()
897+ mess = f"{ sci_image .image .name } -{ templ_image .image .name } "
898+ diff_var_path = self .dia_out_dir / f"diff_var_{ mess } "
899+ except :
900+ i_failed = True
901+ self .failures ['variance' ].append (fail_info )
902+
903+ if 'apply_decorrelation' in steps and not i_failed :
904+ try :
883905 mess = f"{ sci_image .image .name } -{ templ_image .image .name } "
884- diff_var_path = self .dia_out_dir / f"diff_var_{ mess } "
885-
886- if 'apply_decorrelation' in steps :
887- mess = f"{ sci_image .image .name } -{ templ_image .image .name } "
888- decorr_psf_path = self .dia_out_dir / f"decorr_psf_{ mess } "
889- decorr_zptimg_path = self .dia_out_dir / f"decorr_zptimg_{ mess } "
890- decorr_diff_path = self .dia_out_dir / f"decorr_diff_{ mess } "
891-
892- images = [ sfftifier .PixA_DIFF_GPU , diff_var ,
893- sfftifier .PixA_Ctarget_GPU , sfftifier .PSF_target_GPU ]
894- savepaths = [ decorr_diff_path , diff_var_path ,
895- decorr_zptimg_path , decorr_psf_path ]
896- headers = [ sfftifier .hdr_target , sfftifier .hdr_target ,
897- sfftifier .hdr_target , None ]
898-
899- for img , savepath , hdr in zip ( images , savepaths , headers ):
900- with nvtx .annotate ( "apply_decor" , color = 0xccccff ):
901- SNLogger .info ( f"...apply_decor to { savepath } " )
902- decorimg = sfftifier .apply_decorrelation ( img )
903- with nvtx .annotate ( "submit writefits" , color = 0xff8888 ):
904- SNLogger .info ( f"...writefits { savepath } " )
905- fits_writer_pool .apply_async ( self .write_fits_file ,
906- ( cp .asnumpy ( decorimg ).T , hdr , savepath ), {},
907- error_callback = partial (log_fits_write_error , savepath ) )
908- sci_image .decorr_psf_path [ templ_image .image .name ] = decorr_psf_path
909- sci_image .decorr_zptimg_path [ templ_image .image .name ] = decorr_zptimg_path
910- sci_image .decorr_diff_path [ templ_image .image .name ] = decorr_diff_path
911- sci_image .diff_var_path [ templ_image .image .name ] = diff_var_path
912-
913- if self .keep_intermediate :
906+ decorr_psf_path = self .dia_out_dir / f"decorr_psf_{ mess } "
907+ decorr_zptimg_path = self .dia_out_dir / f"decorr_zptimg_{ mess } "
908+ decorr_diff_path = self .dia_out_dir / f"decorr_diff_{ mess } "
909+
910+ images = [ sfftifier .PixA_DIFF_GPU , diff_var ,
911+ sfftifier .PixA_Ctarget_GPU , sfftifier .PSF_target_GPU ]
912+ savepaths = [ decorr_diff_path , diff_var_path ,
913+ decorr_zptimg_path , decorr_psf_path ]
914+ headers = [ sfftifier .hdr_target , sfftifier .hdr_target ,
915+ sfftifier .hdr_target , None ]
916+
917+ for img , savepath , hdr in zip ( images , savepaths , headers ):
918+ with nvtx .annotate ( "apply_decor" , color = 0xccccff ):
919+ SNLogger .info ( f"...apply_decor to { savepath } " )
920+ decorimg = sfftifier .apply_decorrelation ( img )
921+ with nvtx .annotate ( "submit writefits" , color = 0xff8888 ):
922+ SNLogger .info ( f"...writefits { savepath } " )
923+ fits_writer_pool .apply_async ( self .write_fits_file ,
924+ ( cp .asnumpy ( decorimg ).T , hdr , savepath ), {},
925+ error_callback = partial (log_fits_write_error , savepath ) )
926+ sci_image .decorr_psf_path [ templ_image .image .name ] = decorr_psf_path
927+ sci_image .decorr_zptimg_path [ templ_image .image .name ] = decorr_zptimg_path
928+ sci_image .decorr_diff_path [ templ_image .image .name ] = decorr_diff_path
929+ sci_image .diff_var_path [ templ_image .image .name ] = diff_var_path
930+ except :
931+ i_failed = True
932+ self .failures ['apply_decorrelation' ].append (fail_info )
933+
934+ if self .keep_intermediate and not i_failed :
914935 # Each key is the file prefix addition.
915936 # Each list has [descriptive filetype, image file name, data, header].
916937
@@ -978,7 +999,7 @@ def log_fits_write_error( savepath, x ):
978999 fits_writer_pool .join ()
9791000 SNLogger .info ( "...FITS writer processes done." )
9801001
981- if 'make_stamps' in steps :
1002+ if 'make_stamps' in steps and not i_failed :
9821003 SNLogger .info ( "Starting to make stamps..." )
9831004 with nvtx .annotate ( "make stamps" , color = 0xff8888 ):
9841005
@@ -1026,7 +1047,7 @@ def log_stamp_err( sci_image, templ_image, x ):
10261047 SNLogger .info ( f"After make_stamps, memory usage = { tracemalloc .get_traced_memory ()[1 ]/ (1024 ** 2 ):.2f} MB" )
10271048
10281049 lightcurve_path = None
1029- if 'make_lightcurve' in steps :
1050+ if 'make_lightcurve' in steps and not i_failed :
10301051 with nvtx .annotate ( "make_lightcurve" , color = 0xff8888 ):
10311052 lightcurve_path = self .make_lightcurve ()
10321053
0 commit comments