Netcdf (一)

由于工作原因最近看了下Netcdf:

NetCDF
1 NetCDF
1.1概述(Overview)
NetCDF (network Common Data Form) is a set of software libraries and machine-independent data formats that support the creation, access, and sharing of array-oriented scientific data. Distributions are provided for Java and C/C++/Fortran. See the netCDF web site for more information.
NetCDF全称为network Common Data Format( “网络通用数据格式”),是一个软件库与机器无关的数据格式,支持创建,访问基于数组的科研数据。分别提供了对Java和C / C++ / Fortran语言。
对程序员来说,它和zip、jpeg、bmp文件格式类似,都是一种文件格式的标准。netcdf文件开始的目的是用于存储气象科学中的数据,现在已经成为许多数据采集软件的生成文件的格式。
   从数学上来说,netcdf存储的数据就是一个多自变量的单值函数。用公式来说就是f(x,y,z,...)=value, 函数的自变量x,y,z等在netcdf中叫做维(dimension)或坐标轴(axix),函数值value在netcdf中叫做变量(Variables)。而自变量和函数值在物理学上的一些性质,比如计量单位(量纲)、物理学名称在netcdf中就叫属性(Attributes)。
1.2 数组理解
NetCDF是以数组为基础来对数据读写操作的,所以需要对数组理解明白,我们接触的二维数组比较容易理解,如果是三维、四维等多维数组的理解:
基础:
	//静态初始化
	int a[][] = {{1,2},{2,3}};
	//动态初始化
	int c[][] = new int[2][];
	int d[][] = new int[2][3];
	/*********多维数组声明和初始化是从高维到低维 以下都是语法错误的:
	 *int b[2][] = {{1,2},{2,3}};
	 *int c[][] = new int[][];
	 *int c[][] = new int[][4];
	 *********多维数组可以看成以高维数组作为元素的数组*/
如:int c[][] = new int[2][];
	c[0] = new int[3];
	c[1] = new int[3];
在内存中如下存放:
 
