Hello there,
I’m trying to extract data within a polygon from a NetCDF file using GMT, with all data outside the polygon set to NaN. I’m using the following command:
gmt grdcut dt_antarctic_multimission_sea_level_20130102.nc -FSouthern_boundary.txt+c -G20130102_SLA.nc
However, the output isn’t as expected. The polygon is defined in Southern_boundary.txt
, and I’m testing with a single day’s data but plan to apply this to a 20-year mean dataset. Here is the link to access the data and polygon.
I have even tried a few things with Gdal, but using it makes me lose time and the 2D grid size of the dataset.
I’ve checked the polygon format and grid info, but I’m stuck. Any advice on correctly applying the polygon and handling NaN values would be greatly appreciated.
Thanks!
Hello @ghomsi123
What is the output when you try your command? Any message? Why the output isn’t as expected? What is wrong with it?
The data is a multivariable 3D NetCDF file. First dimension appears to be time (only one value though) and then several spatial variables (incl lon and lat of centers of the grid cells) defined on a Cartesian grid without full projection information.
I don’t think a naive calling gmt grdcut ...
like in the topic can be used to work with such data.
I am also curious what is an efficient way to work with it. gdalinfo
and ncdump -h
output for that .nc
file is below.
gdalinfo
output:
$ gdalinfo dt_antarctic_multimission_sea_level_20130102.nc
Driver: netCDF/Network Common Data Format
Files: dt_antarctic_multimission_sea_level_20130102.nc
Size is 512, 512
Metadata:
NC_GLOBAL#cdm_data_type=Grid
NC_GLOBAL#comment=Sea Surface Height measured by Altimetry and derived variables
NC_GLOBAL#contact=aviso@altimetry.fr
NC_GLOBAL#Conventions=CF-1.7
NC_GLOBAL#creator_email=aviso@altimetry.fr
NC_GLOBAL#creator_name=ANTARCTIC_OCEAN_PROTOTYPE
NC_GLOBAL#creator_url=https://www.aviso.altimetry.fr
NC_GLOBAL#date_created=2023-06-07 07:23:12Z
NC_GLOBAL#date_issued=2023-06-07 07:23:12Z
NC_GLOBAL#date_modified=2023-06-07 07:23:12Z
NC_GLOBAL#geospatial_lat_max=-32.197273
NC_GLOBAL#geospatial_lat_min=-89.841728
NC_GLOBAL#geospatial_lat_resolution=25km
NC_GLOBAL#geospatial_lat_units=degrees_north
NC_GLOBAL#geospatial_lon_max=179.83583
NC_GLOBAL#geospatial_lon_min=-179.83583
NC_GLOBAL#geospatial_lon_resolution=25km
NC_GLOBAL#geospatial_lon_units=degrees_east
NC_GLOBAL#geospatial_vertical_max=0
NC_GLOBAL#geospatial_vertical_min=0
NC_GLOBAL#geospatial_vertical_positive=down
NC_GLOBAL#geospatial_vertical_resolution=point
NC_GLOBAL#geospatial_vertical_units=m
NC_GLOBAL#Grid=Subset of Southern Hemisphere 25km EASE2 Grid
NC_GLOBAL#history=Created on 2023-06-07 07:23:12Z by ANTARCTIC_OCEAN_PROTOTYPE
NC_GLOBAL#institution=CLS,CNES
NC_GLOBAL#keywords=Oceans > Ocean Topography > Sea Surface Height
NC_GLOBAL#keywords_vocabulary=NetCDF COARDS Climate and Forecast Standard Names
NC_GLOBAL#Metadata_Conventions=Unidata Dataset Discovery v1.0
NC_GLOBAL#platform=SARAL/AltiKa, CryoSat-2, Sentinel-3A
NC_GLOBAL#processing_level=L4
NC_GLOBAL#product_version=2.0
NC_GLOBAL#project=CNES DUACS R&D
NC_GLOBAL#source=Altimetry measurements
NC_GLOBAL#ssalto_duacs_comment=The reference mission used for the altimeter inter-calibration processing is SARAL/AltiKa.
NC_GLOBAL#standard_name_vocabulary=NetCDF Climate and Forecast (CF) Metadata Convention Standard Name Table v37
NC_GLOBAL#summary=SSALTO/DUACS Delayed-Time Level-4 sea surface height and derived variables measured by multi-satellite altimetry observations over Antarctic Southern Ocean.
NC_GLOBAL#time_coverage_duration=P1D
NC_GLOBAL#time_coverage_end=2013-01-02 00:00:00Z
NC_GLOBAL#time_coverage_resolution=P1D
NC_GLOBAL#time_coverage_start=2013-01-02 00:00:00Z
NC_GLOBAL#title=DT merged all satellites Antarctic Southern Ocean Gridded SSALTO/DUACS Sea Surface Height L4 product and derived variables
Subdatasets:
SUBDATASET_1_NAME=NETCDF:"dt_antarctic_multimission_sea_level_20130102.nc":latitude
SUBDATASET_1_DESC=[350x350] latitude (32-bit floating-point)
SUBDATASET_2_NAME=NETCDF:"dt_antarctic_multimission_sea_level_20130102.nc":longitude
SUBDATASET_2_DESC=[350x350] longitude (32-bit floating-point)
SUBDATASET_3_NAME=NETCDF:"dt_antarctic_multimission_sea_level_20130102.nc":sla
SUBDATASET_3_DESC=[1x350x350] sea_surface_height_above_sea_level (32-bit floating-point)
SUBDATASET_4_NAME=NETCDF:"dt_antarctic_multimission_sea_level_20130102.nc":adt
SUBDATASET_4_DESC=[1x350x350] sea_surface_height_above_sea_level (32-bit floating-point)
SUBDATASET_5_NAME=NETCDF:"dt_antarctic_multimission_sea_level_20130102.nc":ugos
SUBDATASET_5_DESC=[1x350x350] surface_geostrophic_eastward_sea_water_velocity (32-bit floating-point)
SUBDATASET_6_NAME=NETCDF:"dt_antarctic_multimission_sea_level_20130102.nc":vgos
SUBDATASET_6_DESC=[1x350x350] surface_geostrophic_northward_sea_water_velocity (32-bit floating-point)
SUBDATASET_7_NAME=NETCDF:"dt_antarctic_multimission_sea_level_20130102.nc":ugosa
SUBDATASET_7_DESC=[1x350x350] surface_geostrophic_eastward_sea_water_velocity_assuming_sea_level_for_geoid (32-bit floating-point)
SUBDATASET_8_NAME=NETCDF:"dt_antarctic_multimission_sea_level_20130102.nc":vgosa
SUBDATASET_8_DESC=[1x350x350] surface_geostrophic_northward_sea_water_velocity_assuming_sea_level_for_geoid (32-bit floating-point)
Corner Coordinates:
Upper Left ( 0.0, 0.0)
Lower Left ( 0.0, 512.0)
Upper Right ( 512.0, 0.0)
Lower Right ( 512.0, 512.0)
Center ( 256.0, 256.0)
ncdump -h
output:
$ ncdump -h dt_antarctic_multimission_sea_level_20130102.nc
netcdf dt_antarctic_multimission_sea_level_20130102 {
dimensions:
time = 1 ;
x = 350 ;
y = 350 ;
variables:
float time(time) ;
time:axis = "T" ;
time:calendar = "gregorian" ;
time:long_name = "Time" ;
time:standard_name = "time" ;
time:units = "days since 1950-01-01 00:00:00" ;
float latitude(x, y) ;
latitude:axis = "Y" ;
latitude:long_name = "Latitude" ;
latitude:standard_name = "latitude" ;
latitude:units = "degrees_north" ;
latitude:valid_min = -89.84173f ;
latitude:valid_max = -32.19727f ;
float longitude(x, y) ;
longitude:axis = "X" ;
longitude:long_name = "Longitude" ;
longitude:standard_name = "longitude" ;
longitude:units = "degrees_east" ;
longitude:valid_min = -179.8358f ;
longitude:valid_max = 179.8358f ;
float sla(time, x, y) ;
sla:_FillValue = 9.96921e+36f ;
sla:comment = "The sea level anomaly is the sea surface height above mean sea surface; it is referenced to the [1993, 2012] period; see the product user manual for details" ;
sla:coordinates = "longitude latitude" ;
sla:long_name = "Sea level anomaly" ;
sla:standard_name = "sea_surface_height_above_sea_level" ;
sla:units = "m" ;
float adt(time, x, y) ;
adt:_FillValue = 9.96921e+36f ;
adt:comment = "The absolute dynamic topography is the sea surface height above geoid; the adt is obtained as follows: adt=sla+mdt where mdt is the mean dynamic topography; see the product user manual for details" ;
adt:coordinates = "longitude latitude" ;
adt:long_name = "Absolute dynamic topography" ;
adt:standard_name = "sea_surface_height_above_sea_level" ;
adt:units = "m" ;
float ugos(time, x, y) ;
ugos:_FillValue = 9.96921e+36f ;
ugos:coordinates = "longitude latitude" ;
ugos:long_name = "Absolute geostrophic velocity: zonal component" ;
ugos:standard_name = "surface_geostrophic_eastward_sea_water_velocity" ;
ugos:units = "m/s" ;
float vgos(time, x, y) ;
vgos:_FillValue = 9.96921e+36f ;
vgos:coordinates = "longitude latitude" ;
vgos:long_name = "Absolute geostrophic velocity: meridian component" ;
vgos:standard_name = "surface_geostrophic_northward_sea_water_velocity" ;
vgos:units = "m/s" ;
float ugosa(time, x, y) ;
ugosa:_FillValue = 9.96921e+36f ;
ugosa:comment = "The geostrophic velocity anomalies are referenced to the [1993, 2012] period" ;
ugosa:coordinates = "longitude latitude" ;
ugosa:long_name = "Geostrophic velocity anomalies: zonal component" ;
ugosa:standard_name = "surface_geostrophic_eastward_sea_water_velocity_assuming_sea_level_for_geoid" ;
ugosa:units = "m/s" ;
float vgosa(time, x, y) ;
vgosa:_FillValue = 9.96921e+36f ;
vgosa:coordinates = "longitude latitude" ;
vgosa:long_name = "Geostrophic velocity anomalies: meridian component" ;
vgosa:standard_name = "surface_geostrophic_northward_sea_water_velocity_assuming_sea_level_for_geoid" ;
vgosa:units = "m/s" ;
// global attributes:
:Conventions = "CF-1.7" ;
:Metadata_Conventions = "Unidata Dataset Discovery v1.0" ;
:cdm_data_type = "Grid" ;
:comment = "Sea Surface Height measured by Altimetry and derived variables" ;
:contact = "aviso@altimetry.fr" ;
:creator_email = "aviso@altimetry.fr" ;
:creator_name = "ANTARCTIC_OCEAN_PROTOTYPE" ;
:creator_url = "https://www.aviso.altimetry.fr" ;
:date_created = "2023-06-07 07:23:12Z" ;
:date_issued = "2023-06-07 07:23:12Z" ;
:date_modified = "2023-06-07 07:23:12Z" ;
:geospatial_lat_max = -32.19727f ;
:geospatial_lat_min = -89.84173f ;
:geospatial_lat_resolution = "25km" ;
:geospatial_lat_units = "degrees_north" ;
:geospatial_lon_max = 179.8358f ;
:geospatial_lon_min = -179.8358f ;
:geospatial_lon_resolution = "25km" ;
:geospatial_lon_units = "degrees_east" ;
:geospatial_vertical_max = 0. ;
:geospatial_vertical_min = 0. ;
:geospatial_vertical_positive = "down" ;
:geospatial_vertical_resolution = "point" ;
:geospatial_vertical_units = "m" ;
:history = "Created on 2023-06-07 07:23:12Z by ANTARCTIC_OCEAN_PROTOTYPE" ;
:institution = "CLS,CNES" ;
:keywords = "Oceans > Ocean Topography > Sea Surface Height" ;
:keywords_vocabulary = "NetCDF COARDS Climate and Forecast Standard Names" ;
:platform = "SARAL/AltiKa, CryoSat-2, Sentinel-3A" ;
:processing_level = "L4" ;
:product_version = "2.0" ;
:Grid = "Subset of Southern Hemisphere 25km EASE2 Grid" ;
:project = "CNES DUACS R&D" ;
:source = "Altimetry measurements" ;
:ssalto_duacs_comment = "The reference mission used for the altimeter inter-calibration processing is SARAL/AltiKa." ;
:standard_name_vocabulary = "NetCDF Climate and Forecast (CF) Metadata Convention Standard Name Table v37" ;
:summary = "SSALTO/DUACS Delayed-Time Level-4 sea surface height and derived variables measured by multi-satellite altimetry observations over Antarctic Southern Ocean." ;
:time_coverage_duration = "P1D" ;
:time_coverage_end = "2013-01-02 00:00:00Z" ;
:time_coverage_resolution = "P1D" ;
:time_coverage_start = "2013-01-02 00:00:00Z" ;
:title = "DT merged all satellites Antarctic Southern Ocean Gridded SSALTO/DUACS Sea Surface Height L4 product and derived variables" ;
}