Posted onInCodingViews: Valine: Word count in article: 1.3kReading time ≈5 mins.
失踪人口回归,本篇来介绍下R语言读取大型NetCDF文件的一些实践。
1 NetCDF数据简介
先给一段Wiki上关于NetCDF的定义。
1 2 3
NetCDF (Network Common Data Form) is a set of software libraries and self-describing, machine-independent data formats that support the creation, access, and sharing of array-oriented scientific data. The project homepage is hosted by the Unidata program at the University Corporation for Atmospheric Research (UCAR). They are also the chief source of netCDF software, standards development, updates, etc. The format is an open standard. NetCDF Classic and 64-bit Offset Format are an international standard of the Open Geospatial Consortium.
The project started in 1988 and is still actively supported by UCAR. The original netCDF binary format (released in 1990, now known as "netCDF classic format") is still widely used across the world and continues to be fully supported in all netCDF releases. Version 4.0 (released in 2008) allowed the use of the HDF5 data file format. Version 4.1 (2010) added support for C and Fortran client access to specified subsets of remote data via OPeNDAP. Version 4.3.0 (2012) added a CMake build system for Windows builds. Version 4.7.0 (2019) added support for reading Amazon S3 objects. Further releases are planned to improve performance, add features, and fix bugs.
#To obtain the longitude, latitude, time, and name of variable long <- ncvar_get(nc_pre, 'lon') lat <- ncvar_get(nc_pre, 'lat')
#Calculate numbers of rows and columns of the specific study area LonIdx <- which(long[] > 115 & long[] < 121) LatIdx <- which(lat[] > 23 & lat[] < 29)
pre <- ncvar_get(nc_pre, 'pre', start = c(LonIdx[1], LatIdx[1],1), count = c(length(LonIdx), length(LatIdx),1)) fillvalue <- ncatt_get(nc_pre, "pre", "missing_value") pre[pre==fillvalue$value] <- NA