def calculate_values(detector, filt, mjd, aper): # parameters can be removed from obsmode as needed obsmode = 'wfc3,{},{},mjd#{},aper#{}'.format(detector, filt, mjd, aper) bp = stsyn.band(obsmode) # STMag photflam = bp.unit_response(stsyn.conf.area) # inverse sensitivity in flam stmag = -21.1 - 2.5 * log10(photflam.value) # Pivot Wavelength and bandwidth photplam = bp.pivot() # pivot wavelength in angstroms bandwidth = bp.photbw() # bandwidth in angstroms # ABMag abmag = stmag - 5 * log10(photplam.value) + 18.6921 # Vegamag #for some reason stsyn.Vega doesn't load so we redefine it stsyn.Vega = SourceSpectrum.from_vega() obs = Observation( stsyn.Vega, bp, binset=bp.binset ) # synthetic observation of vega in bandpass using vega spectrum vegamag = -obs.effstim(flux_unit='obmag', area=stsyn.conf.area) return obsmode, photplam.value, bandwidth.value, photflam.value, stmag, abmag, vegamag.value
def get_phot(mwave, mflux, band_names, band_resp_filenames): """ Compute the magnitudes in the requested bands. Parameters ---------- mwave : vector wavelengths of model flux mflux : vector model fluxes band_names: list of strings names of bands requested band_resp_filename : list of strings filenames of band response functions for the requested bands Outputs ------- bandinfo : BandData object """ # get a BandData object bdata = BandData("BAND") # path for non-HST band response curves data_path = pkg_resources.resource_filename("measure_extinction", "data/Band_RespCurves/") # compute the fluxes in each band for k, cband in enumerate(band_names): if "HST" in cband: bp_info = cband.split("_") bp = STS.band("%s,%s,%s" % (bp_info[1], bp_info[2], bp_info[3])) ncband = "%s_%s" % (bp_info[1], bp_info[3]) else: bp = SpectralElement.from_file("%s%s" % (data_path, band_resp_filenames[k])) ncband = cband # check if the wavelength units are in microns instead of Angstroms # may not work if max(bp.waveset) < 500 * u.Angstrom: print("filter wavelengths not in angstroms") exit() # a.waveset *= 1e4 iresp = bp(mwave) bflux = np.sum(iresp * mflux) / np.sum(iresp) bflux_unc = 0.0 bdata.band_fluxes[ncband] = (bflux, bflux_unc) # calculate the band magnitudes from the fluxes bdata.get_band_mags_from_fluxes() # get the band fluxes from the magnitudes # partially redundant, but populates variables useful later bdata.get_band_fluxes() return bdata
def norm_one_filter(instrument, filter_, clobber=False): try: bp = stsynphot.band('%s,im,%s' % (instrument.lower(), filter_.lower())) #normalized_throughput = bp.throughput / bp.throughput.max() # set max to 1.0 bp = bp / bp.throughput.max() # set max to 1 t = astropy.Table() t.add_column('WAVELENGTH', bp.wave, unit=bp.waveunits.name) t.add_column('THROUGHPUT', bp.throughput) t.add_keyword('TELESCOP', 'JWST') t.add_keyword('INSTRUME', instrument) t.add_keyword('FILTER', filter_) t.add_keyword('SOURCE', f'{_SYNPHOT_PKG}, normalized to peak=1') t.write("%s/%s/filters/%s_throughput.fits" % (WebbPSF_basepath, instrument, filter_)) print("Wrote throughput.fits for %s %s" % (instrument, filter_)) except: print("Error for %s %s" % (instrument, filter_))
def bandpass(self): obsmode = "wfc3,ir," + self.filter.lower() return stsyn.band(obsmode)
hst_hdul = fits.open(image_file) date = hst_hdul[0].header["DATE-OBS"] obsdate = Time(date).mjd hst_filter = hst_ut.get_image_filter(hst_hdul[0].header) instrument = hst_hdul[0].header["INSTRUME"] obs_mode = hst_hdul[1].header["PHOTMODE"] if "WFC3" in obs_mode: keywords = obs_mode.split(" ") obsmode = "%s,%s,%s,mjd#%.2f" % (keywords[0], keywords[1], keywords[2], obsdate) elif "WFC2" in obs_mode: keywords = obs_mode.split(",") #['WFPC2', '1', 'A2D7', 'F656N', '', 'CAL'] obsmode = "%s,%s,%s,%s,%s" % (keywords[0], keywords[1], keywords[2], keywords[3], keywords[5]) elif "WFC1" in obs_mode: obsmode = obs_mode.replace(" ", ",") bp = stsyn.band(obsmode) rect_width = bp.rectwidth() print(rect_width) units = hst_hdul[1].header["BUNIT"] exp_time = float(hst_hdul[0].header["EXPTIME"]) detector = hst_hdul[0].header["DETECTOR"] if "DETECTOR" in hst_hdul[0].header else "" pivot_wavelength = float(hst_hdul[1].header["PHOTPLAM"]) filter_bandwidth = float(hst_hdul[1].header["PHOTBW"]) #rect_width = filter_bandwidth * u.AA # if UV filter then https://www.stsci.edu/files/live/sites/www/files/home/hst/instrumentation/wfc3/documentation/instrument-science-reports-isrs/_documents/2017/WFC3-2017-14.pdf # use phftlam1 keyword for UV filters uv_filters = ["F200LP", "F300X", "F218W", "F225W", "F275W", "FQ232N", "FQ243N", "F280N"] if detector == "UVIS" and filter in uv_filters: photflam = float(hst_hdul[0].header["PHTFLAM1"]) elif "PHOTFLAM" in hst_hdul[0].header: photflam = float(hst_hdul[0].header["PHOTFLAM"])
def make_libfile(): """ Extract filters from STSYNPHOT and save to main library file. """ # wfc3_obsmodes_uvis wfc3_uvis = [ "f218w", "f225w", "f275w", "f336w", "f390m", "f390w", "f410m", "f438w", "f467m", "f475w", "f547m", "f555w", "f606w", "f621m", "f625w", "f689m", "f763m", "f775w", "f814w", "f845m", ] wfc3_ir = [ "f098m", "f105w", "f110w", "f125w", "f127m", "f139m", "f140w", "f153m", "f160w", ] wfpc2 = [ "f122m", "f157w", "f336w", "f410m", "f467m", "f547m", "f439w", "f569w", "f675w", "f791w", "f170w", "f185w", "f218w", "f255w", "f300w", "f380w", "f555w", "f622w", "f450w", "f606w", "f702w", "f814w", ] acs_wfc = [ "f435w", "f475w", "f550m", "f555w", "f606w", "f625w", "f775w", "f814w", ] # galex galex = ["fuv", "nuv"] # Open hd5 file for writing hf = h5py.File(__ROOT__ + "filters.hd5", "w") # Create group for nice hierarchical structure f = hf.create_group("filters") # Define arrays for "contents" / descriptive information tablenames = [] observatories = [] instruments = [] names = [] norms = [] cwaves = [] pwaves = [] comments = [] # Loop through WFC3_UVIS filters for filt in wfc3_uvis: # define uvis 1 and uvis2 modes mode_1 = "wfc3, uvis1, " + filt mode_2 = "wfc3, uvis2, " + filt # pull bandpasses from stsynphot for the two uvis modes bp_1 = stsyn.band(mode_1) bp_2 = stsyn.band(mode_2) # extract the wavelength array wave = bp_1.waveset # compute the average bandpass between uvis1 and uvis2 bp_avg = np.average([bp_1(wave), bp_2(wave)], axis=0) # define the filter name filter_name = "HST_WFC3_" + filt.upper() # build array of wavelength and throughput arr = np.array( list(zip(wave.value.astype(np.float64), bp_avg.astype(np.float64))), dtype=[("WAVELENGTH", "float64"), ("THROUGHPUT", "float64")], ) # append dataset to the hdf5 filters group f.create_dataset(filter_name, data=arr) # generate filter instance to compute relevant info newfilt = phot.Filter(wave, bp_avg, name=filt.upper()) # populate contents lists with relevant information tablenames.append(filter_name) observatories.append("HST") instruments.append("WFC3") names.append(newfilt.name) norms.append(newfilt.norm.value) cwaves.append(newfilt.cl.value) pwaves.append(newfilt.lpivot.value) comments.append("avg of uvis1 and uvis2") # Loop through WFC3_IR filters for filt in wfc3_ir: # define ir mode mode = "wfc3, ir, " + filt # pull bandpasses from stsynphot for the two uvis modes bp = stsyn.band(mode) # extract the wavelength array wave = bp.waveset # define the filter name filter_name = "HST_WFC3_" + filt.upper() # build array of wavelength and throughput arr = np.array( list( zip(wave.value.astype(np.float64), bp(wave).astype(np.float64))), dtype=[("WAVELENGTH", "float64"), ("THROUGHPUT", "float64")], ) # append dataset to the hdf5 filters group f.create_dataset(filter_name, data=arr) # generate filter instance to compute relevant info newfilt = phot.Filter(wave, bp(wave), name=filt.upper()) # populate contents lists with relevant information tablenames.append(filter_name) observatories.append("HST") instruments.append("WFC3") names.append(newfilt.name) norms.append(newfilt.norm.value) cwaves.append(newfilt.cl.value) pwaves.append(newfilt.lpivot.value) comments.append("") # Loop through WFPC2 filters for filt in wfpc2: # define chips 1, 2, 3, 4 modes mode_1 = "wfpc2, 1, " + filt mode_2 = "wfpc2, 2, " + filt mode_3 = "wfpc2, 3, " + filt mode_4 = "wfpc2, 4, " + filt # pull bandpasses from stsynphot for the two uvis modes bp_1 = stsyn.band(mode_1) bp_2 = stsyn.band(mode_2) bp_3 = stsyn.band(mode_3) bp_4 = stsyn.band(mode_4) # extract the wavelength array wave = bp_1.waveset # compute the average bandpass between uvis1 and uvis2 bp_avg = np.average( [bp_1(wave), bp_2(wave), bp_3(wave), bp_4(wave)], axis=0) # define the filter name filter_name = "HST_WFPC2_" + filt.upper() # build array of wavelength and throughput arr = np.array( list(zip(wave.value.astype(np.float64), bp_avg.astype(np.float64))), dtype=[("WAVELENGTH", "float64"), ("THROUGHPUT", "float64")], ) # append dataset to the hdf5 filters group f.create_dataset(filter_name, data=arr) # generate filter instance to compute relevant info newfilt = phot.Filter(wave, bp_avg, name=filt.upper()) # populate contents lists with relevant information tablenames.append(filter_name) observatories.append("HST") instruments.append("WFPC2") names.append(newfilt.name) norms.append(newfilt.norm.value) cwaves.append(newfilt.cl.value) pwaves.append(newfilt.lpivot.value) comments.append("avg of 1, 2, 3, 4") # Loop through ACS filters for filt in acs_wfc: # define wfc1, wfc2 modes mode_1 = "acs, wfc1, " + filt mode_2 = "acs, wfc2, " + filt # pull bandpasses from stsynphot for the two uvis modes bp_1 = stsyn.band(mode_1) bp_2 = stsyn.band(mode_2) # extract the wavelength array wave = bp_1.waveset # compute the average bandpass between uvis1 and uvis2 bp_avg = np.average([bp_1(wave), bp_2(wave)], axis=0) # define the filter name filter_name = "HST_ACS_WFC_" + filt.upper() # build array of wavelength and throughput arr = np.array( list(zip(wave.value.astype(np.float64), bp_avg.astype(np.float64))), dtype=[("WAVELENGTH", "float64"), ("THROUGHPUT", "float64")], ) # append dataset to the hdf5 filters group f.create_dataset(filter_name, data=arr) # generate filter instance to compute relevant info newfilt = phot.Filter(wave, bp_avg, name=filt.upper()) # populate contents lists with relevant information tablenames.append(filter_name) observatories.append("HST") instruments.append("ACS_WFC") names.append(newfilt.name) norms.append(newfilt.norm.value) cwaves.append(newfilt.cl.value) pwaves.append(newfilt.lpivot.value) comments.append("avg of wfc1 and wfc2") # Loop through GALEX filters: for filt in galex: # define ir mode mode = "galex," + filt # pull bandpasses from stsynphot for the two uvis modes bp = stsyn.band(mode) # extract the wavelength array wave = bp.waveset # define the filter name filter_name = "GALEX_" + filt.upper() # build array of wavelength and throughput arr = np.array( list( zip(wave.value.astype(np.float64), bp(wave).astype(np.float64))), dtype=[("WAVELENGTH", "float64"), ("THROUGHPUT", "float64")], ) # append dataset to the hdf5 filters group f.create_dataset(filter_name, data=arr) # generate filter instance to compute relevant info newfilt = phot.Filter(wave, bp(wave), name=filt.upper()) # populate contents lists with relevant information tablenames.append(filter_name) observatories.append("GALEX") instruments.append("GALEX") names.append(newfilt.name) norms.append(newfilt.norm.value) cwaves.append(newfilt.cl.value) pwaves.append(newfilt.lpivot.value) comments.append("") # smash the contents arrays together contents = np.array( list( zip( tablenames, observatories, instruments, names, norms, cwaves, pwaves, comments, )), dtype=[ ("TABLENAME", "S40"), ("OBSERVATORY", "S30"), ("INSTRUMENT", "S30"), ("NAME", "S10"), ("NORM", "<f8"), ("CWAVE", "<f8"), ("PWAVE", "<f8"), ("COMMENT", "S100"), ], ) # add the contents array as an hd5 dataset hf.create_dataset("content", data=contents) # close the file hf.close()