示例#1
0
    def __init__(self, px1File = None, vxxFile = None, px1ELFile = None, vxxELFile = None):
        self.px1 = None
        self.vxx = None
        
        self.px1 = fitsQ3DataCube(px1File)
        self.vxx = fitsQ3DataCube(vxxFile)

        if px1ELFile:
            self.px1.loadEmLinesDataCube(px1ELFile)
                
        if vxxELFile:
            self.vxx.loadEmLinesDataCube(vxxELFile)
            
        self.radial_init()
示例#2
0
def try_q055_instead_q054(califaID, **kwargs):
    from pycasso import fitsQ3DataCube
    config = kwargs.get('config', -1)
    EL = kwargs.get('EL', False)
    GP = kwargs.get('GP', False)
    elliptical = kwargs.get('elliptical', False)
    K = None
    P = CALIFAPaths()
    P.set_config(config)
    pycasso_file = P.get_pycasso_file(califaID)
    if not os.path.isfile(pycasso_file):
        P.pycasso_suffix = P.pycasso_suffix.replace('q054', 'q055')
        pycasso_file = P.get_pycasso_file(califaID)
        print(pycasso_file)
        if os.path.isfile(pycasso_file):
            K = fitsQ3DataCube(P.get_pycasso_file(califaID))
            if elliptical:
                K.setGeometry(*K.getEllipseParams())
            if EL:
                emlines_file = P.get_emlines_file(califaID)
                if not os.path.isfile(emlines_file):
                    P.emlines_suffix = P.emlines_suffix.replace('q054', 'q055')
                    emlines_file = P.get_emlines_file(califaID)
                    print(emlines_file)
                    if os.path.isfile(emlines_file):
                        K.loadEmLinesDataCube(emlines_file)
            if GP:
                gasprop_file = P.get_gasprop_file(califaID)
                if not os.path.isfile(gasprop_file):
                    P.gasprop_suffix = P.gasprop_suffix.replace('q054', 'q055')
                    gasprop_file = P.get_gasprop_file(califaID)
                    print(gasprop_file)
                    if os.path.isfile(gasprop_file):
                        K.GP = GasProp(gasprop_file)
    return K
示例#3
0
def load_gal_cubes(args, califaID,
                   pycasso_cube_file=None,
                   eml_cube_file=None,
                   gasprop_cube_file=None):
    '''
        Open PyCASSO SUPERFITS (K), EmissionLines FITS (K.EL) and
        GasProp FITS (K.GP)

        The directories and suffixes are in:
        args.[pycasso_cube_[dir,suffix],
              eml_cube_[dir,suffix],
              gasprop_cube_[dir,suffix]]
    '''
    from pycasso import fitsQ3DataCube
    if pycasso_cube_file is None:
        pycasso_cube_file = califaID + args.pycasso_cube_suffix
    K_cube = fitsQ3DataCube(args.pycasso_cube_dir + pycasso_cube_file)
    filenames = [pycasso_cube_file, '', '']
    if args.EL:
        if eml_cube_file is None:
            eml_cube_file = califaID + args.eml_cube_suffix
        K_cube.loadEmLinesDataCube(args.eml_cube_dir + eml_cube_file)
        filenames.insert(1, eml_cube_file)
    if args.GP:
        from CALIFAUtils.objects import GasProp
        # GasProp in CALIFAUtils.objects
        if gasprop_cube_file is None:
            gasprop_cube_file = califaID + args.gasprop_cube_suffix
        K_cube.GP = GasProp(args.gasprop_cube_dir + gasprop_cube_file)
        filenames.insert(2, gasprop_cube_file)
    return K_cube, filenames
示例#4
0
def getCube(root, galaxyId, sampleId, component, HLR=None):
    filename = '%s_synthesis_%s_%s.fits' % (galaxyId, sampleId, component)
    filepath = path.join(root, filename)
    K = fitsQ3DataCube(filepath)
    pa, ba = K.getEllipseParams()
    K.setGeometry(pa, ba, HLR)
    #K.qMask &= K.filterResidual__yx()
    #K.qMask &= (K.zoneToYX(K.adevS, extensive=False) < 10.0)
    return K
示例#5
0
def load_gal_cubes(args, califaID):
    pycasso_cube_file = args.pycasso_cube_dir + califaID + args.pycasso_cube_suffix
    K = fitsQ3DataCube(pycasso_cube_file)
    if args.EL:
        eml_cube_file = args.eml_cube_dir + califaID + args.eml_cube_suffix
        K.loadEmLinesDataCube(eml_cube_file)
    if args.GP:
        gasprop_cube_file = args.gasprop_cube_dir + califaID + args.gasprop_cube_suffix
        K.GP = GasProp(gasprop_cube_file)
    return K
