aerosol package¶
aerosol.functions module¶
Aerosol number-size distribution is assumed to be a pandas DataFrame where
- index:
time, pandas.DatetimeIndex
- columns:
size bin diameters in meters, float
- values:
normalized concentration dN/dlogDp in cm-3, float
- aerosol.functions.air_viscosity(temp)¶
Calculate air viscosity using Enskog-Chapman theory
- Parameters:
- tempfloat or numpy.array
air temperature, unit: K
- Returns:
- float or numpy.array
viscosity of air, unit: m2 s-1
- aerosol.functions.beta(dp, temp, pres, diffusivity, molar_mass)¶
Calculate Fuchs Sutugin correction factor
Sutugin et al. (1971): https://doi.org/10.1016/0021-8502(71)90061-9
- Parameters:
- dpfloat or numpy.array (m,)
aerosol particle diameter(s), unit: m
- tempfloat or numpy.array (n,1)
temperature, unit: K
- presfloat or numpy.array (n,1)
pressure, unit: Pa
- diffusivityfloat or numpy.array (n,1)
diffusivity of the gas that is condensing, unit: m2/s
- molar_massfloat
molar mass of the condensing gas, unit: g/mol
- Returns:
- float or numpy.array (n,m)
Fuchs Sutugin correction factor for each particle diameter and temperature/pressure unit: m2/s
- aerosol.functions.binary_diffusivity(temp, pres, Ma, Mb, Va, Vb)¶
Binary diffusivity in a mixture of gases a and b
Fuller et al. (1966): https://doi.org/10.1021/ie50677a007
- Parameters:
- tempfloat or numpy.array
temperature, unit: K
- presfloat or numpy.array
pressure, unit: Pa
- Mafloat
relative molecular mass of gas a, unit: dimensionless
- Mbfloat
relative molecular mass of gas b, unit: dimensionless
- Vafloat
diffusion volume of gas a, unit: dimensionless
- Vbfloat
diffusion volume of gas b, unit: dimensionless
- Returns:
- float or numpy.array
binary diffusivity, unit: m2 s-1
- aerosol.functions.calc_coags(df, dp, temp, pres)¶
Calculate coagulation sink
Kulmala et al (2012): doi:10.1038/nprot.2012.091
- Parameters:
- dfpandas.DataFrame
Aerosol number size distribution
- dpfloat or array
Particle diameter(s) for which you want to calculate the CoagS, unit: m
- temppandas.Series or float
Ambient temperature corresponding to the data, unit: K If single value given it is used for all data
- prespandas.Series or float
Ambient pressure corresponding to the data, unit: Pa If single value given it is used for all data
- Returns:
- pandas.DataFrame
Coagulation sink for the given diamater(s), unit: s-1
- aerosol.functions.calc_conc(df, dmin, dmax)¶
Calculate particle number concentration from aerosol number-size distribution
- Parameters:
- dfpandas.DataFrame
Aerosol number-size distribution
- dminfloat or array
Size range lower diameter(s), unit: m
- dmaxfloat or array
Size range upper diameter(s), unit: m
- Returns:
- pandas.DataFrame
Number concentration in the given size range(s), unit: cm-3
- aerosol.functions.calc_cs(df, temp, pres)¶
Calculate condensation sink, assuming that the condensing gas is sulfuric acid in air with aerosol particles.
Kulmala et al (2012): doi:10.1038/nprot.2012.091
- Parameters:
- dfpandas.DataFrame
aerosol number size distribution (dN/dlogDp)
- temppandas.Series or float
Ambient temperature corresponding to the data, unit: K If single value given it is used for all data
- prespandas.Series or float
Ambient pressure corresponding to the data, unit: Pa If single value given it is used for all data
- Returns:
- pandas.Series
condensation sink time series, unit: s-1
- aerosol.functions.calc_formation_rate(dp1, dp2, conc, coags, gr)¶
Calculate particle formation rate
Kulmala et al (2012): doi:10.1038/nprot.2012.091
- Parameters:
- dp1float or array
Lower diameter of the size range(s), unit: m
- dp2float or array
Upper diameter of the size range(s), unit m
- concpandas.DataFrame
particle number concentration timeseries in the size range(s), unit cm-3
- coagspandas.DataFrame
Coagulation sink timeseries for particles in the size range(s). unit s-1
Usually approximated as coagulation sink for particle size in the lower limit of the size range, unit s-1
- grfloat or array
Growth rate for particles out of the size range(s), unit nm h-1
- Returns:
- pandas.DataFrame
particle formation rate for diameter(s), unit: cm3 s-1
- aerosol.functions.calc_ion_formation_rate(dp1, dp2, conc_pos, conc_neg, conc_pos_small, conc_neg_small, conc, coags, gr)¶
Calculate ion formation rate
Kulmala et al (2012): doi:10.1038/nprot.2012.091
- Parameters:
- dp1float or numpy.array
Lower diameter of the size range(s), unit: m
- dp2float or numpy.array
Upper diameter of the size range(s), unit: m
- conc_pospandas.DataFrame
Positive ion number concentration in the size range(s), unit: cm-3. Each size range corresponds to a column in the dataframe
- conc_negpandas.DataFrame
Negative ion number concentration in the size range(s), unit: cm-3
- conc_pos_smallpandas.DataFrame
Positive ion number concentration for ions smaller than size range(s), unit: cm-3
- conc_neg_smallpandas.DataFrame
Negative ion number concentration for ions smaller than size range(s), unit: cm-3
- concpandas.DataFrame
Particle number concentration in the size range(s), unit: cm-3
- coagspandas.DataFrame
Coagulation sink for particles in the size range(s). unit: s-1
- grfloat or numpy.array
Growth rate for particles out of the size range(s), unit: nm h-1
- Returns:
- pandas.DataFrame
Negative ion formation rate(s), unit : cm3 s-1
- pandas.DataFrame
Positive ion formation rate(s), unit: cm3 s-1
- aerosol.functions.coagulation_coef(dp1, dp2, temp, pres)¶
Calculate Brownian coagulation coefficient (Fuchs)
- Parameters:
- dp1float or numpy.array (m,)
first particle diameter, unit: m
- dp2float or numpy.array (m,)
second particle diameter, unit: m
- tempfloat or numpy.array (n,1)
air temperature, unit: K
- presfloat or numpy.array (n,1)
air pressure, unit: Pa
- Returns:
- float or numpy.array
Brownian coagulation coefficient (Fuchs),
for example if all parameters are arrays the function returns a 2d array where the entry at i,j correspoinds to the coagulation coefficient for particle sizes dp1[i] and dp2[i] at temp[j] and pres[j].
unit m3 s-1
- aerosol.functions.datenum2datetime(datenum)¶
Convert from matlab datenum to python datetime
- Parameters:
- datenumfloat or int
A serial date number representing the whole and fractional number of days from 1-Jan-0000 to a specific date (MATLAB datenum)
- Returns:
- pandas.Timestamp
- aerosol.functions.datetime2datenum(dt)¶
Convert from python datetime to matlab datenum
- Parameters:
- dtdatetime object
- Returns:
- float
A serial date number representing the whole and fractional number of days from 1-Jan-0000 to a specific date (MATLAB datenum)
- aerosol.functions.diam2mob(dp, temp, pres, ne)¶
Convert electrical mobility diameter to electrical mobility in air
- Parameters:
- dpfloat or numpy.array (m,)
particle diameter(s), unit : m
- tempfloat or numpy.array (n,1)
ambient temperature, unit: K
- presfloat or numpy.array (n,1)
ambient pressure, unit: Pa
- neint
number of charges on the aerosol particle
- Returns:
- float or numpy.array
particle electrical mobility or mobilities, unit: m2 s-1 V-1
- aerosol.functions.dndlogdp2dn(df)¶
Convert from normalized number concentrations to unnormalized number concentrations.
- Parameters:
- dfpandas.DataFrame
Aerosol number-size distribution (dN/dlogDp)
- Returns:
- pandas.DataFrame
Aerosol number size distribution (dN)
- aerosol.functions.mean_free_path(temp, pres)¶
Calculate mean free path in air
- Parameters:
- tempfloat or numpy.array
air temperature, unit: K
- presfloat or numpy.array
air pressure, unit: Pa
- Returns:
- float or numpy.array
mean free path in air, unit: m
- aerosol.functions.mob2diam(Zp, temp, pres, ne)¶
Convert electrical mobility to electrical mobility diameter in air
- Parameters:
- Zpfloat
particle electrical mobility or mobilities, unit: m2 s-1 V-1
- tempfloat
ambient temperature, unit: K
- presfloat
ambient pressure, unit: Pa
- neinteger
number of charges on the aerosol particle
- Returns:
- float
particle diameter, unit: m
- aerosol.functions.particle_diffusivity(dp, temp, pres)¶
Particle brownian diffusivity in air
- Parameters:
- dpfloat or numpy.array (m,)
particle diameter, unit: m
- tempfloat or numpy.array (n,1)
air temperature, unit: K
- presfloat or numpy.array (n,1)
air pressure, unit: Pa
- Returns:
- float or numpy.array (m,) or (n,m)
Brownian diffusivity in air for particles of size dp, and at each temperature/pressure value unit m2 s-1
- aerosol.functions.particle_mean_free_path(dp, temp, pres)¶
Particle mean free path in air
- Parameters:
- dpfloat or numpy.array (m,)
particle diameter, unit: m
- tempfloat or numpy.array (n,1)
air temperature, unit: K
- presfloat or numpy.array (n,1)
air pressure, unit: Pa
- Returns:
- float or numpy.array (m,) or (n,m)
Particle mean free path for each dp, unit: m
- aerosol.functions.particle_thermal_speed(dp, temp)¶
Particle thermal speed
- Parameters:
- dpfloat or numpy.array (m,)
particle diameter, unit: m
- tempfloat or numpy.array (n,1)
air temperature, unit: K
- Returns:
- float or numpy.array (m,) or (n,m)
Particle thermal speed for each dp at each temperature point, unit: m s-1
- aerosol.functions.slipcorr(dp, temp, pres)¶
Slip correction factor in air
- Parameters:
- dpfloat or numpy array (m,)
particle diameter, unit m
- tempfloat or numpy.array (n,1)
air temperature, unit K
- presfloat or numpy.array (n,1)
air pressure, unit Pa
- Returns:
- float or numpy.array (m,) or (n,m)
Cunningham slip correction factor for each particle diameter, if temperature and pressure and arrays then for each particle diameter at different pressure/temperature values. unit dimensionless
- aerosol.functions.tubeloss(diam, flowrate, tubelength, temp, pres)¶
Calculate diffusional particle losses to walls of straight cylindrical tube assuming a laminar flow regime
- Parameters:
- diamnumpy.array (m,)
Particle diameters for which to calculate the losses, unit: m
- flowratenumpy.array (n,)
unit: L/min
- tubelengthfloat
Length of the cylindrical tube unit: m
- tempnumpy.array (n,)
temperature unit: K
- presnumpy.array (n,)
air pressure unit: Pa
- Returns:
- numpy.array (n,m)
Fraction of particles passing through. Each column represents diameter and each each row represents different temperature pressure and flowrate value
aerosol.plotting module¶
- aerosol.plotting.generate_log_ticks(min_exp, max_exp)¶
Generate ticks and ticklabels for log axis
- Parameters:
- min_expint
The exponent in the smallest power of ten
- max_expint
The exponent in the largest power of ten
- Returns:
- numpy.array
minor tick values
- numpy.array
major tick values
- list of strings
major tick labels (powers of ten)
- aerosol.plotting.generate_timeticks(t_min, t_max, minortick_interval, majortick_interval, ticklabel_format)¶
- Parameters:
- t_minpandas timestamp
- t_maxpandas timestamp
- majortick_intervalpandas date frequency string
See for all options here: https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases
- minortick_intervalpandas date frequency string
- ticklabel_formatpython date format string
See for all options here: https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-code
- Returns:
- pandas DatetimeIndex
minor tick values
- pandas DatetimeIndex
major tick values
- pandas Index containing strings
major tick labels
- aerosol.plotting.plot_aerosol_dist(v, ax, cmap=<matplotlib.colors.LinearSegmentedColormap object>, norm=<matplotlib.colors.Normalize object>, xminortick_interval='1H', xmajortick_interval='2H', xticklabel_format='%H:%M')¶
Plot aerosol particle number-size distribution surface plot
- Parameters:
- vpandas.DataFrame or list of pandas.DataFrames
Aerosol number size distribution (continuous index)
- axaxes object
axis on which to plot the data
- cmapmatplotlib colormap
Colormap to use, default is rainbow
- normmatplotlib.colors norm
Define how to normalize the colors. Default is linear normalization
- xminortick_intervalpandas date frequency string
See for all options here: https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases
- xmajortick_intervalpandas date frequency string
- xticklabel_formatstr
See for all options here: https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-code
- aerosol.plotting.rotate_xticks(ax, degrees)¶
- Parameters:
- axmatplotlib axes
- degreesint or float
number of degrees to rotate the ticklabels
- aerosol.plotting.stacked_plots(df, height_coef=3, spacing_coef=1.5, plot_type='plot', color=None, cmap=None, **kwargs)¶
Vertically stacked overlapping plots
- Parameters:
- dfpandas.DataFrame
first column is plotted to lower/foremost plot
- height_coefint or float
scales the height of the subplots
- spacing_coefint or float
scales the vertical spacing between subplots
- plot_typestr
“scatter”, “plot” or “fill_between” corresponding to the matplotlib functions of the same name.
- colormatplotlib color
- cmapmatplotlib colormap
can apply to any plot_type
- **kwargsoptional properties passed on to the plot_type
- Returns:
- matplotlib figure
- matplotlib axes
lowest subplot x-axes
- matplotlib axes
lowest subplot y-axes
- aerosol.plotting.subplot_aerosol_dist(vlist, grid, cmap=<matplotlib.colors.LinearSegmentedColormap object>, norm=<matplotlib.colors.Normalize object>, xminortick_interval='1H', xmajortick_interval='2H', xticklabel_format='%H:%M', keep_inner_ticklabels=False, subplot_padding=None, subplot_labels=None, label_color='black', label_size=10, column_titles=None)¶
Plot aerosol size distributions (subplots)
- Parameters:
- vlistlist of pandas.DataFrames
Aerosol size distributions (continuous index)
- gridtuple (rows,columns)
define number of rows and columns
- cmapmatplotlib colormap
Colormap to use, default is rainbow
- normmatplotlib.colors norm
Define how to normalize the colors. Default is linear normalization
- xminortick_intervalstr
A pandas date frequency string. See for all options here: https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases
- xmajortick_intervalstr
A pandas date frequency string
- xticklabel_formatstr
Date format string. See for all options here: https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-code
- keep_inner_ticklabelsbool
If True, use ticklabels in all subplots. If False, use ticklabels only on outer subplots.
- subplot_paddingnumber or None
Adjust space between subplots
- subplot_labelslist of str or None
The labels to put to labels the subplots with
- label_colorstr
- label_sizefloat
- column_titleslist of strings or None
- Returns:
- figure object
- array of axes objects