示例#1
0
def getFilterList(filterList, outfile='filters.hd5'):
    url = 'http://svo2.cab.inta-csic.es//theory/fps3/fps.php?ID='
    filters = []
    fnames = []
    for filt in filterList:
        try:
            g, fname = get_filter_svo(filt, url=url)
        except ValueError:
            try:
                g, fname = get_filter_file(filt)
            except OSError:
                print(
                    "Filter ", filt,
                    " could not be found on the SVO or in the local directory. \nPlease check where to find this filter. \nContinuing to the next filter "
                )
                continue
        filters.append(g)
        fnames.append(fname)
    _ = subprocess.call(['rm', 'temp.vot'])
    h = h5py.File(outfile, 'w')
    h.create_group('filters')
    h.close()
    h = pyp.HDF_Library(source=outfile)
    #Don't try to add a filter if it's already in there
    _, u = np.unique([f.name for f in filters], return_index=True)
    for f in list(np.array(filters)[u]):
        h.add_filter(f)
    return fnames
示例#2
0
def makeFilterSet(filterNames = [], infile = 'filters.csv', libraryFile = 'filters.hd5'):
    """Download filter transmission curves from the Spanish Virtual Observatory.
    The resulting filter library is saved as an hd5 file, to be ingested into pyphot.
    INPUTS:
           1) filterNames, a list of the filter names as on the SVO/VOSA site. If specified, infile
           is ignored.
           2) infile, a two-column CSV file of which the second column must contain
           must contain the names of the SVO/VOSA filter files to download.
           The first column is not currently used, but can contain identifying information
           for each filter that connects it back to the data.
           The filter names can be in the order of occurrence in the data, and may include
           repetitions (as it is quite possible that the data is compiled from a number of
           differing sets of observations).
    OUTPUT: libraryFile, an HDF file containing information about all the filters for which this is requested.

    At the moment, the header in the output files only contains the DetectorType specification if the filter
        is a photon counter (DetectorType value = "1"). We read in the entire file and check for the occurrence
        of this line and set the detector type accordingly.
    """
    if filterNames == []:
        tin = Table.read(infile, format = 'csv', names = ('column', 'filtername'))
        filterNames = list(tin['filtername'])
    url = 'http://svo2.cab.inta-csic.es//theory/fps3/fps.php?ID='
    filters = []
    #Each filter is downloaded into a temporary file via curl.
    #   The temporary file is deleted after all the filters are downloaded.
    for f in filterNames:
    #for t in tin:
        print("Downloading filter " + f)
        _ = subprocess.call(['curl', '-o', 'temp.vot', url + f])
        with open('temp.vot') as g:
            content = g.readlines()
        if any("DetectorType" in c for c in content):
            det_type = 'photon'
        else:
            det_type = 'energy'
        temp = Table.read('temp.vot', format = 'votable')
        g = pyp.Filter(np.array(temp['Wavelength']), np.array(temp['Transmission']), \
                       name = f.replace('/','_'), unit = temp['Wavelength'].unit.name, \
                       dtype = det_type)
        filters.append(g)
    _ = subprocess.call(['rm', 'temp.vot'])
    #Instantiate an hdf5 object to store filter information
    h = h5py.File(libraryFile, 'w')
    h.create_group('filters')
    h.close()
    h = pyp.HDF_Library(source = libraryFile)
    #Add filters to this object, without repetition.
    _, u = np.unique([f.name for f in filters], return_index = True)
    for f in list(np.array(filters)[u]):
        h.add_filter(f)
