当前位置:网站首页>解析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文件;
边栏推荐
- Conceptual analysis of DDD Domain Driven Design
- Deep learning ~11+ a new perspective on disease-related miRNA research
- Tsingsee green rhino video "cloud side end" +ai intelligent security system is integrated into the mainstream development trend
- How to configure the national standard platform easygbs neutral version?
- Listed JD Logistics: breaking through again
- 文本转语音功能上线,可以体验专业播音员的服务,诚邀试用
- 深度学习~11+高分疾病相关miRNA研究新视角
- VaR in PHP_ export、print_ r、var_ Differences in dump debugging
- Database migration tool flyway vs liquibase (II)
- [cloud based co creation] interpretation of harmonyos application and service ecology
猜你喜欢

How to write controller layer code gracefully?

FreeRTOS overview and experience
Deep parsing and implementation of redis pub/sub publish subscribe mode message queue

Linker --- linker

Opencv learning notes - regions of interest (ROI) and image blending

ArrayList # sublist these four holes, you get caught accidentally

一纸英雄帖,激起千层浪,横跨10国,一线大厂都派人来了!-GWEI 2022-新加坡

Group planning - General Review

Opencv learning notes - Discrete Fourier transform

Ten thousand campus developers play AI in a fancy way. It's enough to see this picture!
随机推荐
Single gene pan cancer + simple experiment can be published 7 points+
Detailed explanation of the execution order of the expression and loop body in the for loop
数据标注科普:十种常见的图像标注方法
Clickhouse uses distributed join of pose series
Process of solving easydss virtual live video jam and instability problems by replacing push-pull stream Library
巴比特 | 元宇宙每日必读:618成绩已然揭晓,在这份还算满意的答卷背后,数字藏品做出了多少贡献?...
How can I open an account with new bonds? Is it safe
A "full cloud" journey of a quasi financial system
How does the video networking / network penetration tool easynts permanently delete one of the devices?
打新债可以申请多少 开户是安全的吗
ArrayList # sublist these four holes, you get caught accidentally
What is the reason why the video intelligent analysis platform easycvr is locally controllable but the superior equipment cannot control the subordinate equipment?
Jupyter notebook service installation and startup
2021-06-02: given the head node of a search binary tree, it will be transformed into an ordered two-way linked list with head and tail connected.
Automatic reconstruction of pod after modifying resource object
VaR in PHP_ export、print_ r、var_ Differences in dump debugging
RTMP streaming platform easydss video on demand interface search bar development label fuzzy query process introduction
GLOG from getting started to getting started
Embedded must learn! Detailed explanation of hardware resource interface - based on arm am335x development board (Part 1)
The world's largest meat processor has been "blackmailed", how many industries will blackmail virus poison?