コード例 #1
0
           
           
        # airmass
        airmass=airmass_num
        amfileindex=int(airmass_num*1000)
        
        # Ozone    
        oz_val=oz_num
        oz_str='O3 '+str(oz_num)+ ' DU'
        ozfileindex=int(oz_num/10.)
        
            
        BaseFilename=BaseFilename_part1+atmkey+'_'+Proc+'_'+Mod+'_z'+str(amfileindex)+'_'+WVXX+str(wvfileindex) +'_'+OZXX+str(ozfileindex)                   
                    
        verbose=True
        uvspec = UVspec.UVspec()
        uvspec.inp["data_files_path"]  =  libradtranpath+'data'                
        uvspec.inp["atmosphere_file"]  = libradtranpath+'data/atmmod/'+atmosphere+'.dat'
        uvspec.inp["albedo"]           = '0.2' # doesn't matter
    
        uvspec.inp["rte_solver"] = rte_eq
            
            
                
        if Mod == 'rt':
            uvspec.inp["mol_abs_param"] = molmodel + ' ' + molresol
        else:
            uvspec.inp["mol_abs_param"] = molmodel

        # Convert airmass into zenith angle 
        am=airmass
def ProcessSimulationaer2(airmass_num, pwv_num, oz_num, alpha_num, beta_num,
                          press_num):
    """
    ProcessSimulationaer2(airmass_num,pwv_num,oz_num,alpha_num,beta_num)
    with aerosol simulation is performed
    default profile
    """

    print '--------------------------------------------'
    print ' 1) airmass = ', airmass_num
    print ' 2) pwv = ', pwv_num
    print ' 3) oz = ', oz_num
    print ' 4) alpha = ', alpha_num
    print ' 5) beta = ', beta_num
    print ' 6) pressure =', press_num
    print '--------------------------------------------'

    ensure_dir(TOPDIR)

    # build the part 1 of filename
    BaseFilename_part1 = Prog + '_' + Obs + '_' + Rte + '_'

    Proc = 'as'  # Absoprtion + Rayleigh + aerosols

    # Set up type of run
    runtype = 'aerosol_special'  #'no_scattering' #aerosol_special #aerosol_default# #'clearsky'#
    if Proc == 'sc':
        runtype = 'no_absorption'
        outtext = 'no_absorption'
    elif Proc == 'ab':
        runtype = 'no_scattering'
        outtext = 'no_scattering'
    elif Proc == 'sa':
        runtype == 'clearsky'
        outtext = 'clearsky'
    elif Proc == 'ae':
        runtype = 'aerosol_default'
        outtext = 'aerosol_default'
    elif Proc == 'as':
        runtype = 'aerosol_special'
        outtext = 'aerosol_special'
    else:
        runtype == 'clearsky'
        outtext = 'clearsky'

#   Selection of RTE equation solver
    if Rte == 'pp':  # parallel plan
        rte_eq = 'disort'
    elif Rte == 'ps':  # pseudo spherical
        rte_eq = 'sdisort'

