예제 #1
0
 def gensubgrid(theta_av):
     """
     **Partial function**
     Generate the chunk of grid corresponding to a given theta_av
     based on the initial grid g0
     """
     _args = {}
     for e, k in enumerate(kwargs):
         if hasattr(theta_av, '__iter__'):
             _args[k] = theta_av[e]
         else:
             _args[k] = theta_av
     tau = oAv.function(g0.lamb * 1e-4, Alambda=True, **_args)
     outputSEDs = g0.seds * numpy.exp(-tau)[None, :]
     #copy original grid
     t = Table(g0.grid.data,
               header=g0.grid.header,
               name=g0.grid.header['NAME'])
     for k, v in _args.iteritems():
         t.addCol([v] * t.nrows, name=k)
     g = grid.SpectralGrid()
     g.lamb = g0.lamb[:]
     g.seds = outputSEDs
     g.grid = t
     return g, theta_av
예제 #2
0
파일: grid_test.py 프로젝트: ezbc/planckpy
    def test_spectralgrid_fit_profiles():

        import os
        reload(grid)
        file_dir = '/d/bip3/ezbc/taurus/data/galfa/'
        file_name = 'taurus.galfa.cube.bin.4arcmin.fits'
        box = [300,300,325,325]
        noise_range = [(-110,-90),(90,110)]

        spGrid = grid.SpectralGrid(file_dir + file_name, box = box,
                noiseRange = noise_range,
                basesubtract = True)

        guesses = [40,5,6]

        spGrid.fit_profiles(
                grow_pos = (312,312),
                guesses=guesses,
                ncomp=len(guesses)/3,
                alpha=0.001,
                coords='image',
                number_of_fits=10,
                verbose=True)

        os.system('rm -rf Test')
예제 #3
0
파일: grid_test.py 프로젝트: ezbc/planckpy
    def test_spectralgrid_init():

        file_dir = '/d/bip3/ezbc/taurus/data/galfa/'
        file_name = 'taurus.galfa.cube.bin.4arcmin.fits'
        box = [300,300,325,325]
        noise_range = [(-110,-90),(90,110)]

        spGrid = grid.SpectralGrid(file_dir + file_name, box = box,
                noiseRange = noise_range,
                basesubtract = True)

        assert spGrid.cube is not None
예제 #4
0
def getFakeCluster(g,
                   age,
                   Z,
                   filts,
                   err=0.1,
                   suffix='0',
                   Nstars=None,
                   oAv=None,
                   **kwargs):
    """ Generate a fake sed from a model grid
    INPUTS:
        idx     int                     index number on the grid
        age     float                   age of the desired population
        Z       float                   metallicity of the desired population
        filters list[filter]            list of filter names
    OUTPUTS:
        fakein  int                     the index of the model on the grid
        lamb    ndarray[float, ndim=1]  wavelength taken from the grid
        fakesed ndarray[float, ndim=1]  resulting SED

    KEYWORDS:
        suffix  str                 suffix used to store the cluster table
        err     float               proportional error to consider on the fluxes
        Nstars  int                 number of stars in the population (None = all possible stars)
        oAv     ExtinctionLaw       if provided, apply extinction function using **kwargs

        **kwargs if provided, extra keywords are used to apply an extinction
    """
    # find all the stars matching age and Z criteria
    glogA = numpy.unique(g.logA)
    gZ = numpy.unique(g.Z)
    _logA = glogA[numpy.argmin(abs(glogA - numpy.log10(age)))]
    _Z = gZ[numpy.argmin(abs(gZ - Z))]
    idx = numpy.where((g.logA == _logA) & (g.Z == _Z))[0]
    # Restrict to Nstars is provided
    if Nstars is not None:
        idx = numpy.random.randint(0, len(idx), min([len(idx), Nstars]))

    fakeseds = g.seds[idx]
    # Compute extinction is requested
    if (oAv is not None) & (len(kwargs) > 0):
        tau = oAv(g.lamb * 1e-4, Alambda=True, **kwargs)
        fakeseds *= exp(-tau)[None, :]
    ## extract photometry
    gg = grid.SpectralGrid()
    gg.lamb = g.lamb
    gg.seds = fakeseds
    gg.grid = g.grid[idx]
    seds = gg.getSEDs(filts, absFlux=True)

    seds.grid.addCol(idx, name='idx')

    for k, v in kwargs.iteritems():
        seds.grid.header[k] = v

    filter_names = []
    for ek, nk in enumerate(filts):
        fname = nk.name
        seds.grid.addCol(seds.seds[:, ek], name=fname)
        seds.grid.addCol(seds.seds[:, ek] * err, name=fname + 'err')
        filter_names.append(nk.name)
    seds.grid.header['logA'] = _logA
    seds.grid.header['Z'] = _Z

    seds.grid.write('Tests/cl_%s.fits' % suffix)
    del seds

    obs = observations.Observations('Tests/cl_%s.fits' % suffix)
    obs.setFilters(filter_names)
    return obs
예제 #5
0

################################################################################
# Loading cfa grid of persues
################################################################################

import grid
cfa = grid.load_grid('perseus.cfa.138_62.5sigma')

grid.plot_ncompImage(cfa)

box=[0,36,180,180]
reload(grid)
perseus_galfa = grid.SpectralGrid('../galfa/'+\
        'perseus.galfa.cube.bin.4arcmin.fits',
                        box=box,
                        noiseScale=10.,
                        noiseRange=((-110,-90),(90,110)),
                        basesubtract=True)
guesses = [48,5,10]
perseus_galfa.fit_profiles(
        growPos = (138,62),
        tileSaveFreq=100,
        threshold = 1,
        #filename='perseus.galfa.138_62.10',
        guesses=guesses,
        ncomp=len(guesses)/3,
        alpha=0.001,
        coords='image',
        numberOfFits=1e6,
        COcube=cfa,
        COwidthScale=1.)