示例#6
0
def read_one_cube(gal, **kwargs):
    print(kwargs)
    from pycasso import fitsQ3DataCube
    EL = kwargs.get('EL', None)
    GP = kwargs.get('GP', None)
    config = kwargs.get('config', kwargs.get('v_run', -1))
    verbose = kwargs.get('verbose', None)
    debug = kwargs.get('debug', None)
    work_dir = kwargs.get('work_dir', None)
    paths = CALIFAPaths(work_dir=work_dir, config=config)
    pycasso_cube_filename = paths.get_pycasso_file(gal)
    debug_var(debug, pycasso=pycasso_cube_filename)
    elliptical = kwargs.get('elliptical', False)
    K = None
    try:
        K = fitsQ3DataCube(pycasso_cube_filename)
        K._fits_filename = pycasso_cube_filename
        if elliptical:
            pa, ba = K.getEllipseParams()
            print(K.pa, K.ba, pa, ba)
            K.setGeometry(*K.getEllipseParams())
            print(K.pa, K.ba)
        if verbose is not None:
            print('PyCASSO: Reading file: %s' % pycasso_cube_filename, file=sys.stderr)
        if not isinstance(EL, type(None)):
            if EL is True:
                emlines_cube_filename = paths.get_emlines_file(gal)
            else:
                emlines_cube_filename = EL
            debug_var(debug, emlines=emlines_cube_filename)
            try:
                K.loadEmLinesDataCube(emlines_cube_filename)
                K.EL._fits_filename = emlines_cube_filename
                if verbose is not None:
                    print('EL: Reading file: %s' % emlines_cube_filename, file=sys.stderr)
            except IOError:
                print('EL: File does not exists: %s' % emlines_cube_filename, file=sys.stderr)
        if GP is True:
            gasprop_cube_filename = paths.get_gasprop_file(gal)
            debug_var(debug, gasprop=gasprop_cube_filename)
            try:
                K.GP = GasProp(gasprop_cube_filename)
                K.GP._fits_filename = gasprop_cube_filename
                if verbose is not None:
                    print('GP: Reading file: %s' % gasprop_cube_filename, file=sys.stderr)
            except IOError:
                print('GP: File does not exists: %s' % gasprop_cube_filename, file=sys.stderr)
    except IOError:
        print('PyCASSO: File does not exists: %s' % pycasso_cube_filename, file=sys.stderr)
    del paths
    return K
示例#7
0
def get_images(db):
    K = fitsQ3DataCube(db, smooth=False)
    mask = ~K.qMask
    qSignal = np.ma.array(K.qSignal, mask=mask)
    qNoise = np.ma.array(K.qNoise, mask=mask)
    
#     PA, ba = K.getEllipseParams()
    
    model = galaxy_model(K.x0, K.y0, bulge=True, disk=True,
                         I_e=1, r_e=12, n=1.5, PA_b=90.0, ell_b=0.5,
                         I_0=1, h=12, PA_d=90, ell_d=0.5)
    PSF = moffat_psf(fwhm=2.4, size=9)
    fitter = Imfit(model, PSF, quiet=True)
    fitter.fit(qSignal, qNoise)
    model_image = fitter.getModelImage()
    model = fitter.getModelDescription()
    bulge_image, disk_image = create_model_images(qSignal.shape, PSF, model)
    bulge_image = np.ma.array(bulge_image, mask=mask)
    disk_image = np.ma.array(disk_image, mask=mask)
    bulge_frac = bulge_image / model_image
    disk_frac = disk_image / model_image
    bulge_noise = np.sqrt(bulge_frac) * qNoise
    disk_noise = np.sqrt(disk_frac) * qNoise
    return model, qSignal, qNoise, model_image, bulge_image, bulge_noise, disk_image, disk_noise
示例#8
0
#!/usr/bin/python
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib as mpl
from matplotlib import pyplot as plt
from scipy import stats as st
from pycasso import fitsQ3DataCube
from parser_opt import *

args = parser_args()

print('Output directory: %s' % args.outputdir)

K = fitsQ3DataCube(args.fitsfile)

#xxx