#   Selection of absorption model
    molmodel = 'reptran'
    if Mod == 'rt':
        molmodel = 'reptran'
    if Mod == 'lt':
        molmodel = 'lowtran'
    if Mod == 'kt':
        molmodel = 'kato'
    if Mod == 'k2':
        molmodel = 'kato2'
    if Mod == 'fu':
        molmodel = 'fu'
    if Mod == 'cr':
        molmodel = 'crs'

    # for simulation select only two atmosphere
    #theatmospheres = np.array(['afglus','afglms','afglmw','afglt','afglss','afglsw'])
    atmosphere_map = dict()  # map atmospheric names to short names
    atmosphere_map['afglus'] = 'us'
    atmosphere_map['afglms'] = 'ms'
    atmosphere_map['afglmw'] = 'mw'
    atmosphere_map['afglt'] = 'tp'
    atmosphere_map['afglss'] = 'ss'
    atmosphere_map['afglsw'] = 'sw'

    theatmospheres = []
    for skyindex in Atm:
        if re.search('us', skyindex):
            theatmospheres.append('afglus')
        if re.search('sw', skyindex):
            theatmospheres.append('afglsw')

    # 1) LOOP ON ATMOSPHERE
    for atmosphere in theatmospheres:
        #if atmosphere != 'afglus':  # just take us standard sky
        #    break
        atmkey = atmosphere_map[atmosphere]

        # manage input and output directories and vary the ozone
        TOPDIR2 = TOPDIR + '/' + Rte + '/' + atmkey + '/' + Proc + '/' + Mod
        ensure_dir(TOPDIR2)
        INPUTDIR = TOPDIR2 + '/' + 'in'
        ensure_dir(INPUTDIR)
        OUTPUTDIR = TOPDIR2 + '/' + 'out'
        ensure_dir(OUTPUTDIR)

        # loop on molecular model resolution
        #molecularresolution = np.array(['COARSE','MEDIUM','FINE'])
        # select only COARSE Model
        molecularresolution = np.array(['COARSE'])
        for molres in molecularresolution:
            if molres == 'COARSE':
                molresol = 'coarse'
            elif molres == 'MEDIUM':
                molresol = 'medium'
            else:
                molresol = 'fine'

        #water vapor
        pwv_val = pwv_num
        pwv_str = 'H2O ' + str(pwv_val) + ' MM'
        wvfileindex = int(10 * pwv_val)

        #aerosols
        #aerosol_angstrom alpha beta
        # tau = beta * lambda^-alpha, lambda in microns
        aerosol_str = str(alpha_num) + ' ' + str(beta_num)
        aer_index = int(alpha_num * 100.)

        # airmass
        airmass = airmass_num
        amfileindex = int(airmass_num * 10)

        # Ozone
        oz_str = 'O3 ' + str(oz_num) + ' DU'
        ozfileindex = int(oz_num / 10.)

        BaseFilename = BaseFilename_part1 + atmkey + '_' + Proc + '_' + Mod + '_z' + str(
            amfileindex) + '_' + WVXX + str(wvfileindex) + '_' + OZXX + str(
                ozfileindex) + '_' + AEXX2 + str(aer_index)

        verbose = True
        uvspec = UVspec.UVspec()
        uvspec.inp["data_files_path"] = libradtranpath + 'data'

        uvspec.inp[
            "atmosphere_file"] = libradtranpath + 'data/atmmod/' + atmosphere + '.dat'
        uvspec.inp["albedo"] = '0.2'

        uvspec.inp["rte_solver"] = rte_eq

        if Mod == 'rt':
            uvspec.inp["mol_abs_param"] = molmodel + ' ' + molresol
        else:
            uvspec.inp["mol_abs_param"] = molmodel

        # Convert airmass into zenith angle
        am = airmass
        sza = math.acos(1. / am) * 180. / math.pi

        # Should be no_absorption
        if runtype == 'aerosol_default':
            uvspec.inp["aerosol_default"] = ''
        elif runtype == 'aerosol_special':
            uvspec.inp["aerosol_default"] = ''  # wrong effect
            #uvspec.inp["aerosol_vulcan"]= 1          # Aerosol type above 2km
            #uvspec.inp["aerosol_haze"]=6            # Aerosol type below 2km
            #uvspec.inp["aerosol_season"]=1          # Summer season
            #uvspec.inp["aerosol_visibility"]= 50.0   # Visibility

            uvspec.inp["aerosol_angstrom"] = aerosol_str

        if runtype == 'no_scattering':
            uvspec.inp["no_scattering"] = ''
        if runtype == 'no_absorption':
            uvspec.inp["no_absorption"] = ''

        # set up the ozone value
        uvspec.inp["mol_modify"] = pwv_str
        uvspec.inp["mol_modify2"] = oz_str

        # rescale pressure   if reasonable pressure values are provided
        if press_num > 600. and press_num < 1015.:
            uvspec.inp["pressure"] = press_num
        else:
            print "creazy pressure p=", press_num, ' hPa'

        uvspec.inp["output_user"] = '******'
        uvspec.inp["altitude"] = OBS_Altitude  # Altitude LSST observatory
        uvspec.inp[
            "source"] = 'solar ' + libradtranpath + 'data/solar_flux/kurudz_1.0nm.dat'
        #uvspec.inp["source"] = 'solar '+libradtranpath+'data/solar_flux/kurudz_0.1nm.dat'
        uvspec.inp["sza"] = str(sza)
        uvspec.inp["phi0"] = '0'
        uvspec.inp["wavelength"] = '250.0 1200.0'
        uvspec.inp["output_quantity"] = 'reflectivity'  #'transmittance' #
        #       uvspec.inp["verbose"] = ''
        uvspec.inp["quiet"] = ''

        if "output_quantity" in uvspec.inp.keys():
            outtextfinal = outtext + '_' + uvspec.inp["output_quantity"]

        inputFilename = BaseFilename + '.INP'
        outputFilename = BaseFilename + '.OUT'
        inp = os.path.join(INPUTDIR, inputFilename)
        out = os.path.join(OUTPUTDIR, outputFilename)

        uvspec.write_input(inp)
        uvspec.run(inp, out, verbose, path=libradtranpath)

    return OUTPUTDIR, outputFilename
