コード例 #1
0
    def run_mctherm(self):
        logger.info("Executing RADMC3D with mctherm mode")

        if not os.path.isdir(self.radmc_dir):
            msg = "radmc working directory not found: {self.radmc_dir}"
            raise FileNotFoundError(msg)

        tools.shell(
            f"radmc3d mctherm setthreads {self.n_thread}",
            cwd=self.radmc_dir,
            error_keyword="ERROR",
            log_prefix="    ",
        )

        cwd = os.getcwd()
        os.chdir(self.radmc_dir)
        self.rmcdata = rmca.readData(ispec=self.molname)  # radmc3dData()
        os.chdir(cwd)
コード例 #2
0
def getGasAbundance(grid=None, ppar=None, ispec=''):
    """
    Function to create the conversion factor from volume density to number density of molecule ispec.
    The number density of a molecule is rhogas * abun

    INPUT:
    ------
        grid - An instance of the radmc3dGrid class containing the spatial and wavelength grid
        ppar - Dictionary containing all parameters of the model
        ispec - The name of the gas species whose abundance should be calculated

    OUTPUT:
    -------
        returns the abundance as a Numpy array
    """

    # Read the dust density and temperature
    try:
        data = readData(ddens=True, dtemp=True, binary=True)
    except:
        try:
            data = readData(ddens=True, dtemp=True, binary=False)
        except:
            print 'WARNING!!'
            print 'No data could be read in binary or in formatted ascii format'
            print '  '
            return 0

    # Calculate continuum optical depth
    data.getTau(axis='xy', wav=0.55)


    nspec = len(ppar['gasspec_mol_name'])
    if ppar['gasspec_mol_name'].__contains__(ispec):

        sid   = ppar['gasspec_mol_name'].index(ispec)
        # Check where the radial and vertical optical depth is below unity
        gasabun = np.zeros([grid.nx, grid.ny, grid.nz], dtype=np.float64)

        for spec in range(nspec):
            gasabun[:,:,:] = ppar['gasspec_mol_abun'][sid]


        for iz in range(data.grid.nz):
            for iy in range(data.grid.ny):
                ii = (data.taux[:,iy,iz]<ppar['gasspec_mol_dissoc_taulim'][sid])
                gasabun[ii,iy,iz] = 1e-90

                ii = (data.dusttemp[:,iy,iz,0]<ppar['gasspec_mol_freezeout_temp'][sid])
                gasabun[ii,iy,iz] =  ppar['gasspec_mol_abun'][sid] * ppar['gasspec_mol_freezeout_dfact'][sid]

        #for iz in range(data.grid.nz):
            #for iy in range(data.grid.ny/2):

                #ii = (data.tauy[:,iy,iz]<ppar['gasspec_mol_dissoc_taulim'][sid])
                #gasabun[ii,iy,iz] = 1e-90
                #gasabun[ii,data.grid.ny-1-iy,iz] = 1e-90

    else:
        gasabun = np.zeros([grid.nx, grid.ny, grid.nz], dtype=np.float64) + 1e-10
        print 'WARNING !!!'
        print 'Molecule name "'+ispec+'" is not found in gasspec_mol_name'
        print 'A default 1e-10 abundance will be used'
        print ' '



    #gasabun = np.zeros([grid.nx, grid.ny, grid.nz], dtype=np.float64)
    #gasabun[:,:,:] = ppar['gasspec_mol_abun'][0] / (2.4*mp)

    return gasabun
