当前位置:网站首页>解析nc格式文件,GRB格式文件的依赖包edu.ucar.netcdfAll的api 学习
解析nc格式文件,GRB格式文件的依赖包edu.ucar.netcdfAll的api 学习
2022-06-24 12:33:00 【一天不写代码难受】
目录
0 目的
网上对于这个依赖包的学习资料是比较的少,所以整理这个包里面,工作中我们可以用到的一些api进行学习
https://www.unidata.ucar.edu/
https://www.unidata.ucar.edu/software/netcdf/examples/programs/
https://docs.unidata.ucar.edu/netcdf-java/5.1/userguide/common_data_model_overview.html#data-access-layer-object-model
https://docs.unidata.ucar.edu/netcdf-java/5.1/userguide/using_netcdf_java_artifacts.html
python
https://unidata.github.io/MetPy/latest/examples
1 为什么要学习这个依赖
现在有很多的格式的数据,比如气象专业的数据,一般是使用nc格式文件进行存储,我们拿到这个文件,在我们的项目代码里面,要进行解析,这个nc格式的文件是二进制流,所以需要使用专业的工具进行解析,这个依赖就是帮助我们在我们的项目里面进行解析nc 格式的
2 通用数据模型
Common Data Model 具有三层,它们建立在彼此之上以依次添加更丰富的语义:
1 数据访问层,也称为句法层,处理数据的读取和写入。
2 坐标系层标识数据数组的坐标。坐标是科学数据的一个完全
通用的概念;我们还确定了专门的地理参考坐标系,
这对地球科学界很重要。
3 Scientific Feature Types层识别特定类型的数据,
例如网格、径向和点数据,为每种数据添加专门的方法。
3 数据访问层对象模型

3.1 Dataset
Dataset = 数据集
数据集可以是 netCDF、HDF5、GRIB 等文件、OPeNDAP 数据集、文件集合或可通过 netCDF API 访问的任何其他内容。我们有时使用术语CDM 数据集来表示任何这些可能性,并强调数据集不必是 netCDF 格式的文件。
我们经常使用的数据集类型是:
nc 格式 GRB 格式,DAT格式
3.2 Group
Group = 组
组是属性、维度、EnumTypedef、变量和嵌套组的容器。Dataset 中的 Groups 形成一个层次树,就像磁盘上的目录一样。Dataset 中始终至少有一个 Group,即根 Group,其名称为空字符串。
3.3 Variable
Variable = 变量
变量是数据的容器。它有一个数据类型、一组定义其数组形状的维度,以及一组可选的属性。它使用的任何共享维度都必须在同一组或父组中。

3.4 Dimension
维度用于定义变量的数组形状。它可以在变量之间共享,这提供了一种简单而强大的关联变量的方法。共享维度时,它在组内具有唯一名称。如果没有限制,维度的长度可能会增加。如果是variableLength,那么实际长度是依赖于数据的,只有通过读取数据才能找到。variableLength Dimension 不能共享或不受限制。
3.5 Attribute
属性具有名称和值,并将任意元数据与变量或组相关联。该值是字符串或数值的标量或一维数组,因此可能的数据类型为(String、byte、short、int、long、float、double)。整数类型(byte、short、int、long)可以是有符号的或无符号的。
3.6 结构
结构是一种包含其他变量的变量,类似于 C 中的结构或关系数据库中的 行。通常,结构中的数据在物理上紧密地存储在磁盘上,因此可以高效地同时检索结构中的所有数据。结构中包含的变量是成员变量,只能在其包含结构的上下文中读取。
3.7 序列
序列是一维结构,其长度在您实际读取数据之前是未知的。要访问序列中的数据,您只能遍历序列,一次从一个结构实例中获取数据。
3.8 EnumTypedef
EnumTypedef是字符串的枚举,由 enum 类型的变量使用。
3.9 数组
数组包含从磁盘或网络读取变量后的实际数据。您可以通过调用read()或其变体从变量中获取数组。数组是矩形的(如 Fortran 数组)。每个 DataType 都有一个专门的 Array 类型。
4 坐标系对象模型