コード例 #3
0
    def GetUVSPECImageInputVals(self, fi):
        """
        Input is uvspec input file name.

        The following variables are set

        nx,ny,xpos,ypos,altitude,nrgb

        Their definitions are given in the libRadtran user's guide
        for the options mc_sample_grid and mc_sensorposition.

        Note that this function does not work properly if comments
        included on the same line as the above options, in the
        uvspec input file given as input.
         """

        vals = UVspec.get_vals(fi,'mc_sample_grid')
        if len(vals) == 2:
            self.nx = int(vals[0])
            self.ny = int(vals[1])
            self.AspectRatio = float(self.ny)/float(self.nx)
        else:
            print "Input file ",fi, " did not contain mc_sample_grid"
            print "This is not a panorama input file. Exiting."
            exit(0)
        vals = UVspec.get_vals(fi,'mc_panorama_view')
        if len(vals) == 4:
            self.phi1 = float(vals[0])
            self.phi2 = float(vals[1])
            self.theta1 = float(vals[2])
            self.theta2 = float(vals[3])
            self.theta1_org = float(vals[2])
            self.theta2_org = float(vals[3])
        else:
            print "Input file ",fi, " did not contain mc_panorama_view"
            print "This is not a panorama input file. Exiting."
            exit(0)

        vals = UVspec.get_vals(fi,'umu')
        if len(vals) == 1:
            self.umu = float(vals[0])

            # Shift theta to align with viewing direction.
            self.thetacenter = 0.5*(self.theta1+self.theta2)
            self.umudeg = np.rad2deg(np.arccos(self.umu))
            self.theta1 = self.theta1-self.thetacenter + self.umudeg
            self.theta2 = self.theta2-self.thetacenter + self.umudeg

        vals = UVspec.get_vals(fi,'mc_panorama_alignment')
        if len(vals)== 1:
            self.mc_panorama_alignment=True
        else:
            self.mc_panorama_alignment=False
            print "Input file ",fi, " with camera not aligned"
            print "Sure this is correct?"


        vals = UVspec.get_vals(fi,'mc_sensorposition')
        if len(vals) == 3:
            self.xpos     = float(vals[0])
            self.ypos     = float(vals[1])
            self.altitude = float(vals[2])


        vals = UVspec.get_vals(fi,'source')
        if vals[0] == 'thermal':
            self.thermal=True
        else:
            self.thermal=False

        vals = UVspec.get_vals(fi,'output')
        self.nrgb = 1

        if len(vals) == 1:
            if vals[0] == 'rgb':
                self.nrgb = 3