0
votes

I have a NetCDF file containing wind conditions (speed, direction, u, v) over time at specified coordinates (irregular grid composed of 110804 nodes). The latitudes and longitudes are stored as variables which makes it very difficult to work with the dataset in space dimension (spatial subsetting, interpolating on a new grid).

Dimensions:    (node: 110804, time: 385)
Coordinates:
  * time       (time) datetime64[ns] 1999-12-15 ... 1999-12-31
Dimensions without coordinates: node
Data variables:
    uwnd       (time, node) float32 ...
    vwnd       (time, node) float32 ...
    longitude  (node) float32 -8.53543 -8.500304 -8.53419 ... -7.5 -7.5 -7.5
    latitude   (node) float32 51.632282 51.654434 51.65914 ... 50.8125 50.875
    wndS       (time, node) float32 9.426028 9.41913 ... 4.1617303 4.104875
    wndDir     (time, node) float32 -175.74115 -176.34778 ... 125.2176 124.07719

After opening the dataset with xarray, how can I convert the variables "latitude" and "longitude" as dimensions/coordinates of the dataset ?

1
This can be solved using NCO, if that helps. I'll post a solution if so - Robert Wilson
I'd be very gratefull if you post a solution. I have never used NCO, and my current first steps are hard work... - Baptiste Le Mauff

1 Answers

0
votes

You can normally do this using NCO. The following will generate the command to try:

nco_command = "ncatted "
lon_name = "longitude"
lat_name = "latitude"
variables = ["uwnd", "vwnd", "wndS", "wndDir"]
for vv in variables:
    nco_command += (
    "-a coordinates," + vv + ",c,c,'" + lon_name + " " + lat_name + "' "
    )
nco_command = nco_command + " infile.nc outfile.nc"
nco_command

Just run that on the command line and replace the file names, of course. This code will add new dimensions for all variables list under variables. This almost always works for converting variables to dimensions/coordinates.