def get_variance_map2(a_plus_b, a_minus_b, bias_mask2, pix_mask, gain): #variance0 = a_minus_b #a_minus_b = a-b msk = bias_mask2 | pix_mask | ~np.isfinite(a_minus_b) from destriper import destriper variance0 = destriper.get_destriped(a_minus_b, msk, pattern=64, remove_vertical=False, hori=False) #variance0 = a_minus_b # stsci_median cannot be used due to too many array error. #ss = stsci_median([m1 for m1 in variance0],) dd1 = np.ma.array(variance0, mask=msk) ss = np.ma.median(dd1, axis=0) variance_ = variance0.copy() variance_[msk] = np.nan st = np.nanstd(variance_) st = np.nanstd(variance_[np.abs(variance_) < 3 * st]) variance_[np.abs(variance_ - ss) > 3 * st] = np.nan import scipy.ndimage as ni x_std = ni.median_filter(np.nanstd(variance_, axis=0), 11) variance_map0 = np.zeros_like(variance_) + x_std**2 variance_map = variance_map0 + np.abs( a_plus_b) / gain # add poison noise in ADU return variance_map
def get_variance_map2(a_plus_b, a_minus_b, bias_mask2, pix_mask, gain): #variance0 = a_minus_b #a_minus_b = a-b msk = bias_mask2 | pix_mask | ~np.isfinite(a_minus_b) from destriper import destriper variance0 = destriper.get_destriped(a_minus_b, msk, pattern=64, remove_vertical=False, hori=False) #variance0 = a_minus_b # stsci_median cannot be used due to too many array error. #ss = stsci_median([m1 for m1 in variance0],) dd1 = np.ma.array(variance0, mask=msk) ss = np.ma.median(dd1, axis=0) variance_ = variance0.copy() variance_[msk] = np.nan st = np.nanstd(variance_) st = np.nanstd(variance_[np.abs(variance_) < 3*st]) variance_[np.abs(variance_-ss) > 3*st] = np.nan import scipy.ndimage as ni x_std = ni.median_filter(np.nanstd(variance_, axis=0), 11) variance_map0 = np.zeros_like(variance_) + x_std**2 variance_map = variance_map0 + np.abs(a_plus_b)/gain # add poison noise in ADU return variance_map
def make_combined_image_thar(helper, band, obsids): """ simple median combine with destripping. Suitable for sky. """ filenames, basename, master_obsid = helper.get_base_info(band, obsids) hdu_list = [pyfits.open(fn)[0] for fn in filenames] _data = stsci_median([hdu.data for hdu in hdu_list]) from destriper import destriper data = destriper.get_destriped(_data) return data
def get_1d_median_specs(fits_names, ap): #hdu_list = [pyfits.open(fn)[0] for fn in fits_names] from load_fits import load_fits_data hdu_list = [load_fits_data(fn) for fn in fits_names] _data = stsci_median([hdu.data for hdu in hdu_list]) from destriper import destriper data = destriper.get_destriped(_data) s = ap.extract_spectra_v2(data) from storage_descriptions import (COMBINED_IMAGE_DESC, ONED_SPEC_JSON_DESC) r = PipelineProducts("1d median specs") r.add(COMBINED_IMAGE_DESC, PipelineImageBase([], data)) r.add(ONED_SPEC_JSON_DESC, PipelineDict(orders=ap.orders, specs=s)) return r
def make_flatoff_hotpixmap(self, sigma_clip1=100, sigma_clip2=10, medfilter_size=None, destripe=True): flat_off_cards = [] flat_off = stsci_median(self.data_list) if destripe: flat_offs = destriper.get_destriped(flat_off) flat_off_cards.append(Card(("HISTORY", "IGR: image destriped."))) hotpix_mask = bp.badpixel_mask(flat_offs, sigma_clip1=sigma_clip1, sigma_clip2=sigma_clip2, medfilter_size=medfilter_size) bg_std = flat_offs[~hotpix_mask].std() flat_off_cards.append(Card(("BG_STD", bg_std, "IGR: stddev of combined flat"))) flat_off_image = PipelineImageBase(flat_off_cards, flat_offs) hotpix_mask_image = PipelineImageBase([], hotpix_mask) from storage_descriptions import (FLAT_OFF_DESC, FLATOFF_JSON_DESC, HOTPIX_MASK_DESC) r = PipelineProducts("flat off products") r.add(FLAT_OFF_DESC, flat_off_image) r.add(HOTPIX_MASK_DESC, hotpix_mask_image) r.add(FLATOFF_JSON_DESC, PipelineDict(bg_std=bg_std)) return r
def get_1d_median_specs(fits_names, ap): hdu_list = [pyfits.open(fn)[0] for fn in fits_names] _data = stsci_median([hdu.data for hdu in hdu_list]) from destriper import destriper data = destriper.get_destriped(_data) s = ap.extract_spectra_v2(data) from storage_descriptions import (COMBINED_IMAGE_DESC, ONED_SPEC_JSON_DESC) r = PipelineProducts("1d median specs") r.add(COMBINED_IMAGE_DESC, PipelineImage([], data)) r.add(ONED_SPEC_JSON_DESC, PipelineDict(orders=ap.orders, specs=s)) return r
def make_flatoff_hotpixmap(self, sigma_clip1=100, sigma_clip2=10, medfilter_size=None, destripe=True): flat_off_cards = [] flat_off = stsci_median(self.data_list) if destripe: flat_offs = destriper.get_destriped(flat_off) flat_off_cards.append(Card(("HISTORY", "IGR: image destriped."))) hotpix_mask = bp.badpixel_mask(flat_offs, sigma_clip1=sigma_clip1, sigma_clip2=sigma_clip2, medfilter_size=medfilter_size) bg_std = flat_offs[~hotpix_mask].std() flat_off_cards.append( Card(("BG_STD", bg_std, "IGR: stddev of combined flat"))) flat_off_image = PipelineImageBase(flat_off_cards, flat_offs) hotpix_mask_image = PipelineImageBase([], hotpix_mask) from storage_descriptions import (FLAT_OFF_DESC, FLATOFF_JSON_DESC, HOTPIX_MASK_DESC) r = PipelineProducts("flat off products") r.add(FLAT_OFF_DESC, flat_off_image) r.add(HOTPIX_MASK_DESC, hotpix_mask_image) r.add(FLATOFF_JSON_DESC, PipelineDict(bg_std=bg_std)) return r
return hdus # data_list = [hdu.data for hdu in hdu_list] # return data_list def get_combined_image(hdus): #, destripe=True): # destripe=True): data_list = [hdu.data for hdu in hdus] from stsci_helper import stsci_median im = stsci_median(data_list) return im if 0: cards = [] if destripe: from destriper import destriper im = destriper.get_destriped(im) cards.append(Card("HISTORY", "IGR: image destriped.")) return im, cards
hdus = [load_fits_data(fn_) for fn_ in filenames] return hdus # data_list = [hdu.data for hdu in hdu_list] # return data_list def get_combined_image(hdus): #, destripe=True): # destripe=True): data_list = [hdu.data for hdu in hdus] from stsci_helper import stsci_median im = stsci_median(data_list) return im if 0: cards = [] if destripe: from destriper import destriper im = destriper.get_destriped(im) cards.append(Card("HISTORY", "IGR: image destriped.")) return im, cards