(part of the AQMEII-NA_N2O family of projects)

table of contents


Uses bash to drive NCL and R code to

  1. "reunit" the data from CLM-CN-N2O's mgN/m^2 to molN2O/s (what CMAQ wants).
  2. 2D-regrid the data (in netCDF format) from global/unprojected to a projected subdomain (AQMEII-NA).
  3. "retemporalize" from monthly timestep to hourly, creating CMAQ-style emissions files (e.g., this, when gunziped) containing hourly emissions usable for any day in the month labeled (e.g., 200801 in the link).
  4. check that mass is (more or less) conserved in all of the above

Currently does not provide a clean or general-purpose (much less packaged) solution! This project merely shows how to perform 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.
  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 if needed, too). If you fork, contribute back: make a pull request!
  4. Run the driver: $ ./CLMCN_driver.sh This will download input, then run
    • an NCL script to convert raw-input concentrations to units appropriate for CMAQ.
    • an R script to plot the reunit-ed netCDF data, regrid it, and plot the output. The driver should display an input PDF and an output PDF if properly configured.
    • an NCL script to "retemporalize" the regridded output into monthly files (since the input is monthly) with hourly timesteps (since at this point we have "flat temporality": we assume emission at constant mol/s for each hour of the month).
    • 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 mgN) in output vs input, and compares that to an estimation of the land area of the output domain relative to the input domain. Current output is

          Is N2O conserved from input to output? units=mgN
          (note (US land area)/(earth land area) ~= 6.15e-02)
                     input      input     output     output           
          month     global        NAs  AQMEII-NA        NAs     out/in
              1   3.83e+14          0   2.22e+12          0   5.78e-03
              2   4.24e+14          0   2.33e+12          0   5.49e-03
              3   4.67e+14          0   3.46e+12          0   7.41e-03
              4   4.94e+14          0   6.60e+12          0   1.34e-02
              5   4.94e+14          0   1.02e+13          0   2.06e-02
              6   6.95e+14          0   1.77e+13          0   2.54e-02
              7   8.61e+14          0   1.84e+13          0   2.14e-02
              8   1.01e+15          0   1.74e+13          0   1.73e-02
              9   8.08e+14          0   1.64e+13          0   2.03e-02
             10   6.02e+14          0   1.04e+13          0   1.73e-02
             11   4.72e+14          0   5.01e+12          0   1.06e-02
             12   4.49e+14          0   3.67e+12          0   8.18e-03


  1. Retest with newest regrid_utils! Currently, repo_diff.sh shows the following local diffs:
    • get_filepath_from_template.ncl
    • string.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)