Exemplo n.º 1
0
def load_fluxes_LSDCatForcedRun(line1='CIV1548',line2='CIII1908',fluxcol='F_3KRON',
                                datadir='/Users/kschmidt/work/MUSE/ciii_candidates/fluxAndEWmeasurements/'
                                        'ForceFluxC3inMUSE_fullrun161031/',
                                redshiftcat='/Users/kschmidt/work/catalogs/MUSE_GTO/candels_1-24_emline_master_v2.1.fits',
                                convert_Flux2Lbol=False,verbose=True):
    """
    Loading the flux output from an LSDcat run and potentially turning it into bolometric luminoisity.
    Returning data array to be plotted on NEGOAL diagrams

    --- EXAMPLE OF USE ---
    import NEOGALmodels as nm
    lumarray = nm.load_fluxes_LSDCatForcedRun(line1='CIV1548',line2='CIII1908',fluxcol='F_3KRON',convert_Flux2Lbol=True)


    """
    if verbose: print ' - Loading redshift catalog: \n   '+redshiftcat
    z_data       = pyfits.open(redshiftcat)[1].data
    linenamesdic = nm.linenames()
    if verbose: print ' - Grabbing files with flux measurements in data directory: \n   '+datadir
    fluxfiles = glob.glob(datadir+'*_linelist_fluxes.fits')
    Nfiles    = len(fluxfiles)
    if Nfiles == 0:
        sys.exit("Didn't find any *_linelist_fluxes.fits files in datadir="+datadir)

    outputarray = np.ones([Nfiles,11])*-99

    for ff, ffile in enumerate(fluxfiles):
        f_data   = pyfits.open(ffile)[1].data
        objid    = ffile.split('/')[-1][:8]
        objent   = np.where(z_data['UNIQUE_ID'] == objid)[0]
        if len(objent) != 1:
            if verbose: print ' - WARNING Found '+str(len(objent))+' matches to '+str(objid)+' in redshift catalog'
            continue

        line1name = linenamesdic[line1][0]
        line2name = linenamesdic[line2][0]
        line1ent = np.where(f_data['LINENAME'] == line1name)[0]
        line2ent = np.where(f_data['LINENAME'] == line2name)[0]
        if (len(line1ent) != 1) or (len(line2ent) != 1):
            if verbose: print ' - WARNING No match in flux table for '+line1+' and '+line2+' for '+str(objid)
            continue

        redshift     = z_data['REDSHIFT'][objent]
        redshifterr  = z_data['REDSHIFT_ERR'][objent]
        lineflux1    = f_data[fluxcol][line1ent]
        linefluxerr1 = f_data[fluxcol+'_ERR'][line1ent]
        lineflux2    = f_data[fluxcol][line2ent]
        linefluxerr2 = f_data[fluxcol+'_ERR'][line2ent]

        if convert_Flux2Lbol:
            Lbol1, Lbolerr1 = nm.convert_Fline2Lbol(lineflux1,linefluxerr1,redshift,verbose=False)
            Lbol2, Lbolerr2 = nm.convert_Fline2Lbol(lineflux2,linefluxerr2,redshift,verbose=False)
        else:
            Lbol1, Lbolerr1 = -99, -99
            Lbol2, Lbolerr2 = -99, -99

        outputarray[ff,:] = int(objid), redshift, redshifterr, \
                            lineflux1, linefluxerr1, lineflux2, linefluxerr2, \
                            Lbol1, Lbolerr1, Lbol2, Lbolerr2,

    return outputarray
Exemplo n.º 2
0
def plot_LvsL_multiple(line1='CIV1548',line2='CIII1908',line1range=[1e3,1e8],line2range=[1e0,1e8],
                       outputdir='./',verbose=True):
    """
    Plotting the model grids for all possible combinations of free and fixed parameters
    for two specific lines

    --- EXAMPLE OF USE ---
    import NEOGALmodels as nm
    nm.plot_LvsL_multiple(outputdir='NEOGALplots_clean1611XX/')

    """
    modeldata = nm.load_model('combined',verbose=verbose)

    if verbose: print ' - Putting together permutations of chosen setups for plotting'
    infodic          = {}
    infodic['Zgas']  = [False,0.0001,0.006,0.040], True
    infodic['logUs'] = [False,-1.0,-2.5,-4.0]    , False
    infodic['xid']   = [False,0.1,0.3,0.5]       , False
    infodic['nh']    = [False,10,100,1000,10000] , False
    infodic['CO']    = [False,0.1,0.38,1.4]      , False
    infodic['Mcut']  = [False,100,300]           , False

    variables = [infodic['Zgas'][0],infodic['logUs'][0],infodic['xid'][0],
                 infodic['nh'][0],infodic['CO'][0],infodic['Mcut'][0]]

    permutations            = list(itertools.product(*variables))
    permutations_with2false = [sublist for sublist in permutations if sublist.count(False) == 2.]
    Nplots                  = len(permutations_with2false)

    if verbose: print ' - With the restriction Nfalse=2 the setup will results in '+str(Nplots)+\
                      ' plots (if model data allows)'
    if verbose: print ' - These will be saved to the output directory: '+outputdir
    for pp, perm in enumerate(permutations_with2false):
        Zval     = perm[0]
        Uval     = perm[1]
        Xival    = perm[2]
        Nhval    = perm[3]
        COval    = perm[4]
        Mval     = perm[5]

        plotname = outputdir+'NEOGALmodelgrid_Zgas'+str(Zval).replace('.','p')+\
                   '_logU'+str(Uval).replace('.','p')+\
                   '_xid'+str(Xival).replace('.','p')+\
                   '_nH'+str(Nhval).replace('.','p')+\
                   '_CO'+str(COval).replace('.','p')+\
                   '_Mcut'+str(Mval).replace('.','p')+'.pdf'

        plotname = plotname.replace('False','Free')

        if verbose:
            plotno    = pp+1
            infostr = ' - Generating plot '+str("%.4d" % plotno)+'/'+str("%.4d" % Nplots)+': '+plotname.split('/')[-1]+'    '
            sys.stdout.write("%s\r" % infostr)
            sys.stdout.flush()

        if not Zval:
            logp1 = True
        else:
            logp1 = False

        nm.plot_LvsL(modeldata,line1=line1,line2=line2,logx=True,logy=True,logp1=logp1,logp2=False,verbose=False,
                     Zgas=Zval,logU=Uval,xid=Xival,nh=Nhval,COratio=COval,Mcutoff=Mval,
                     fixxrange=line1range,fixyrange=line2range,plotname=plotname)

    print '\n   ... done'