def systematics(units='muHz'): """ Return a list of known systematic effects from the Kepler satellite. """ ffile = config.get_datafile('catalogs/kepler','systematics.dat') systems = ascii.read2recarray(ffile) systems['frequency'] = conversions.nconvert(systems['unit'],units,systems['frequency']) systems['e_frequency'] = conversions.nconvert(systems['unit'],units,systems['e_frequency']) systems['w_frequency'] = conversions.nconvert(systems['unit'],units,systems['w_frequency']) return systems
def systematics(units='muHz'): """ Return a list of known systematic effects from the Kepler satellite. """ ffile = config.get_datafile('catalogs/kepler', 'systematics.dat') systems = ascii.read2recarray(ffile) systems['frequency'] = conversions.nconvert(systems['unit'], units, systems['frequency']) systems['e_frequency'] = conversions.nconvert(systems['unit'], units, systems['e_frequency']) systems['w_frequency'] = conversions.nconvert(systems['unit'], units, systems['w_frequency']) return systems
def update_info(zp=None): """ Update information in zeropoint file, e.g. after calibration. Call first L{ivs.sed.model.calibrate} without arguments, and pass the output to this function. @param zp: updated contents from C{zeropoints.dat} @type zp: recarray """ zp_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "zeropoints.dat") zp_, comms = ascii.read2recarray(zp_file, return_comments=True) existing = [str(i.strip()) for i in zp_["photband"]] resp_files = sorted(glob.glob(os.path.join(os.path.dirname(os.path.abspath(__file__)), "filters/*"))) resp_files = [os.path.basename(ff) for ff in resp_files if not os.path.basename(ff) in existing] resp_files.remove("HUMAN.EYE") resp_files.remove("HUMAN.CONES") resp_files.remove("CONES.EYE") if zp is None: zp = zp_ logger.info("No new calibrations; previous information on existing response curves is copied") else: logger.info("Received new calibrations contents of zeropoints.dat will be updated") # -- update info on previously non existing response curves new_zp = np.zeros(len(resp_files), dtype=zp.dtype) logger.info("Found {} new response curves, adding them with default information".format(len(resp_files))) for i, respfile in enumerate(resp_files): new_zp[i]["photband"] = respfile new_zp[i]["eff_wave"] = float(eff_wave(respfile)) new_zp[i]["type"] = "CCD" new_zp[i]["vegamag"] = np.nan new_zp[i]["ABmag"] = np.nan new_zp[i]["STmag"] = np.nan new_zp[i]["Flam0_units"] = "erg/s/cm2/AA" new_zp[i]["Fnu0_units"] = "erg/s/cm2/AA" new_zp[i]["source"] = "nan" zp = np.hstack([zp, new_zp]) sa = np.argsort(zp["photband"]) ascii.write_array( zp[sa], "zeropoints.dat", header=True, auto_width=True, comments=["#" + line for line in comms[:-2]], use_float="%g", )
def get_info(photbands=None): """ Return a record array containing all filter information. The record arrays contains following columns: - photband - eff_wave - type - vegamag, vegamag_lit - ABmag, ABmag_lit - STmag, STmag_lit - Flam0, Flam0_units, Flam0_lit - Fnu0, Fnu0_units, Fnu0_lit, - source @param photbands: list of photbands to get the information from. The input order is equal to the output order. If C{None}, all filters are returned. @type photbands: iterable container (list, tuple, 1Darray) @return: record array containing all information on the requested photbands. @rtype: record array """ zp_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "zeropoints.dat") zp = ascii.read2recarray(zp_file) for iph in custom_filters: if iph == "_prefer_file": continue if "zp" in custom_filters[iph]: zp = np.hstack([zp, custom_filters[iph]["zp"]]) zp = zp[np.argsort(zp["photband"])] # -- list photbands in order given, and remove those that do not have # zeropoints etc. if photbands is not None: order = np.searchsorted(zp["photband"], photbands) zp = zp[order] keep = zp["photband"] == photbands zp = zp[keep] return zp
def search(ID,radius=1.,filename=None): """ Retrieve datafiles from the Coralie catalogue. We search on coordinates, pulled from SIMBAD. If the star ID is not recognised, a string search is performed to match the 'targ name' field in the FITS headers. Only the s1d_A data are searched. @param ID: ID of the star, understandable by SIMBAD @type ID: str @param radius: search radius around the coordinates @type radius: 1 @param filename: write summary to outputfile if not None @type filename: str @return: record array with summary information on the observations, as well as their location (column 'filename') @rtype: numpy rec array """ data = ascii.read2recarray(config.get_datafile(os.path.join('catalogs','coralie'),'CoralieFullDataOverview.tsv'),splitchar='\t') info = sesame.search(ID) if info: ra,dec = info['jradeg'],info['jdedeg'] keep = np.sqrt((data['ra']-ra)**2 + (data['dec']-dec)**2) < radius/60. else: keep = [((re.compile(ID).search(objectn) is not None) and True or False) for objectn in data['object']] keep = np.array(keep) data = data[keep] logger.info('Found %d spectra'%(len(data))) if filename is not None: ascii.write_array(data,filename,auto_width=True,header=True) else: return data
def get_lines(teff,logg,z=0,atoms=None,ions=None,wrange=(-inf,inf),\ blend=0.0): """ Retrieve line transitions and strengths for a specific stellar type Selection wavelength range in angstrom. Ions should be a list of ions to include. This can either be a string or a number A lines is considerd a blend if the closest line is closer than C{blend} angstrom. Returns record array with fields C{wavelength}, C{ion} and C{depth}. Example usage: Retrieve all Silicon lines between 4500 and 4600 for a B1V star. >>> data = get_lines(20000,4.0,atoms=['Si'],wrange=(4500,4600)) >>> p = pl.figure() >>> p = pl.vlines(data['wavelength'],1,1-data['depth']) See how the depth of the Halpha line varies wrt temperature: >>> teffs = range(5000,21000,1000) + range(22000,32000,2000) + range(30000,50000,50000) >>> depths = np.zeros((len(teffs),7)) >>> for i,teff in enumerate(teffs): ... data = get_lines(teff,5.0,ions=['HI'],wrange=(3800,7000)) ... depths[i] = data['depth'] >>> p = pl.figure();p = pl.title('Depth of Balmer lines (Halpha-Heta)') >>> p = pl.plot(teffs,1-depths,'o-') >>> p = pl.xlabel('Effective temperature');p = pl.grid() """ #-- get filepath filename = 'mask.%d.%02d.p%02d'%(int(teff),int(logg*10),int(z)) filename = config.get_datafile(stellar,filename) #-- read in the data and extract relevant columns data = ascii.read2recarray(filename,skip_lines=1,dtype=[('wavelength','f8'),('ion','f8'),('depth','f8'),('c3','f8'),('c4','f8'),('c5','f8')]) data = pl.mlab.rec_drop_fields(data,['c3','c4','c5']) data['wavelength'] *= 10. #-- remove blends if blend>0: blends_left = np.hstack([0,np.diff(data['wavelength'])]) blends_right= np.hstack([np.diff(data['wavelength']),1e10]) keep = (blends_left>blend) & (blends_right>blend) data = data[keep] #-- only keep those transitions within a certain wavelength range keep = (wrange[0]<=data['wavelength']) & (data['wavelength']<=wrange[1]) data = data[keep] #-- only keep those transitions that belong to certain ions or atoms if atoms is not None or ions is not None: keep = np.array(np.zeros(len(data)),bool) else: keep = np.array(np.ones(len(data)),bool) if atoms is not None: #-- convert all atoms to their number and select the appropriate ones atoms = [(isinstance(atom,str) and atomcode.index(atom.title()) or atom) for atom in atoms] for atom in atoms: keep = keep | (np.abs(data['ion']-atom)<0.5) if ions is not None: #-- convert all ions to their number and select the appropriate ones ions = [(isinstance(ion,str) and name2ioncode(ion) or ion) for ion in ions] for ion in ions: keep = keep | (np.abs(data['ion']-ion)<0.005) return data[keep]
#-- store in easy to use recarrays dtype = [('name', 'a20')] + [(pb.split('.')[-1], 'f8') for pb in photbands] synthetic = np.array(synthetic, dtype=dtype) dtype = [('name', 'a20')] + [(pb.split('.')[-1] , 'f8') for pb in photbands] +\ [('e_'+pb.split('.')[-1] , 'f8') for pb in photbands] observed = np.array(observed, dtype=dtype) #-- write results to file ascii.write_array(synthetic, synfile, sep=',') ascii.write_array(observed, obsfile, sep=',') else: #-- load results from file dtype = [('name', 'a20')] + [(pb.split('.')[-1], 'f8') for pb in photbands] synthetic = ascii.read2recarray(synfile, splitchar=',', dtype=dtype) dtype = [('name', 'a20')] + [(pb.split('.')[-1] , 'f8') for pb in photbands] +\ [('e_'+pb.split('.')[-1] , 'f8') for pb in photbands] observed = ascii.read2recarray(obsfile, splitchar=',', dtype=dtype) #-- add some minimal error is non is given observationaly for band in ['e_' + pb.split('.')[-1] for pb in photbands]: observed[band] = np.where(observed[band] <= minerror, minerror, observed[band]) #=================================================================================== # Zero point calculation and plotting #=================================================================================== def fit_zp(ax, band, c1, c2):
def get_lines(teff,logg,z=0,atoms=None,ions=None,wrange=(-inf,inf),\ blend=0.0): """ Retrieve line transitions and strengths for a specific stellar type Selection wavelength range in angstrom. Ions should be a list of ions to include. This can either be a string or a number A lines is considerd a blend if the closest line is closer than C{blend} angstrom. Returns record array with fields C{wavelength}, C{ion} and C{depth}. Example usage: Retrieve all Silicon lines between 4500 and 4600 for a B1V star. >>> data = get_lines(20000,4.0,atoms=['Si'],wrange=(4500,4600)) >>> p = pl.figure() >>> p = pl.vlines(data['wavelength'],1,1-data['depth']) See how the depth of the Halpha line varies wrt temperature: >>> teffs = range(5000,21000,1000) + range(22000,32000,2000) + range(30000,50000,50000) >>> depths = np.zeros((len(teffs),7)) >>> for i,teff in enumerate(teffs): ... data = get_lines(teff,5.0,ions=['HI'],wrange=(3800,7000)) ... depths[i] = data['depth'] >>> p = pl.figure();p = pl.title('Depth of Balmer lines (Halpha-Heta)') >>> p = pl.plot(teffs,1-depths,'o-') >>> p = pl.xlabel('Effective temperature');p = pl.grid() """ #-- get filepath filename = 'mask.%d.%02d.p%02d' % (int(teff), int(logg * 10), int(z)) filename = config.get_datafile(stellar, filename) #-- read in the data and extract relevant columns data = ascii.read2recarray(filename, skip_lines=1, dtype=[('wavelength', 'f8'), ('ion', 'f8'), ('depth', 'f8'), ('c3', 'f8'), ('c4', 'f8'), ('c5', 'f8')]) data = pl.mlab.rec_drop_fields(data, ['c3', 'c4', 'c5']) data['wavelength'] *= 10. #-- remove blends if blend > 0: blends_left = np.hstack([0, np.diff(data['wavelength'])]) blends_right = np.hstack([np.diff(data['wavelength']), 1e10]) keep = (blends_left > blend) & (blends_right > blend) data = data[keep] #-- only keep those transitions within a certain wavelength range keep = (wrange[0] <= data['wavelength']) & (data['wavelength'] <= wrange[1]) data = data[keep] #-- only keep those transitions that belong to certain ions or atoms if atoms is not None or ions is not None: keep = np.array(np.zeros(len(data)), bool) else: keep = np.array(np.ones(len(data)), bool) if atoms is not None: #-- convert all atoms to their number and select the appropriate ones atoms = [(isinstance(atom, str) and atomcode.index(atom.title()) or atom) for atom in atoms] for atom in atoms: keep = keep | (np.abs(data['ion'] - atom) < 0.5) if ions is not None: #-- convert all ions to their number and select the appropriate ones ions = [(isinstance(ion, str) and name2ioncode(ion) or ion) for ion in ions] for ion in ions: keep = keep | (np.abs(data['ion'] - ion) < 0.005) return data[keep]