prop = {
    'arr'   : [ K.at_flux__yx, np.log10(K.aZ_flux__yx / 0.019), K.A_V__yx, K.v_0__yx, K.v_d__yx ],
    'label' : [ r'$\langle \log\ t \rangle_L\ [yr]$', r'$\log\ \langle Z \rangle_L\ [Z_\odot]$', r'$A_V\ [mag]$', r'$v_\star\ [km/s]$', r'$\sigma_\star\ [km/s]$' ],
    'name'  : [ 'at_flux', 'aZ_flux', 'AV', 'v0', 'vd' ]
}

f, axArr = plt.subplots(3, 3)
f.set_size_inches((15, 13))

for ax in f.axes:
    ax.set_axis_off()

galimg = plt.imread(args.galaxyimgfile)
        res_bin_cen = np.arange(res_bin_low, res_bin_upp + res_bin_stp,
                                res_bin_stp)
        res_bin_edges = np.append((res_bin_cen - res_bin_stp / 2.0),
                                  (res_bin_cen[-1] + res_bin_stp / 2.0))
        Nres_bins = len(res_bin_cen)

        histR = np.zeros((Nres_bins))
        histS = np.zeros((Nres_bins))
        histU = np.zeros((Nres_bins))

        Ng = N_gals

        for iGal, gal in enumerate(gals):
            #for iGal, K in loop_cubes(gals.tolist(), imax = maxGals, v_run = v_run):
            f_gal = '/data/CALIFA/legacy/q053/superfits/Bgsd6e/' + gal + '_synthesis_eBR_v20_q053.d22a512.ps03.k1.mE.CCM.Bgsd6e.fits'
            K = fitsQ3DataCube(f_gal)
            if K is None:
                print '%s: file not found' % f_gal
                Ng = Ng - 1
                continue
            # Setup is* 1/0 flags to select (zone,lambda) pixels which are Ok in different senses; isOk__lz wraps them all together
            isFlagOk__lz = np.where(K.f_flag == 0, 1, 0)
            isErrOk__lz = np.where(K.f_err > 0, 1, 0)
            isWeiOk__lz = 0 * isFlagOk__lz + 1
            isZoneBlueOk__z = np.asarray(K.filterResidual(w2=4600),
                                         dtype=np.int)

            # if input-given excludeWei0 is True than f_wei = 0 points are excluded from the stats
            # otherwise, em-lines and other masked lambdas (including the blue egde) DO enter the stats!
            if excludeWei0:
                isWeiOk__lz = np.where(K.f_wei > 0, 1, 0)
示例#10
0
from scipy import stats as st

mpl.rcParams['font.size']       = 24
mpl.rcParams['axes.labelsize']  = 24
mpl.rcParams['axes.titlesize']  = 26
mpl.rcParams['xtick.labelsize'] = 15
mpl.rcParams['ytick.labelsize'] = 15 
mpl.rcParams['font.family']     = 'serif'
mpl.rcParams['font.serif']      = 'Times New Roman'

gal = 'K0802'
#fUsed = 'f_obs_norm'
fUsed = 'f_syn_norm'

P = pcalifa.PCAlifa()
K = fitsQ3DataCube('/Users/lacerda/CALIFA/gal_fits/px1_q043.d14a/%s_synthesis_eBR_px1_q043.d14a512.ps03.k1.mE.CCM.Bgsd6e.fits' % gal)
P.readPCAlifaFits('/Users/lacerda/LOCAL/data/%s_synthesis_eBR_px1_q043.d14a512.ps03.k1.mE.CCM.Bgsd6e_%s_PCA_0.95_STMASK.fits' % (gal, fUsed))

prop = {
    'arr'   : [ K.at_flux__z, np.log10(K.aZ_flux__z / 0.019), K.A_V, K.v_0, K.v_d ],
    'arr__yx'   : [ K.at_flux__yx, np.log10(K.aZ_flux__yx / 0.019), K.A_V__yx, K.v_0__yx, K.v_d__yx ],
    'label' : [ r'$\langle \log\ t \rangle_L\ [yr]$', r'$\log\ \langle Z \rangle_L\ [Z_\odot]$', r'$A_V\ [mag]$', r'$v_\star\ [km/s]$', r'$\sigma_\star\ [km/s]$', r'eigenvector' ],
    'filePrefix' : [ 'at_flux',  'logaZ_flux' ,'A_V', 'v_0', 'v_d' ]
}

iTomo = 2
iProp = 2
#inv = 1
inv = -1

