def __init__(self, filter, mask=None): """ This class handles the optical filter functionality. It is build around speclite: http://speclite.readthedocs.io/en/latest/ It accepts speclite fitlerresponse or sequences, allowing for full customization of the fitlers. :param filter: a speclite FitlerResponse or FilterSequence :param mask: an initial mask on the filters (bool array) that remains fixed """ # we explicitly violate duck typing here in order to have one routine # to return values from the filters (speclite appends 's' to the end of sequence calls) if isinstance(filter, spec_filters.FilterResponse): # we will make a sequence self._filters = spec_filters.FilterSequence([filter]) elif isinstance(filter, spec_filters.FilterSequence): self._filters = filter # type: spec_filters.FilterSequence else: raise NotASpeclikeFilter( "filter must be a speclite FilterResponse or FilterSequence" ) if mask is not None: tmp = [] for condition, response in zip(mask, self._filters): if condition: tmp.append(response) self._filters = spec_filters.FilterSequence(tmp) self._names = np.array([name.split("-")[1] for name in self._filters.names]) self._long_name = self._filters.names # haven't set a likelihood model yet self._model_set = False self._n_filters = len(self._filters) # calculate the FWHM self._calculate_fwhm()
def __init__(self, lam, flam, family='sdss2010-*', axis=0, redshift=None): self.filters = filters.load_filters(family) if redshift is not None: self.filters = filters.FilterSequence([ f_.create_shifted(band_shift=redshift) for f_ in self.filters ]) else: pass # spectral dimension has to be the final one nl0 = flam.shape[axis] flam, self.lam = self.filters.pad_spectrum(spectrum=np.moveaxis( flam, axis, -1), wavelength=lam, method='zero') self.flam = np.moveaxis(flam, -1, axis) if self.flam.shape[axis] > nl0: warn('spectrum has been padded, bad mags possible', Spec2PhotWarning) self.ABmags = self.filters.get_ab_magnitudes(spectrum=self.flam, wavelength=self.lam, axis=axis).as_array()
def __init__(self): """ holds all the observatories/instruments/filters :param library_file: """ # get the filter file with h5py.File(get_speclite_filter_library(), "r") as f: self._instruments = [] for observatory in tqdm(f.keys(), desc="Loading photometric filters"): log.debug(f"loading {observatory}") sub_dict = {} for instrument in f[observatory].keys(): sub_dict[instrument] = instrument # create a node for the observatory this_node = ObservatoryNode(sub_dict) # attach it to the object if observatory == "2MASS": xx = "TwoMass" else: xx = observatory setattr(self, xx, this_node) # now get the instruments for instrument in f[observatory].keys(): # update the instruments self._instruments.append(instrument) # create the filter response via speclite this_grp = f[observatory][instrument] filters = [] for ff in this_grp.keys(): grp = this_grp[ff] this_filter = spec_filter.FilterResponse( wavelength=grp["wavelength"][()] * u.Angstrom, response=grp["transmission"][()], meta=dict( group_name=instrument, band_name=ff, )) filters.append(this_filter) fgroup = spec_filter.FilterSequence(filters) # attach the filters to the observatory setattr(this_node, instrument, fgroup) self._instruments.sort()