@@ -77,29 +77,47 @@ def process_new_frame(fits_file, user_config):
7777 cutout_data *= mjd_gain_exptime_dict ['gain' ] / mjd_gain_exptime_dict ['exptime' ]
7878 # unit: electron per second
7979
80- # ok, now subtract sky!
80+ # ok, now estimate and subtract sky!
8181 cutout_data_sub , bkg = subtract_background (cutout_data ,
8282 mask_sources_first = user_config ['mask_sources_before_background' ],
8383 n_boxes = user_config ['background_estimation_n_boxes' ])
84+ # we keep doing this because it is a nice way of getting the background RMS.
85+ # however, if the user specifies that the background is already subtracted, just use the
86+ # original data.
87+ if not user_config ['do_background_subtraction' ]:
88+ cutout_data_sub = cutout_data
89+ # read the background stats:
8490 sky_level_electron_per_second = float (bkg .globalback )
8591 background_rms_electron_per_second = float (bkg .globalrms )
8692 logger .info (f' file { fits_file } : background estimated.' )
8793
88- # before we write, let's keep as much as we can from our previous header
89- new_header = wcs .to_header ()
90- # then copy non-WCS entries from the original header
91- for key in header :
92- if key not in new_header and not key .startswith ('WCSAXES' ) and not key .startswith (
93- 'CRPIX' ) and not key .startswith ('CRVAL' ) and not key .startswith ('CDELT' ) and not key .startswith (
94- 'CTYPE' ) and not key .startswith ('CUNIT' ) and not key .startswith ('CD' ) and key not in ['COMMENT' ,
95- 'HISTORY' ]:
96- if key .strip (): # some headers are weird
97- new_header [key ] = header [key ]
94+ new_header = header .copy ()
95+ # here we branch: if already plate solved, we keep the header intact.
96+ # if not, we delete wcs keywords and populate an initial one from astropy
97+ if not user_config ['already_plate_solved' ]:
98+ wcs_header = wcs .to_header ()
99+ # then copy non-WCS entries from the original header
100+ for key in header :
101+ if (
102+ key in wcs_header
103+ or key .startswith ('WCSAXES' )
104+ or key .startswith ('CRPIX' )
105+ or key .startswith ('CRVAL' )
106+ or key .startswith ('CDELT' )
107+ or key .startswith ('CTYPE' )
108+ or key .startswith ('CUNIT' )
109+ or key .startswith ('CD' )
110+ or key .startswith ('A_' )
111+ or key .startswith ('B_' )
112+ ):
113+ del new_header [key ]
114+ #
115+ new_header .update (wcs_header )
98116 # now we can write the file
99117 write_file = user_config ['workdir' ] / copied_image_relpath
100118 logger .info (f' Writing file: { write_file } ' )
101119 fits .writeto (write_file , cutout_data_sub .astype (np .float32 ),
102- header = new_header , overwrite = True )
120+ header = new_header , overwrite = True , output_verify = "silentfix" )
103121 # and find sources
104122 # (do plots if toggle set)
105123 do_plot = user_config .get ('source_extraction_do_plots' , False )
0 commit comments