propLabel = prop['label'][iProp]
示例#11
0
    outdata.Ntot__R = np.zeros((args.N_R_bins), dtype='int')
    outdata.W6563__z = K.EL.EW[iHa]
    outdata.W6563__yx = K.zoneToYX(outdata.W6563__z, extensive=False)
    outdata.bin_segmap__Ryx = np.zeros((args.N_R_bins, K.N_y, K.N_x),
                                       dtype='bool')
    from astropy import constants as C
    c = C.c.to('km/s').value
    v_0_Ha = c * (K.EL.pos[iHa] - 6563.) / 6563.
    outdata.v_0 = np.where(K.EL._setMaskLineSNR('6563', 1), K.v_0, v_0_Ha)
    # outdata.v_0 = K.v_0
    return outdata


if __name__ == '__main__':
    args = parser_args()
    K = fitsQ3DataCube(args.superfits)
    K.loadEmLinesDataCube(args.emlfits)
    print K.califaID, np.unique(K.f_flag), K.header['FLAGS_ID']
    K.close()
    sys.exit(1)
    # Set geometry
    K.setGeometry(*K.getEllipseParams())
    wl_of = K.l_obs
    outdata = create_outdata(args, K)
    W6563__z = outdata.W6563__z
    # Loop in radial bins
    for iR, (l_edge,
             r_edge) in enumerate(zip(args.R_bin__r[0:-1], args.R_bin__r[1:])):
        sel_zones = np.bitwise_and(
            np.greater_equal(K.zoneDistance_HLR, l_edge),
            np.less(K.zoneDistance_HLR, r_edge))
示例#12
0
    g3 = A3 * np.exp(-(x - mu3)**2 / (2. * sigma3**2))
    return g1 + g2 + g3


def adjust_N2Ha(l_obs, f_res, constrains, x0, bounds):
    to_min = lambda p: np.square(f_res - gauss(p, l_obs)).sum()
    return minimize(to_min,
                    x0=x0,
                    constraints=cons,
                    method='SLSQP',
                    bounds=bounds,
                    options=dict(ftol=1e-8, eps=1e-5))


# load CALIFA 10 PyCASSO Voronoi SN20 cube
K = fitsQ3DataCube(
    'K0010_synthesis_eBR_v20_q054.d22a512.ps03.k1.mE.CCM.Bgstf6e.fits')
K.loadEmLinesDataCube(
    'K0010_synthesis_eBR_v20_q054.d22a512.ps03.k1.mE.CCM.Bgstf6e.EML.MC100.fits'
)

iN2e = K.EL.lines.index('6548')
iHa = K.EL.lines.index('6563')
iN2d = K.EL.lines.index('6583')
'''
x0 is an array with A1, lambda1, sigma1, A2, lambda2, sigma2, A3, lambda3, sigma3
initial values. They will be fitted.
'''
x0 = [1., 6548, 1., 1., 6563, 1., 3., 6583, 6583. / 6548.]
d_x0i = {
    'A1': 0,
    'lambda1': 1,
示例#13
0
# for dirpath, dirs, files in os.walk(sys.argv[1]):
#    for filename in fnmatch.filter(files, '*.fits'):

t = Table('/Users/lacerda/dev/astro/AllGalaxies/CALIFA_class_num.fits')
# filesuffix = "_synthesis_eBR_v20_q036.d13c512.ps03.k2.mC.CCM.Bgsd61.fits"
filesuffix = "_synthesis_eBR_v20_q043.d14a512.ps03.k1.mE.CCM.Bgsd6e.fits"
# filesuffix = "_synthesis_eBR_px1_q043.d14a512.ps03.k1.mE.CCM.Bgsd6e.fits"

for i, (califaID, califaName, Name, RA, DE, hubtyp, bar, merg) in enumerate(t.data):
    fitsFile = '%sK%04d%s' % (sys.argv[1], califaID, filesuffix)
    strHubType = morphHubbleType[hubtyp]
    print fitsFile

    if os.path.isfile(fitsFile):
        K = fitsQ3DataCube(fitsFile)

        O_rf__lz, M_rf__lz, rf_norm__z = v0RestFrame(K, np.interp)

        # NaD Masks
        NaD_mask = ((K.l_obs < NaD.get_lineEdge_low()) | (K.l_obs > NaD.get_lineEdge_top()))
        NaDSideBandLow_mask = ((K.l_obs < NaD.get_sideBandLeftEdge_low()) | (K.l_obs > NaD.get_sideBandLeftEdge_top()))
        NaDSideBandUp_mask = ((K.l_obs < NaD.get_sideBandRightEdge_low()) | (K.l_obs > NaD.get_sideBandRightEdge_top()))
        NaDSideBands_mask = NaDSideBandLow_mask & NaDSideBandUp_mask
        NaDSideBandsAndLine_mask = ((K.l_obs < NaD.get_sideBandLeftEdge_low()) | (K.l_obs > NaD.get_sideBandRightEdge_top()))

        # Median flux in every zone spectra
        NaDSideBands_median__z = np.median(M_rf__lz[~NaDSideBands_mask, :], axis = 0)

        # NaD Delta EW
        l_step = 2
示例#14
0
        'El_IC_6563__HII', 'El_IC_6563__G', 'HaHbC__HII', 'HaHbC__G',
        'tauT_6563__HII', 'tauC_6563__HII', 'tauC_6563__G'
]:
    outtable[outvar] = np.zeros(len(gal_ids))

