コード例 #1
0
def main():

    # initial condition
    RH_init = .95
    T_init  = 285.2
    p_init  = 95000.
    r_init  = fn.rh_to_rv(RH_init, T_init, p_init) 

    # calculate rhod for initial gas mixing ratio
    rhod_init   = fn.rhod_calc(T_init, p_init, r_init)
    # initial condition for trace geses
    SO2_g_init  = fn.mole_frac_to_mix_ratio(200e-12, p_init, cm.M_SO2,  T_init, rhod_init)
    O3_g_init   = fn.mole_frac_to_mix_ratio(50e-9,   p_init, cm.M_O3,   T_init, rhod_init)
    H2O2_g_init = fn.mole_frac_to_mix_ratio(500e-12, p_init, cm.M_H2O2, T_init, rhod_init)
    CO2_g_init  = fn.mole_frac_to_mix_ratio(360e-6,  p_init, cm.M_CO2,  T_init, rhod_init)
    NH3_g_init  = fn.mole_frac_to_mix_ratio(100e-12, p_init, cm.M_NH3,  T_init, rhod_init)
    HNO3_g_init = fn.mole_frac_to_mix_ratio(100e-12, p_init, cm.M_HNO3, T_init, rhod_init)

    # output
    z_max       = 20. #200.
    dt          = .05
    outfreq     = int(z_max / dt / 100)
    w           = 1.
    sd_conc     = 2048

    # turn on chemistry
    chem_dsl = True
    chem_dsc = True
    chem_rct = True

    # define output for moments and chemistry
    out_bin_chem = '{"plt_rw":   {"rght": 1, "left": 0, "drwt": "wet", "lnli": "lin", "nbin": 1, "moms": [0, 1, 3]},\
                     "plt_rd":   {"rght": 1, "left": 0, "drwt": "dry", "lnli": "lin", "nbin": 1, "moms": [0, 1, 3]},\
                     "plt_ch":   {"rght": 1, "left": 0, "drwt": "dry", "lnli": "lin", "nbin": 1,\
                                  "moms": ["O3_a",   "H2O2_a", "H", "SO2_a", "S_VI", "CO2_a",  "NH3_a",  "HNO3_a"]}}'

    out_bin      = '{"plt_rw": {"rght": 1, "left": 0, "drwt": "wet", "lnli": "lin", "nbin": 1, "moms": [0, 1, 3]},\
                     "plt_rd": {"rght": 1, "left": 0, "drwt": "dry", "lnli": "lin", "nbin": 1, "moms": [0, 1, 3]}}'

    # run parcel model
    parcel(dt = dt, z_max = z_max, w = w, outfreq = outfreq,\
           T_0 = T_init, p_0 = p_init, r_0 = r_init,\
           SO2_g = SO2_g_init, O3_g  = O3_g_init,  H2O2_g = H2O2_g_init,\
           CO2_g = CO2_g_init, NH3_g = NH3_g_init, HNO3_g = HNO3_g_init,\
           outfile="test_plot_chem_closed.nc",\
           sd_conc = sd_conc,\
           chem_dsl = chem_dsl, chem_dsc = chem_dsc, chem_rct = chem_rct, \
           out_bin = out_bin_chem)

    data = netcdf.netcdf_file("test_plot_chem.nc", "r")

    plot_chem(data, output_folder = "../outputs", output_title = "/test_plot_chem_")

    netcdf.close()
    subprocess.call(["rm", "test_plot_chem.nc"])
