# Help with plotting netCDF variable: grid spacing problem

**URL:** <https://forum.generic-mapping-tools.org/t/help-with-plotting-netcdf-variable-grid-spacing-problem/2175>\
**Category:** Q&A\
**Created:** [October 7, 2021, 1:44pm UTC](https://forum.generic-mapping-tools.org/t/help-with-plotting-netcdf-variable-grid-spacing-problem/2175 "2021-10-07T13:44:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anita](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@Anita](https://forum.generic-mapping-tools.org/u/Anita)\
**Post date:** [October 7, 2021, 1:44pm UTC](https://forum.generic-mapping-tools.org/t/help-with-plotting-netcdf-variable-grid-spacing-problem/2175/1 "2021-10-07T13:44:38Z")

</div>

Hi!

I started using GMT lately, so I am absolutely a beginner. I was thinking about using GMT for visualizing our modelled, gridded datasets, which have netCDF format.  
I ran into a problem referring to wrong grid spacing recognition of GMT. However I guess the problem is rather with the definition of the dimension of the netCDF variables I’d like to draw. My dataset has a spatial resolution of 0.1°.  
In the netCDF file the dimension of the variable is given in number of gridcells (in west\_east and south\_north directions), and I have the longitude and latitude information as separate variables.  
The domain is: 14E-25E, 45N-50N. I am looking for some kind of help, maybe somebody knows how to “tell” GMT that my netCDF file has 110x51 cells but with resolution of 0.1° on the given domain. I copy ncdump -h and grdinfo -F  
informations about an example file.

Informations: this file (out.2019123100\_2020010100\_eves.nc) here is a raw CHIMERE model output, we usually select the first level, and perform some time averaging and are interested in the air pollutants like CO, NO2 and so on.

ncdump -h out.2019123100\_2020010100\_eves.nc

netcdf out.2019123100\_2020010100\_eves {  
dimensions:  
Time = UNLIMITED ; // (25 currently)  
DateStrLen = 19 ;  
west\_east = 111 ;  
south\_north = 51 ;  
bottom\_top = 10 ;  
vcoord\_dim = 10 ;  
wavelength\_dim = 5 ;  
nbins = 10 ;  
ninterv = 11 ;  
variables:  
double lon(south\_north, west\_east) ;  
lon:units = “degrees\_east” ;  
lon:long\_name = “Longitude” ;  
double lat(south\_north, west\_east) ;  
lat:units = “degrees\_north” ;  
lat:long\_name = “Latitude” ;  
double a\_vcoord(vcoord\_dim) ;  
a\_vcoord:units = “no\_units” ;  
a\_vcoord:long\_name = “A\_sigma\_coefficient” ;  
double b\_vcoord(vcoord\_dim) ;  
b\_vcoord:units = “no\_units” ;  
b\_vcoord:long\_name = “B\_sigma\_coefficient” ;  
double cut\_off\_diameters(ninterv) ;  
cut\_off\_diameters:units = “meters” ;  
cut\_off\_diameters:long\_name = “cut\_off\_diameters” ;  
double mmd(nbins) ;  
mmd:units = “meters” ;  
mmd:long\_name = “Mean\_Mass\_Median\_Diameters” ;  
float wavelength(wavelength\_dim) ;  
wavelength:units = “nm” ;  
wavelength:long\_name = “Wavelength” ;  
char Times(Time, DateStrLen) ;  
Times:units = “Date string” ;  
Times:long\_name = “WRF-style Times” ;  
float O3(Time, bottom\_top, south\_north, west\_east) ;  
O3:units = “ug/m3” ;  
O3:long\_name = “O3 Concentration” ;  
float NO2(Time, bottom\_top, south\_north, west\_east) ;  
NO2:units = “ug/m3” ;  
NO2:long\_name = “NO2 Concentration” ;  
float NO(Time, bottom\_top, south\_north, west\_east) ;  
NO:units = “ppb vol” ;  
NO:long\_name = “NO Concentration” ;  
float PAN(Time, bottom\_top, south\_north, west\_east) ;  
PAN:units = “ppb vol” ;  
PAN:long\_name = “PAN Concentration” ;  
float HNO3(Time, bottom\_top, south\_north, west\_east) ;  
HNO3:units = “ppb vol” ;  
HNO3:long\_name = “HNO3 Concentration” ;  
float H2O2(Time, bottom\_top, south\_north, west\_east) ;  
H2O2:units = “ppb vol” ;  
H2O2:long\_name = “H2O2 Concentration” ;  
float HONO(Time, bottom\_top, south\_north, west\_east) ;  
HONO:units = “ppb vol” ;  
HONO:long\_name = “HONO Concentration” ;  
float SO2(Time, bottom\_top, south\_north, west\_east) ;  
SO2:units = “ug/m3” ;  
SO2:long\_name = “SO2 Concentration” ;  
float CO(Time, bottom\_top, south\_north, west\_east) ;  
CO:units = “ppb vol” ;  
CO:long\_name = “CO Concentration” ;  
…

grdinfo -F out.2019123100\_2020010100\_eves.nc?PM10

out.2019123100\_2020010100\_eves.nc: Title: PM10 Concentration  
out.2019123100\_2020010100\_eves.nc: Command: File /vol4/home/lazar\_k/chimere2017/BIGFILES/OUTPUTS/changed\_emission/eves/rundir/out.2019123100\_2020010100\_eves.nc was generated on Wed Sep 23 07:42:49 2020 by lazar\_k on ucs02.met.hu  
out.2019123100\_2020010100\_eves.nc: Remark:  
out.2019123100\_2020010100\_eves.nc: Gridline node registration used  
out.2019123100\_2020010100\_eves.nc: Grid file format: nf (# 18) GMT netCDF format (float) (COARDS-compliant) [DEFAULT]  
out.2019123100\_2020010100\_eves.nc: x\_min: 0.0000000  
out.2019123100\_2020010100\_eves.nc: x\_max: 110.0000000  
out.2019123100\_2020010100\_eves.nc: x\_inc: 1.0000000  
out.2019123100\_2020010100\_eves.nc: name: ▒▒  
out.2019123100\_2020010100\_eves.nc: nx: 111  
out.2019123100\_2020010100\_eves.nc: y\_min: 0.0000000  
out.2019123100\_2020010100\_eves.nc: y\_max: 50.0000000  
out.2019123100\_2020010100\_eves.nc: y\_inc: 1.0000000  
out.2019123100\_2020010100\_eves.nc: name: ▒▒  
out.2019123100\_2020010100\_eves.nc: ny: 51  
out.2019123100\_2020010100\_eves.nc: zmin: -nan  
out.2019123100\_2020010100\_eves.nc: zmax: -nan  
out.2019123100\_2020010100\_eves.nc: name: PM10 Concentration [ug/m3]  
out.2019123100\_2020010100\_eves.nc: scale\_factor: 1 add\_offset: 0

I could plot a variable with grdimage on a nice map, but it looks like the grid spacing is 1° and not 0.1°. Is there a way, without interpolation, to change the grid spacing with/within GMT commands?

I use GMT version 4.5.15. (I know it is not the most up-to-date version, but that is what we have at my workplace at the moment.)

Thanks in advance for your help, ideas.

Regards,  
Anita

---

<div class="post-metadata">

**Author:** ![maxrjones](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/maxrjones/32/2698_2.png) [@maxrjones](https://forum.generic-mapping-tools.org/u/maxrjones)\
**Post date:** [October 7, 2021, 4:41pm UTC](https://forum.generic-mapping-tools.org/t/help-with-plotting-netcdf-variable-grid-spacing-problem/2175/2 "2021-10-07T16:41:49Z")

</div>

Hi Anita,

You can modify region/interval header information using grdedit -R -A. Here’s the grdedit documentation for GMT 4.5: [https://docs.generic-mapping-tools.org/4.5/](https://docs.generic-mapping-tools.org/4.5/). That said, my recommendation would be to write out the lat/lon coordinates when creating the files rather than manipulating the header info afterwards.

Regards,

Meghan

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [October 7, 2021, 5:00pm UTC](https://forum.generic-mapping-tools.org/t/help-with-plotting-netcdf-variable-grid-spacing-problem/2175/3 "2021-10-07T17:00:39Z")

</div>

GMT expects netCDF files to be COARDS compliant. Try add =gd to file to see if GDAL ca read

---

<div class="post-metadata">

**Author:** ![Anita](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@Anita](https://forum.generic-mapping-tools.org/u/Anita)\
**Post date:** [October 8, 2021, 6:39am UTC](https://forum.generic-mapping-tools.org/t/help-with-plotting-netcdf-variable-grid-spacing-problem/2175/4 "2021-10-08T06:39:33Z")

</div>

Hi Meghan,

Thank you for your reply. I tried the grdedit command:

grdedit out.2019123100\_2020010100\_eves.nc -R14/45/25/50r -A

grdedit: NetCDF: Variable not found [out.2019123100\_2020010100\_eves.nc]

I also tried to select one variable to check:

grdedit out.2019123100\_2020010100\_eves.nc?PM10 -R14/45/25/50r -A

grdedit: NetCDF: Variable not found [out.2019123100\_2020010100\_eves.nc?PM10]

But I can not use grdedit. The problem is, I guess, that my variables to plot are not 2-D, they have more dimensions (lat, lon, level, time) And grdedit operates on 2-D grids. Maybe first I have to reduce the dimension. And try the grdedit command afterwards.  
But it seems to me also, that the best solution is to manipulate the input file’s sturcture to be compatible with GMT input file formats.

Thanks again,

Anita

---

<div class="post-metadata">

**Author:** ![Anita](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@Anita](https://forum.generic-mapping-tools.org/u/Anita)\
**Post date:** [October 8, 2021, 6:43am UTC](https://forum.generic-mapping-tools.org/t/help-with-plotting-netcdf-variable-grid-spacing-problem/2175/5 "2021-10-08T06:43:19Z")

</div>

Hi,

Thank you for your reply. If I understood well, you recommended to try:  
grdinfo out.2019123100\_2020010100\_eves.nc=gd

I got:

ERROR 4: `out.2019123100\_2020010100\_eves.nc’ not recognised as a supported file format.

Unable to open out.2019123100\_2020010100\_eves.nc.  
grdinfo: GMT ERROR: grid x increment \<= 0.0  
grdinfo: GMT ERROR: grid y increment \<= 0.0  
grdinfo: Use grdedit -A on your grid file to make region and increments compatible [out.2019123100\_2020010100\_eves.nc=gd]  
out.2019123100\_2020010100\_eves.nc: Title: Grid imported trhough GDAL  
out.2019123100\_2020010100\_eves.nc: Command:  
out.2019123100\_2020010100\_eves.nc: Remark:  
out.2019123100\_2020010100\_eves.nc: Gridline node registration used  
out.2019123100\_2020010100\_eves.nc: Unrecognized grid file format! Probably not a GMT grid  
out.2019123100\_2020010100\_eves.nc: x\_min: 0 x\_max: 0 x\_inc: 0 name: x nx: 0  
out.2019123100\_2020010100\_eves.nc: y\_min: 0 y\_max: 0 y\_inc: 0 name: y ny: 0  
out.2019123100\_2020010100\_eves.nc: z\_min: 0 z\_max: 0 name: z  
out.2019123100\_2020010100\_eves.nc: scale\_factor: 1 add\_offset: 0

So my input file, with it’s present format is not compatible with GMT.  
I think I need to find out, how to change the dimension of my input file’s variables to have longitudes and latitudes rather than number of gridcells in x and y direction.

Thanks again,  
Anita

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [October 8, 2021, 10:33am UTC](https://forum.generic-mapping-tools.org/t/help-with-plotting-netcdf-variable-grid-spacing-problem/2175/6 "2021-10-08T10:33:52Z")

</div>

Trying to process this data with a \> 10 years old software is probably not the best solution.

I’m sure it would be a one-liner with the method exemplified at

> **[Aqua SST · RemoteS.jl](https://www.generic-mapping-tools.org/RemoteS.jl/dev/gallery/Aqua_sst/remotes_L2_SST/)**

---

<div class="post-metadata">

**Author:** ![Anita](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@Anita](https://forum.generic-mapping-tools.org/u/Anita)\
**Post date:** [October 11, 2021, 5:57am UTC](https://forum.generic-mapping-tools.org/t/help-with-plotting-netcdf-variable-grid-spacing-problem/2175/7 "2021-10-11T05:57:31Z")

</div>

Hi,

Thank you for your reply and suggestion.

Anita
