【问题标题】:Writing to a NetCDF3 file using module netcdf4 in python在 python 中使用模块 netcdf4 写入 NetCDF3 文件
【发布时间】:2017-02-24 02:08:16
【问题描述】:

我在使用 netcdf4 函数写入 netcdf3 文件时遇到问题。我尝试使用创建变量函数,但它给了我这个错误:NetCDF: Attempting netcdf-4 operation on netcdf-3 file

nc = Dataset(root.fileName,'a',format="NETCDF4")

Hycom_U = nc.createVariable('/variables/Hycom_U','float',('time','lat','lon',))

Hycom_V = nc.createVariable('/variables/Hycom_V','f4',('time','lat','lon',))

nc=

root group (NETCDF3_CLASSIC data model, file format NETCDF3):
    netcdf_library_version: 4.1.3
    format_version: HFRNet_1.0.0
    product_version: HFRNet_1.1.05
    Conventions: CF-1.0
    title: Near-Real Time Surface Ocean Velocity, Hawaii,
2 km Resolution
    institution: Scripps Institution of Oceanography
    source: Surface Ocean HF-Radar
    history: 22-Feb-2017 00:55:46: NetCDF file created
22-Feb-2017 00:55:46: Filtered U and V by GDOP < 1.25 ;
FMRC Best Dataset
    references: Terrill, E. et al., 2006. Data Management and Real-time
Distribution in the HF-Radar National Network. Proceedings
of the MTS/IEEE Oceans 2006 Conference, Boston MA,
September 2006.
    creator_name: Mark Otero
    creator_email: motero@ucsd.edu
    creator_url: http://cordc.ucsd.edu/projects/mapping/
    summary: Surface ocean velocities estimated from HF-Radar are
representative of the upper 0.3 - 2.5 meters of the
ocean.  The main objective of near-real time
processing is to produce the best product from
available data at the time of processing.  Radial
velocity measurements are obtained from individual
radar sites through the U.S. HF-Radar Network.
Hourly radial data are processed by unweighted
least-squares on a 2 km resolution grid of Hawaii
to produce near real-time surface current maps.
    geospatial_lat_min: 20.487279892
    geospatial_lat_max: 21.5720806122
    geospatial_lon_min: -158.903594971
    geospatial_lon_max: -157.490005493
    grid_resolution: 2km
    grid_projection: equidistant cylindrical
    regional_description: Unites States, Hawaiian Islands
    cdm_data_type: GRID
    featureType: GRID
    location: Proto fmrc:HFRADAR,_US_Hawaii,_2km_Resolution,_Hourly_RTV
    History: Translated to CF-1.0 Conventions by Netcdf-Java CDM (NetcdfCFWriter)
Original Dataset = fmrc:HFRADAR,_US_Hawaii,_2km_Resolution,_Hourly_RTV; Translation Date = Thu Feb 23 13:35:32 GMT 2017
    dimensions(sizes): time(25), lat(61), lon(77)
    variables(dimensions): float32 u(time,lat,lon), float64 time_run(time), float64 time(time), float32 lat(lat), float32 lon(lon), float32 v(time,lat,lon)
    groups: 

我可以使用哪些 netcdf 3 操作将数据添加到文件中?我发现我可以通过简单地这样做nc.variables["Hycom_U"]=U2直接添加数据来手动添加数据,但没有别的。有没有更好的方法来做到这一点?

【问题讨论】:

    标签: python-3.x netcdf4


    【解决方案1】:

    我认为问题在于您声称该文件为 netCDF4 格式:

    nc = Dataset(root.fileName,'a',format="NETCDF4")`
    

    但您确实想表明它是 netCDF3:

    nc = Dataset(root.fileName,'a',format="NETCDF3_CLASSIC")
    

    可以在here找到其他文档。

    【讨论】:

    • 不幸的是它不能解决问题。我尝试了不同的格式,它们都给出了相同的错误。 :(
    【解决方案2】:

    我想通了!我根本无法使用路径作为变量名。

    Hycom_U = nc.createVariable('Hycom_U','float',('time','lat','lon',))

    它为我正确地创建了一个变量。

    【讨论】:

      猜你喜欢
      • 2014-12-30
      • 2012-08-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-12
      • 2019-09-24
      • 2020-12-19
      • 2017-05-01
      • 2011-09-17
      相关资源
      最近更新 更多