Esempio n. 1
0
    ##CALLING DISORT
    rfldir_array = []
    rfldn_array = []
    flup_array = []
    dfdt_array = []
    uavg_array = []
    uu_array = []
    albmed_array = []
    trnmed_array = []

    for i in range (n_data):

        [rfldir, rfldn, flup, dfdt, uavg, uu, albmed, trnmed] =\
            disort.run(dTau=dTau, iphas=iphas,  uphas=[p_array[i]], w0=[w0_array[i]], gg=gg,
                       umu0=umu0, phi0=phi0, albedo=albedo, fbeam=fbeam,
                       umu=umu, phi=phi, maxmom=maxmom, prnt=prnt)

        rfldir_array.append(rfldir)
        rfldn_array.append(rfldn)
        flup_array.append(flup)
        dfdt_array.append(dfdt)
        uavg_array.append(uavg)
        uu_array.append(uu)
        albmed_array.append(albmed)
        trnmed_array.append(trnmed)



    for i in range(len(uu_array)):
        print(uu_array[i])
Esempio n. 2
0
    # [rfldir, rfldn, flup, dfdt, uavg, uu, albmed, trnmed] =\
    #                                 disort.run(dTau, w0=w0, iphas=iphas, gg=gg,
    #                                            umu0=umu0, phi0=phi0, albedo=albedo, fbeam=fbeam,
    #                                            utau=uTau, umu=umu, phi=phi)

    # CASE IMPLEMENTED IN run_disort.f
    dTau  = np.array([0.0, 0.0, 0.0, 1.0, 0.0, 0.0])
    iphas = np.array([2, 2, 2, 3, 2, 2])
    w0    = np.array([0.5, 0.5, 0.5, 0.899999976, 0.5, 0.5])
    N = len(dTau)
    gg     = np.ones(N)*0.85
    prnt   = np.array([True, True, True, False, True])

    [rfldir, rfldn, flup, dfdt, uavg, uu, albmed, trnmed] =\
                                    disort.run(dTau, w0=w0, iphas=iphas, gg=gg,
                                               umu0=umu0, phi0=phi0, albedo=albedo, fbeam=fbeam,
                                               utau=uTau, umu=umu, phi=phi, prnt=prnt)

    print '\n\n'
    print '########################################### REFERENCE ###############################################'
    print '\n\n'
    print ' ****************************************************************************************************'
    print ' DISORT: Test Case No. 10a:  like 9c, USRANG = True                                                  '
    print ' ****************************************************************************************************'
    print ''
    print ' No. streams =  32     No. computational layers =   6'
    print '   2 User optical depths :    0.0000    1.0000'
    print '   4 User polar angle cosines : -1.00000 -0.50000  0.50000  1.00000'
    print '   3 User azimuthal angles :     0.00    60.00   120.00'
    print ' No thermal emission'
    print ' Boundary condition flag: IBCND = 0'