コード例 #2
0
ファイル: test_chem_henry.py プロジェクト: trontrytel/parcel
def data(request):
    # initial condition
    RH_init = .999999
    T_init  = 300.
    p_init  = 100000.
    r_init  = cm.eps * RH_init * cm.p_vs(T_init) / (p_init - RH_init * cm.p_vs(T_init))

    # calculate rhod for gas init cond
    th_0      = T_init * (cm.p_1000 / p_init)**(cm.R_d / cm.c_pd)
    rhod_init = cm.rhod(p_init, th_0, r_init)

    # init cond for trace gases
    SO2_g_init  = fn.mole_frac_to_mix_ratio(200e-12, p_init, cm.M_SO2,  T_init, rhod_init)
    O3_g_init   = fn.mole_frac_to_mix_ratio(50e-9,   p_init, cm.M_O3,   T_init, rhod_init)
    H2O2_g_init = fn.mole_frac_to_mix_ratio(500e-12, p_init, cm.M_H2O2, T_init, rhod_init)
    CO2_g_init  = fn.mole_frac_to_mix_ratio(360e-6,  p_init, cm.M_CO2,  T_init, rhod_init)
    NH3_g_init  = fn.mole_frac_to_mix_ratio(100e-12, p_init, cm.M_NH3,  T_init, rhod_init)
    HNO3_g_init = fn.mole_frac_to_mix_ratio(100e-12, p_init, cm.M_HNO3, T_init, rhod_init)

    # aerosol size distribution
    mean_r = .08e-6 / 2
    gstdev = 2.
    n_tot  = 566.e6

    # output
    sd_conc     = 1
    outfreq     = 50
    z_max       = 300.
    outfile     = "test_chem_henry.nc"
    dt          = 0.1
    wait        = 100

    parcel(dt = dt, z_max = z_max, outfreq = outfreq, wait=wait,\
          T_0 = T_init, p_0 = p_init, r_0 = r_init,\
          SO2_g = SO2_g_init, O3_g  = O3_g_init,  H2O2_g = H2O2_g_init,\
          CO2_g = CO2_g_init, NH3_g = NH3_g_init, HNO3_g = HNO3_g_init,\
          outfile = outfile,\
          chem_dsl = True, chem_dsc = True, chem_rct = False,\
          aerosol = \
            '{"test": {"kappa": 0.5, "mean_r": [' + str(mean_r) + '], "gstdev": [' + str(gstdev) + '], "n_tot": [' + str(n_tot) + ']}}',\
          sd_conc = sd_conc,\
          out_bin = \
            '{"radii": {"rght": 1.0, "left": 0.0, "drwt": "wet", "lnli": "lin", "nbin": 1, "moms": [0, 3]},\
              "chem" : {"rght": 1.0, "left": 0.0, "drwt": "wet", "lnli": "lin", "nbin": 1,\
               "moms": ["O3_a", "H2O2_a", "SO2_a", "CO2_a", "NH3_a", "HNO3_a", "H"]}}')

    data = netcdf.netcdf_file("test_chem_henry.nc", "r")

    # removing all netcdf files after all tests                                      
    def removing_files():
        subprocess.call(["rm", "test_chem_henry.nc"])

    request.addfinalizer(removing_files)
    return data
コード例 #3
0
def main():
    RH_init = .99999
    T_init = 300.
    p_init = 100000.
    r_init = cm.eps * RH_init * cm.p_vs(T_init) / (p_init -
                                                   RH_init * cm.p_vs(T_init))

    # calculate rhod for initial gas mixing ratio
    th_0 = T_init * (cm.p_1000 / p_init)**(cm.R_d / cm.c_pd)
    rhod_init = cm.rhod(p_init, th_0, r_init)

    SO2_g_init = fn.mole_frac_to_mix_ratio(200e-12, p_init, cm.M_SO2, T_init,
                                           rhod_init)
    O3_g_init = fn.mole_frac_to_mix_ratio(50e-9, p_init, cm.M_O3, T_init,
                                          rhod_init)
    H2O2_g_init = fn.mole_frac_to_mix_ratio(500e-12, p_init, cm.M_H2O2, T_init,
                                            rhod_init)
    CO2_g_init = fn.mole_frac_to_mix_ratio(360e-6, p_init, cm.M_CO2, T_init,
                                           rhod_init)
    NH3_g_init = fn.mole_frac_to_mix_ratio(100e-12, p_init, cm.M_NH3, T_init,
                                           rhod_init)
    HNO3_g_init = fn.mole_frac_to_mix_ratio(100e-12, p_init, cm.M_HNO3, T_init,
                                            rhod_init)

    outfreq = 50
    z_max = 50.
    outfile = "test_chem_henry.nc"
    dt = 0.1
    wait = 1000
    sd_conc = 1

    # run parcel run!
    parcel(dt = dt, z_max = z_max, outfreq = outfreq, wait=wait,\
            T_0 = T_init, p_0 = p_init, r_0 = r_init, sd_conc=sd_conc,\
            SO2_g = SO2_g_init, O3_g  = O3_g_init,  H2O2_g = H2O2_g_init,\
            CO2_g = CO2_g_init, NH3_g = NH3_g_init, HNO3_g = HNO3_g_init,\
            outfile = outfile,\
            chem_dsl = True, chem_dsc = False, chem_rct = False,\
            out_bin = \
            '{"radii": {"rght": 1, "left": 0, "drwt": "wet", "lnli": "lin", "nbin": 1, "moms": [0, 3]},\
              "chem" : {"rght": 1, "left": 0, "drwt": "wet", "lnli": "lin", "nbin": 1,\
                  "moms": ["O3_a", "H2O2_a", "SO2_a", "CO2_a", "NH3_a", "HNO3_a", "H"]}}'                                                                                         )

    data = netcdf.netcdf_file(outfile, "r")

    #plot
    plot_henry(data, output_folder="../outputs")

    #cleanup
    data.close()
    subprocess.call(["rm", "test_chem_henry.nc"])
