示例#1
0
文件: runp.py 项目: jtollefs/pyplanet
freqs = oldFreqs
freqs=10.
print 'Reading input file ',sys.argv[1]

j = planet.planet('jupiter')
gasFile = 1
cloudFile = 1
if len(sys.argv) > 2:
    cloudFile = 2
j.atm.readGas(sys.argv[gasFile])
j.atm.readCloud(sys.argv[cloudFile])

j.atm.tweakAtm()
j.atm.computeProp()
regrid.regrid(j.atm,regridType=j.atm.config.regridType,Pmin=j.atm.config.pmin,Pmax=j.atm.config.pmax)
j.atm.nAtm=len(j.atm.gas[0])

b = [90.,0.0,0.2,0.4,0.6,0.7,0.8,0.9]
j.run(freqs,b=b,outputType='batch')
nfreq,nTB = splitFile()
shutil.copy('specoutputline.dat','limb.dat')

j.run('reuse','disc',outputType='batch')
dfreq,dTB = splitFile()

fp = open('runpResults.dat','a')
fn = sys.argv[1].split('/')
s = fn[-1]+'\t'
fp.write(s)
s = ''
示例#2
0
def subtract(flux1, time1, cadence, q, factor, cfilepath, centroid_type,
             cutoutdims, cluster, isolation):

    workingdir = os.getcwd()

    if centroid_type == 'e':
        os.chdir(cfilepath)
        centroids = np.loadtxt(f'{cluster}q{q}centroid.dat', delimiter=',')
        os.chdir(workingdir)
        x_shifts = centroids[:, 0]
        y_shifts = centroids[:, 1]

    # make mask first before cutting down flux
    mask = gaussmask(factor, flux1.shape[1], flux1.shape[2], isolation)

    # cut down both mask and flux, i.e. get rid of zeros
    flux1, mask = zerocutter(flux1, mask, factor)

    # prepare arrays/get dimensions etc
    if centroid_type == 'e':
        fluxnew, timenew, x_shifts, y_shifts = nc.nancleaner3d_c(
            flux1, time1, x_shifts, y_shifts)
    elif centroid_type == 't':
        fluxnew, timenew = nc.nancleaner3d(flux1, time1)
    dump, newcadence = nc.nancleaner3d(flux1, cadence)
    timespan = fluxnew.shape[0]

    # regridding
    oldy, oldx = fluxnew.shape[1], fluxnew.shape[2]  # reset dims
    newy, newx = fluxnew.shape[1] * factor, fluxnew.shape[2] * factor
    re_flux = np.zeros((timespan, newy, newx))
    shifted = np.zeros((timespan, newy, newx))

    nanmask = np.asarray(np.where(np.isnan(fluxnew) == True))
    rg_nanmask = np.array(
        (nanmask[0], nanmask[1] * factor, nanmask[2] * factor))

    for i in range(timespan):
        interpolant = spi.RectBivariateSpline(np.arange(oldy),
                                              np.arange(oldx),
                                              np.nan_to_num(fluxnew[i]),
                                              kx=1,
                                              ky=1)
        re_flux[i] = interpolant(np.linspace(0, oldy - 1, newy),
                                 np.linspace(0, oldx - 1,
                                             newx))  #/ (factor*factor)

    # regridding base cutout for plotting (oy vey)
    avg_original = np.nanmean(fluxnew, axis=0)
    regridded_base = rg.regrid(avg_original, factor)

    # centroiding
    originalmask = np.zeros(flux1[0].shape)  #+3
    originalmask[cutoutdims - 2:cutoutdims + 1,
                 cutoutdims - 2:cutoutdims + 1] += 3  # 3x3 box for checking
    mask_rg = rg.regrid_slow(originalmask, factor)
    if centroid_type == 't':
        x_cent, y_cent = ct.centroid(timespan, re_flux, mask_rg)
        midx, midy = (newx - 1) / 2, (newy - 1) / 2
        x_shifts = (x_cent - midx)
        y_shifts = (y_cent - midy)
    elif centroid_type == 'e':
        x_cent = 0
        y_cent = 0

    for i in range(timespan):
        interpolant = spi.RectBivariateSpline(np.arange(newy),
                                              np.arange(newx),
                                              re_flux[i, :, :],
                                              kx=1,
                                              ky=1)
        # interpolant = spi.interp2d(np.arange(newy), np.arange(newx), re_flux[i,:,:], kind='cubic')
        shifted[i, :, :] = interpolant(
            np.linspace(0 - y_shifts[i], newy - y_shifts[i], newy),
            np.linspace(0 - x_shifts[i], newx - x_shifts[i], newx))

    avgshift = np.nanmean(shifted, axis=0)

    # mask making
    maskrange = np.nanmax(avgshift) - np.nanmin(avgshift)
    # maskmax = np.nanmax(avgshift) - 0.5 * maskrange
    maskmin = np.nanmin(avgshift) + 0.05 * maskrange  # cut for background

    # defining six different standard masks
    # maskarr = np.zeros((6,newy,newx))
    # maskarr[0][(cutoutdims-1)*factor:cutoutdims*factor,(cutoutdims-1)*factor:cutoutdims*factor] +=1
    # maskarr[1][(cutoutdims-2)*factor:(cutoutdims+1)*factor,(cutoutdims-1)*factor:cutoutdims*factor] += 1
    # maskarr[1][(cutoutdims-1)*factor:cutoutdims*factor,(cutoutdims-2)*factor:(cutoutdims-1)*factor] += 1
    # maskarr[1][(cutoutdims-1)*factor:cutoutdims*factor,cutoutdims*factor:(cutoutdims+1)*factor] += 1
    # maskarr[2] += 1
    # maskarr[3] += circle(9, factor, oldy, oldx)
    # maskarr[4] += circle(5, factor, oldy, oldx)
    # maskarr[5] += circle(3, factor, oldy, oldx)
    # if mask != None:
    #    maskarr = np.delete(maskarr, np.delete(np.arange(6), mask), axis=0)

    # annulus
    mask_bg = np.zeros((newy, newx))
    counter = 0
    for index, val in np.ndenumerate(avgshift):
        if avgshift[index] < maskmin:  # and np.isnan(avgshift[index]) == False:
            mask_bg[index] = -1
            counter += 1

    # calculating background
    lclength = len(timenew)
    for j in range(lclength):
        bg = np.nansum(shifted[j][np.where(mask_bg == -1)])
        bg /= counter
        shifted[j] -= bg

    avgflux = np.nanmean(shifted, axis=0)  # new average image after
    output = np.c_[newcadence, timenew]

    new_flux = np.zeros(lclength)

    ap_av = np.nansum(avgflux * mask)
    for j in range(lclength):
        placeholder = shifted[j] - avgflux
        aperture = np.nansum(placeholder * mask)
        # annulus = sum(placeholder[np.where(mask==-1)])
        # annulus /= counter
        new_flux[j] = aperture + ap_av  #- annulus

    output = np.c_[output, new_flux]

    # for deprecated version with multiple masks:
    # for i in range(maskarr.shape[0]):
    #    new_flux = np.zeros(lclength)

    #    ap_av = np.nansum(avgflux[np.where(maskarr[i]==1)])
    #    for j in range(lclength):
    #       placeholder = shifted[j] - avgflux
    #       aperture = np.nansum(placeholder[np.where(maskarr[i]==1)])
    #       # annulus = sum(placeholder[np.where(mask==-1)])
    #       # annulus /= counter
    #       new_flux[j] = aperture + ap_av #- annulus

    #    output = np.c_[output, new_flux]

    return output, mask, avgflux, regridded_base, x_cent, y_cent  # prev maskarr