def get_fluxes(pres_output,pres,temp,wave,Tau,Omega,cosz,Lstar,alpha_surf, \
                   output_angle = None,
                   N_streams=4,doThermal=False,Ts=None,sourceFn=None, \
                   UsrTau=None,UsrAng=None ):

    # ---
    # setup pyDISORT:
    params_disort = {}
    params_disort['verbose'] = 0  # 0 = suppress header

    # cosine of viewing zenith angle where to output the RT fields (Default: 1.)
    if output_angle is None:
        params_disort['umu'] = 1.
    else:
        params_disort[
            'umu'] = output_angle  # (CAREFUL: might have to be monotonically increasing?)

    # Output returned at computational or user-defined tau,angles?
    #     (default: returns ouput at user-defined angles)
    #  -> note: I haven't gotten the computational option to work..
    if UsrTau is not None:
        params_disort['UsrTau'] = UsrTau
    if UsrAng is not None:
        params_disort['UsrAng'] = UsrAng

    # ---
    # if output is at user-defined levels:
    #    define those levels
    if pres_output == "toa":
        # (if we only want TOA output)
        p = np.array([0.])

        def get_utau(tau=None, p=None, pres=None):
            return np.array([0.])
    elif pres_output == "input":
        # (output on input grid)
        p = pres

        def get_utau(tau, p=None, pres=None):
            utau = tau
            return utau
    else:
        # (output at user-defined pressures)
        #     interpolate on log tau
        #     at toa: tau=0-> -inf -> NaN  with this method. manually fix
        #     also can get utau>max(tau) because of round-off?? manually fix -> still crashes!
        p = pres_output

        def get_utau(tau, p, pres):
            utau = 10**(np.interp(p, pres, np.log10(tau)))
            utau[np.isnan(utau)] = 0.
            return utau

    # ---
    params_disort['iphas'] = 2  # phase function: 1=isotropic, 2=rayleigh
    params_disort['gg'] = 0.  # asymmetry parameter. =0 for Rayleigh
    params_disort['umu0'] = cosz
    params_disort['albedo'] = alpha_surf
    params_disort['Nstr'] = N_streams  # number of streams  -> ??

    params_disort['ibcnd'] = 0

    # using spectrally resolved stellar source function?
    # need same dims as 'wave'!
    if sourceFn is not None:
        source = sourceFn(wave)
    else:
        source = wave * 0. + Lstar

    # show more/less output?
    params_disort['prnt'] = np.array([False, False, False, False, False])

    # include thermal emission?
    params_disort['plank'] = doThermal

    if doThermal:
        # careful about mid-level vs interfaces..
        params_disort['temp'] = temp
        params_disort['btemp'] = Ts
        params_disort['temis'] = 0.  # emissivity of top boundary
        params_disort['ttemp'] = 0.  #Tstrat   # doesn't matter if temis=0?

        # HERE: assume fixed dnu in wave grid!!
        dwave = np.diff(wave)[0]

    # ---
    # iterate over spectral grid:
    #    cast p into array form, to deal with float input..

    Idirect_grid = np.zeros((len(np.array(p)), len(wave)))
    Iplus_grid = np.zeros((len(np.array(p)), len(wave)))
    Iminus_grid = np.zeros((len(np.array(p)), len(wave)))

    # --
    for nu in wave:
        # ...
        if doThermal:
            params_disort['wvnmlo'] = nu - dwave / 2.
            params_disort['wvnmhi'] = nu + dwave / 2.

        # direct beam source:
        params_disort['fbeam'] = source[nu ==
                                        wave]  # (don't include cosz here!)

        # optical thickness:
        tau = np.squeeze(Tau[:, nu == wave])  # 1d

        # single scattering albedo:
        #    careful: tau is computed from kappa via trapz rule -> apply same to omega!
        #    i.e., int[f(x)dx] = sum [f(i+1)+f(i)]*0.5 * dx(i)
        omega = np.squeeze(Omega[:, nu == wave])  # 1d
        params_disort['w0'] = 0.5 * (omega[0:-1] + omega[1:])

        #
        params_disort['utau'] = get_utau(tau, p, pres)

        #
        dtau = np.diff(tau)

        #
        Idirect, Iminus, Iplus, dfdt, uavg, uu, albmed, trnmed = disort.run(
            dtau, **params_disort)

        Idirect_grid[:, nu ==
                     wave] = Idirect[:, np.newaxis]  # cast into right shape..
        Iplus_grid[:, nu == wave] = Iplus[:, np.newaxis]
        Iminus_grid[:, nu == wave] = Iminus[:, np.newaxis]

    if doThermal:
        # THERMAL EMISSION has units=W/m2. transform to W/m2/cm-1:
        Idirect_grid = Idirect_grid / dwave
        Iplus_grid = Iplus_grid / dwave
        Iminus_grid = Iminus_grid / dwave

    return Idirect_grid, Iplus_grid, Iminus_grid