コード例 #4
0
ファイル: henry_plot.py プロジェクト: djarecka/parcel
def main():
    RH_init = .99999
    T_init  = 300.
    p_init  = 100000.
    r_init  = cm.eps * RH_init * cm.p_vs(T_init) / (p_init - RH_init * cm.p_vs(T_init))

    # calculate rhod for initial gas mixing ratio
    th_0      = T_init * (cm.p_1000 / p_init)**(cm.R_d / cm.c_pd)
    rhod_init = cm.rhod(p_init, th_0, r_init)

    SO2_g_init  = fn.mole_frac_to_mix_ratio(200e-12, p_init, cm.M_SO2,  T_init, rhod_init)
    O3_g_init   = fn.mole_frac_to_mix_ratio(50e-9,   p_init, cm.M_O3,   T_init, rhod_init)
    H2O2_g_init = fn.mole_frac_to_mix_ratio(500e-12, p_init, cm.M_H2O2, T_init, rhod_init)
    CO2_g_init  = fn.mole_frac_to_mix_ratio(360e-6,  p_init, cm.M_CO2,  T_init, rhod_init)
    NH3_g_init  = fn.mole_frac_to_mix_ratio(100e-12, p_init, cm.M_NH3,  T_init, rhod_init)
    HNO3_g_init = fn.mole_frac_to_mix_ratio(100e-12, p_init, cm.M_HNO3, T_init, rhod_init)

    outfreq     = 50
    z_max       = 50.
    outfile     = "test_chem_henry.nc"
    dt          = 0.1
    wait        = 1000
    sd_conc     = 1

    # run parcel run!
    parcel(dt = dt, z_max = z_max, outfreq = outfreq, wait=wait,\
            T_0 = T_init, p_0 = p_init, r_0 = r_init, sd_conc=sd_conc,\
            SO2_g = SO2_g_init, O3_g  = O3_g_init,  H2O2_g = H2O2_g_init,\
            CO2_g = CO2_g_init, NH3_g = NH3_g_init, HNO3_g = HNO3_g_init,\
            outfile = outfile,\
            chem_dsl = True, chem_dsc = False, chem_rct = False,\
            out_bin = \
            '{"radii": {"rght": 1, "left": 0, "drwt": "wet", "lnli": "lin", "nbin": 1, "moms": [0, 3]},\
              "chem" : {"rght": 1, "left": 0, "drwt": "wet", "lnli": "lin", "nbin": 1,\
                  "moms": ["O3_a", "H2O2_a", "SO2_a", "CO2_a", "NH3_a", "HNO3_a", "H"]}}')

    data = netcdf.netcdf_file(outfile,"r")

    #plot
    plot_henry(data, output_folder = "../outputs")

    #cleanup
    data.close()
    subprocess.call(["rm", "test_chem_henry.nc"])
コード例 #5
0
def data(request):
    # initial condition
    RH_init = .999999
    T_init = 300.
    p_init = 100000.
    r_init = cm.eps * RH_init * cm.p_vs(T_init) / (p_init -
                                                   RH_init * cm.p_vs(T_init))

    # calculate rhod for gas init cond
    th_0 = T_init * (cm.p_1000 / p_init)**(cm.R_d / cm.c_pd)
    rhod_init = cm.rhod(p_init, th_0, r_init)

    # init cond for trace gases
    SO2_g_init = fn.mole_frac_to_mix_ratio(200e-12, p_init, cm.M_SO2, T_init,
                                           rhod_init)
    O3_g_init = fn.mole_frac_to_mix_ratio(50e-9, p_init, cm.M_O3, T_init,
                                          rhod_init)
    H2O2_g_init = fn.mole_frac_to_mix_ratio(500e-12, p_init, cm.M_H2O2, T_init,
                                            rhod_init)
    CO2_g_init = fn.mole_frac_to_mix_ratio(360e-6, p_init, cm.M_CO2, T_init,
                                           rhod_init)
    NH3_g_init = fn.mole_frac_to_mix_ratio(100e-12, p_init, cm.M_NH3, T_init,
                                           rhod_init)
    HNO3_g_init = fn.mole_frac_to_mix_ratio(100e-12, p_init, cm.M_HNO3, T_init,
                                            rhod_init)

    # aerosol size distribution
    mean_r = .08e-6 / 2
    gstdev = 2.
    n_tot = 566.e6

    # output
    sd_conc = 1
    outfreq = 50
    z_max = 300.
    outfile = "test_chem_henry.nc"
    dt = 0.1
    wait = 100

    parcel(dt = dt, z_max = z_max, outfreq = outfreq, wait=wait,\
          T_0 = T_init, p_0 = p_init, r_0 = r_init,\
          SO2_g = SO2_g_init, O3_g  = O3_g_init,  H2O2_g = H2O2_g_init,\
          CO2_g = CO2_g_init, NH3_g = NH3_g_init, HNO3_g = HNO3_g_init,\
          outfile = outfile,\
          chem_dsl = True, chem_dsc = True, chem_rct = False,\
          aerosol = \
            '{"test": {"kappa": 0.5, "mean_r": [' + str(mean_r) + '], "gstdev": [' + str(gstdev) + '], "n_tot": [' + str(n_tot) + ']}}',\
          sd_conc = sd_conc,\
          out_bin = \
            '{"radii": {"rght": 1.0, "left": 0.0, "drwt": "wet", "lnli": "lin", "nbin": 1, "moms": [0, 3]},\
              "chem" : {"rght": 1.0, "left": 0.0, "drwt": "wet", "lnli": "lin", "nbin": 1,\
               "moms": ["O3_a", "H2O2_a", "SO2_a", "CO2_a", "NH3_a", "HNO3_a", "H"]}}'                                                                                      )

    data = netcdf.netcdf_file("test_chem_henry.nc", "r")

    # removing all netcdf files after all tests
    def removing_files():
        subprocess.call(["rm", "test_chem_henry.nc"])

    request.addfinalizer(removing_files)
    return data