2 参考网站
http://www.unidata.ucar.edu/
2.1 Unidata
2.2.1 About 
Unidata is a diverse community of over 160 institutions vested in the common goal of sharing data, and tools to access and visualize that data. For 20 years Unidata has been providing data, tools, and support to enhance earth-system education and research. In an era of increasing data complexity, accessibility, and multidisciplinary integration, Unidata provides a rich set of services and tools.
Unidatay是一个多样化的社区。对通用数据共享,处理工具,数据访问,可视化等处理,近20年来Unidata已提供数据,工具和支持,以加强地球系统教育和研究。在一个日益复杂的数据,交通方便,和多学科融合的时代,Unidata提供的服务和丰富的工具集。
2.2.2 DATA
The Unidata Program helps researchers and educators acquire and use earth-related data. Most of the data are provided in "real time" or "near-real time" — that is, the data are sent to participants almost as soon as the observations are made. Unidata is a data facilitator, not a data archive center. We provide a mechanism whereby educators and researchers, by participating in our Internet Data Distribution (IDD) system, may subscribe to streams of current data that interest them.
Unidata项目帮助研究人员和教育工作者获得和使用地球相关的数据。大部分数据为实时数据或者临近数据,将数据发送到需要参与的对象。 Unidata是数据处理,而不是数据存储中心。
Available Data Types:(现有数据类型)
Forecast Model Output:出型预报
Satellite Data:卫星数据
Radar Data:雷达数据
Lightning Data:闪电数据
Wind Profiler Data:风分析的数据
Aircraft-Borne (ACARS):航空传播数据
GPS Meteo. (SuomiNet):GPS数据
…………
3 NetCDF文件结构
3.1 变量(Variables)
变量对应着真实的物理数据。比如我们家里的电表,每个时刻显示的读数表示用户的到该时刻的耗电量。这个读数值就可以用netcdf里的变量来表示。它是一个以时间为自变量(或者说自变量个数为一维)的单值函数。再比如在气象学中要作出一个气压图,就是“东经xx度,北纬yy度的点的大气压值为多少帕”,这是一个二维单值函数,两维分别是经度和纬度。函数值为大气压。
从上面的例子可以看出,netcdf中的变量就是一个N维数组,数组的维数就是实际问题中的自变量个数,数组的值就是观测得到的物理值。变量(数组值)在netcdf中的存储类型有六种,ascii字符(char) ,字节(byte), 短整型(short), 整型(int), 浮点(float), 双精度(double)。
3.2 维(dimension)
一个维对应着函数中的某个自变量,或者说函数图象中的一个坐标轴,在线性代数中就是一个N维向量的一个分量(这也是维这个名称的由来)。在netcdf中,一个维具有一个名字和范围(或者说长度,也就是数学上所说的定义域,可以是离散的点集合或者连续的区间)。在netcdf中,维的长度基本都是有限的,最多只能有一个具有无限长度的维。
3.3 属性(Attribute)
属性对变量值和维的具体物理含义的注释或者说解释。因为变量和维在netcdf中都只是无量纲的数字,要想让人们明白这些数字的具体含义,就得靠属性这个对象了。在netcdf中,属性由一个属性名和一个属性值(一般为字符串)组成。比如,在某个cdl文件(cdl文件的具体格式在下一节中讲述)中有这样的代码段:
temperature:units = "celsius" ;
前面的temperature是一个已经定义好的变量(Variable),即温度,冒号后面的units就是属性名,表示物理单位,=后面的就是units这个属性的值,为“celsius” ,即摄氏度,整个一行代码的意思就是温度这个物理量的单位为celsius。
3.4 表现形式(Representations)
Representations of netCDF CF(Climate and Forecast) Dimension and Variable Information:
CDL text, ncML, ncML with coordinate system extensions, and ncML-GML
3.4.1 CDL
网址:http://mailman.unidata.ucar.edu/software/netcdf/docs/netcdf/CDL-Syntax.html#CDL-Syntax
     netcdf example_1plus  {  // CDL with CF addions     
     dimensions:         // dimension names and lengths are declared first
             lat = 5, lon = 10, level = 4, time = unlimited;
   
     variables:          // variable types, names, shapes, attributes
             short   time(time);
                         time:standard_name  = "time";
                         time:units      = "hours since 1996-1-1";
             int     lat(lat), lon(lon), level(level);
                         lat:units       = "degrees_north";
                         lat:standard_name = "latitude";
                         lon:units       = "degrees_east";
                         lon:long_name = "longitude";
                         level:standard_name     = "air_pressure";
                         level:units     = "millibars";
             float   temp(time,level,lat,lon);
                         temp:long_name     = "temperature";
                         temp:standard_name     = "air_temperature";
                         temp:units         = "celsius";
             float   rh(time,lat,lon);
                         rh:long_name = "relative humidity";
                         rh:valid_range = 0.0, 1.0;      // min and max

             // global attributes
                         :source = "Fictional Model Output";
                         :Conventions = "CF-1.0";
     
     data:                // optional data assignments
             level   = 1000, 850, 700, 500;
             lat     = 20, 30, 40, 50, 60;
             lon     = -160,-140,-118,-96,-84,-52,-45,-35,-25,-15;
             time    = 12;
             rh      =.5,.2,.4,.2,.3,.2,.4,.5,.6,.7,
                      .1,.3,.1,.1,.1,.1,.5,.7,.8,.8,
                      .1,.2,.2,.2,.2,.5,.7,.8,.9,.9,
                      .1,.2,.3,.3,.3,.3,.7,.8,.9,.9,
                       0,.1,.2,.4,.4,.4,.4,.7,.9,.9;
     } 
如上:0.5表示time为12,lon为-160,lat为20的三维数据
	  0.2表示time为12,lon为-140,lat为20的三维数据
      0  time为12,表示lon为-160,lat为60的三维数据