dset_nb_days['thresh'] = ('thresh', np.array([0, 1, 5]))
dset_nb_days['nbdays'] = (('thresh','lat','lon'), arr_nb)

dset_nb_days = xr.Dataset(dset_nb_days)

# dset_nb_days.sel(thresh=5)['nbdays'].plot()

new_res = 5

new_lon = np.linspace(lon[0], lon[-1], len(lon) * new_res, endpoint=True)

new_lat = np.linspace(lat[0], lat[-1], len(lat) * new_res, endpoint=True)

dset_30_days.load()

new_lon, new_lat, matm = regrid(dset_30_days.sum('time')['trmm'].data, lon, lat, new_lon, new_lat)

lons, lats = np.meshgrid(new_lon, new_lat)

sys.path.append(os.path.join(os.environ['HOME'], 'pythonlibs'))

import nclcmaps as ncm

cmap = ncm.cmap('GMT_drywet')

proj = ccrs.PlateCarree()

f, ax = plt.subplots(figsize=(10, 8), subplot_kw=dict(projection=proj))

ax.set_extent([domain['lonmin'], domain['lonmax'], domain['latmin'], domain['latmax']])
示例#4
0
def sapper(flux1, time1, cadence, q, factor, cutoutdims, isolation):

    workingdir = os.getcwd()

    # regridding
    fluxnew, timenew = nc.nancleaner3d(flux1, time1)

    # make mask first before cutting down flux
    mask = gaussmask(factor, flux1.shape[1], flux1.shape[2], isolation)

    # cut down both mask and flux, i.e. get rid of zeros
    flux1, mask = zerocutter(flux1, mask, factor)

    dump, newcadence = nc.nancleaner3d(flux1, cadence)
    timespan = fluxnew.shape[0]
    oldy, oldx = fluxnew.shape[1], fluxnew.shape[2]
    newy, newx = fluxnew.shape[1] * factor, fluxnew.shape[2] * factor
    re_flux = np.zeros((timespan, newy, newx))

    nanmask = np.asarray(np.where(np.isnan(fluxnew) == True))
    rg_nanmask = np.array(
        (nanmask[0], nanmask[1] * factor, nanmask[2] * factor))

    for i in range(timespan):
        re_flux[i] = rg.regrid(fluxnew[i], factor)

    # regridding base cutout for plotting (oy vey)
    avg_original = np.mean(fluxnew, axis=0)
    regridded_base = rg.regrid(avg_original, factor)
    avgflux = np.mean(re_flux, axis=0)

    # mask making
    maskrange = np.nanmax(avgflux) - np.nanmin(avgflux)
    maskmin = np.nanmin(avgflux) + 0.05 * maskrange  # cut for background

    # annulus
    mask_bg = np.zeros((newy, newx))
    counter = 0
    for index, val in np.ndenumerate(avgflux):
        if avgflux[index] < maskmin:  # and np.isnan(avgshift[index]) == False:
            mask_bg[index] = -1
            counter += 1

    # calculating background
    lclength = len(timenew)
    for j in range(lclength):
        bg = np.nansum(re_flux[j][np.where(mask_bg == -1)])
        bg /= counter
        re_flux[j] -= bg

    avgflux = np.mean(re_flux, axis=0)  # new average image after
    output = np.c_[newcadence, timenew]

    ap_av = np.nansum(avgflux * mask)

    new_flux = np.zeros(lclength)

    for j in range(lclength):
        placeholder = re_flux[j] - avgflux
        aperture = np.nansum(placeholder * mask)
        # annulus = sum(placeholder[np.where(mask==-1)])
        # annulus /= counter
        new_flux[j] = aperture + ap_av  #- annulus

    output = np.c_[output, new_flux]

    return output, mask, avgflux, regridded_base