コード例 #6
0
ファイル: chem_conditions.py プロジェクト: djarecka/parcel
r_init  = fn.rh_to_rv(RH_init, T_init, p_init)

# STP conditions (needed to initialize dry radii distribution)
p_stp = 101325
T_stp = 273.15 + 15

# calculate rhod for initial gas mixing ratio
rhod_init   = fn.rhod_calc(T_init, p_init, r_init)

# calculate density of air in the model and in standard conditions 
# (needed to initialize dry radii distribution)
rho_init = p_init / T_init / (r_init / (1.+r_init) * cm.R_v + 1./ (1.+r_init) * cm.R_d)
rho_stp  = p_stp  / T_stp / cm.R_d

# initial condition for trace geses
SO2_g_init  = fn.mole_frac_to_mix_ratio(200e-12, p_init, cm.M_SO2,  T_init, rhod_init)
O3_g_init   = fn.mole_frac_to_mix_ratio(50e-9,   p_init, cm.M_O3,   T_init, rhod_init)
H2O2_g_init = fn.mole_frac_to_mix_ratio(500e-12, p_init, cm.M_H2O2, T_init, rhod_init)
CO2_g_init  = fn.mole_frac_to_mix_ratio(360e-6,  p_init, cm.M_CO2,  T_init, rhod_init)
NH3_g_init  = fn.mole_frac_to_mix_ratio(100e-12, p_init, cm.M_NH3,  T_init, rhod_init)
HNO3_g_init = fn.mole_frac_to_mix_ratio(100e-12, p_init, cm.M_HNO3, T_init, rhod_init)

# aerosol size distribution
mean_r = .04e-6
gstdev = 2.
n_tot  = 566.e6 * rho_stp / rho_init

# chem process toggling
chem_dsl = False
chem_dsc = False
chem_rct = False
コード例 #7
0
# STP conditions (needed to initialize dry radii distribution)
p_stp = 101325
T_stp = 273.15 + 15

# calculate rhod for initial gas mixing ratio
rhod_init = fn.rhod_calc(T_init, p_init, r_init)

# calculate density of air in the model and in standard conditions
# (needed to initialize dry radii distribution)
rho_init = p_init / T_init / (r_init / (1. + r_init) * cm.R_v + 1. /
                              (1. + r_init) * cm.R_d)
rho_stp = p_stp / T_stp / cm.R_d

# initial condition for trace geses
SO2_g_init = fn.mole_frac_to_mix_ratio(200e-12, p_init, cm.M_SO2, T_init,
                                       rhod_init)
O3_g_init = fn.mole_frac_to_mix_ratio(50e-9, p_init, cm.M_O3, T_init,
                                      rhod_init)
H2O2_g_init = fn.mole_frac_to_mix_ratio(500e-12, p_init, cm.M_H2O2, T_init,
                                        rhod_init)
CO2_g_init = fn.mole_frac_to_mix_ratio(360e-6, p_init, cm.M_CO2, T_init,
                                       rhod_init)
NH3_g_init = fn.mole_frac_to_mix_ratio(100e-12, p_init, cm.M_NH3, T_init,
                                       rhod_init)
HNO3_g_init = fn.mole_frac_to_mix_ratio(100e-12, p_init, cm.M_HNO3, T_init,
                                        rhod_init)

# aerosol size distribution
mean_r = .04e-6
gstdev = 2.
n_tot = 566.e6 * rho_stp / rho_init