GithubHelp home page GithubHelp logo

barronh / aqmbc Goto Github PK

View Code? Open in Web Editor NEW
9.0 4.0 2.0 3.2 MB

Air Quality Model Boundary Condition Tools

License: GNU General Public License v3.0

Makefile 0.06% Python 62.97% Jupyter Notebook 36.97%

aqmbc's Introduction

aqmbc

Air Quality Model Boundary Condition (aqmbc) Tools

Air Quality Model Boundary Conditions is a tool to create time and space boundary conditions for an Air Quality Model from one or many data sources.

aqmbc is a python tool to make boundary conditions for CMAQ.

The key value of aqmbc is to provide a single interface to multiple models. This makes maintaining a system easy to acheive and hopefully easy to use.

Currently, aqmbc supports:

  • GEOS-Chem v12 and v14
  • CMAQ (Hemispheric or Regional)
  • NASA GMAO's GEOS-CF
  • RAQMS

To do:

  • aqmbc would like to support WACCM, AM4, and CAMS
  • A future version will allow for explicit output of CAMx readable boundary conditions. For now, use the cmaq2camx tools to convert these files.

Documentation

https://barronh.github.io/aqmbc

Installation

pip install git+https://github.com/barronh/aqmbc.git

or

pip install https://github.com/barronh/aqmbc/archive/refs/heads/main.zip

Example

# Create a working directory with standard configurations
python -m aqmbc --template examples
cd examples
# Edit a standard configuration file to point to your inputs/outputs
# - gcncv12.cfg
# - gcnd49v11.cfg
# - raqms.cfg
# Or make your own cfg
python -m aqmbc gcncv12.cfg
# Right now, the raqms reader/interpolator must be defined at runtime
# If using raqms, run python raqms.py

This process makes files that mirror the global air quality model structure. However, CMAQ requires hourly lateral boundary condition files with instantaneous values for every hour edges (24/day + 1).

It is often convenient to concatenate all days in a month using ncrcat or other tools. Below is an example using PseudoNetCDF.

import PseudoNetCDF as pnc
import glob

paths = (
    sorted(glob.glob('BCON/*2016-01-*.12US1.BCON.nc'))
    + sorted(glob.glob('BCON/*2016-02-01*.12US1.BCON.nc'))
)
mf = pnc.pncmfopen(paths, format='ioapi', stackdim='TSTEP')
mf.save('BCON_2016-01.12US1.BCON.nc')

If your data has fewer than hourly values, you will also need to add interpolation. Currently, these steps are not supported because the possibilities are too varied. I recommend xarray for this type of processing.

How to Contribute

  • If you add a new set of definitions (new version of GEOS-Chem or a new model), consider opening an issue on github and posting it there. It would be great to include these in future versions.
  • If you find a bug, open an issue.

Prerequisites

  • PseudoNetCDF (github.com/barronh/PseudoNetCDF).
  • pyproj

aqmbc's People

Contributors

barronh avatar

Stargazers

Leo avatar Alex Zhang avatar Seyed Hamid avatar Iara da Silva avatar Shigan Liu avatar Gordon avatar Patrick Ferraz avatar Pankaj Kumar avatar  avatar

Watchers

James Cloos avatar  avatar  avatar Patrick Ferraz avatar

aqmbc's Issues

PSURF and TMPU is not defined

Hi Barron,

I'm trying to run aqmbc with the definition gc12_to_ae7.expr. When I used pncglobal2cmaq it was possible to define AIRMOLDEN with default values ​​for TMPU and PSURF, the definition gc_airmolden.expr has this rule but I was unable to identify how I can define PSURF and TMPU.

I tried adding the content below in the first two lines of the gc_airmolden.expr file:

PSURF = (np.ones_like(O3[:,0][:, None])*1013.25)
TMPU = (np.ones_like(O3[:])*np.array([287.7,286.9,286.0,285.2,284.3,283.4,282.6,281.7,280.7,279.8,278.9,277.9,276.8,275.3,273.6,271.8,270.0,268.2,265.8,262.8,259.7,256.4,252.9,249.2,245.2,241.0,236.4,230.5,223.6,216.8,216.6,216.6,216.6,216.6,216.6,216.6,216.6,217.5,219.8,222.0,225.3,233.6,250.5,269.2,260.0,237.7,214.3])[None, :47, None, None])

but there is a problem with the shape:

Traceback (most recent call last):
  File "bcon.py", line 431, in <module>
    history=str(args))
  File "bcon.py", line 196, in bc
    outf = func(outf)
  File "bcon.py", line 124, in translate
    outf = infile.eval(exprstr, inplace=False)
  File "/home/patrick.ferraz/.conda/envs/pseudonetcdf/lib/python3.6/site-packages/PseudoNetCDF/core/_files.py", line 995, in eval
    exec(comp, None, vardict)
  File "none", line 3, in <module>
