Regridding I/O API files

What is the easiest way to regrid an existing I/O API file (originally with latlon grids at 0.1 degrees resolution to be changed to resolution of 0.5 degrees and the variable values regridded accordingly)?

Use I/O API M3TOOLS programs mtxcalc and mtxcple. See

https://cjcoats.github.io/ioapi/MTXCALC.html
https://cjcoats.github.io/ioapi/MTXCPLE.html

Thanks! Of the two functions you pointed to, one creates the conversion matrix, and the other actually converts. And to use them, an appropriate GRIDDESC file entry is needed. I’ll give it a try. Thanks again!

I wanted to get a GRIDDESC file for the output from WRF, and use its coordinate system + grid as a reference to convert all other files to. However, when I use the command wrfgriddesc, I get the message
wrfgriddesc: Command not found
I am using IO/API 3.1 version, by the way.

Just realized that the two M3 functions
MTXCALC
MTXCPLE
can only be used if you are transforming IO/API file to a finer grid. I need to do the opposite - that is convert a fine 0.1 degree grid to a coarse 0.5 degree grid. What are my options here?

skunwar wrote:

[skunwar] skunwar https://forum.cmascenter.org/u/skunwar
November 6

Just realized that the two M3 functions
MTXCALC
MTXCPLE
can only be used if you are transforming IO/API file to a finer grid. I
need to do the opposite - that is convert a fine 0.1 degree grid to a
coarse 0.5 degree grid. What are my options here?

No. You’re thinking about “m3cple”, which does bilinear interpolation.

What is being done is this: For a refinement of the output-grid,
calculate where the output-grid cell-centers fall in the input-grid,
and use that info to compute an aggregation-matrix.

Then “mtxcple” uses that aggregation-matrix to re-grid…

Thanks Carlie! Just to be clear on the concept of aggregation matrix when converting a fine grid to coarse grid, I made a diagram:

The fine source grid A cell# 11 would provide value for the coarse grid B cell#1 in the aggregation matrix? As an example, I would need to write a script that would only select row 2, col 1 cell from the entire collection of 9 grid-cells in source grid A for the aggregation matrix in grid cell# 1 target grid B - I am understanding it correctly?

skunwar wrote:

[skunwar] skunwar https://forum.cmascenter.org/u/skunwar
November 7

Thanks Carlie! Just to be clear on the concept of aggregation matrix when
converting a fine grid to coarse grid, I made a diagram:

image
https://aws1.discourse-cdn.com/standard10/uploads/cmas/original/1X/b28a211869fcdd616c1407b7b25cfe83acc5a7ed.png

The fine source grid A cell# 11 would provide value for the coarse grid B
cell#1 in the aggregation matrix? As an example, I would need to write a
script that would only select row 2, col 1 cell from the entire collection
of 9 grid-cells in source grid A for the aggregation matrix in grid cell#
1 target grid B - I am understanding it correctly?

For grid-B cell-1 (“B1”), the aggregation matrix would take

 F*(A1 + A2 + A3 + a10 + A11 + A12 + A19 + A20 + A21)/9

where F is a scaling-constant from the user (default 1, as for averaging
met data; for emissions data, F needs to be nesting-ratio^2 = 9).

This is an easy case, where grid-A is a “refinement” of grid-B. For the
more general case (where A and B have different coordinate systems, and
the grids don’t match up exactly), it is a bit more complicated, which is
where the sub-sampling comes in…

Thanks- That makes it clear!

To do the above-said aggregation on each coarse cell in the IO/API file (containing the conversion matrix), what m3tool would you recommend? I am a little new to IO/API files processing.

Do you have guidance for us as to how to select values for COL_REFINEMENT and ROW_REFINEMENT while using mtxcalc and mtxcple to regrid? I am trying to convert from a coarse 2.5 deg by 2 deg lon-lat grid to a fine 12km by 12km lambert conformal grid.

For that great a difference in resolution, particularly because the output grid is much finer than the input grid, I’d just use M3Tools program m3cple, which does bilinear interpolation to the output-grid cell-centers. mtxcple is much more for the cases when the output-grid resolution is as coarse or coarser than the input.

See https://cjcoats.github.io/ioapi/M3CPLE.html

I used m3cple and overall, the result was better than mtxcple (which had only given only 0s everywhere) but I am seeing negative numbers in some gridcells in the OUTFILE and was wondering what could have caused it? I can only guess that I didn’t use synch file but not sure if that is the reason.

[skunwar] skunwar https://forum.cmascenter.org/u/skunwar
May 28

I used m3cple and overall, the result was better than mtxcple (which had
only given only 0s everywhere) but I am seeing negative numbers in some
gridcells in the OUTFILE and was wondering what could have caused it? I
can only guess that I didn’t use synch file but not sure if that is the
reason.

Do you have “missing” in the data? Simple bilinear interpolation does
not know how to deal with that. – Carlie

I do have missing data filled with some standard value, so maybe setting that to zero would regrid fine?

That’s still going to cause artifacts.

For the missing-data-regridding case you need a gridding algorithm that checks for missings, and that does appropriate weighting even when they are present. Bilinear, spline, and other higher-order algorithms won’t work in that situation.

One reasonable approach for that might be to modify I/O API routine CBARNES1() (cbarnes1.f: see https://cjcoats.github.io/ioapi/CBARNES.html) to handle missing data correctly, and then build a “driver” program to use that as its computational kernel. Or else filter out all the “missing” data, and feed the resulting filtered data into the existing CBARNES1.

Early on in the Models-3 project that created CMAQ, it was decided that bugs in “missing”-data handling were so pervasive that the entire situation should be excluded: “missing” data should be filtered out during the data-import process, so that “missing” data was never allowed into the system.