.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/hcmaq_example.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_hcmaq_example.py: Hemispheric CMAQ LBC for CMAQ ============================= This example shows how to use aqmbc with a synthetic Hemispheric CMAQ. * Create synthetic exmaple files. * Extract assuming no translation (same gas and aerosols as target). * Display figures and statistics. .. GENERATED FROM PYTHON SOURCE LINES 12-18 .. code-block:: default from os.path import basename import aqmbc import numpy as np import matplotlib.pyplot as plt .. GENERATED FROM PYTHON SOURCE LINES 19-21 Create Fake Hemispheric CMAQ Files ---------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 21-46 .. code-block:: default inpaths = [ 'HCMAQFAKECONC.20190401_0000z.nc4', 'HCMAQFAKECONC.20190701_0000z.nc4', ] tmpf = aqmbc.options.getmetaf( bctype='icon', gdnam='5940NHEMI2', vgnam='EPA_44L' ) keys = ['O3', 'ASO4I', 'ASO4J'] for k in keys: v = tmpf.createVariable(k, 'f', ('TSTEP', 'LAY', 'ROW', 'COL')) v.setncatts(dict(long_name=k.ljust(16), var_desc=k.ljust(80))) tmpf.variables['ASO4I'].units = 'micrograms/m**3'.ljust(16) tmpf.variables['ASO4J'].units = 'micrograms/m**3'.ljust(16) tmpf.variables['O3'].units = 'ppmV'.ljust(16) tgtx = np.log(tmpf.VGLVLS[1:]) o3vals = np.interp(tgtx, np.log([.01, .2, .3, 1]), [1, .1, .06, .04]) so4vals = np.interp(tgtx, np.log([.01, .2, .6, .9, 1]), [.06, .06, 0.2, 1, 1]) for i, (inpath, factor) in enumerate(zip(inpaths, [1, .9])): tmpf.variables['O3'][:] = o3vals[None, :, None, None] * factor tmpf.variables['ASO4I'][:] = so4vals[None, :, None, None] * 0.01 * factor tmpf.variables['ASO4J'][:] = so4vals[None, :, None, None] * 0.99 * factor tmpf.subset(keys).save(inpath, format='NETCDF3_CLASSIC', verbose=0).close() .. GENERATED FROM PYTHON SOURCE LINES 47-49 Tranlate Files and Make Time-independent ---------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 49-73 .. code-block:: default gdnam = '12US1' suffix = f'_{gdnam}_BCON.nc' metaf = aqmbc.options.getmetaf(bctype='bcon', gdnam=gdnam, vgnam='EPA_35L') # For "real" VGLVLS use # METBDYD_PATH = '...' # metaf = pnc.pncopen(METCRO3D_PATH, format='ioapi') bcpaths = [] for inpath in inpaths: print(inpath, flush=True) outpath = basename(inpath).replace('.nc4', suffix) history = f'From {outpath}' outf = aqmbc.bc( inpath, outpath, metaf, vmethod='linear', exprpaths=[], format_kw={'format': 'ioapi'}, history=history, clobber=True, verbose=0 ) if outf is not None: # if not already archived aqmbc.cmaq.timeindependent(outf) bcpaths.append(outpath) .. GENERATED FROM PYTHON SOURCE LINES 74-76 Figures and Statistics ---------------------- .. GENERATED FROM PYTHON SOURCE LINES 76-81 .. code-block:: default vprof = aqmbc.report.get_vertprof(bcpaths) statdf = aqmbc.report.getstats(bcpaths) statdf.to_csv('hcmaq_summary.csv') .. GENERATED FROM PYTHON SOURCE LINES 82-84 Visualize Vertical Profiles --------------------------- .. GENERATED FROM PYTHON SOURCE LINES 84-89 .. code-block:: default fig = aqmbc.report.plot_2spc_vprof(vprof) fig.suptitle('Fake Hemispheric CMAQ Boundary Conditions for CMAQ') fig.savefig('hcmaq_profiles.png') .. GENERATED FROM PYTHON SOURCE LINES 90-92 Barplot of Concentrations ------------------------- .. GENERATED FROM PYTHON SOURCE LINES 92-95 .. code-block:: default fig = aqmbc.report.plot_gaspm_bars(statdf) fig.savefig('hcmaq_bar.png') .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.000 seconds) .. _sphx_glr_download_auto_examples_hcmaq_example.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: hcmaq_example.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: hcmaq_example.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_