LATLON to ROWCOL and Vice-versa

Hi,

could you please answer the following?

(1) What is the (easy to use) m3tool to locate an arbitrary (lat,lon) point in the model grid? That is to convert lat lon to ROW, COL, and also the other way around.
(2) Suppose both models, WRF and CMAQ, use the same projection (LAMBERT); is the method of creating the grid (for mass points) exactly the same in both cases?

Thanks

M3Tools program projtool – see https://cjcoats.github.io/ioapi/PROJTOOL.html It does lots of different things but one of them is coordinates to col-row.
It’s intended to be run interactively from the command line, by the way.

Thank you. I think my question was not that clear. I wanted to map an arbitrary lat Lon point in geographic coordinates (e.g location of an observation from EPA sites, say in the standard WGS84 datum) to Row col indices in the model.

Any simplifying hints?
Thanks

This is somewhat more involved than you think.

Geographic coordinates (Lat-Lon) are independent of geodetic spheroid. Cartesian model coordinates (e.g., the Lambert projections typically used for CMAQ) do depend upon geodetic spheroid. Since the model-grids are defined in terms of these Cartesian model coordinates, they likewise do depend upon choice of spheroid.

For historical reasons (i.e., the stubbornness of the meteorology community; we tried to get WRF to work in terms of WGS84, but NCAR would not go along.), CMAQ modeling is typically done in terms of a Normal Sphere with radius 6370000 meters.

See https://cjcoats.github.io/ioapi/SETSPHERE.html for the routine used to set geodetic spheroid, using environment variable IOAPI_ISPH. Note that projtool uses this routine to set its working spheroid.

What you need to do is to use projtool twice: first to go from Lat-Lon to Cartesian X-Y, and then to go from X-Y to grid based COL-ROW

Thank you. So, if I have set the IOAPI_ISPH to 20 (20 means Normal Sphere (MM5 / WRF-ARW) R_Earth=6370000), would then the two coordinate systems: (WRF-ARW) and CMAQ , be equal (a set of (lat, lon) pairs in both the systems represent exactly the same set of corresponding points on the spherical earth)?

Actually, I am not sure how the projection string (something like +proj=lcc +lat_1=25 +lat_0=25 +lon_0=-95 ....) would be written for CMAQ files.

Thanks.

Here’s the grid&coordinates reference page: https://cjcoats.github.io/ioapi/GRIDS.html

projtool uses a GRIDDESC file to define the grids and projections with which it works…

You asked about going in both directions between LAT/LON and COL/ROW.
The MCIP files GRIDCRO2D and GRIDDOT2D files have variables LAT, LON, LATD, and LOND, which give coordinates for the grid cell centers of the “cross” and “dot” points.
Does that help?

| cgnolte
June 4 |

  • | - |

You asked about going in both directions between LAT/LON and COL/ROW.
The MCIP files GRIDCRO2D and GRIDDOT2D files have variables LAT, LON, LATD, and LOND, which give coordinates for the grid cell centers of the “cross” and “dot” points.
Does that help?


Visit

Topic or reply to this email to respond.

To unsubscribe from these emails, click here.

I have been using GRIDCRO2D for those last lons, but the question was about locating any lat Lon point, from regular datum (wgs84 for example), on CMAQ grid. The complicating thing is the projection . I use lambert, by the way. I think CMAQ (default in v5.3.1) reference datum is quite close, if not the same, to standard datum wgs84 (used by google maps?)? In that case, lat lons in mcip files would be equivalent to those from wgs84

Again the idea is for comparison of point measurements with model values.

It sounds as if what you want is to use M3Tools program gridprobe ([https://cjcoats.github.io/ioapi/GRIDPROBE.html](see https://cjcoats.github.io/ioapi/GRIDPROBE.html):
The gridprobe program interpolates/extracts the time series for a specified variable for a specified set of points from a GRIDDED3 input file INFILE , and writes the resulting time series as an M3IO file of type CUSTOM3 or as columns to a (human-readable) ASCII REPORT -file with optional header, or both. Points to be extracted are specified in terms of Lat-Lon coordinates taken from an ASCII POINTS file.

Thank you; I will try with that. …

I tried but the program is asking for entering row col (which I don’t know). I only have lat, lon information and was assuming the m3probe would figure out it.

Now enter list of points to be probed
Enter column for this point, or 0 to end list [1] >>

I have setenv POINTS file_latlon.csv, and this file has comma-separated lat,lon pairs - one point on each line
… something like this
lat,lon
33.006179,-110.785797
33.419017,-110.82967

@cjcoats

Thank you

sorry, I think I mixed m3probe with gridprobe. If I again see a problem will ask; otherwise thank you.

Seems like I was doing okay following https://cjcoats.github.io/ioapi/GRIDPROBE.html
( setenv INFILE
setenv POINTS
setenv REPORT or “NONE”
setenv OUTFILE or “NONE”
setenv HEADER <ASCII header on ${REPORT}? (Y/N) [N]>
m3probe [and answer the prompts])

But why the m3probe not reading lat lon’s from the input (POINTS) file, rather than asking for row col to enter?

Oops – you have m3probe where you need gridprobe:
*setenv INFILE *
*setenv POINTS *
setenv REPORT or “NONE”
setenv OUTFILE or “NONE”
setenv HEADER <ASCII header on ${REPORT}? (Y/N) [N]>
gridprobe [and answer the prompts])

Thank you! But, again got some error (probably it has to do with the formatting of the text file with POINTS? my text file has the following two lines and nothing else
33.006,-110.785
33.419,-110.829
). The error is the following.

 File "POINTS" opened for input on unit:  99
 /home/user/files/pm_sites.csv

 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Interpolation Points and Grid-Normal coordinates

forrtl: severe (27): too many records in I/O statement, unit -5, file Internal Formatted Write

What should be the format of the POINTS file? Thanks

That turns out to be a bug that crept into m3tools/gridprobe somehow. Line 249 of gridprobe.f90 should be:
WRITE( MESG, '( I3, A, 4( F14.7, :, 2X, A ) )' ) K, ': LAT=', YLAT(K), 'LON=', XLON(K), 'C=', XX(K), 'R=', YY(K)

(Note XX(K) instead of XX). That has now been fixed, and both repositories have been updated. You can either (a) fix your copy (as indicated above) and do a make in m3tools; or git pull the corrected gridprobe.f90 and do a make in m3tools; or download the entire tar-ball from the CMAS web-site and re-build everything.

1 Like

Thanks. It seems working.