Skip to content

Commit

Permalink
Merge pull request #91 from winter-telescope/diffmaglim
Browse files Browse the repository at this point in the history
add diffmaglim to dataframe
  • Loading branch information
virajkaram authored Aug 18, 2022
2 parents bfbc657 + 640ff76 commit 32b7dd8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
4 changes: 3 additions & 1 deletion winterdrp/processors/candidates/candidate_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,10 @@ def generate_candidates_table(self, scorr_catalog_name, sci_resamp_imagename, re
det_srcs['programid'] = fits.getval(sci_resamp_imagename, 'PROGID')
det_srcs['fid'] = fits.getval(sci_resamp_imagename, 'FILTERID')
det_srcs['candid'] = np.array(det_srcs['jd']*100, dtype=int)*10000 + np.arange(len(det_srcs))
det_srcs['diffmaglim'] = fits.getval(diff_filename,'DIFFMLIM' )
det_srcs = det_srcs.to_pandas()

logger.info(det_srcs['diffmaglim'])

return det_srcs

def _apply_to_images(
Expand Down
35 changes: 20 additions & 15 deletions winterdrp/processors/zogy/zogy.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,38 +53,43 @@ def _apply_to_images(
ref_rms_image, sci_rms, ref_rms, dx=ast_unc_x, dy=ast_unc_y)

diff_image_path = sci_image_path.replace('.fits', '') + '.diff.fits'
diff_psf_path = diff_image_path + '.psf'
scorr_image_path = sci_image_path.replace('.fits', '') + '.scorr.fits'

scorr_mean, scorr_median, scorr_std = sigma_clipped_stats(S_corr)
logger.info(f"Scorr mean, median, STD is {scorr_mean}, {scorr_median}, {scorr_std}")
sci_rms_data, _ = self.open_fits(os.path.join(self.get_sub_output_dir(), sci_rms_image))
ref_rms_data, _ = self.open_fits(os.path.join(self.get_sub_output_dir(), ref_rms_image))
diff_rms_image = np.sqrt(sci_rms_data ** 2 + ref_rms_data ** 2)
diff_rms_mean, diff_rms_median, diff_rms_std = sigma_clipped_stats(diff_rms_image)
diff_rms_path = diff_image_path + '.unc'

header["DIFFIMG"] = diff_image_path
header["DIFFPSF"] = diff_psf_path
header["DIFFSCR"] = scorr_image_path
header["DIFFUNC"] = diff_rms_path
noise = np.sqrt(np.nansum(np.square(P_D)*np.square(diff_rms_median)))/np.nansum(np.square(P_D))
header["DIFFMLIM"] = -2.5*np.log10(noise*5) + float(header["TMC_ZP"])

self.save_fits(data=D,
header=header,
path=os.path.join(self.get_sub_output_dir(), diff_image_path))

diff_psf_path = diff_image_path + '.psf'
self.save_fits(data=P_D,
header=None,
path=os.path.join(self.get_sub_output_dir(), diff_psf_path))

scorr_image_path = sci_image_path.replace('.fits', '') + '.scorr.fits'
scorr_header = header.copy()
scorr_header[latest_mask_save_key] = header['SCORMASK']
self.save_fits(data=S_corr,
header=scorr_header,
path=os.path.join(self.get_sub_output_dir(), scorr_image_path))
scorr_mean, scorr_median, scorr_std = sigma_clipped_stats(S_corr)
logger.info(f"Scorr mean, median, STD is {scorr_mean}, {scorr_median}, {scorr_std}")
sci_rms_data, _ = self.open_fits(os.path.join(self.get_sub_output_dir(), sci_rms_image))
ref_rms_data, _ = self.open_fits(os.path.join(self.get_sub_output_dir(), ref_rms_image))
diff_rms_image = np.sqrt(sci_rms_data ** 2 + ref_rms_data ** 2)

diff_rms_path = diff_image_path + '.unc'
self.save_fits(data=diff_rms_image,
header=header,
path=os.path.join(self.get_sub_output_dir(), diff_rms_path))

header["DIFFIMG"] = diff_image_path
header["DIFFPSF"] = diff_psf_path
header["DIFFSCR"] = scorr_image_path
header["DIFFUNC"] = diff_rms_path

# for temp_file in temp_files:
# logger.info(f"{diff_rms_std}, {diff_rms_median}, {diff_std} DIFFMAGLIM {header['DIFFMLIM']}")
# # for temp_file in temp_files:
# os.remove(temp_file)
# logger.info(f"Deleted temporary file {temp_file}")
diff_images.append(D)
Expand Down

0 comments on commit 32b7dd8

Please sign in to comment.