# Calculate galaxy by galaxy
for ig, gal_id in enumerate(gal_ids):

    # Define file names
    pycasso_file = path.join(fits_dir % pycasso_subdir,
                             file_name % (gal_id, pycasso_suffix))
    emlines_file = path.join(fits_dir % emlines_subdir,
                             file_name % (gal_id, emlines_suffix))

    # Read the pycasso and the emission line cubes
    c = fitsQ3DataCube(pycasso_file)
    c.loadEmLinesDataCube(emlines_file)

    # Get the number of ionizing photons for the base
    shape__tZ = c.popmu_ini__tZyx.shape[:2]
    log_QH_base__tZ = t['log_QH'].reshape(shape__tZ)

    # This is just to check that the reshaping is doing the proper thing
    t__tZ = t['age_base'].reshape(shape__tZ)
    Z__tZ = t['Z_base'].reshape(shape__tZ)
    check_t = np.all(
        np.isclose(c.ageBase, 10**t__tZ[..., 0], rtol=1.e-5, atol=1e-5))
    check_Z = np.all(
        np.isclose(c.metBase, Z__tZ[0, ...], rtol=1.e-5, atol=1e-5))
    if (not check_t) | (not check_Z):
        sys.exit('Please check your square base.')
示例#15
0
#!/usr/bin/python
import sys
import numpy as np
from pycasso import fitsQ3DataCube

fitsfile = sys.argv[1]

K = fitsQ3DataCube(fitsfile)

total = K.zoneArea_pix.size
onepix = np.where(K.zoneArea_pix == 1)[0].size
morethanten = np.where(K.zoneArea_pix > 10)[0].size

onepixperc = onepix / np.double(total)
morethantenperc = morethanten / np.double(total)
z = np.double(K.masterListData['z'])

arc2rad = 0.0000048481368111
c = 3.e5
H0 = 73.

umpixpc = 1. * arc2rad * (z * c / H0) * 1.e6

print '%s & %s & $%d$ & $%d$ & $%.2f$ & $%d$ & $%.2f$ & $%.2f$ \\\\' % (K.galaxyName, K.califaID, total, onepix, onepixperc, morethanten, morethantenperc, umpixpc)
示例#16
0
    delta_tau__g        = tau_V_neb__g - tau_V__g
    EW_HaHb__z          = EW_Ha__z / EW_Hb__z
    EW_HaHb__g          = EW_Ha__g / EW_Hb__g
    
    mask_nuc__g         = dist_zone_HLR__g <= 0.5
    mask_nuc__z         = dist_zone_HLR__z <= 0.5  
    mask_disc__g        = (dist_zone_HLR__g > 0.5) & (dist_zone_HLR__g <= 2)
    mask_disc__z        = (dist_zone_HLR__z > 0.5) & (dist_zone_HLR__z <= 2)
    mask_off__g         = dist_zone_HLR__g > 2.
    mask_off__z         = dist_zone_HLR__z > 2.

    CALIFASuffix = '_synthesis_eBR_' + versionSuffix + '512.ps03.k1.mE.CCM.' + baseCode + '.fits'
    CALIFAFitsFile = superFitsDir + galName + CALIFASuffix
    galaxyImgFile = imgDir + galName + '.jpg'
     
    K = fitsQ3DataCube(CALIFAFitsFile)
    #Setup elliptical-rings geometry
    pa, ba = K.getEllipseParams()
    K.setGeometry(pa, ba)
     
    tipos, tipo, tipo_m, tipo_p = get_morfologia(galName)
     
    emLinesSuffix = '_synthesis_eBR_' + versionSuffix + '512.ps03.k1.mE.CCM.' + baseCode + '.EML.MC100.fits'
    emLinesFitsFile = emLinesFitsDir + galName + emLinesSuffix
    K.loadEmLinesDataCube(emLinesFitsFile)
    
    #nebular 
    EW_HaHb__yx         = K.zoneToYX(EW_HaHb__z, extensive = False)
    
    #EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
    # #stellar
