@@ -45,7 +45,8 @@ def setup(self, config, base, image_num, obj_num, ignore, logger):
4545 req = { 'det_name' : str }
4646 opt = { 'size' : int , 'xsize' : int , 'ysize' : int , 'dtype' : None ,
4747 'apply_sky_gradient' : bool , 'apply_fringing' : bool ,
48- 'boresight' : galsim .CelestialCoord , 'camera' : str , 'nbatch' : int }
48+ 'boresight' : galsim .CelestialCoord , 'camera' : str , 'nbatch' : int ,
49+ 'nbatch_per_checkpoint' : int }
4950 params = GetAllParams (config , base , req = req , opt = opt , ignore = ignore + extra_ignore )[0 ]
5051
5152 # Let the user override the image size
@@ -86,6 +87,7 @@ def setup(self, config, base, image_num, obj_num, ignore, logger):
8687 try :
8788 self .checkpoint = galsim .config .GetInputObj ('checkpoint' , config , base , 'LSST_Image' )
8889 self .nbatch = params .get ('nbatch' , 100 )
90+ self .nbatch_per_checkpoint = params .get ('nbatch_per_checkpoint' , 1 )
8991 except galsim .config .GalSimConfigError :
9092 self .checkpoint = None
9193 # Batching is also useful for memory reasons, to limit the number of stamps held
@@ -149,7 +151,8 @@ def buildImage(self, config, base, image_num, obj_num, logger):
149151 chk_name = 'buildImage_%s' % (self .det_name )
150152 saved = self .checkpoint .load (chk_name )
151153 if saved is not None :
152- full_image , all_bounds , all_vars , start_num , extra_builder = saved
154+ full_image , all_bounds , all_vars , delta_start_num , extra_builder = saved
155+ start_num = delta_start_num + base .get ('start_obj_num' , 0 )
153156 if extra_builder is not None :
154157 base ['extra_builder' ] = extra_builder
155158 all_stamps = [galsim ._Image (np .array ([]), b , full_image .wcs ) for b in all_bounds ]
@@ -223,13 +226,15 @@ def buildImage(self, config, base, image_num, obj_num, logger):
223226 # Don't save the full stamps. All we need for FlattenNoiseVariance is the bounds.
224227 # Everything else about the stamps has already been handled above.
225228 all_bounds = [stamp .bounds for stamp in all_stamps ]
226- data = (full_image , all_bounds , all_vars , end_obj_num ,
229+ delta_end_obj_num = end_obj_num - base .get ('start_obj_num' , 0 )
230+ data = (full_image , all_bounds , all_vars , delta_end_obj_num ,
227231 base .get ('extra_builder' ,None ))
228- self .checkpoint .save (chk_name , data )
229- logger .warning ('File %d: Completed batch %d with objects [%d, %d), and wrote '
230- 'checkpoint data to %s' ,
231- base .get ('file_num' , 0 ), batch + 1 , start_obj_num , end_obj_num ,
232- self .checkpoint .file_name )
232+ logger .warning ('File %d: Completed batch %d with objects [%d, %d)' ,
233+ base .get ('file_num' , 0 ), batch + 1 , start_obj_num , end_obj_num )
234+ if (batch % self .nbatch_per_checkpoint == 0
235+ or batch + 1 == nbatch ):
236+ self .checkpoint .save (chk_name , data )
237+ logger .warning ('Wrote checkpoint data to %s' , self .checkpoint .file_name )
233238
234239 # Bring the image so far up to a flat noise variance
235240 current_var = galsim .config .FlattenNoiseVariance (
0 commit comments