ValueError: operands could not be broadcast together with shapes (24,35,164) (1,47,1,1)
make[1]: *** [ts20150117.bpch.BCON.nc] Error 1
make[1]: Leaving directory `/scratch/patrick.ferraz/numerical_models/aqmbc_2/BCON'
make: *** [bcon] Error 2

can not read GEOS-Chem output

I tried to successfully installed the aqmbc and want to process GEOS-Chem output (v14.01.1, 4x5 full chemistry) for my 12US2 CMAQ simulations, but the aqmbc can not read the netCDF file. Below are my .cfg file and the error. I checked my Python environment, with the PseudoNetCDF and pyproj installed.

########################## cfg #######################
; GDNAM must exists as a projection in GRIDDESC
gdnam=12US2
griddesc=GRIDDESC
; VGTOP is the WRF model top in Pascals and VGLVLS are the
; edges of each level in WRF dry-sigma coordinate top
vgtop=5000
vglvls=[
1.0, 0.9975, 0.995, 0.99, 0.985, 0.98, 0.97, 0.96, 0.95, 0.94,
0.93, 0.92, 0.91, 0.9, 0.88, 0.86, 0.84, 0.82, 0.8, 0.77,
0.74, 0.7, 0.65, 0.6, 0.55, 0.5, 0.45, 0.4, 0.35, 0.3,
0.25, 0.2, 0.15, 0.1, 0.05, 0.0
]

; Use linear or conserve to inteprolate vertically
; Linear simplifies the source coordinate to an approximation
; of sigma and interpolates to centers. Conserve uses layer
; edges of both the input and output to conserve mixing ratios.
; Concentrations are mole-weighted levels.
vinterp=linear

; Use expressions to translate input model to CMAQ
expressions=[
"${rcpath}/definitions/gc/gcnc_airmolden.expr",
"${rcpath}/definitions/gc/gc12_to_cb6r3.expr",
"${rcpath}/definitions/gc/gc12_soas_to_ae7.expr"
]

[source]
; Sources currently supported are GEOS-Chem bcph, GEOS-Chem netcdf, and CMAQ
; input is a strftime template that will be evaluated for each day.
input=input/GEOSChem.BoundaryConditions.%Y%m%d_0000z.nc4

; Format should have a format keyword and options
; a common option is "nogroup": true for GEOS-Chem bpch
format={"format": "gcnc"}
; Dims translates dimension names from the source to CMAQ
dims={
"TSTEP": "time",
"LAY": "lev",
"ROW": "lat",
"COL": "lon"
}

[ICON]
; Usually, you only want a couple ICON, so you specify the
; date individually
;dates=["2016-01-01"]
dates=["2019-07-01"]
output=ICON/GEOSChem.SpeciesBC.%Y%m%d_0000z.${GDNAM}.ICON.nc

[BCON]
; BCON are provided for each day, so you specify a range

########################## Error ######################
ozone.umd.edu{hhe}1008: python -m aqmbc gcncv12.cfg
[common]
overwrite = False
verbose = 0
pwd = /data/chemstg67/hhe/geos-chem/cmaq_bc
rcpath = /data/chemstg67/hhe/geos-chem/cmaq_bc
gdnam = 12US2
griddesc = GRIDDESC
vgtop = 5000
vglvls = [
1.0, 0.9975, 0.995, 0.99, 0.985, 0.98, 0.97, 0.96, 0.95, 0.94,
0.93, 0.92, 0.91, 0.9, 0.88, 0.86, 0.84, 0.82, 0.8, 0.77,
0.74, 0.7, 0.65, 0.6, 0.55, 0.5, 0.45, 0.4, 0.35, 0.3,
0.25, 0.2, 0.15, 0.1, 0.05, 0.0
]
vinterp = linear
expressions = [
"${rcpath}/definitions/gc/gcnc_airmolden.expr",
"${rcpath}/definitions/gc/gc12_to_cb6r3.expr",
"${rcpath}/definitions/gc/gc12_soas_to_ae7.expr"
]

[source]
input = input/GEOSChem.BoundaryConditions.%Y%m%d_0000z.nc4
format = {"format": "gcnc"}
dims = {
"TSTEP": "time",
"LAY": "lev",
"ROW": "lat",
"COL": "lon"
}

[ICON]
dates = ["2019-07-01"]
output = ICON/GEOSChem.SpeciesBC.%Y%m%d_0000z.${GDNAM}.ICON.nc

[BCON]
start_date = 2019-07-01
end_date = 2019-07-02
freq = d
output = BCON/GEOSChem.SpeciesBC.%Y%m%d_0000z.${GDNAM}.BCON.nc

Converting input/GEOSChem.BoundaryConditions.20190701_0000z.nc4 to BCON/GEOSChem.SpeciesBC.20190701_0000z.12US2.BCON.nc
open
Traceback (most recent call last):
File "/data/chemstg67/hhe/python/anaconda3/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "/data/chemstg67/hhe/python/anaconda3/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/data/chemstg67/hhe/python/anaconda3/lib/python3.7/site-packages/aqmbc/main.py", line 36, in
runcfg(args.config)
File "/data/chemstg67/hhe/python/anaconda3/lib/python3.7/site-packages/aqmbc/init.py", line 117, in runcfg
bc(**opts)
File "/data/chemstg67/hhe/python/anaconda3/lib/python3.7/site-packages/aqmbc/bcon.py", line 182, in bc
infile = pnc.pncopen(inpath, **format_kw)
File "/data/chemstg67/hhe/python/anaconda3/lib/python3.7/site-packages/PseudoNetCDF/_getreader.py", line 153, in pncopen
outfile = reader(*args, **kwds)
File "/data/chemstg67/hhe/python/anaconda3/lib/python3.7/site-packages/PseudoNetCDF/geoschemfiles/_gcnc.py", line 213, in init
netcdf.init(self, *args, **kwds)
File "/data/chemstg67/hhe/python/anaconda3/lib/python3.7/site-packages/PseudoNetCDF/core/_files.py", line 2471, in init
NetCDFFile.init(self, *args, **kwds)
File "src/netCDF4/_netCDF4.pyx", line 2463, in netCDF4._netCDF4.Dataset.init
File "src/netCDF4/_netCDF4.pyx", line 2026, in netCDF4._netCDF4._ensure_nc_success
OSError: [Errno -51] NetCDF: Unknown file format: b'input/GEOSChem.BoundaryConditions.20190701_0000z.nc4'

Boundary conditions layers problem

I have run the aqmbc software to process the GEOS-Chem outputs for CMAQ. In the .cfg file I have the following setting:

vgtop=5000
vglvls=[
1.0, 0.9975, 0.995, 0.99, 0.985, 0.98, 0.97, 0.96, 0.95, 0.94,
0.93, 0.92, 0.91, 0.9, 0.88, 0.86, 0.84, 0.82, 0.8, 0.77,
0.74, 0.7, 0.65, 0.6, 0.55, 0.5, 0.45, 0.4, 0.35, 0.3,
0.25, 0.2, 0.15, 0.1, 0.05, 0.0
]

The generated outputs have 47 layers (I select 47L GEOS_Chem and please see below) instead of 35 for my CMAQ. What should I do to change that?

netcdf GEOSChem.SpeciesBC.20160101_0000z.12US2.BCON.nc {
dimensions:
PERIM = 1288 ;
TSTEP = UNLIMITED ; // (240 currently)
LAY = 47 ;
VAR = 1 ;
DATE-TIME = 2 ;

vertical interpolation doesn't work

Hello,

I tried to map GC outputs (lev=72) to the CMAQ BCON format. But the output is still "LAY 72". I used _vglvls as the default setting in bcon.py.
The command I used shown as below:
python bcon.py -O --expr ../definitions/gc/gcnc_airmolden.expr --expr ../definitions/gc/gc12_to_ae6_nvPOA.expr --interp linear --format gcnc --grid TEST ../CONC/GCHP.SpeciesConc.20180701_0330z.nc4 GCHP.SpeciesConc.20180701_0330z.nc4.BCON.nc

Could you help me about this problem? Thanks in advance.

cmaq can't read the output

Hello,

I used aqmbc to generate BCON files from Geos-Chem to CMAQ 5.3.2, but the CMAQ model doesn't work and the error was shown as below. I'm new to the CMAQ model and wonder whether you could help me solve the problem?

Thanks in advance!

--->> WARNING in subroutine READ3
Requested variable "
OXYL.units = "p" not available
M3WARN: DTBUF 8:00:00 June 24, 2018 (2018175:080000)

 *** ERROR ABORT in subroutine retrieve_boundar on PE 000
 Could not read BNDY_CONC_1                              file

PM3EXIT: DTBUF 8:00:00 June 24, 2018
Date and time 8:00:00 June 24, 2018 (2018175:080000)

GEOS-Chem Benchmark Unused Species

Using verbose=9 shows 158 unused species with translating GEOS-Chem benchmark to boundary conditions. Of those, 72 are advected species.

  • The SOG/SOA are not used because we are using the SOAP and SOAS speciation.
  • Many CFCs are not available in CMAQ and so are not used.
  • Iodine is not in CMAQ
  • MVK species are likely not a big issue.
  • CMAQ doesn't have a benzene PAN
  • CMAQ doesn't have MPN
  • DMS should be added to the definition.
  • Others?

The full list is shown below:

Dropped 158
Advected 72
AERI: "Iodine on aerosol"
AONITA: "Aerosol-phase organonitrates from aromatics"
AROMP4: "Generic C4 product of aromatics"
AROMP5: "C5 unsaturated dicarbonyl"
BZCO3H: "Perbenzoic acid"
BZPAN: "Peroxybenzoylnitrate"
BrSALA: "Fine sea salt bromine"
BrSALC: "Coarse sea salt bromine"
CFC11: "CFC-11"
CFC113: "CFC-113"
CFC114: "CFC-114"
CFC115: "CFC-115"
CFC12: "CFC-12"
CH3Br: "Methyl bromide"
CH3CCl3: "Methyl chloroform"
CLOCK: "Clock tracer for diagnosing age of air"
Cl2O2: "Dichlorine dioxide"
ClOO: "Chlorine dioxide"
DMS: "Dimethyl sulfide"
H1211: "Halon 1211, Freon 12B1"
H1301: "Halon 1301, Freon 13B1"
H2402: "Halon 2402"
H2O: "Water vapor"
HAC: "Hydroxyacetone"
HCFC123: "HCFC-123, Freon 123"
HCFC141b: "HCFC-141b, Freon 141b"
HCFC142b: "HCFC-142b, Freon 142b"
HCFC22: "HCFC-22, Freon 22"
HMML: "hydroxymethyl-methyl-a-lactone"
HMS: "Hydroxymethanesulfonate"
HPETHNL: "Hydroperoxy ethanal"
INDIOL: "Generic aerosol-phase organonitrate hydrolysis product"
IONITA: "Aer-phase organic nitrate from isoprene precursors"
ISALA: "Fine sea salt iodine"
ISALC: "Coarse sea salt iodine"
LVOC: "Gas-phase low-volatility non-IEPOX product of RIP ox"
LVOCOA: "Aer-phase low-volatility non-IEPOX product of RIP ox"
MCRDH: "Dihydroxy-methacrolein"
MCRENOL: "Lumped enols from MVK/MACR"
MONITA: "Aer-phase organic nitrate from monoterpene precursors"
MPN: "Methyl peroxy nitrate"
MVKDH: "dihydroxy-MVK"
MVKHC: "MVK hydroxy-carbonyl"
MVKHCB: "MVK hydroxy-carbonyl"
MVKHP: "MVK hydroxy-hydroperoxide"
MVKPC: "MVK hydroperoxy-carbonyl"
N2O: "Nitrous oxide"
NAP: "Naphtalene/IVOC surrogate"
OClO: "Chlorine dioxide"
PYAC: "Pyruvic acid"
SALAAL: "Accumulation mode sea salt alkalinity"
SALACL: "Chloride in Accumulation mode sea salt aerosol"
SALCAL: "Coarse mode sea salt alkalinity"
SALCCL: "Chloride in Coarse mode sea salt aerosol"

SOA Species
SOAGX: "Aerosol-phase glyoxal"
SOAIE: "Aerosol-phase IEPOX"
ASOA1: "Lumped non-volatile aerosol products of light aromatics + IVOCs"
ASOA2: "Lumped non-volatile aerosol products of light aromatics + IVOCs"
ASOA3: "Lumped non-volatile aerosol products of light aromatics + IVOCs"
ASOAN: "Lumped non-volatile aerosol products of light aromatics + IVOCs"
ASOG1: "Lumped non-volatile gas products of light aromatics + IVOCs"
ASOG2: "Lumped non-volatile gas products of light aromatics + IVOCs"
ASOG3: "Lumped non-volatile gas products of light aromatics + IVOCs"
TSOA0: "Lumped semivolatile aerosol products of monoterpene + sesquiterpene oxidation"
TSOA1: "Lumped semivolatile aerosol products of monoterpene + sesquiterpene oxidation"
TSOA2: "Lumped semivolatile aerosol products of monoterpene + sesquiterpene oxidation"
TSOA3: "Lumped semivolatile aerosol products of monoterpene + sesquiterpene oxidation"
TSOG0: "Lumped semivolatile gas products of monoterpene + sesquiterpene oxidation"
TSOG1: "Lumped semivolatile gas products of monoterpene + sesquiterpene oxidation"
TSOG2: "Lumped semivolatile gas products of monoterpene + sesquiterpene oxidation"
TSOG3: "Lumped semivolatile gas products of monoterpene + sesquiterpene oxidation"
pFe: "Anthropogenic iron"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.