Project

General

Profile

Referencing dimensions in the definition of a variable

Added by Fabrizio Amoruso almost 2 years ago

Hallo everybody,

I have a peculiar problem that I am somehow not managing to resolve even with the great help provided by searching through this forum.

Attached you will find a file called 'Mean_sea_level_19500101.nc', which is one of multiple files containing bespoke historical sea level data downloaded from Copernicus. This is one of multiple files, in that I have the entire annual series from 1950 up to 2100 (RCP4.5/8.5), i.e. 150 unique files.

The issue with this file is that it has three 1D variables: mean_sea_level (which I am trying to extract for a specific lat/lon location via interpolation), station_x_coordinate/station_y_coordinate (coordinates of the stations), stations (the station numbers for which the sea level data have been measured/modeled, each station having its own x/y coordinates).

The positioning of the stations is not continuative, meaning a potential plot of this dataset would be a scatter plot map with stations spotted on a European lat/lon grid and a "NaN" value for the remaining cells. Each file from 1950 to 2100 would contain the same grid of stations, just different values for mean_sea_level for each year.

My problem is that I cannot manage to create a georeferenced map using x/y coordinates for the mean_sea_level variable . The header of mean_sea_level is in fact:

 float mean_sea_level(stations=43119, time=1);
  :_FillValue = NaNf; // float
  :units = "m";
  :long_name = "mean_sea_level";
  :short_name = "mean_sea_level";
  :coordinates = "station_x_coordinate station_y_coordinate";

meaning that the variable "mean_sea_level" references the stations and the stations reference their own x/y coordiantes.
To be able to produce a map that I can then interpolate, I need to redefine the header of the "mean_sea_level" variable in order for it to become:

 float mean_sea_level(station_x_coordinate=43119, station_y_coordinate=43119, time=1);
  :_FillValue = NaNf; // float
  :units = "m";
  :long_name = "mean_sea_level";
  :short_name = "mean_sea_level";
  :coordinates = "station_x_coordinate station_y_coordinate";

But I do not know if this is the correct method or how to implement it using ncatted.
Any help will be greatly appreciated, many thanks!


Replies (1)

RE: Referencing dimensions in the definition of a variable - Added by Karin Meier-Fleischer over 1 year ago

Hi Fabrizio,

sorry for the late reply. If you do not solve the issue already here is one way to remap the data to a lonlat grid. First, you have to reorder the variable's dimension from (stations, time) to (time,stations) with NCO's ncpdq, then you can use CDO's remapnn operator to remap the data to a global 0.5 degree grid for example.

#!/usr/bin/env ksh

ncpdq -a time,stations Mean_sea_level_19500101.nc \
                       Mean_sea_level_19500101_reorder_dim.nc

export REMAP_EXTRAPOLATE=off 
export CDO_GRIDSEARCH_RADIUS=0.5 

cdo -remapnn,global_0.5 Mean_sea_level_19500101_reorder_dim.nc \
                        Mean_sea_level_19500101_global_0.5.nc
    (1-1/1)