コード例 #3
0
ファイル: ppdisk.py プロジェクト: psheehan/radmc3d-0.41
def getGasAbundance(grid=None, ppar=None, ispec=''):
    """Calculates the molecular abundance. 
    
    The number density of a molecule is rhogas * abun 
   
    Parameters
    ----------
    grid  : radmc3dGrid
            An instance of the radmc3dGrid class containing the spatial and wavelength grid
    
    ppar  : dictionary
            Dictionary containing all parameters of the model 
    
    ispec : str
            The name of the gas species whose abundance should be calculated

    Returns
    -------
    Returns an ndarray containing the molecular abundance at each grid point
    """

    # Read the dust density and temperature
    try: 
        data = analyze.readData(ddens=True, dtemp=True, binary=True)
    except:
        try: 
            data = analyze.readData(ddens=True, dtemp=True, binary=False)
        except:
            print('WARNING!!')
            print('No data could be read in binary or in formatted ascii format')
            print('  ')
            return 0

    # Calculate continuum optical depth 
    data.getTau(axis='xy', wav=0.55)
    

    nspec = len(ppar['gasspec_mol_name'])
    if ppar['gasspec_mol_name'].__contains__(ispec):

        sid   = ppar['gasspec_mol_name'].index(ispec)
        # Check where the radial and vertical optical depth is below unity
        gasabun = np.zeros([grid.nx, grid.ny, grid.nz], dtype=np.float64)  
        
        for spec in range(nspec):
            gasabun[:,:,:] = ppar['gasspec_mol_abun'][sid]
           

        for iz in range(data.grid.nz):
            for iy in range(data.grid.ny):
                ii = (data.taux[:,iy,iz]<ppar['gasspec_mol_dissoc_taulim'][sid])
                gasabun[ii,iy,iz] = 1e-90

                ii = (data.dusttemp[:,iy,iz,0]<ppar['gasspec_mol_freezeout_temp'][sid])
                gasabun[ii,iy,iz] =  ppar['gasspec_mol_abun'][sid] * ppar['gasspec_mol_freezeout_dfact'][sid]
        
        #for iz in range(data.grid.nz):
            #for iy in range(data.grid.ny/2):

                #ii = (data.tauy[:,iy,iz]<ppar['gasspec_mol_dissoc_taulim'][sid])
                #gasabun[ii,iy,iz] = 1e-90
                #gasabun[ii,data.grid.ny-1-iy,iz] = 1e-90

    else:
        gasabun = np.zeros([grid.nx, grid.ny, grid.nz], dtype=np.float64) + 1e-10
        print('WARNING !!!')
        print('Molecule name "'+ispec+'" is not found in gasspec_mol_name')
        print('A default 1e-10 abundance will be used')
        print(' ' )



    #gasabun = np.zeros([grid.nx, grid.ny, grid.nz], dtype=np.float64) 
    #gasabun[:,:,:] = ppar['gasspec_mol_abun'][0] / (2.4*mp)

    return gasabun