示例#5
0
freqs = oldFreqs
freqs = 10.
print 'Reading input file ', sys.argv[1]

j = planet.planet('jupiter')
gasFile = 1
cloudFile = 1
if len(sys.argv) > 2:
    cloudFile = 2
j.atm.readGas(sys.argv[gasFile])
j.atm.readCloud(sys.argv[cloudFile])

j.atm.tweakAtm()
j.atm.computeProp()
regrid.regrid(j.atm,
              regridType=j.atm.config.regridType,
              Pmin=j.atm.config.pmin,
              Pmax=j.atm.config.pmax)
j.atm.nAtm = len(j.atm.gas[0])

b = '0.0,0.2,0.4,0.6,0.7,0.8,0.9<90'
j.run(freqs, b=b, outputType='batch')
nfreq, nTB = splitFile()
shutil.copy('specoutputline.dat', 'limb.dat')

j.run('reuse', 'disc', outputType='batch')
dfreq, dTB = splitFile()

fp = open('runpResults.dat', 'a')
fn = sys.argv[1].split('/')
s = fn[-1] + '\t'
fp.write(s)
示例#6
0
    def run(self,Pmin=None,Pmax=None,regridType=None,gasType=None,cloudType=None,otherType=None,tweak=True,plot=None,verbose=None):
        """This is the standard pipeline"""
        ###Set run defaults
        if Pmin == None:
            Pmin = self.config.pmin
        if Pmax == None:
            Pmax = self.config.pmax
        if regridType == None:
            regridType = self.config.regridType
        if verbose==None:
            verbose = self.verbose
        if plot==None:
            plot = self.plot
        if gasType==None:
            gasType = self.config.gasType
        if cloudType==None:
            cloudType = self.config.cloudType
        if otherType==None:
            otherType = self.config.otherType
        self.nAtm = 0

        ### Generate gas profile (gasType is 'read' or 'compute')
        if not self.gasGen.has_key(gasType):
            print 'Error:  No such gasType: '+gasType
            return 0
        else:
            self.gasGen[gasType](verbose=verbose)

        if not self.batch:
            ### Generate cloud profile (cloudType is 'read' or 'compute')
            if not self.cloudGen.has_key(cloudType):
                print 'Error:  No such cloudType: '+cloudType
                return 0
            else:
                self.cloudGen[cloudType](verbose=verbose)

            if tweak:  # This loads and calls the module 'tweakFile'
                self.tweakAtm()

            ### Compute other parameters that are needed
            if not self.propGen.has_key(self.config.otherType):
                print 'Error:  no such otherTpe: '+otherType
                return 0
            else:
                self.propGen[otherType](verbose=verbose)

            ### Put onto common grid
            regridded = regrid.regrid(self,regridType=regridType,Pmin=Pmin,Pmax=Pmax)
            self.nAtm = len(self.gas[0])

            angularDiameter = 2.0*math.atan(self.layerProperty[self.config.LP['R']][0]/self.config.distance)
            print 'angular radius = %f arcsec' % ((180.0/np.pi)*3600.0*angularDiameter/2.0)
        
            ### Plot data
            if plot:
                self.plotTP()
                self.plotGas()
                self.plotCloud()
                self.plotProp()

        return self.nAtm
