aqmbc package
Subpackages
Submodules
aqmbc.bcon module
- aqmbc.bcon.bc(inpath, outpath, metaf, tslice=None, vmethod='conserve', exprpaths=None, clobber=False, dimkeys=None, format_kw=None, history='', speedup=None, timeindependent=False, verbose=1, minvalue=None)[source]
- Parameters:
inpath (str) – path to input file
outpath (str) – path to output file
metaf (netcdf-like) – Metadata file (CRO for ICON, BDY for BCON)
tslice (slice) – Optional time slice (e.g., slice(0) for ICON)
vmethod (str) – method to use for vertical interpolation (conserve or linear)
exprpaths (list) – text files with species translations
clobber (bool) – overwrite existing files
speedup (bool) – slice file to load into memory. More mem, but faster
timeindependent (bool) – If True and input has just 1 time, write out as an IOAPI time-independent file.
minvalue (scalar) – Passed to translate
- Return type:
None
Notes
Saves BCON or ICON to file.
- Operations:
window
horizontal extraction
vertical interpolation
species translation
- aqmbc.bcon.dimparser(dimstr)[source]
- Parameters:
dimstr (str) – key=value pairs delimited by commas
- Returns:
out – mapping table between IOAPI gridded and input dimensions
- Return type:
dict
- aqmbc.bcon.formatparser(fmtstr)[source]
- Parameters:
fmtstr (str) – string with format and option key value pairs delimited by commas option key value pairs should be in a format consistent with dict call dict(key1=val1, key2=val2, …)
- Returns:
out – format=first word otherkeys=key value pairs delimited by commas
- Return type:
dict
- aqmbc.bcon.ijslice(infile, metaf, i, j, dimkeys, verbose=1)[source]
- Parameters:
infile (netcdf-like) – input file
metafile (netcdf-like) – file with longitude and latitude
- Returns:
bconf
- Return type:
file at metaf
- aqmbc.bcon.kinterp(infile, metaf, vmethod, verbose=1)[source]
- Parameters:
infile (netcdf-like) – input file
metaf (netcdf-like) – file with longitude and latitude
vmethod (str) – method for vertical inteprolation (conserve or linear)
- Returns:
bconvf
- Return type:
file at new vertical levels
- aqmbc.bcon.saveioapi(inf, outf, outpath, metaf, dimkeys, timeindependent=False, verbose=1)[source]
- Parameters:
inf (netcdf-like file) – Must support getTimes method
outf (netcdf-like file) – file for output
metaf (netcdf-like file) – metadata file
dimkeys (dict) – translation dictionary for dimensions
timeindependent (bool) – If True and number of times is 1, the file will be stored as IOAPI time-independent
Results –
------- –
out (netcdf-like file) – file that was output
aqmbc.cmaq module
- aqmbc.cmaq.cmaqready(date, inpaths, outpath=None, verbose=0, minvalue=1e-30)[source]
Concatenate inpaths on time and then interpolate to 25h instantaneous times for CMAQ. Also trims FILEDESC and HISTORY if they are too long.
- Parameters:
date (date-like or string) – Date for CMAQ-ready file.
inpaths (list or str) – List of paths to use as the source or template to find inputs
outpath (str or None) – If None, return the file. Otherwise, write it out and return the path
verbose (int) – Level of verbosity
minvalue (scalar) – Minimum value
- Returns:
outpath – Output file or path.
- Return type:
str or dataset
aqmbc.exprlib module
- aqmbc.exprlib.gc12
options for GEOS-Chem version 12 for CB6r3 with AE7 aerosols
- Type:
tuple
- aqmbc.exprlib.gc12_soas
same as above, but for the Simple SOA option.
- Type:
tuple
- aqmbc.exprlib.gc14
options for GEOS-Chem version 14 with CB6r5 with AE7 aerosols
- Type:
tuple
- aqmbc.exprlib.gc14_soas
same as above, but for the simple SOA option.
- Type:
tuple
- aqmbc.exprlib.raqms
cb6r4 and ae6 definitions for RAQMS
- Type:
tuple
aqmbc.options module
- aqmbc.options.getmetaf(bctype='bcon', gdnam='12US1', vgnam='EPA_35L', gdpath=None)[source]
- bctypestr
bcon (boundary) or icon (initial) boundary conditions.
- gdnamstr
Name of grid in gdpath
- vgnamstr
Name of vertical grid (must exist in vglvls)
- gdpathstr or None
If none, looks for GRIDDESC environment, then looks for a local file, then uses the default.
aqmbc.report module
- aqmbc.report.barplot(ds, bar_kw=None)[source]
- Parameters:
ds (pandas.Series) – Series get from makestats or getstats
bar_kw (mappable) – Options for the barplot function (including ax)
- Returns:
ax – Axes object with barplot
- Return type:
matplotlib.axes.Axes
- aqmbc.report.get_vertprof(inbcon, varkeys=None, func='mean', verbose=0, outpath=None)[source]
- Parameters:
inbcon (list or str) –
If str, inbcon = sorted(glob.glob(inbcon)) If list, items should be str or xarray.Dataset object.
If str, infiles = [xr.open_dataset(inpath) for inpath in inbcon] If Datasets, infiles = inbcon
varkeys (list or None) – variable keys (if None, use all)
func (str) – Name of function to apply to each variable (min, mean, max, median)
verbose (int) – Level of verbosity
outpath (str or None) – Path to save (or retrieve) the vertical profile from
- Returns:
vf – Variables have func applied to all dimensions except for LAY.
- Return type:
xarray.Dataset
- aqmbc.report.getstats(inbcon, varkeys=None, verbose=0, add_summary=True, outpath=None, draft=False)[source]
- Parameters:
inbcon (list or str) –
If str, inbcon = sorted(glob.glob(inbcon)) If list, items should be str or xarray.Dataset object.
If str, infiles = [xr.open_dataset(inpath) for inpath in inbcon] If Datasets, infiles = inbcon
If outpath is not None, inbcon must be a str or list of paths
varkeys (list) – List of variable keys to process
verbose (int) – Level of verbosity
add_summary (bool) – Add summary level data
outpath (str or None) – Path to save (or retrieve) results from. Cached results will only be used if the outpath file is newer than all the inputs.
draft (bool) – If True, use actual_range and actual_median properties instead of file data.
- Returns:
statdf – Dataframe with rows for each file and variable combination. Each row has min, mean, median, max, std
- Return type:
pandas.DataFrame
- aqmbc.report.make_vertprof(inbcon, varkeys=None, func='mean', verbose=0)[source]
- Parameters:
inbcon (list or str) –
If str, inbcon = sorted(glob.glob(inbcon)) If list, items should be str or xarray.Dataset object.
If str, infiles = [xr.open_dataset(inpath) for inpath in inbcon] If Datasets, infiles = inbcon
varkeys (list or None) – variable keys (if None, use all)
func (str) – Name of function to apply to each variable (min, mean, max, median)
verbose (int) – Level of verbosity
- Returns:
vf – Variables have func applied to all dimensions except for LAY.
- Return type:
xarray.Dataset
- aqmbc.report.makestats(inbcon, varkeys=None, verbose=0, draft=False)[source]
- Parameters:
inbcon (list or str) –
If str, inbcon = sorted(glob.glob(inbcon)) If list, items should be str or xarray.Dataset object.
If str, infiles = [xr.open_dataset(inpath) for inpath in inbcon] If Datasets, infiles = inbcon
varkeys (list) – List of variable keys to process
verbose (int) – Level of verbosity
draft (bool) – If True, use actual_range and actual_median properties instead of file data.
- Returns:
statdf – Dataframe with rows for each file and variable combination. Each row has min, mean, median, max, std
- Return type:
pandas.DataFrame
- aqmbc.report.plot_gaspm_bars(statdf, filekey='Overall', metric='median', sortmetric='median')[source]
- aqmbc.report.plot_vprof(vmean, vmin=None, vmax=None, ax=None, **kwds)[source]
- Parameters:
vmean (xarray.DataArray) – Average of vertical profile at time steps; must have the TSTEP and LAY dimensions
vmin (xarray.DataArray) – Optional lower and upper bounds
vmax (xarray.DataArray) – Optional lower and upper bounds
ax (matplotlit.axes.Axes) – Optional axes to add lines to.
kwds (mappable) – Properties for lines
- Returns:
ax – If ax was provided, the same ax is returned. Otherwise, a new ax is created using subplots.
- Return type:
matplotlit.axes.Axes
- aqmbc.report.reportfromcfg(cfgobjs, cfgtype='path')[source]
Runs getstats, and get_vertprof and save to disk If summaryfigs=’y’, run plot_gaspm_bars and plot_2spc_vprof and save results to disk.
- Parameters:
cfgobjs (list) – List of paths, files, or dictionaries
cfgtype (str) – ‘path’, ‘file’, or ‘dict’
- Return type:
None
- aqmbc.report.summarize(statdf, append=True)[source]
- Parameters:
statdf (pandas.DataFrame) – DataFrame from makestats or getstats
append (bool) – If True, add record to statdf and return full dataframe.
- Returns:
statdf – Add Overall record for each variable where mean and std are averages, unit and min are their minimums, max is its maximum, and median is its median.
- Return type:
pandas.DataFrame
Module contents
Code for making CMAQ-ready boundary condition files
Contents
- bconmodule
module with functions for making boundary condition files
- cmaqmodule
module for making files CMAQ ready
- reportmodule
module with convenience functions for reporting
- defnpathstr
Path to all definition files available in examples.
- runcfgfunction
Function to run aqmbc from configuration files
Examples
Ex Python GEOS-Chem
import PseudoNetCDF as pnc import aqmbc
inpath = ‘/path/to/geoschem.nc’ bcpath = ‘BCON.nc’ # using built in expressions exprpaths = [f’{aqmbc.defnpath}/gc/gcnc_airmolden.expr’,
f’{aqmbc.defnpath}/gc/gc14_to_cb6r5.expr’]
metaf = pnc.pncopen(‘/path/to/METCRO3D_ANYDATE’, format=’ioapi’) bc(inpath, bcpath, metaf, vmethod=’linear’, exprpaths=exprpaths,
dimkeys=dict(TSTEP=’time’, LAY=’lev’, ROW=’lat’, COL=’lon’), format_kw=’gcnc’, history=’just a test’)
Ex Scripting
python -m aqmbc -t runfolder cd runfolder # copy a cfg file as run.cfg # edit run.cfg for your application. python -m aqmbc run.cfg
Version History
- 0.4.1: Update bc and cmaqready to apply a minimum value and allow inpaths
to be provided by a template. The minimum value (minvalue) can be set in the common configuration section. Also, improved reporting functions and automated reporting via the config file.
- 0.4.0: Change verbose to string for newer configparser compat
Update FILEDESC and HISTORY outputs to limit to 60*80 char Added cmaq module with cmaqready to stack, interpolate, and when necessary clean metadata. Added some reporting tools, expression library and examples. Needs better documentation on many objects.
- aqmbc.bc(inpath, outpath, metaf, tslice=None, vmethod='conserve', exprpaths=None, clobber=False, dimkeys=None, format_kw=None, history='', speedup=None, timeindependent=False, verbose=1, minvalue=None)[source]
- Parameters:
inpath (str) – path to input file
outpath (str) – path to output file
metaf (netcdf-like) – Metadata file (CRO for ICON, BDY for BCON)
tslice (slice) – Optional time slice (e.g., slice(0) for ICON)
vmethod (str) – method to use for vertical interpolation (conserve or linear)
exprpaths (list) – text files with species translations
clobber (bool) – overwrite existing files
speedup (bool) – slice file to load into memory. More mem, but faster
timeindependent (bool) – If True and input has just 1 time, write out as an IOAPI time-independent file.
minvalue (scalar) – Passed to translate
- Return type:
None
Notes
Saves BCON or ICON to file.
- Operations:
window
horizontal extraction
vertical interpolation
species translation
- aqmbc.runcfg(cfgobjs, cfgtype='path', warningfilter='ignore', dryrun=False, speedup=None)[source]
- Parameters:
cfgobjs (list) – List of paths, files, or dictionaries
cfgtype (str) – ‘path’, ‘file’, or ‘dict’
warningfilter (str) – str accepted by warnings.simplefilter
dryrun (bool) – If True, return config after testing parsing.
speedup (bool or None) – If True, use more memory but run faster. If None, heursitcally decide.