コード例 #4
0
def commence(rundir, polunitlen=-2, dis=400, polmax=None, 
        dooutput_op=1, pltopwav=None, 
        dooutput_im=1, imlim=None, imUnits=None, imxlim=None, imylim=None,opltr=None,imaxisUnits='au',
        dooutput_wavim=1, anglim=None, angcmap=None, 
        dooutput_xy=0, xyinx=None, tdxlim=None, tdylim=None, 
        dooutput_minor=0, 
        dooutput_stokes=0,
        dooutput_conv=0, fwhm=None, pa=[[0]], 
        dooutput_alpha=0, 
        dooutput_fits=0, bwidthmhz=2000., coord='03h10m05s -10d05m30s',
        dooutput_los=0, dokern=False, 
        dooutput_sed=0, pltsed=None, 
        dooutput_compreal=0
        ):
    """
    dooutput_conv : bool
        to output the convolved images
    imlim : list
           list of two elements for vmin, vmax of output_im image
    imxlim : tuple
        x coordinate limit for image in AU
    imylim : tuple
        y coordinate limit for image in AU
    xyinx : tuple
            2 element tuple to specify which image to plot xy. 
            In (a,b) where a is the index for inclination and b is for wavelength
    tdxlim : tuple
    tdylim : tuple
        2 element tuple
    fwhm : list
         number of different resolutions by number of wavelengths in image.out
    pa   : list
         number of different resolutions by number of wavelengths in image.out

    pltsed : 2d array
             [0,:] for wavelength
             [1,:] for observed flux
    opltr : list of floats
        the radii that is desired for overplot in au
    """

    if os.path.isdir(rundir) is False:
        raise ValueError('rundir does not exist: %s'%rundir)

    # stokes inputs for fits files
    stokespref = ['I', 'Q', 'U', 'V']

    # inclinations for image
    fname = os.path.join(rundir, 'inp.imageinc')
    imageinc = fntools.zylreadvec(fname)
    ninc = len(imageinc)

    # read parameter file
    parobj = params.radmc3dPar()
    parobj.readPar(fdir=rundir)

    # opacity
    op = dustopac.radmc3dDustOpac()
    res = op.readMasterOpac(fdir=rundir)
    op.readOpac(fdir=rundir, ext=res['ext'], scatmat=res['scatmat'], alignfact=res['align'][0])
    fkabs = interpolate.interp1d(op.wav[0], op.kabs[0], kind='linear')
    fksca = interpolate.interp1d(op.wav[0], op.ksca[0], kind='linear')
    dinfo = op.readDustInfo()
    if res['align'][0]:
        kpara90 = op.kpara[0][0,-1]
        korth90 = op.korth[0][0,-1]
    else:
        kpara90 = 1.
        korth90 = 1.

    # read dust density and temperature
    dat = analyze.readData(fdir=rundir, binary=False, ddens=True, dtemp=True)
    # see if heatsource.inp exists to read accretion luminosity
    if os.path.isfile(os.path.join(rundir, 'heatsource.inp')):
        qvisdat = analyze.readData(fdir=rundir, binary=False, qvis=True)
        acclum = qvisdat.getHeatingLum()
    else:
        acclum = 0.

    temp2d = np.squeeze(dat.dusttemp[:,:,0,0])
    if dokern:
        kern = np.array([[1,1,1,1,1], 
                         [1,2,2,2,1],
                         [1,2,3,2,1], 
                         [1,2,2,2,1],
                         [1,1,1,1,1]], dtype=np.float64)
        kern = kern / sum(kern)
        temp2d = convolve(temp2d, kern, boundary='fill', fill_value=0.)
    rho2d = np.squeeze(dat.rhodust[:,:,0,0])
    reg = rho2d < 1e-32
    rho2d[reg] = 1e-32
    rholog = np.log10(rho2d)
    raxis = dat.grid.xi
    rstg = dat.grid.x
    ttaaxis = dat.grid.yi
    ttastg = dat.grid.y

    # output opacity
    if dooutput_op:
        pngname = rundir+'/out_opacity.png'
        getOutput_op(op, res, dinfo, pngname, pltopwav=pltopwav)

    # spectrum
    if dooutput_sed and os.path.isfile('inp.spectruminc'):
        star = star = radsources.radmc3dRadSources()
        star.readStarsinp(fdir=rundir)
        sedinc = fntools.zylreadvec('inp.spectruminc')
        nsedinc = len(sedinc)
        for ii in range(nsedinc):
           fname = rundir + '/myspectrum.i%d.out'%(sedinc[ii])
           spec = image.radmc3dImage()
           spec.readSpectrum(fname=fname, dpc=dis)
           pngname = rundir + '/out_sed.i%d.png'%(sedinc[ii])
           getOutput_sed(spec, pngname, star=star, pltsed=pltsed)

    # start iterating image related 
    for ii in range(ninc):
        fname = os.path.join(rundir, 'myimage.i%d.out'%(imageinc[ii]))
        im = image.readImage(fname=fname)

        fname = os.path.join(rundir, 'mytausurf1.i%d.out'%(imageinc[ii]))
        if os.path.isfile(fname):
            tauim = image.readImage(fname=fname)
        else:
            tauim = None

        fname = rundir + '/mytau3d.i%d.out'%(imageinc[ii])
        if os.path.isfile(fname):
            tau3d = image.readTauSurf3D(fname=fname)
        else:
            tau3d = None

        fname = os.path.join(rundir,'myoptdepth.i%d.out'%(imageinc[ii]))
        if os.path.isfile(fname):
            optim = image.readImage(fname=fname)
        else:
            optim = None
 
        camwavfile = os.path.join(rundir, 'camera_wavelength_micron.inp.image')
        if os.path.isfile(camwavfile):
            camwav = image.readCameraWavelength(fname=rundir+'/camera_wavelength_micron.inp.image')
        else:
            camwav = im.wav
        ncamwav = len(camwav)

        # line of sight properties along minor axis
        if dooutput_minor or dooutput_los:
            ylostemp = range(im.ny)
            ylosdens = range(im.ny)
            for iy in range(im.ny):
                ym = im.y[iy]
                lostemp = los.extract(imageinc[ii]*natconst.rad, ym, temp2d, 
                    raxis, rstg,ttaaxis,ttastg,0.)
                losdens = los.extract(imageinc[ii]*natconst.rad, ym, rholog, 
                    raxis, rstg,ttaaxis,ttastg,-32.)
                losdens['valcell'] = 10.**(losdens['valcell'])
                losdens['valwall'] = 10.**(losdens['valwall'])
                ylostemp[iy] = lostemp
                ylosdens[iy] = losdens

        # plot images through all wavelengths
        if dooutput_wavim:
            pngname = rundir + '/out_wavim.i%d.png'%imageinc[ii]
            getOutput_wavim(im, dis, pngname, imTblim=imlim, imxlim=imxlim, imylim=imylim, 
                opltr=opltr, inc=imageinc[ii], anglim=anglim, angcmap=angcmap)

        # plot spectral index through all wavelengths
        if dooutput_alpha and (ncamwav > 0):
            pngname = rundir + '/out_alpha.i%d.png'%(imageinc[ii])
            getOutput_alpha(im, op, pngname, opltr=opltr, inc=imageinc[ii])

        ifreq = 0
        for ifreq in range(ncamwav):
            kext = fkabs(camwav[ifreq]) + fksca(camwav[ifreq])

            if dooutput_im:
                pngname = rundir+'/out_im.i%d.f%d.png'%(imageinc[ii],camwav[ifreq])
                getOutput_im(ifreq, dis, im, optim, tauim, polunitlen, fkabs, fksca, 
                    pngname, polmax=polmax, imlim=None, imUnits='Tb', 
                    xlim=imxlim, ylim=imylim, 
                    opltr=opltr, inc=imageinc[ii], axisUnits=imaxisUnits)

            if dooutput_xy:
                if xyinx is not None:
                    if (xyinx[0] == ii) and (xyinx[1] == ifreq):
                        pngname = rundir+'/out_xy.i%d.f%d.png'%(imageinc[ii],camwav[ifreq])
                        getOutput_xy(ifreq, tau3d, dat, acclum, tdxlim, tdylim, pngname=pngname, parobj=parobj)

                else:
                    pngname = rundir+'/out_xy.i%d.f%d.png'%(imageinc[ii],camwav[ifreq])
                    getOutput_xy(ifreq, tau3d, dat, acclum, tdxlim, tdylim, pngname=pngname, parobj=parobj)

            if dooutput_minor:
                pngname=rundir+'/out_minor.i%d.f%d.png'%(imageinc[ii],camwav[ifreq])
                getOutput_minor(ifreq, im, optim, kpara90, korth90, kext, 
                            ylostemp, ylosdens, pngname)
            if dooutput_stokes:
                pngname=rundir+'/out_stokes.i%d.f%d.png'%(imageinc[ii],camwav[ifreq])
                getOutput_stokes(ifreq, dis, im, pngname, polmax=polmax)

            if dooutput_los:
                pngname = rundir + '/out_los.i%d.f%d.png'%(imageinc[ii],camwav[ifreq])
                getOutput_los(camwav[ifreq], fkabs, fksca, losdens, lostemp, pngname)

            if dooutput_fits:
            # output to fits file
                if im.stokes: #if stokes image
                    for isk in range(4):
                        fitsname = os.path.join(rundir, 'myimage.i%d.f%d.%s.fits'%(imageinc[ii], camwav[ifreq],stokespref[isk]) )
                        im.writeFits(fname=fitsname, dpc=dis, casa=True, 
                            bandwidthmhz=bwidthmhz, coord=coord, 
                            stokes=stokespref[isk], ifreq=ifreq, overwrite=True)
                else:
                    fitsname = os.path.join(rundir, 'myimage.i%d.f%d.fits'%(imageinc[ii], camwav[ifreq]) )
                    im.writeFits(fname=fitsname, dpc=dis, casa=True,
                        bandwidthmhz=bwidthmhz, coord=coord, 
                        stokes='I', ifreq=ifreq, overwrite=True)


        if (dooutput_conv) & (fwhm is not None):
            npa = len(pa)
            for ipa in range(npa):
                conv = im.imConv(dpc=dis, psfType='gauss', fwhm=fwhm[ipa], pa=pa[ipa])

                # plot convolved image through all wavelengths
                if dooutput_wavim:
                    pngname = rundir + '/out_wavim.i%d.b%d.png'%(imageinc[ii], ipa)
                    getOutput_wavim(conv, dis, pngname, imTblim=imlim, 
                        imxlim=imxlim, imylim=imylim, opltr=opltr, inc=imageinc[ii], 
                        anglim=anglim, angcmap=angcmap)

                for ifreq in range(ncamwav):
                    if dooutput_im:
                        pngname = rundir+'/out_im.i%d.f%d.b%d.png'%(imageinc[ii],camwav[ifreq], ipa)
                        getOutput_im(ifreq, dis, conv, optim, tauim, polunitlen, 
                            fkabs, fksca, pngname, polmax=polmax, 
                            imlim=imlim, imUnits=imUnits, 
                            xlim=imxlim, ylim=imylim, opltr=opltr, inc=imageinc[ii], 
                            axisUnits=imaxisUnits)