示例#17
0
    h5file = '%s/dev/astro/PhD_dust2gas/runs/v20_q050.d15a.h5' % os.environ['HOME']
    pycasso_cube_suffix = '_synthesis_eBR_v20_q050.d15a512.ps03.k1.mE.CCM.Bgsd6e.fits'
    eml_cube_suffix = '_synthesis_eBR_v20_q050.d15a512.ps03.k1.mE.CCM.Bgsd6e.EML.MC100.fits'
    gasprop_cube_suffix = '_synthesis_eBR_v20_q050.d15a512.ps03.k1.mE.CCM.Bgsd6e.EML.MC100.GasProp.fits'
    img_dir = '%s/CALIFA/images/' % os.environ['HOME']
    pycasso_cube_file = pycasso_cube_dir + califaID + pycasso_cube_suffix
    eml_cube_file = eml_cube_dir + califaID + eml_cube_suffix
    gasprop_cube_file = gasprop_cube_dir + califaID + gasprop_cube_suffix
    default_kwargs_imshow = dict(origin='lower', interpolation='nearest', aspect='equal', cmap='viridis')
    AVtoTauV = 1. / (np.log10(np.exp(1)) / 0.4)

    tSF__T = np.array([1, 3.2, 10, 50, 100]) * 1e7
    N_T = len(tSF__T)

    # Load all data from fits
    K = fitsQ3DataCube(pycasso_cube_file)
    K.loadEmLinesDataCube(eml_cube_file)
    K.GP = GasProp(gasprop_cube_file)

    # Set galaxy geometry using ellipses
    pa, ba = K.getEllipseParams()
    K.setGeometry(pa, ba)

    tau_V__r = np.ma.masked_all((N_R_bins))
    tau_V_npts__r = np.ma.masked_all((N_R_bins))
    tau_V_me__r = np.ma.masked_all((N_R_bins))
    tau_V_me_npts__r = np.ma.masked_all((N_R_bins))
    tau_V_L__r = np.ma.masked_all((N_R_bins))

    tau_V__yx = K.A_V__yx * AVtoTauV
    tau_V__r, tau_V_npts__r = K.radialProfile(prop=tau_V__yx, bin_r=R_bin__r, rad_scale=K.HLR_pix, return_npts=True)
    frame = InitialModelFrame(None, wx.ID_ANY, image, noise, psf, model_file,
                              'Initial Model Finder', plot_title)
    frame.Show()
    app.MainLoop()
################################################################################


args = parse_args()
if args.verbose:
    logger.setLevel(-1)
    logger.debug('Verbose output enabled.')

cube = args.cube[0]
model_file = args.cube[0] + '.initmodel'
title = path.basename(cube)

logger.info('Loading cube: %s' % cube)
K = fitsQ3DataCube(args.cube[0])

logger.info('Creating PSF (FWHM=%f, beta=%f, size=%d)' % (args.psfFWHM, args.psfBeta, args.psfSize))
psf = moffat_psf(args.psfFWHM, args.psfBeta, size=args.psfSize)

flags = ~K.qMask | (K.qSignal <= 0.0) | (K.qNoise <= 0.0)
flux = np.ma.array(K.qSignal, mask=flags)
noise = np.ma.array(K.qNoise, mask=flags)

logger.info('Running GUI...')
run_app(flux, noise, psf, model_file, title)
logger.info('Exiting GUI.')

示例#19
0
        kernel = - 2 / sigma**3 * x * np.exp(-x**2 / sigma**2)
        dsigma = ndimage.convolve1d(I, kernel, mode='reflect')
        return np.array([d_I_Be, d_Re, d_I_D0, d_R0, dsigma]).T


    def __call__(self, r):
        r, fmt = _convert_input(r, self.param_dim)
        result = self.eval(r, self.param_sets)
        return _convert_output(result, fmt)
################################################################################

f_norm = 1e-17
min_rad = 2.5


K = fitsQ3DataCube('../../../cubes.200/K0127_synthesis_eBR_v20_q036.d13c512.ps03.k2.mC.CCM.Bgsd61.fits')

