def extract_ifu_sensitivity_cube(self, ifuslot, datevshot=None, cache_sim_interp=True): """ Extract the sensitivity cube from IFU (ifuslot). If multiple shots are saved in the file specify which to use with datevshot Parameters ---------- ifuslot : string the IFU slot to extract datevshot : string (Optional) the datevshot if multiple shots are stored in the HDF5. If None then test that one shot is present and return the IFU for that cache_sim_interp : bool cache the simulation interpolator to speed up execution (default: True) Returns ------- scube : hetdex_api.flux_limits.sensitivity_cube:SensitivityCube the sensitivity cube """ # Use first shot if dateshot not specified if not datevshot: shots = self.h5file.list_nodes(self.h5file.root) nshots = len(shots) if nshots > 1: _logger.warn( """Datevshot not specified but multiple shots in file! Using first in file.""" ) shot = shots[0] else: shot = self.h5file.get_node(self.h5file.root, name=datevshot) if self.h5mask: mask = self.h5mask.get_node(self.h5mask.root.Mask, name=ifuslot).read() else: mask = None # Now get the desired IFU ifu = self.h5file.get_node(shot, name=ifuslot) # Extract the data we need for a sensitivity cube header = ifu.attrs.header wavelengths = ifu.attrs.wavelengths alphas = ifu.attrs.alphas # Remove any aperture correction sigmas = ifu.read() / ifu.attrs.aper_corr try: nsigma = ifu.attrs.nsigma except AttributeError as e: if self.flim_model == "hdr1": nsigma = 6.0 else: nsigma = 1.0 print("No nsigma found, assuming nsigma={:2.1f} ".format(nsigma)) # Force apcor to be 1.0 here, so we don't double count it return SensitivityCube(sigmas, header, wavelengths, alphas, nsigma=nsigma, flim_model=self.flim_model, aper_corr=self.aper_corr, mask=mask, cache_sim_interp=cache_sim_interp)
def create_sensitivity_cube_from_astrom(racen, deccen, pa, nx, ny, nz, ifusize, wrange=[3470.0, 5542.0], **kwargs): """ Return an (empty) sensitivity cube object to fill with data from simulations later Parameters ---------- racen, deccen : float the central coordinates of the IFU pa : float the IFU rotation nx, ny, nz : int the dimensions of the cube in ra, dec, wave ifusize : float the length of an IFU side in arcsec wrange : array (optional) the lower and upper wavelength limits in Angstrom ***kwargs : arguments to pass to SensitivityCube """ cards = {} cards["NAXIS"] = 3 cards["NAXIS1"] = nx cards["NAXIS2"] = ny cards["NAXIS3"] = nz cards["CTYPE1"] = "RA---TAN" cards["CTYPE2"] = "DEC--TAN" cards["CTYPE3"] = "Wave " cards["CUNIT1"] = "deg " cards["CUNIT2"] = "deg " cards["CRPIX1"] = nx / 2. + 0.5 cards["CRPIX2"] = ny / 2. + 0.5 cards["CRPIX3"] = 1.0 coord = SkyCoord(racen * u.deg, deccen * u.deg) cards["CRVAL1"] = racen #deg cards["CRVAL2"] = deccen #deg cards["CRVAL3"] = wrange[0] #AA deltapix = (float(ifusize) / nx / 3600.0) # this is rotation in focal plane, maybe not the IFU rot = deg2rad(pa) cards["CROTA2"] = pa cards["CD1_1"] = deltapix * cos(rot) cards["CD1_2"] = deltapix * sin(rot) cards["CD1_3"] = 0.0 cards["CD2_1"] = -1.0 * deltapix * sin(rot) cards["CD2_2"] = deltapix * cos(rot) cards["CD2_3"] = 0.0 cards["CD3_1"] = 0.0 cards["CD3_2"] = 0.0 cards["CD3_3"] = (wrange[1] - wrange[0]) / nz header = Header(cards=cards) sigmas = zeros((nz, ny, nx)) alphas = zeros((nz, ny, nx)) return SensitivityCube(sigmas, header, None, alphas, aper_corr=1.0, nsigma=1.0, **kwargs)
def itercubes(self, datevshot=None, cache_sim_interp=True): """ Iterate over the IFUs Parameters ---------- datevshot : str (Optional) specify a datevshot or just take the first shot in the HDF5 file Yields ------ ifuslot : str the IFU slot of the returned IFU scube : SensitivityCube a sensitivity cube object """ # Use first shot if dateshot not specified if not datevshot: shots = self.h5file.list_nodes(self.h5file.root) nshots = len(shots) if nshots > 1: _logger.warn( """Datevshot not specified but multiple shots in file! Using first in file.""" ) shot = shots[0] else: shot = self.h5file.get_node(self.h5file.root, name=datevshot) first = True warn = True for ifu in shot: # Extract the data we need for a sensitivity cube header = ifu.attrs.header wavelengths = ifu.attrs.wavelengths alphas = ifu.attrs.alphas sigmas = ifu.read() / ifu.attrs.aper_corr if first: verbose = self.verbose first = False else: verbose = False if self.h5mask: mask = self.h5mask.get_node(self.h5mask.root.Mask, name=ifu.name).read() else: mask = None try: nsigma = ifu.attrs.nsigma except AttributeError as e: if self.flim_model == "hdr1": nsigma = 6.0 else: nsigma = 1.0 if warn: print("No nsigma found, assuming nsigma={:2.1f} (warning will not repeat)".format(nsigma)) warn = False # XXX HACK HACK HACK to change alpha #alphas = [-1.9, -1.9] yield ifu.name, SensitivityCube(sigmas, header, wavelengths, alphas, flim_model=self.flim_model, aper_corr=self.aper_corr, nsigma=nsigma, mask=mask, verbose=verbose, cache_sim_interp=cache_sim_interp)