#                    if dooutput_xy:
#                        pngname = rundir+'/out_xy.i%d.f%d.b%d.png'%(imageinc[ii],camwav[ifreq], ipa)
#                        getOutput_xy(ifreq, tauim, tau3d, dat, pngname)

                    if dooutput_minor:
                        pngname=rundir+'/out_minor.i%d.f%d.b%d.png'%(imageinc[ii],camwav[ifreq], ipa)
                        getOutput_minor(ifreq, conv, optim, kpara90, korth90, kext, 
                            ylostemp, ylosdens, pngname)
                    if dooutput_stokes:
                        pngname=rundir+'/out_stokes.i%d.f%d.b%d.png'%(imageinc[ii],camwav[ifreq], ipa)
                        getOutput_stokes(ifreq, dis, conv, pngname, polmax=polmax)

                    if dooutput_fits:
                        if conv.stokes:
                            for isk in range(4):
                                fitsname = os.path.join(rundir, 'myimage.i%d.f%d.%s.b%d.fits'%(imageinc[ii], camwav[ifreq],stokespref[isk], ipa))
                                conv.writeFits(fname=fitsname, dpc=dis, casa=True, 
                                    bandwidthmhz=bwidthmhz, coord=coord, 
                                    stokes=stokespref[isk], ifreq=ifreq, overwrite=True)
                        else:
                            fitsname = os.path.join(rundir, 'myimage.i%d.f%d.b%d.fits'%(imageinc[ii], camwav[ifreq], ipa))
                            conv.writeFits(fname=fitsname, dpc=dis, casa=True, 
                                bandwidthmhz=bwidthmhz, coord=coord, 
                                stokes='I', ifreq=ifreq, overwrite=True)
                # free up this memory
                del conv

        # free up the memory before going to next iteration
        del im
        del tauim
        del tau3d
        del optim