.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/gcbc_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_gcbc_example.py: GEOS-Chem Benchmark LBC for CMAQ ================================ This example shows how to use aqmbc with GEOS-Chem's publicly available benchmark outputs. * Dowload from Harvard (if not previously downloaded). * Define translations. * Extract, translate, and create time-independent files. * Display figures and statistics. Time-independence allows files to be used in CMAQ with multiple dates in the same month, or as a climatology for other years. .. GENERATED FROM PYTHON SOURCE LINES 15-22 .. code-block:: default from os.path import basename, exists import aqmbc import matplotlib.pyplot as plt import requests import tarfile .. GENERATED FROM PYTHON SOURCE LINES 23-25 Download from Harvard --------------------- .. GENERATED FROM PYTHON SOURCE LINES 25-53 .. code-block:: default inpaths = [ 'OutputDir/GEOSChem.SpeciesConc.20190401_0000z.nc4', 'OutputDir/GEOSChem.SpeciesConc.20190701_0000z.nc4', ] if any([not exists(p) for p in inpaths]): # Download 7G tar file rurl = 'http://ftp.as.harvard.edu/gcgrid/geos-chem/1yr_benchmarks/' url = f'{rurl}/14.0.0-rc.0/GCClassic/FullChem/OutputDir.tar.gz' dest = basename(url) if not exists(dest): with requests.get(url, stream=True) as r: r.raise_for_status() with open(dest, 'wb') as f: for chunk in r.iter_content(chunk_size=1024*1024): f.write(chunk) else: print('Using cached OutputDir.tar.gz') # Unzip only files that will be used. tf = tarfile.open(dest) for memb in tf.getmembers(): if memb.path in inpaths: if not exists(memb.path): tf.extract(memb) else: print('Using cached', memb.path) .. GENERATED FROM PYTHON SOURCE LINES 54-59 Define Chemical Translation --------------------------- Using gc14_o3so4.expr, which only uses ozone and sulfate aerosols. .. GENERATED FROM PYTHON SOURCE LINES 59-69 .. code-block:: default print(aqmbc.exprlib.avail('gc')) # Show all possible expressions exprpaths = aqmbc.exprlib.exprpaths([ # for a full run, 'gcnc_airmolden.expr', # keep this 'gc14_o3so4.expr', # Comment this # 'gc14_to_cb6r5.expr', 'gc14_to_cb6mp.expr', # Uncomment this # 'gc14_soas_to_ae7.expr' # uncomment this ], prefix='gc') .. GENERATED FROM PYTHON SOURCE LINES 70-72 Tranlate Files and Make Time-independent ---------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 72-97 .. code-block:: default gdnam = '12US1' gcdims = aqmbc.options.dims['gc'] suffix = f'_{gdnam}_BCON.nc' metaf = aqmbc.options.getmetaf(bctype='bcon', gdnam=gdnam, vgnam='EPA_35L') # For "real" VGLVLS use # METBDY3D_PATH = '...' # METCRO3D_PATH = '...' # metaf = pnc.pncopen(METBDY3D_PATH, format='ioapi').subset(['PRES']) # pnc.conventions.ioapi.add_cf_from_ioapi(metaf) 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=exprpaths, dimkeys=gcdims, format_kw={'format': 'gcbench'}, history=history, clobber=True, verbose=0, timeindependent=True ) bcpaths.append(outpath) .. GENERATED FROM PYTHON SOURCE LINES 98-100 Figures and Statistics ---------------------- .. GENERATED FROM PYTHON SOURCE LINES 100-105 .. code-block:: default vprof = aqmbc.report.get_vertprof(bcpaths) statdf = aqmbc.report.getstats(bcpaths) statdf.to_csv('gcbc_summary.csv') .. GENERATED FROM PYTHON SOURCE LINES 106-108 Plot Vertical Profiles ~~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 108-113 .. code-block:: default fig = aqmbc.report.plot_2spc_vprof(vprof) fig.suptitle('GEOS-Chem v14 Boundary Conditions for CMAQ') fig.savefig('gcbc_profiles.png') .. GENERATED FROM PYTHON SOURCE LINES 114-116 Plot Normalized Means ~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 116-119 .. code-block:: default fig = aqmbc.report.plot_gaspm_bars(statdf) fig.savefig('gcbc_bar.png') .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.000 seconds) .. _sphx_glr_download_auto_examples_gcbc_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: gcbc_example.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: gcbc_example.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_