params = np.zeros(K.Nl_obs, dtype=[('I_Be', '<f8'), ('R_e', '<f8'), ('I_D0', '<f8'), ('R_0', '<f8'), ('sigma', '<f8'), ('pa', '<f8'), ('ba', '<f8')])
for i in xrange(993, K.Nl_obs):
    print i
    # TODO: moving average
    fl__yx = K.f_syn__lyx[i]
    pa, ba = K.getEllipseParams(fl__yx)
    K.setGeometry(pa, ba)
    mask = K.qMask & (K.pixelDistance__yx >= min_rad)
    rl = K.pixelDistance__yx[mask]
    sort_ix = np.argsort(rl)
    rl = rl[sort_ix]
    fl__r = fl__yx[mask][sort_ix] / f_norm

    gal_model = GalaxyModel(I_Be=fl__r.max(), R_e=K.HLR_pix, I_D0=fl__r.max()/2.0, R_0=K.HLR_pix, sigma=1.5)
示例#20
0
    lambda_zero = 5500.0
    dl = lambda_zero * target_vd / c
    print 'Fixing kinematics: v_d = %.1f km/s (%.1f \\AA @ 5500 \\AA) ...' % (target_vd, dl)
    flux, error, flags = fix_kinematics(K.l_obs, flux, error,
                                        flags, K.v_0, K.v_d, target_vd)
    assert np.isfinite(flux[~flags]).all()
    assert np.isfinite(error[~flags]).all()
    assert np.isfinite(flags).all()

    assert (flux[~flags] > 0.0).all()
    assert (error[~flags] > 0.0).all()
    
    return flux * K.flux_unit, error * K.flux_unit, flags, target_vd


K = fitsQ3DataCube('../cubes.px1/K0858_synthesis_eBR_px1_q050.d15a500.ps03.k1.mE.CCM.Bgsd6e.fits')
flux_fix, _, flags_fix, target_vd = fix_k(K)

flux = np.ma.array(K.f_obs, mask=K.f_flag)
flux_fix = np.ma.array(flux_fix, mask=flags_fix)


plot_setup()
width_pt = 448.07378
width_in = width_pt / 72.0 * 0.9
fig = plt.figure(figsize=(width_in, width_in * 0.7))

z = 50
norm = flux[:, z].max()

label = r'$v_0 = %d\,\mathrm{km}/\mathrm{s},\ v_d = %d\,\mathrm{km}/\mathrm{s}$' % (K.v_0[z], K.v_d[z])
示例#21
0
parser = argparse.ArgumentParser(description='Compute reddening laws.')
parser.add_argument('db', type=str, nargs=1,
                   help='CALIFA superFITS.')
parser.add_argument('--fixk', dest='fixKinematics', action='store_true',
                    help='Fix kinematics.')
parser.add_argument('--vd', dest='targetVd', default=0.0, type=float,
                    help='Velocity dispersion to be convolved with the spectra (if --fixk).')
parser.add_argument('--lll', dest='lambdaLowerLimit', default=0.0, type=float,
                    help='Lower limit in lambda when fitting.')
parser.add_argument('--outdir', dest='outdir', default='.', type=str,
                    help='Output directory for figures.')

args = parser.parse_args()

print 'Opening file %s' % args.db[0]
K = fitsQ3DataCube(args.db[0])
calId = K.califaID
pipeVer = K.header['pipe vers']
sn_vor = K.header['sn_vor']