示例#3
0
def makeFilterSet(infile='filters.csv', outfile='filters.hd5'):
    """Download filter transmission curves from the Spanish Virtual Observatory and write into an HDF file.

    Keyword arguments:
    infile -- (default 'filters.csv')
        name of two-column CSV file, with the first column containing a unique name for the filter,
        and the second column containing the name of the filter as specified on the SVO/VOSA webpage. For
        example, a row "IRAC45, Spitzer/IRAC.I2" in infile will download the IRAC 4.5 µm filter curve.

        If the name in the second column does not match any filters on the SVO database, the code will
        search the local machine. This allows the user to incorporate filter files not available on the SVO.
        In this case, the filter profile must be a CSV, with two header lines providing the column content
        as well as the units for the wavelength, and the detector type. For example:
                Wavelength, Transmission
                um, energy
                0.5, 0.00
                0.6, 0.10

    outfile -- (default 'filters.hd5') name of output HDF file.

    Notes: The current SVO data only specify the DetectorType if the filter is a photon counter, by setting
    DetectorType = "1". This script reads in the entire file and checks for the occurrence of this line
    to set the detector type in the output file accordingly. The SVO has said that they will improve
    the implementation of this keyword in the future.
    """

    tin = Table.read(infile, format = 'csv', \
                     names = ('column', 'filtername'))
    url = 'http://svo2.cab.inta-csic.es//theory/fps3/fps.php?ID='
    filters = []
    for t in tin:
        try:
            #Look for the filter in the SVO database
            _ = subprocess.call(
                ['curl', '-o', 'temp.vot', url + t['filtername']])
            with open('temp.vot') as f:
                content = f.readlines()
            if any("DetectorType" in c for c in content):
                det_type = 'photon'
            else:
                det_type = 'energy'
            temp = Table.read('temp.vot', format='votable')
            g = pyp.Filter(np.array(temp['Wavelength']), np.array(temp['Transmission']), \
                           name = t['filtername'].replace('/','_'), unit = temp['Wavelength'].unit.name, \
                           dtype = det_type)
        except:
            #Look for the filter on the local machine
            header = np.loadtxt(t['filtername'] + '.csv',
                                max_rows=2,
                                delimiter=',',
                                dtype='str')
            data = np.loadtxt(t['filtername'] + '.csv',
                              skiprows=2,
                              delimiter=',')
            #Note: dtype in the following line is the detector type of the filter
            g = pyp.Filter(data[:, 0], data[:, 1], name = t['filtername'].replace('/', '_'), unit = header[1, 0], \
                           dtype = header[1, 1])
        filters.append(g)
    _ = subprocess.call(['rm', 'temp.vot'])
    h = h5py.File(outfile, 'w')
    h.create_group('filters')
    h.close()
    h = pyp.HDF_Library(source=outfile)
    #Don't try to add a filter if it's already in there
    _, u = np.unique([f.name for f in filters], return_index=True)
    for f in list(np.array(filters)[u]):
        h.add_filter(f)
示例#4
0
import pyphot  #synthetic photometry
from astropy.table import Table  #synthetic photometry
import numpy as np  #input/output
from astropy.io import fits  #input/output
from matplotlib import pyplot as plt  #visualisation
pkgdir = '/usr/local/lib/python2.7/site-packages/pyphot/'  #Edit this depending on user
libsdir = '/usr/local/lib/python2.7/site-packages/pyphot/libs/'  #Edit this depending on user
demodir = '/Users/sundar/work/pyphot/pyphot/demo/'  #Edit this depending on user
"""Load entire HDF5 library"""
libsdir = '/Users/sundar/work/pyphot/pyphot/libs/'
libraryName = libsdir + 'synphot_PhIReSSTARTer.hd5'
#filterLibrary = pyphot.get_library(fname=libraryName)
filterLibrary = pyphot.HDF_Library(libraryName)
"""Names of the first ten filters available in the library"""
filterNames = filterLibrary.get_library_content()
for i in range(9):
    print filterNames[i]
"""Load information for a single filter"""
ans_3300 = filterLibrary.load_filters(
    ['ans_3300'])  #result is a list, even for a single filter!
"""Load information for a list of filters"""
filters = filterLibrary.load_filters(['ans_3300', 'steward_k'])
"""View filter information"""
ans_3300[0].info()
"""We will use the same set of filters for both examples below"""
filterNames = [
    'MCPS_U', 'MCPS_B', 'MCPS_U', 'MCPS_I', '2MASS_J', '2MASS_H', '2MASS_Ks',
    'SPITZER_IRAC_36', 'SPITZER_IRAC_45', 'SPITZER_IRAC_58', 'SPITZER_IRAC_80',
    'SPITZER_MIPS_24'
]
libraryName = libsdir + 'synphot_PhIReSSTARTer.hd5'