Help with plotting netCDF variable: grid spacing problem

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

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

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

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

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

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

Hi,

Thank you for your reply and suggestion.

Anita