4.1 变量
**一个变量可以有零个或多个坐标系,其中包含一个或多个坐标轴。**如果 CoordinateAxis 的维度集是变量的维度集的子集,则 CoordinateAxis 只能是变量的 CoordinateSystem 的一部分。这确保了变量中的每个数据点对于 CoordinateSystem 中的每个 CoordinateAxis 都有一个对应的坐标值。
5 api 学习
5.1 打开nc文件open()
String filename = "E:\\格点\\nc\\66.nc";
NetcdfFile ncfile = null;
try {
ncfile = NetcdfFile.open(filename);
// 控制台输出
System.out.println(ncfile);
} catch (IOException ioe) {
System.out.println("trying to open " + filename+ioe);
} finally {
if (null != ncfile) try {
ncfile.close();
} catch (IOException ioe) {
System.out.println("trying to open " + filename+ioe);
}
}
5.2 findVariable()
根据特定的变量名称,获取当前变量里面的具体属性
private static void process(NetcdfFile ncfile){
String varName = "hyai";
Variable v = ncfile.findVariable(varName);
if (null == v) return;
try {
System.out.println(v);
} finally {
}
}

5.3
6 导入依赖
我们项目里面加入这个依赖,相当于加入这个解析nc文件的软件
<dependency>
<groupId>edu.ucar</groupId>
<artifactId>netcdfAll</artifactId>
<version>5.1.0</version>
</dependency>
7 打开 nc 文件
我们有一个nc文件
意思就是根据代码,将这个二进制文件里面的内容读取出来,我们看看使用代码读取到的东西是什么。把读取到的东西进行控制台输出,和读取TXT文件一样,
String filename = "E:\\格点\\nc\\66.nc";
NetcdfFile ncfile = null;
try {
ncfile = NetcdfFile.open(filename);
// 控制台输出
System.out.println(ncfile);
} catch (IOException ioe) {
System.out.println("trying to open " + filename+ioe);
} finally {
if (null != ncfile) try {
ncfile.close();
} catch (IOException ioe) {
System.out.println("trying to open " + filename+ioe);
}
}
输出的东西是

可以发现,输出的东西就是使用panoply 软件打开的nc文件;
边栏推荐
- Is it safe to apply for new bonds to open an account
- How to develop mRNA vaccine? 27+ pancreatic cancer antigen and immune subtype analysis to tell you the answer!
- Can Tencent's tendis take the place of redis?
- Concentrate on research preparation, Tencent cloud, see you next year!
- 怎样购买打新债 开户是安全的吗
- Opencv learning notes -- Separation of color channels and multi-channel mixing
- 怎么申请打新债 开户是安全的吗
- Group planning - General Review
- 炒伦敦金短线稳定赚钱技巧?在哪里炒伦敦金安全靠谱?
- FreeRTOS overview and experience
猜你喜欢

FreeRTOS overview and experience
Database migration tool flyway vs liquibase (II)
![[go language questions] go from 0 to entry 4: advanced usage of slice, elementary review and introduction to map](/img/7a/16b481753d7d57f50dc8787eec8a1a.png)
[go language questions] go from 0 to entry 4: advanced usage of slice, elementary review and introduction to map

How is the e-commerce red envelope realized? For interview (typical high concurrency)

How can a shell script (.Sh file) not automatically close or flash back after execution?

从《梦华录》的争议性,谈谈数字版权作品的价值泡沫

Opencv learning notes - Discrete Fourier transform

How to write controller layer code gracefully?

Installation and operation of libuv

《回归故里》阅读笔记
随机推荐
Getting started with scrapy
What are the low threshold financial products in 2022? Not much money
How to write controller layer code gracefully?
How can a shell script (.Sh file) not automatically close or flash back after execution?
5分+的单基因泛癌纯生信思路!
[Tencent cloud 618 countdown!] Promotion strategy of the promotion activities
怎样申请打新债 开户是安全的吗
Smart photovoltaic energy - visualization of photovoltaic power generation energy management and control in the park
我在深圳,到哪里开户比较好?现在网上开户安全么?
Flink snapshot analysis: operators for locating large states and data skew
深度学习~11+高分疾病相关miRNA研究新视角
Remote terminal RTU slope monitoring and early warning
LS-DYNA beginner's experience
Kubernetes log viewer - kubetail
11+文章-机器学习打造ProTICS框架-深度揭示了不同分子亚型中肿瘤浸润免疫细胞对预后的影响
巧妙构思-铁死亡调节因子分型预后发6+
Argo 全家桶如何让 DevOps 变的更容易?
The opportunity to teach cloud development a lesson has finally come!
Installing sqlserver extension PDO of PHP under Linux_ sqlsrv
How does easygbs, a national standard platform, solve the problem that information cannot be carried across domains?