netcdf - 使用 NCML 减少 netCDF 文件中的维度

标签 netcdf ncml thredds

我正在尝试使用 NCML 将 CF-1.4 文件“转换”为 CF-1.6。特别感兴趣的是如何 1) 删除维度,然后 2) 更改变量的维度。例如,下面是两个 ncdump 的顶部( netCDF )文件。第一个是CF-1.4,尺寸time , z , latlon .在这个文件中,变量(例如,temp)是这四个函数的函数:temp(time,z,lat,lon) .我想通过 NCML 将其转换为 CF-1.6 文件,如第二个文件所示,其中 z/lat/lon不再是维度,变量只是时间的函数。谢谢,

文件 1:

netcdf wqb_1.4 {
dimensions:
        time = UNLIMITED ; // (109008 currently)
        z = 1 ;
        lat = 1 ;
        lon = 1 ;
variables:
        float time(time) ;
                time:long_name = "Time" ;
                time:standard_name = "time" ;
                time:short_name = "time" ;
                time:axis = "T" ;
                time:units = "minutes since 2008-01-01 00:00:00 -10:00" ;
        float z(z) ;
                z:long_name = "depth below mean sea level" ;
                z:standard_name = "depth" ;
                z:short_name = "depth" ;
                z:axis = "z" ;
                z:units = "meters" ;
        float lat(lat) ;
                lat:long_name = "Latitude" ;
                lat:standard_name = "latitude" ;
                lat:short_name = "lat" ;
                lat:axis = "Y" ;
                lat:units = "degrees_north" ;
        float lon(lon) ;
                lon:long_name = "Longitude" ;
                lon:standard_name = "longitude" ;
                lon:short_name = "lon" ;
                lon:axis = "X" ;
                lon:units = "degrees_east" ;
        float temp(time, z, lat, lon) ;
                temp:long_name = "Temperature" ;
                temp:standard_name = "sea_water_temperature" ;
                temp:short_name = "temp" ;
                temp:units = "Celsius" ;
                temp:coordinates = "time lat lon alt" ;
                temp:valid_range = 10., 35. ;
                temp:_FillValue = -999.f ;
                temp:observation_type = "measured" ;

文件2:
netcdf wqb_1.6 {
dimensions:
        time = UNLIMITED ; // (109008 currently)
        name_strlen = 5 ;
variables:
        char station_name(name_strlen) ;
                station_name:long_name = "wqbaw" ;
                station_name:cf_role = "timeseries_id" ;
        float time(time) ;
                time:long_name = "Time" ;
                time:standard_name = "time" ;
                time:short_name = "time" ;
                time:axis = "T" ;
                time:units = "minutes since 2008-01-01 00:00:00 -10:00" ;
        float z ;
                z:long_name = "depth below mean sea level" ;
                z:standard_name = "depth" ;
                z:short_name = "depth" ;
                z:axis = "z" ;
                z:units = "meters" ;
        float lat ;
                lat:long_name = "Latitude" ;
                lat:standard_name = "latitude" ;
                lat:short_name = "lat" ;
                lat:axis = "Y" ;
                lat:units = "degrees_north" ;
        float lon ;
                lon:long_name = "Longitude" ;
                lon:standard_name = "longitude" ;
                lon:short_name = "lon" ;
                lon:axis = "X" ;
                lon:units = "degrees_east" ;
        float temp(time) ;
                temp:long_name = "Temperature" ;
                temp:standard_name = "sea_water_temperature" ;
                temp:short_name = "temp" ;
                temp:units = "Celsius" ;
                temp:coordinates = "time lat lon alt" ;
                temp:valid_range = 10., 35. ;
                temp:_FillValue = -999.f ;
                temp:observation_type = "measured" ;

最佳答案

更新 :
下面的解决方案似乎有效,但它 没有 :从中提取数据失败 ,正如约翰 M. 发现的那样(参见其他答案)。我们以为我们已经发现保持单一维度是解决方案,但从四维到一维最终会导致错误。正如 Sean A. 指出的那样,您无法使用 NcML 更改变量的形状。

原始“解决方案”(实际上不起作用):

如果您的目标是使您的数据符合 CF-1.6,您可以将该维度设为 station值为 1。所以你可以这样做:

<?xml version="1.0" encoding="UTF-8"?>
<netcdf xmlns="http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2" location="/usgs/data/file1.nc">
  <remove type="dimension" name="lon"/>
  <remove type="dimension" name="lat"/>
  <remove type="dimension" name="z"/>
  <dimension name="station" length="1"/>
  <dimension name="name_strlen" length="20" />
  <variable name="lat" shape="station"/>
  <variable name="lon" shape="station"/>
  <variable name="z" shape="station"/>
  <variable name="temp" shape="time station"/>
  <variable name="site" shape="station name_strlen" type="char">
    <attribute name="standard_name" value="station_id" />
    <attribute name="cf_role" value="timeseries_id" />
    <values> my_station_001 </values>
  </variable>
  <attribute name="Conventions" value="CF-1.6" />
  <attribute name="featureType" value="timeSeries" />
</netcdf>

关于netcdf - 使用 NCML 减少 netCDF 文件中的维度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18857163/

相关文章:

netcdf - 可以使用 NcML 聚合多个 NetCDF 文件集合吗?

java - THREDDS 数据服务器 : Deployment fails in Tomcat 8

r - 编写netcdf时设置坐标系

python - 使用 python-xarray 从多维 netcdf 文件中提取单个变量,同时保留属性/元数据

r - 绘制选定区域的 netcdf 数据

netcdf - 在批处理脚本中使用时强制 NCKS 尝试附加

xml - 使用 ncml 聚合 netcdf 文件?

ncml - 用于匹配目录的正则表达式

netcdf - 使用 Godiva 查看器的 THREDDS 服务器