示例#7
0
    def run(self, Pmin=None, Pmax=None, regridType=None, gasType=None, cloudType=None, otherType=None, tweak=True):
        """This is the standard pipeline"""
        # ##Set run defaults
        if Pmin is None:
            Pmin = self.config.pmin
        if Pmax is None:
            Pmax = self.config.pmax
        if regridType is None:
            regridType = self.config.regridType
        if gasType is None:
            gasType = self.config.gasType
        if cloudType is None:
            cloudType = self.config.cloudType
        if otherType is None:
            otherType = self.config.otherType

        # ## Generate gas profile
        if gasType not in self.gasGen.keys():
            print('Error:  No such gasType: ', gasType)
            return 0
        else:
            self.gasGen[gasType]()
        self.nAtm = len(self.gas[0])

        if self.batch_mode:
            return self.nAtm

        self.chem = {}
        for key in self.config.C:
            if key in ['P', 'T', 'Z', 'DZ']:
                continue
            self.chem[key] = chemistry.ConstituentProperties(key)

        # ## Generate cloud profile
        if cloudType not in self.cloudGen.keys():
            print('Error:  No such cloudType: ', cloudType)
            return 0
        else:
            self.cloudGen[cloudType]()

        # ## Put onto common grid
        if self.verbose:
            print("Regrid:  {}".format(regridType))
        regridded = regrid.regrid(self, regridType=regridType, Pmin=Pmin, Pmax=Pmax)
        self.nAtm = len(self.gas[0])

        if tweak:  # This loads and calls the module as given in the config.par tweakmodule parameter
            self.tweakAtm()

        # ## Compute other parameters that are needed
        if self.config.otherType not in self.propGen.keys():
            print('Error:  no such otherTpe: ', otherType)
            return 0
        else:
            self.propGen[otherType]()

        angularDiameter = 2.0 * math.atan(self.layerProperty[self.config.LP['R']][0] / self.config.distance)
        if self.verbose == 'loud':
            print('angular radius = {} arcsec'.format(utils.r2asec(angularDiameter / 2.0)))

        # ## Plot data
        if self.plot:
            self.plotTP()
            self.plotGas()
            self.plotCloud()
            self.plotProp()

        return self.nAtm
示例#8
0
    def run(self,
            Pmin=None,
            Pmax=None,
            regridType=None,
            gasType=None,
            cloudType=None,
            otherType=None,
            tweak=True):
        """This is the standard pipeline"""
        # ##Set run defaults
        if Pmin is None:
            Pmin = self.config.pmin
        if Pmax is None:
            Pmax = self.config.pmax
        if regridType is None:
            regridType = self.config.regridType
        if gasType is None:
            gasType = self.config.gasType
        if cloudType is None:
            cloudType = self.config.cloudType
        if otherType is None:
            otherType = self.config.otherType

        # ## Generate gas profile
        if gasType not in self.gasGen.keys():
            print('Error:  No such gasType: ', gasType)
            return 0
        else:
            self.gasGen[gasType]()
        self.nAtm = len(self.gas[0])

        if self.batch_mode:
            return self.nAtm

        self.chem = {}
        for key in self.config.C:
            if key in ['P', 'T', 'Z', 'DZ']:
                continue
            self.chem[key] = chemistry.ConstituentProperties(key)

        # ## Generate cloud profile
        if cloudType not in self.cloudGen.keys():
            print('Error:  No such cloudType: ', cloudType)
            return 0
        else:
            self.cloudGen[cloudType]()

        # ## Put onto common grid
        if self.verbose:
            print("Regrid:  {}".format(regridType))
        regridded = regrid.regrid(self,
                                  regridType=regridType,
                                  Pmin=Pmin,
                                  Pmax=Pmax)
        self.nAtm = len(self.gas[0])

        if tweak:  # This loads and calls the module as given in the config.par tweakmodule parameter
            self.tweakAtm()

        # ## Compute other parameters that are needed
        if self.config.otherType not in self.propGen.keys():
            print('Error:  no such otherTpe: ', otherType)
            return 0
        else:
            self.propGen[otherType]()

        angularDiameter = 2.0 * math.atan(
            self.layerProperty[self.config.LP['R']][0] / self.config.distance)
        if self.verbose == 'loud':
            print('angular radius = {} arcsec'.format(
                utils.r2asec(angularDiameter / 2.0)))

        # ## Plot data
        if self.plot:
            self.plotTP()
            self.plotGas()
            self.plotCloud()
            self.plotProp()

        return self.nAtm