(part of the AQMEII-NA_N2O family of projects)

table of contents


Uses bash to drive NCL and R code to

  1. sum various EDGAR-4.2 N2O emission inventories (in netCDF format). These inventories cover sectors/processes of N2O production other than those involving biomass burning, oceans, and soils.
  2. "reunit": convert from (per-gridcell) flux rate (kg/m^2/s) to molar-mass rate (moles/sec, which CMAQ wants).
  3. 2D-regrid from global/unprojected to a projected subdomain (AQMEII-NA).
  4. "retemporalize" from annual timestep to hourly (and tweak metadata)
  5. check that mass is (more or less) conserved in all of the above

creating CMAQ-style emissions files (e.g., this, when gunziped) containing hourly emissions usable for any day in the year. Currently does not provide a clean or general-purpose (much less packaged) solution! but merely shows how to do these tasks using

  • bash (tested with version=3.2.25)
  • NCL (tested with version=6.1.2)
  • R (tested with version=3.0.0) and packages including


To run this code,

  1. git clone this repo. (See commandlines on the project homepage, where you probably are now.)
  2. cd to its working directory (where you cloned it to).
  3. Setup your applications and paths.
    1. Download a copy of these bash utilities to the working directory.
    2. Open the file in in an editor! You will probably need to edit its functions setup_paths and setup_apps to make it work on your platform. Notably you will want to point it to your PDF viewer and NCL and R executables.
    3. You may also want to open the driver (bash) script in an editor and take a look. It should run Out Of The Box, but you might need to tweak something there. In the worst case, you could hardcode your paths and apps in the driver.
    4. Once you've got it working, you may want to fork it. If so, you can automate running your changes with uber_driver.sh (changing that as needed, too).
  4. Run the driver: $ ./EDGAR_driver.sh
  5. This will download input, then run
    • an R script to sum the raw inputs, convert that intermediate product from mass flux to molar-mass rate, and plot it. The driver should display a global plot if properly configured.
    • an R script to regrid the previous product, and plot the output. The driver should display an AQMEII plot if properly configured.
    • an NCL script to generate hourly output suitable for input to CMAQ.
    • an NCL script to check conservation of mass from input to output. Given that the output domain (AQMEII-NA) is significantly smaller than the input domain (global), it merely reports the fraction of mass (as kg) in output vs input, and compares that to an estimate of the land area of the output domain relative to the input domain (since these emissions seem overwhelmingly land-based). Current output includes

          Compare annual emissions reported by EDGAR to our calculated annual emissions:
                     raw input    sum 
          EDGAR      annual sum   calculated
          sector     (kgN2O)      from output   EDGAR/calc
          --------   ----------   -----------   ----------
          combust     3.24e+08     3.23e+08      1.00e+00 
          nonroad     7.79e+07     7.76e+07      1.00e+00 
          road        2.23e+08     2.23e+08      1.00e+00 
          resid       2.85e+08     2.84e+08      1.00e+00 
          petro       6.52e+06     6.52e+06      1.00e+00 
          ind         1.33e+09     1.33e+09      1.00e+00 
          manure      3.36e+08     3.35e+08      1.00e+00 
          runoff      8.94e+08     8.92e+08      1.00e+00 
          waste       3.75e+08     3.74e+08      1.00e+00 
          fff         7.53e+05     7.53e+05      1.00e+00 
          tropo       7.11e+08     6.99e+08      1.02e+00
          Is N2O conserved from input to output? units=kg N2O
          (note (US land area)/(earth land area) ~= 6.15e-02)
              input      input     output     output           
             global        NAs  AQMEII-NA        NAs     out/in
           4.55e+09          0   4.38e+08          0   9.64e-02


  1. Retest with newest regrid_utils! Currently, repo_diff.sh shows the following local diffs:
    • get_filepath_from_template.ncl
    • netCDF.stats.to.stdout.r
    • string.ncl
    • summarize.ncl
    • time.ncl
    • visualization.r
    • refactor more of the common NCL IOAPI-writing code to local IOAPI.ncl?
  2. Move all these TODOs to issue tracker.
  3. *.sh: use bash booleans à la N2O_integration_driver.sh.
  4. Create common project for regrid_resources à la regrid_utils, so I don't hafta hunt down which resource is in which project.
  5. All regrids: how to nudge off/onshore as required? e.g., soil or burning emissions should never be offshore, marine emissions should never be onshore.
  6. All regrid maps: add Caribbean islands (esp Bahamas! for offshore burning), Canadian provinces, Mexican states.
  7. Complain to ncl-talk about NCL "unsupported extensions," e.g., .ncf and <null/> (e.g., MCIP output).
  8. Determine why <- assignment is occasionally required in calls to visualize.*(...).
  9. Fully document platform versions (e.g., linux, compilers, bash, NCL, R).
  10. Test on
    • tlrPanP5 (which now has R package=ncdf4, but readAsciiTable of input .txt's is very slow compared to terrae)
    • HPCC (once problem with ncdf4 on amad1 is debugged: in process with JOB and KMF)