def test_make_mag_column_names(): instrument = 'nircam' filters = ['F090W/CLEAR', 'F090W/WLP8', 'WLM8/F115W', 'F322W2/F323N', 'F444W/F405N', 'F470N/F444W', 'F444W/CLEAR', 'CLEAR/F150W'] std_filters = utils.standardize_filters(instrument, filters) cols = utils.make_mag_column_names(instrument, std_filters) truth = ['nircam_f090w_clear_magnitude', 'nircam_f090w_wlp8_magnitude', 'nircam_f115w_wlm8_magnitude', 'nircam_f322w2_f323n_magnitude', 'nircam_f444w_f405n_magnitude', 'nircam_f444w_f470n_magnitude', 'nircam_f444w_clear_magnitude', 'nircam_f150w_clear_magnitude'] for val, check_val in zip(cols, truth): assert val == check_val instrument = 'niriss' filters = ['F090W', 'F150W/CLEAR', 'F277W/CLEAR', 'CLEAR/F430M'] std_filters = utils.standardize_filters(instrument, filters) cols = utils.make_mag_column_names(instrument, std_filters) truth = ['niriss_f090w_magnitude', 'niriss_f150w_magnitude', 'niriss_f277w_magnitude', 'niriss_f430m_magnitude'] for val, check_val in zip(cols, truth): assert val == check_val instrument = 'fgs' filters = ['guider1', 'guider2'] std_filters = utils.standardize_filters(instrument, filters) cols = utils.make_mag_column_names(instrument, std_filters) truth = ['fgs_guider1_magnitude', 'fgs_guider2_magnitude'] for val, check_val in zip(cols, truth): assert val == check_val
def mag_col_name_to_filter_pupil(colname): """Given a magnitude column name from a source catalog find the filter and pupil name Parameters ---------- colname : str Column name (e.g 'nircam_f090w_magnitude', 'nircam_f090w_clear_magnitude') Returns ------- filter_name : str Name of filter (e.g. 'f090w') pupil_name : str Name of pupil (e.g. 'clear') """ mag_parts = colname.split('_') instrument = mag_parts[0].lower() if len(mag_parts) == 4: filt_pup_str = '{}/{}'.format(mag_parts[1], mag_parts[2]) elif len(mag_parts) == 3: filt_pup_str = mag_parts[1] std_filt_pup_str = standardize_filters(instrument, [filt_pup_str]) std_parts = std_filt_pup_str[0].split('/') if len(std_parts) == 2: filter_name = std_parts[0].lower() pupil_name = std_parts[1].lower() elif len(std_parts) == 1: filter_name = std_parts[0] pupil_name = 'NONE' return filter_name, pupil_name
def add_magnitude_column(self, magnitude_list, magnitude_system='abmag', instrument='', filter_name='', column_name=''): """Add a list of magnitudes to the catalog Parameters ---------- magnitude_list : list Magnitude values corresponding to the input sources magnitude_system : str 'abmag', 'vegamag', or 'stmag' instrument : str Instrument name filter_name : str Filter name (e.g. 'F090W') column_name : str Name to use for the column name. If this is provided, it will override the instrument and filter_name inputs. (e.g. 'nircam_f090w_wlp8_magnitude') """ # Force magnitude list to be a numpy array magnitude_list = np.array(magnitude_list) # Make sure instrument and filter are allowed values if column_name == '': instrument = instrument.lower() filter_name = standardize_filters(instrument, [filter_name.upper()])[0] self.filter_check(instrument, filter_name) # Create the string for the column header if instrument == '' or filter_name == '': header = 'magnitude' else: header = make_mag_column_names(instrument, [filter_name])[0] else: header = column_name # Get a list of magnitude_system for the existing catalog. No mixing of # magnitude systems is currently allowed. keys = self.magnitudes.keys() if len(keys) > 0: current_mag_sys = self.magnitudes[list(keys)[0]][0] else: current_mag_sys = magnitude_system # Make sure this is not a duplicate column if header in self.magnitudes.keys(): raise ValueError(("WARNING: {} entry already exists in catalog. No duplicate entries allowed." .format(header))) # Make sure the magnitude system is consistent elif magnitude_system != current_mag_sys: raise ValueError(("WARNING: only a single magnitude system is allowed per catalog. " "Current catalog is using {}, while the new entry is {}." .format(current_mag_sys, magnitude_system))) else: self.magnitudes[header] = [magnitude_system, magnitude_list] # Update the catalog table self.create_table()
def test_standardize_filters(): instrument = 'nircam' filters = ['F090W', 'F070W/CLEAR', 'CLEAR/F444W', 'F090W/WLP8', 'WLM8/F115W', 'F322W2/F323N', 'F470N/F444W', 'F405N'] std_nircam = utils.standardize_filters(instrument, filters) truth = ['F090W/CLEAR', 'F070W/CLEAR', 'F444W/CLEAR', 'F090W/WLP8', 'F115W/WLM8', 'F322W2/F323N', 'F444W/F470N', 'F444W/F405N'] for std, expected in zip(std_nircam, truth): assert std == expected instrument = 'niriss' filters = ['F090W', 'F115W/CLEAR', 'CLEAR/']