# TODO: Parameterize the dust regions.
dust_lane_poly = {
                  'K0708': [(25.403225806451616, 41.322580645161288), (30.016129032258064, 39.370967741935488), (33.20967741935484, 40.79032258064516), (38.532258064516128, 37.951612903225808), (41.016129032258064, 38.661290322580648), (43.854838709677423, 37.064516129032256), (45.983870967741936, 35.645161290322584), (47.758064516129032, 33.516129032258064), (50.41935483870968, 31.387096774193552), (51.661290322580641, 29.79032258064516), (53.967741935483872, 26.951612903225808), (52.548387096774192, 26.064516129032256), (50.241935483870968, 27.661290322580648), (46.161290322580648, 29.08064516129032), (44.032258064516128, 30.322580645161288), (40.306451612903224, 32.451612903225808), (35.693548387096776, 33.870967741935488), (29.129032258064512, 34.58064516129032), (25.403225806451616, 36.532258064516128), (21.5, 37.596774193548384), (22.20967741935484, 39.903225806451616)],
                  'K0925': [(19.089861751152078, 27.013824884792626), (19.62903225806452, 31.327188940092171), (21.426267281105993, 35.281105990783409), (23.223502304147466, 40.133640552995395), (25.91935483870968, 43.1889400921659), (26.997695852534562, 45.345622119815673), (26.099078341013829, 47.142857142857146), (28.255760368663594, 48.940092165898619), (30.412442396313367, 49.299539170506918), (32.20967741935484, 50.018433179723502), (34.905529953917053, 48.041474654377886), (35.624423963133644, 49.479262672811068), (37.241935483870968, 50.557603686635943), (36.882488479262676, 52.714285714285722), (46.228110599078342, 56.488479262672811), (48.025345622119815, 55.230414746543786), (46.767281105990783, 51.995391705069125), (46.228110599078342, 49.479262672811068), (43.891705069124427, 48.041474654377886), (42.094470046082954, 48.221198156682028), (41.375576036866363, 46.783410138248854), (40.656682027649772, 43.009216589861758), (37.781105990783409, 39.774193548387103), (33.647465437788021, 35.640552995391708), (31.490783410138249, 31.866359447004612), (28.794930875576036, 27.912442396313367), (26.81797235023042, 23.599078341013822), (25.02073732718894, 19.824884792626726), (22.684331797235025, 16.230414746543779), (20.34792626728111, 14.433179723502302), (16.394009216589865, 16.05069124423963), (14.237327188940091, 19.285714285714285), (15.495391705069126, 22.700460829493089), (18.370967741935488, 24.317972350230413)],
                  }
dust_region_poly = {
                    'K0708': [(33.91935483870968, 37.596774193548384), (36.225806451612904, 37.774193548387096), (38.70967741935484, 37.241935483870968), (40.661290322580648, 37.241935483870968), (43.145161290322584, 35.645161290322584), (44.741935483870968, 33.870967741935488), (42.258064516129032, 33.338709677419352), (39.596774193548384, 33.693548387096776), (38.0, 34.758064516129032), (35.870967741935488, 35.112903225806456), (34.274193548387096, 35.112903225806456), (33.387096774193552, 36.177419354838712)],
                    'K0925':[(22.504608294930875, 31.866359447004612), (25.559907834101388, 34.023041474654377), (26.997695852534562, 38.336405529953922), (28.974654377880185, 40.313364055299544), (32.569124423963139, 44.447004608294932), (34.725806451612904, 43.1889400921659), (34.006912442396313, 38.875576036866363), (31.311059907834107, 37.437788018433181), (31.311059907834107, 33.843317972350235), (28.974654377880185, 31.506912442396313), (26.63824884792627, 28.990783410138249), (25.02073732718894, 27.552995391705068), (23.582949308755765, 29.170506912442399)],
                    }

# Plot customization
示例#22
0
    # doppler factor to correct wavelength
    dopp_fact = (1.0 + v_0 / const.c.to('km/s').value)
    # resample matrix
    if R is None:
        R = ReSamplingMatrixNonUniform(lorig=lorig / dopp_fact, lresam=lorig)
    return R, np.tensordot(R, Fobs__l * dopp_fact, (1, 0))


if __name__ == '__main__':
    main_CSP(sys.argv)
    import atpy
    from pycasso import fitsQ3DataCube
    from pystarlight import io
    from pystarlight.util.StarlightUtils import ReSamplingMatrixNonUniform
    K = fitsQ3DataCube(
        '/Users/lacerda/califa/legacy/q054/superfits/Bgstf6e/K0073_synthesis_eBR_v20_q054.d22a512.ps03.k1.mE.CCM.Bgstf6e.fits'
    )
    hdu = fits.open('CSPModels.fits')
    t = atpy.Table(maskfile='Mask.mC', type='starlight_mask')
    wl_sel = (K.l_obs >= t[0]['l_up'])
    for i in range(1, len(t)):
        if (t[i]['weight'] == 0.0):
            wl_sel = wl_sel & ((K.l_obs < t[i]['l_low']) |
                               (K.l_obs > t[i]['l_up']))
    t0 = hdu['BURST_INI'].data
    tau = hdu['BURST_LENGTH'].data
    tauV = hdu['TAU_V'].data
    F_CSP = hdu['F_CSP'].data
    chisquare = np.zeros((len(t0), len(tau), len(tauV), K.N_zone),
                         dtype='float')
    R = ReSamplingMatrixNonUniform(lorig=hdu['L_CSP'].data, lresam=K.l_obs)