def mast2phot(source, results, units, master=None, extra_fields=None): """ Convert/combine MAST record arrays to measurement record arrays. Every line in the combined array represents a measurement in a certain band. This is probably only useful if C{results} contains only information on one target (or you have to give 'ID' as an extra field, maybe). The standard columns are: 1. C{meas}: containing the photometric measurement 2. C{e_meas}: the error on the photometric measurement 3. C{flag}: an optional quality flag 4. C{unit}: the unit of the measurement 5. C{photband}: the photometric passband (FILTER.BAND) 6. C{source}: name of the source catalog You can add extra information from the Mast catalog via the list of keys C{extra_fields}. If you give a C{master}, the information will be added to a previous record array. If not, a new master will be created. The result is a record array with each row a measurement. @param source: name of the Mast source @type source: str @param results: results from Mast C{search} @type results: record array @param units: header of Mast catalog with key name the column name and key value the units of that column @type units: dict @param master: master record array to add information to @type master: record array @param extra_fields: any extra columns you want to add information from @type extra_fields: list of str @return: array with each row a measurement @rtype: record array """ e_flag = 'e_' q_flag = 'q_' #-- basic dtypes dtypes = [('meas', 'f8'), ('e_meas', 'f8'), ('flag', 'a20'), ('unit', 'a30'), ('photband', 'a30'), ('source', 'a50')] #-- MAST has no unified terminology: translations = { 'kepler/kgmatch': { '_r': "Ang Sep (')", '_RAJ2000': 'KIC RA (J2000)', '_DEJ2000': 'KIC Dec (J2000)' } } #-- extra can be added: names = list(results.dtype.names) if extra_fields is not None: if source in translations: translation = translations[source] else: translation = { '_r': '_r', '_RAJ2000': '_RAJ2000', '_DEJ2000': '_DEJ2000' } for e_dtype in extra_fields: try: dtypes.append( (e_dtype, results.dtype[names.index(translation[e_dtype])].str)) except ValueError: if e_dtype != '_r': raise dtypes.append( (e_dtype, results.dtype[names.index('AngSep')].str)) #-- create empty master if not given newmaster = False if master is None or len(master) == 0: master = np.rec.array( [tuple([('f' in dt[1]) and np.nan or 'none' for dt in dtypes])], dtype=dtypes) newmaster = True #-- add fluxes and magnitudes to the record array cols_added = 0 for key in cat_info.options(source): if key[:2] in [e_flag, q_flag] or '_unit' in key or key == 'bibcode': continue photband = cat_info.get(source, key) #-- contains measurement, error, quality, units, photometric band and # source cols = [ results[key][:1], (e_flag + key in cat_info.options(source) and results[cat_info.get(source, e_flag + key)][:1] or np.ones(len(results[:1])) * np.nan), (q_flag + key in cat_info.options(source) and results[cat_info.get(source, q_flag + key)][:1] or np.ones(len(results[:1])) * np.nan), np.array(len(results[:1]) * [units[key]], str), np.array(len(results[:1]) * [photband], str), np.array(len(results[:1]) * [source], str) ] #-- add any extra fields if desired. if extra_fields is not None: for e_dtype in extra_fields: cols += [ e_dtype in results.dtype.names and results[e_dtype][:1] or np.ones(len(results[:1])) * np.nan ] #-- add to the master rows = [] for i in range(len(cols[0])): rows.append(tuple([col[i] for col in cols])) master = np.core.records.fromrecords(master.tolist() + rows, dtype=dtypes) cols_added += 1 #-- fix colours: we have to run through it two times to be sure to have # all the colours N = len(master) - cols_added master_ = vizier._breakup_colours(master[N:]) master_ = vizier._breakup_colours(master_) #-- combine and return master = np.core.records.fromrecords(master.tolist()[:N] + master_.tolist(), dtype=dtypes) #-- skip first line from building if newmaster: master = master[1:] return master
def mast2phot(source,results,units,master=None,extra_fields=None): """ Convert/combine MAST record arrays to measurement record arrays. Every line in the combined array represents a measurement in a certain band. This is probably only useful if C{results} contains only information on one target (or you have to give 'ID' as an extra field, maybe). The standard columns are: 1. C{meas}: containing the photometric measurement 2. C{e_meas}: the error on the photometric measurement 3. C{flag}: an optional quality flag 4. C{unit}: the unit of the measurement 5. C{photband}: the photometric passband (FILTER.BAND) 6. C{source}: name of the source catalog You can add extra information from the Mast catalog via the list of keys C{extra_fields}. If you give a C{master}, the information will be added to a previous record array. If not, a new master will be created. The result is a record array with each row a measurement. @param source: name of the Mast source @type source: str @param results: results from Mast C{search} @type results: record array @param units: header of Mast catalog with key name the column name and key value the units of that column @type units: dict @param master: master record array to add information to @type master: record array @param extra_fields: any extra columns you want to add information from @type extra_fields: list of str @return: array with each row a measurement @rtype: record array """ e_flag = 'e_' q_flag = 'q_' #-- basic dtypes dtypes = [('meas','f8'),('e_meas','f8'),('flag','a20'), ('unit','a30'),('photband','a30'),('source','a50')] #-- MAST has no unified terminology: translations = {'kepler/kgmatch':{'_r':"Ang Sep (')", '_RAJ2000':'KIC RA (J2000)', '_DEJ2000':'KIC Dec (J2000)'}} #-- extra can be added: names = list(results.dtype.names) if extra_fields is not None: if source in translations: translation = translations[source] else: translation = {'_r':'_r','_RAJ2000':'_RAJ2000','_DEJ2000':'_DEJ2000'} for e_dtype in extra_fields: try: dtypes.append((e_dtype,results.dtype[names.index(translation[e_dtype])].str)) except ValueError: if e_dtype != '_r': raise dtypes.append((e_dtype,results.dtype[names.index('AngSep')].str)) #-- create empty master if not given newmaster = False if master is None or len(master)==0: master = np.rec.array([tuple([('f' in dt[1]) and np.nan or 'none' for dt in dtypes])],dtype=dtypes) newmaster = True #-- add fluxes and magnitudes to the record array cols_added = 0 for key in cat_info.options(source): if key[:2] in [e_flag,q_flag] or '_unit' in key or key=='bibcode': continue photband = cat_info.get(source,key) #-- contains measurement, error, quality, units, photometric band and # source cols = [results[key][:1], (e_flag+key in cat_info.options(source) and results[cat_info.get(source,e_flag+key)][:1] or np.ones(len(results[:1]))*np.nan), (q_flag+key in cat_info.options(source) and results[cat_info.get(source,q_flag+key)][:1] or np.ones(len(results[:1]))*np.nan), np.array(len(results[:1])*[units[key]],str), np.array(len(results[:1])*[photband],str), np.array(len(results[:1])*[source],str)] #-- add any extra fields if desired. if extra_fields is not None: for e_dtype in extra_fields: cols += [e_dtype in results.dtype.names and results[e_dtype][:1] or np.ones(len(results[:1]))*np.nan] #-- add to the master rows = [] for i in range(len(cols[0])): rows.append(tuple([col[i] for col in cols])) master = np.core.records.fromrecords(master.tolist()+rows,dtype=dtypes) cols_added += 1 #-- fix colours: we have to run through it two times to be sure to have # all the colours N = len(master)-cols_added master_ = vizier._breakup_colours(master[N:]) master_ = vizier._breakup_colours(master_) #-- combine and return master = np.core.records.fromrecords(master.tolist()[:N]+master_.tolist(),dtype=dtypes) #-- skip first line from building if newmaster: master = master[1:] return master
def gcpd2phot(source,results,units,master=None,e_flag='e_',q_flag='q_',extra_fields=None): """ Convert/combine GCPD record arrays to measurement record arrays. Every line in the combined array represents a measurement in a certain band. The standard columns are: 1. C{meas}: containing the photometric measurement 2. C{e_meas}: the error on the photometric measurement 3. C{flag}: an optional quality flag 4. C{unit}: the unit of the measurement 5. C{photband}: the photometric passband (FILTER.BAND) 6. C{source}: name of the source catalog If you give a C{master}, the information will be added to a previous record array. If not, a new master will be created. Colors will be expanded, derived from the other columns and added to the master. The result is a record array with each row a measurement. Extra fields are not available for the GCPD, they will be filled in with nans. @param source: name of the VizieR source @type source: str @param results: results from VizieR C{search} @type results: record array @param units: header of Vizier catalog with key name the column name and key value the units of that column @type units: dict @param master: master record array to add information to @type master: record array @param e_flag: flag denoting the error on a column @type e_flag: str @param q_flag: flag denoting the quality of a measurement @type q_flag: str @param extra_fields: any extra columns you want to add information from @type extra_fields: list of str @return: array with each row a measurement @rtype: record array """ if cat_info.has_option(source,'e_flag'): e_flag = cat_info.get(source,'e_flag') #-- basic dtypes dtypes = [('meas','f8'),('e_meas','f8'),('flag','a20'), ('unit','a30'),('photband','a30'),('source','a50')] #-- extra can be added, but only if a master is already given!! The reason # is that thre GCPD actually does not contain any extra information, so # we will never be able to add it and will not know what dtype the extra # columns should be #-- extra can be added: names = list(results.dtype.names) if extra_fields is not None: for e_dtype in extra_fields: dtypes.append((e_dtype,'f8')) #-- create empty master if not given newmaster = False if master is None or len(master)==0: master = np.rec.array([tuple([('f' in dt[1]) and np.nan or 'none' for dt in dtypes])],dtype=dtypes) newmaster = True #-- add fluxes and magnitudes to the record array cols_added = 0 for key in cat_info.options(source): if key[:2] =='e_' or key=='bibcode': continue photband = cat_info.get(source,key) #-- contains measurement, error, quality, units, photometric band and # source cols = [results[key][:1], (e_flag+key in cat_info.options(source) and results[cat_info.get(source,e_flag+key)][:1] or np.ones(len(results[:1]))*np.nan), (q_flag+key in results.dtype.names and results[q_flag+key][:1] or np.ones(len(results[:1]))*np.nan), np.array(len(results[:1])*[units[key]],str), np.array(len(results[:1])*[photband],str), np.array(len(results[:1])*['GCPD'],str)] #-- add any extra fields if desired. if extra_fields is not None: for e_dtype in extra_fields: cols += [e_dtype in results.dtype.names and results[e_dtype][:1] or np.ones(len(results[:1]))*np.nan] #-- add to the master rows = [] for i in range(len(cols[0])): rows.append(tuple([col[i] for col in cols])) master = np.core.records.fromrecords(master.tolist()+rows,dtype=dtypes) cols_added += 1 #-- fix colours: we have to run through it two times to be sure to have # all the colours N = len(master)-cols_added master_ = vizier._breakup_colours(master[N:]) for i in range(5): master_ = vizier._breakup_colours(master_) #-- combine and return master = np.core.records.fromrecords(master.tolist()[:N]+master_.tolist(),dtype=dtypes) #-- skip first line from building if newmaster: master = master[1:] return master
def gcpd2phot(source, results, units, master=None, e_flag='e_', q_flag='q_', extra_fields=None): """ Convert/combine GCPD record arrays to measurement record arrays. Every line in the combined array represents a measurement in a certain band. The standard columns are: 1. C{meas}: containing the photometric measurement 2. C{e_meas}: the error on the photometric measurement 3. C{flag}: an optional quality flag 4. C{unit}: the unit of the measurement 5. C{photband}: the photometric passband (FILTER.BAND) 6. C{source}: name of the source catalog If you give a C{master}, the information will be added to a previous record array. If not, a new master will be created. Colors will be expanded, derived from the other columns and added to the master. The result is a record array with each row a measurement. Extra fields are not available for the GCPD, they will be filled in with nans. @param source: name of the VizieR source @type source: str @param results: results from VizieR C{search} @type results: record array @param units: header of Vizier catalog with key name the column name and key value the units of that column @type units: dict @param master: master record array to add information to @type master: record array @param e_flag: flag denoting the error on a column @type e_flag: str @param q_flag: flag denoting the quality of a measurement @type q_flag: str @param extra_fields: any extra columns you want to add information from @type extra_fields: list of str @return: array with each row a measurement @rtype: record array """ if cat_info.has_option(source, 'e_flag'): e_flag = cat_info.get(source, 'e_flag') #-- basic dtypes dtypes = [('meas', 'f8'), ('e_meas', 'f8'), ('flag', 'a20'), ('unit', 'a30'), ('photband', 'a30'), ('source', 'a50')] #-- extra can be added, but only if a master is already given!! The reason # is that thre GCPD actually does not contain any extra information, so # we will never be able to add it and will not know what dtype the extra # columns should be #-- extra can be added: names = list(results.dtype.names) if extra_fields is not None: for e_dtype in extra_fields: dtypes.append((e_dtype, 'f8')) #-- create empty master if not given newmaster = False if master is None or len(master) == 0: master = np.rec.array( [tuple([('f' in dt[1]) and np.nan or 'none' for dt in dtypes])], dtype=dtypes) newmaster = True #-- add fluxes and magnitudes to the record array cols_added = 0 for key in cat_info.options(source): if key[:2] == 'e_' or key == 'bibcode': continue photband = cat_info.get(source, key) #-- contains measurement, error, quality, units, photometric band and # source cols = [ results[key][:1], (e_flag + key in cat_info.options(source) and results[cat_info.get(source, e_flag + key)][:1] or np.ones(len(results[:1])) * np.nan), (q_flag + key in results.dtype.names and results[q_flag + key][:1] or np.ones(len(results[:1])) * np.nan), np.array(len(results[:1]) * [units[key]], str), np.array(len(results[:1]) * [photband], str), np.array(len(results[:1]) * ['GCPD'], str) ] #-- add any extra fields if desired. if extra_fields is not None: for e_dtype in extra_fields: cols += [ e_dtype in results.dtype.names and results[e_dtype][:1] or np.ones(len(results[:1])) * np.nan ] #-- add to the master rows = [] for i in range(len(cols[0])): rows.append(tuple([col[i] for col in cols])) master = np.core.records.fromrecords(master.tolist() + rows, dtype=dtypes) cols_added += 1 #-- fix colours: we have to run through it two times to be sure to have # all the colours N = len(master) - cols_added master_ = vizier._breakup_colours(master[N:]) for i in range(5): master_ = vizier._breakup_colours(master_) #-- combine and return master = np.core.records.fromrecords(master.tolist()[:N] + master_.tolist(), dtype=dtypes) #-- skip first line from building if newmaster: master = master[1:] return master