………………….
3.4.2 NCML
参考网址:http://www.unidata.ucar.edu/software/netcdf/ncml/v2.2/Tutorial.html
<?xml version="1.0" encoding="UTF-8"?>
<netcdf xmlns="http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2" location="T:/GALEON/SimpleSamples/SampleNetCDFbens.nc">
  <dimension name="lat" length="5" />
  <dimension name="lon" length="10" />
  <dimension name="level" length="4" />
  <dimension name="time" length="1" isUnlimited="true" />
  <attribute name="source" type="String" value="Fictional Model Output" />
  <attribute name="Conventions" type="String" value="CF-1.0" />
  <variable name="time" shape="time" type="short">
    <attribute name="standard_name" type="String" value="time" />
    <attribute name="units" type="String" value="hours since 1996-1-1" />
  </variable>
  <variable name="lat" shape="lat" type="int">
    <attribute name="units" type="String" value="degrees_north" />
    <attribute name="standard_name" type="String" value="latitude" />
  </variable>
  <variable name="lon" shape="lon" type="int">
    <attribute name="units" type="String" value="degrees_east" />
    <attribute name="long_name" type="String" value="longitude" />
  </variable>
  <variable name="level" shape="level" type="int">
    <attribute name="standard_name" type="String" value="air_pressure" />
    <attribute name="units" type="String" value="millibars" />
  </variable>
  <variable name="temp" shape="time level lat lon" type="float">
    <attribute name="long_name" type="String" value="temperature" />
    <attribute name="standard_name" type="String" value="air_temperature" />
    <attribute name="units" type="String" value="celsius" />
  </variable>
  <variable name="rh" shape="time lat lon" type="float">
    <attribute name="long_name" type="String" value="relative humidity" />
    <attribute name="valid_range" type="double" value="0.0 1.0" />
  </variable>
</netcdf>
3.4.3 NCML-CS
参考网址:http://www.unidata.ucar.edu/projects/THREDDS/GALEON/NetCDFandStandards.htm
<?xml version="1.0" encoding="UTF-8"?>
<netcdf xmlns="http://www.ucar.edu/schemas/netcdf" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.ucar.edu/schemas/netcdf http://www.unidata.ucar.edu/schemas/netcdf-cs.xsd" uri="T:/GALEON/SimpleSamples/SampleNetCDFbens.nc">
  <dimension name="lat" length="5" />
  <dimension name="lon" length="10" />
  <dimension name="level" length="4" />
  <dimension name="time" length="1" isUnlimited="true" />
  <attribute name="source" type="String" value="Fictional Model Output" />
  <attribute name="Conventions" type="String" value="CF-1.0" />
  <coordinateAxis name="time" shape="time" type="short" units="hours since 1996-1-1" axisType="Time">
    <attribute name="standard_name" type="String" value="time" />
    <attribute name="units" type="String" value="hours since 1996-1-1" />
    <attribute name="_CoordinateAxisType" type="String" value="Time" />
  </coordinateAxis>
  <coordinateAxis name="lat" shape="lat" type="int" units="degrees_north" axisType="Lat">
    <attribute name="units" type="String" value="degrees_north" />
    <attribute name="standard_name" type="String" value="latitude" />
    <attribute name="_CoordinateAxisType" type="String" value="Lat" />
  </coordinateAxis>
  <coordinateAxis name="lon" shape="lon" type="int" units="degrees_east" axisType="Lon">
    <attribute name="units" type="String" value="degrees_east" />
    <attribute name="long_name" type="String" value="longitude" />
    <attribute name="_CoordinateAxisType" type="String" value="Lon" />
  </coordinateAxis>
  <coordinateAxis name="level" shape="level" type="int" units="millibars" axisType="Pressure">
    <attribute name="standard_name" type="String" value="air_pressure" />
    <attribute name="units" type="String" value="millibars" />
    <attribute name="_CoordinateAxisType" type="String" value="Pressure" />
  </coordinateAxis>
  <variable name="temp" shape="time level lat lon" type="float" coordinateSystems="time-level-lat-lon">
    <attribute name="long_name" type="String" value="temperature" />
    <attribute name="standard_name" type="String" value="air_temperature" />
    <attribute name="units" type="String" value="celsius" />
  </variable>
  <variable name="rh" shape="time lat lon" type="float" coordinateSystems="time-lat-lon">
    <attribute name="long_name" type="String" value="relative humidity" />
    <attribute name="valid_range" type="double" value="0.0 1.0" />
  </variable>
  <coordinateSystem name="time-level-lat-lon">
    <coordinateAxisRef ref="time" />
    <coordinateAxisRef ref="level" />
    <coordinateAxisRef ref="lat" />
    <coordinateAxisRef ref="lon" />
  </coordinateSystem>
  <coordinateSystem name="time-lat-lon">
    <coordinateAxisRef ref="time" />
    <coordinateAxisRef ref="lat" />
    <coordinateAxisRef ref="lon" />
  </coordinateSystem>
</netcdf>
…………
 

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值