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://global.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.

I am regridding a larger and coarse ~250km (2 degrees lat/lon) data to finer and smaller 36km domain (lambert conformal conic) with the US at the center:

 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 Input grid parameters
 NCOLS=        72
 NROWS=        45
 GDTYP=         1
 P_ALP -9.9989997574922324E+36
 P_BET -9.9989997574922324E+36
 P_GAM -9.9989997574922324E+36
 XCENT -9.9989997574922324E+36
 YCENT -9.9989997574922324E+36
 XORIG  1.8000000000000000E+02
 YORIG  0.0000000000000000E+00
 XCELL  2.5000000000000000E+00
 YCELL  2.0000000000000000E+00
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 Output grid parameters
 NCOLS=       172
 NROWS=       135
 GDTYP=         2
 P_ALP  3.3000000000000000E+01
 P_BET  4.5000000000000000E+01
 P_GAM -9.7000000000000000E+01
 XCENT -9.7000000000000000E+01
 YCENT  4.0000000000000000E+01
 XORIG -2.9520000000000000E+06
 YORIG -2.4120000000000000E+06
 XCELL  3.6000000000000000E+04
 YCELL  3.6000000000000000E+04
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Regridding with ā€˜m3cpleā€™ gives unmatched patterns between input and output:

There are no fill_values in the input map as discussed a while ago in this thread, so I was not sure where to look for possible errors.

1 Like

Hi,

According to your suggestion, I used the pair of programs mtxcalc+mtxcple to make a file going from a finer grid CN09 to a coarser grid CN27. But I checked the value of the output file GRIDCROD09_cn27.nc (the following picture), which is as 9 times as the value of the input file GRIDCROD09.nc. My F is default 1, the value of the output file variable does not appear to be the average, but the sum of the nine cells.

Could you help me solve this problem? I want to calculate the average value of nine cells.

Regards,
Jin


You need to use the SCALEFAC environment variable for that: this program was initially used for emissions files, which have non-MKS-Standard mass per grid cell units, so that for emissions files you want cell-totals rather than cell-averages. For your case

setenv SCALEFAC 0.1111111

Thanks a lot. I solved my problem.