Exemplo n.º 1
0
def run_model(V, initial_aerosols, T, P, dt, max_steps=1000, solver='lsoda'):
    """
    Setup and run the parcel model with the given set of model and 
    integrator parameters.
    """
    if V <= 0:
        return 0.

    model = ParcelModel(initial_aerosols, V, T, -0.0, P)
    try:
        Smax = model.run(500.0, dt, max_steps, solver=solver, output='smax')
    except ParcelModelError:
        return None
    return Smax
Exemplo n.º 2
0
def run_model(V, initial_aerosols, T, P, dt, S0=-0.0, accom=1.0, max_steps=1000, t_end=500.,
              solver='lsoda', output='smax', terminate=False, solver_args={}):
    """ Setup and run the parcel model with given solver configuration.

    Parameters
    ----------
    V, T, P : float
        Updraft speed and parcel initial temperature and pressure.
    S0 : float, optional, default 0.0
        Initial supersaturation, as a percent. Defaults to 100% relative humidity.
    initial_aerosols : array_like of :class:`AerosolSpecies`
        Set of aerosol populations contained in the parcel.
    dt : float
        Solver timestep, in seconds.
    max_steps : int, optional, default 1000
        Maximum number of steps per solver iteration. Defaults to 1000; setting 
        excessively high could produce extremely long computation times.
    t_end : float, optional, default 500.0
        Model time in seconds after which the integration will stop.
    solver : string, optional, default 'lsoda'
        Alias of which solver to use; see :class:`Integrator` for all options.
    output : string, optional, default 'smax'
        Alias indicating which output format to use; see :class:`ParcelModel` for
        all options.
    solver_args : dict, optional
        Detailed arguments/configuration to pass to the numerical integrator.

    Returns
    -------
    Smax : (user-defined)
        Output from parcel model simulation based on user-specified `output` argument. See
        :class:`ParcelModel` for details.

    Raises
    ------
    ParcelModelError
        If the model fails to initialize or breaks during runtime.

    """
    if V <= 0:
        return 0.

    try: 
        model = ParcelModel(initial_aerosols, V, T, S0, P, accom=accom)
        Smax = model.run(t_end, dt, max_steps, solver=solver, 
                         output=output, terminate=terminate, solver_args=solver_args)
    except ParcelModelError:
        return None
    return Smax
Exemplo n.º 3
0
fig, axes = subplots(2, 1, sharex=True, num=3)

for kappa in mode2_kappas:
    print kappa

    aerosol2 = AerosolSpecies('Mode 2', Lognorm(mu=0.05, sigma=2.0, N=100.),
                              bins=200, kappa=kappa)

    initial_aerosols = [aerosol1, aerosol2, ]
    aer_species = [a.species for a in initial_aerosols]
    aer_dict = dict()
    for aerosol in initial_aerosols:
        aer_dict[aerosol.species] = aerosol

    print "   ... model run",
    pm = ParcelModel(initial_aerosols, V, T0, S0, P0, console=False)
    parcel, aerosols = pm.run(z_top, dt)

    xs = np.arange(501)
    parcel = parcel.ix[parcel.index % 1 == 0]
    aero_subset = {}
    for key in aerosols:
        aerosol = aerosols[key]
        subset = aerosol.ix[aerosol.index % 1 == 0]
        aero_subset[key] = subset
    aerosols2 = aero_subset
    print " done"

    print "   ... activation",
    ## Compute Activation stats
    for species in aer_species:
Exemplo n.º 4
0
for aerosol in initial_aerosols:
    aer_dict[aerosol.species] = aerosol

fig, axes = subplots(3, 1, sharex=True, num=9, figsize=(8,11))

for V in Vs:
    zs = np.linspace(0, z_top, 20001)
    print zs[zs%1 == 0]
    
    ts = zs/V
    print "delta t =", np.diff(ts)[0]
    
    print V, "(%d)" % len(ts)

    print "   ... model run",
    pm = ParcelModel(initial_aerosols, V, T0, S0, P0, console=True)
    parcel, aerosols = pm.run(z_top, ts=ts)

    xs = np.arange(501)
    parcel = parcel.ix[parcel.index % 1. == 0]
    aero_subset = {}
    for key in aerosols:
        aerosol = aerosols[key]
        subset = aerosol.ix[aerosol.index % 1. == 0]
        aero_subset[key] = subset
    aerosols2 = aero_subset
    print " done"

    print "   ... activation",
    ## Compute Activation stats
    for species in aer_species:
Exemplo n.º 5
0
results = {}
N = 5000.0

#for N in aer2Nis:
#    print N
for r in aer2rs:
    print r
    initial_aerosols = [AerosolSpecies('sulf', Lognorm(mu=0.05, sigma=2.0, N=100.),
                              bins=200, kappa=0.6),
                        AerosolSpecies('carbon', {'r_drys': [r, ], 'Nis': [N, ]}, kappa=0.01)]
    aer_species = [a.species for a in initial_aerosols]
    aer_dict = dict()
    for aerosol in initial_aerosols:
        aer_dict[aerosol.species] = aerosol

    pm = ParcelModel(initial_aerosols, V, T0, S0, P0, console=True)
    parcel, aerosols = pm.run(z_top, dt, max_steps=2000)

    parcel = parcel.ix[parcel.index % 1 == 0]
    aerosols2 = {}
    for species in aer_species:
        aerosol = aerosols[species]
        aerosols2[species] = aerosol.ix[aerosol.index % 1 == 0]

    ##

    for species in aer_species:
        if species == 'sulf': continue
        aerosol = aerosols2[species]
        aer_meta = aer_dict[species]
        Nis = aer_meta.Nis
Exemplo n.º 6
0
    aer_dict = dict()
    for aerosol in initial_aerosols:
        aer_dict[aerosol.species] = aerosol

    for V in Vs:
        zs = np.linspace(0, z_top, 6001)
        print zs[zs%1 == 0]

        ts = zs/V
        print "delta t =", np.diff(ts)[0]

        print V, "(%d)" % len(ts)

        print "   ... model run",

        pm = ParcelModel(initial_aerosols, V, T0, S0, P0, console=False)
        parcel, aerosols = pm.run(z_top, ts=ts)

        parcel = parcel.ix[parcel.index % 1. == 0]
        aero_subset = {}
        for key in aerosols:
            aerosol = aerosols[key]
            subset = aerosol.ix[aerosol.index % 1. == 0]
            aero_subset[key] = subset
        aerosols = aero_subset
        pm.write_csv(parcel, aerosols, "./temp_data")

        print "done"

        print "   ... activation"
        params = OrderedDict()