使用 R 中的函数 terra::rast() 创建具有多个 AQUA-MODIS (NetCDF) 文件的 SpatRaster

问题描述 投票:0回答:1

问题

我从Earthdata网站下载了2012年至2024年埃及北红海的叶绿素-a的AQUA-MODIS netcdf文件(总计 = 3422)。

我需要:

  • 堆叠所有 3422 AQUA MODIS netcdf 以在函数 terra::rast()(或等效函数)中创建,以创建 SpatRaster 来计算所有文件的平均叶绿素-a 水平。

我尝试过使用诸如 ncdf4、terra、raster 和 RNetCDF 等软件包,但没有成功 (请参阅下面我的努力)。我还尝试在 Stackoverflow 上寻找解决方案,并根据 ChatGPT 的建议进行了一些故障排除,但没有任何效果。我真的不明白如何找到解决方案。 非常感谢,如果有人可以提供帮助。

这里是获取数据的manifest.txt链接(2024年10月22日到期)

https://oceandata.sci.gsfc.nasa.gov/cgi/getfile/requested_files_2.tar?h=ocdist410&p=/data1/d0703031e30f7f6f/requested_files

将文件读入R:

library(terra) library(ncdf4) library(raster) library(RNetCDF) #Start the file path to all the netcdf files as a variable 'folder' folder<-"~/Documents/GIS_Data/CHL-A/" #Make a list of all the files within the folder files <-list.files(folder, pattern='*.nc', full.names ="TRUE")

循环遍历所有文件路径和 AQUA MODIS netcdf 文件以访问它们:

for (file in files) { nc=open.nc(file) print.nc(nc) }

AQUA MODIS 文件之一的内容

netcdf netcdf4 { // global attributes: NC_CHAR :product_name = "AQUA_MODIS.20221217.L3b.DAY.CHL.x.nc" ; NC_CHAR :title = "MODIS Level-3 Binned Data" ; NC_CHAR :instrument = "MODIS" ; NC_CHAR :platform = "Aqua" ; NC_CHAR :temporal_range = "day" ; NC_INT :start_orbit_number = 109682 ; NC_INT :end_orbit_number = 109698 ; NC_CHAR :date_created = "2024289095750000" ; NC_CHAR :processing_version = "unspecified" ; NC_CHAR :source = "satellite observations from MODIS-Aqua" ; NC_CHAR :history = "/sdps/sdpsoper/Science/OCSSW/DEVEL/bin/l3bin ifile=AQUA_MODIS.20221217.L3b.DAY.CHL.nc ofile=AQUA_MODIS.20221217.L3b.DAY.CHL.x.nc latnorth=37.0000 latsouth=5.1000 lonwest=26.7200 loneast=54.1400" ; NC_CHAR :time_coverage_start = "2022-12-17T00:25:01.000Z" ; NC_CHAR :time_coverage_end = "2022-12-18T02:59:59.000Z" ; NC_FLOAT :northernmost_latitude = 36.8958320617676 ; NC_FLOAT :southernmost_latitude = 5.10416650772095 ; NC_FLOAT :easternmost_longitude = 50.6941337585449 ; NC_FLOAT :westernmost_longitude = 26.7268047332764 ; NC_DOUBLE :geospatial_lat_max = 36.8958320617676 ; NC_DOUBLE :geospatial_lat_min = 5.10416650772095 ; NC_DOUBLE :geospatial_lon_max = 50.6941337585449 ; NC_DOUBLE :geospatial_lon_min = 26.7268047332764 ; NC_CHAR :geospatial_lat_units = "degrees_north" ; NC_CHAR :geospatial_lon_units = "degrees_east" ; NC_CHAR :geospatial_lat_resolution = "4.638312 km" ; NC_CHAR :geospatial_lon_resolution = "4.638312 km" ; NC_CHAR :spatialResolution = "4.638312 km" ; NC_INT :data_bins = 31421 ; NC_FLOAT :percent_data_bins = 0.132233932614326 ; NC_CHAR :units = "chlor_a:mg m^-3" ; NC_CHAR :binning_scheme = "Integerized Sinusoidal Grid" ; NC_CHAR :project = "Ocean Biology Processing Group (NASA/GSFC/OBPG)" ; NC_CHAR :institution = "NASA Goddard Space Flight Center, Ocean Ecology Laboratory, Ocean Biology Processing Group" ; NC_CHAR :standard_name_vocabulary = "CF Standard Name Table v36" ; NC_CHAR :Conventions = "CF-1.6 ACDD-1.3" ; NC_CHAR :naming_authority = "gov.nasa.gsfc.sci.oceandata" ; NC_CHAR :id = "AQUA_MODIS.20221217.L3b.DAY.CHL.x.nc/L3/AQUA_MODIS.20221217.L3b.DAY.CHL.x.nc" ; NC_CHAR :license = "https://science.nasa.gov/earth-science/earth-science-data/data-information-policy/" ; NC_CHAR :creator_name = "NASA/GSFC/OBPG" ; NC_CHAR :publisher_name = "NASA/GSFC/OBPG" ; NC_CHAR :creator_email = "[email protected]" ; NC_CHAR :publisher_email = "[email protected]" ; NC_CHAR :creator_url = "https://oceandata.sci.gsfc.nasa.gov" ; NC_CHAR :publisher_url = "https://oceandata.sci.gsfc.nasa.gov" ; NC_CHAR :processing_level = "L3 Binned" ; NC_CHAR :cdm_data_type = "point" ; NC_CHAR :keywords_vocabulary = "NASA Global Change Master Directory (GCMD) Science Keywords" ; NC_CHAR :keywords = "Earth Science > Oceans > Ocean Chemistry > Pigments > Chlorophyll; Earth Science > Oceans > Ocean Chemistry > Chlorophyll" ; group: level-3_binned_data { dimensions: binListDim = UNLIMITED ; // (31421 currently) binDataDim = UNLIMITED ; // (31421 currently) binIndexDim = UNLIMITED ; // (4320 currently) types: compound binListType { NC_UINT bin_num ; NC_SHORT nobs ; NC_SHORT nscenes ; NC_FLOAT weights ; NC_FLOAT time_rec ; }; // binListType compound binDataType { NC_FLOAT sum ; NC_FLOAT sum_squared ; }; // binDataType compound binIndexType { NC_UINT start_num ; NC_UINT begin ; NC_UINT extent ; NC_UINT max ; }; // binIndexType variables: binListType BinList(binListDim) ; binDataType chlor_a(binDataDim) ; binIndexType BinIndex(binIndexDim) ; } // group level-3_binned_data group: processing_control { // group attributes: NC_CHAR :software_name = "L3BIN" ; NC_CHAR :software_version = "5.14" ; NC_CHAR :input_sources = "AQUA_MODIS.20221217.L3b.DAY.CHL.nc" ; NC_CHAR :l2_flag_names = "ATMFAIL,LAND,HILT,HISATZEN,STRAYLIGHT,CLDICE,COCCOLITH,LOWLW,CHLWARN,CHLFAIL,NAVWARN,MAXAERITER,ATMWARN,HISOLZEN,NAVFAIL,FILTER,HIGLINT" ; group: input_parameters { // group attributes: NC_CHAR :infile = "AQUA_MODIS.20221217.L3b.DAY.CHL.nc" ; NC_CHAR :ofile = "AQUA_MODIS.20221217.L3b.DAY.CHL.x.nc" ; NC_CHAR :pfile = "AQUA_MODIS.20221217.L3b.DAY.CHL.x.nc" ; NC_CHAR :oformat = "netCDF4" ; NC_CHAR :syear = "9999" ; NC_CHAR :eyear = "9999" ; NC_CHAR :sday = "1970001" ; NC_CHAR :eday = "2038018" ; NC_CHAR :sorbit = "-1" ; NC_CHAR :eorbit = "-1" ; NC_CHAR :out_parm = ":DEFAULT:" ; NC_CHAR :processing_version = "unspecified" ; NC_CHAR :reduce_fac = "1" ; NC_CHAR :resolve = "" ; NC_CHAR :merged = "" ; NC_CHAR :loneast = "54.139999" ; NC_CHAR :lonwest = "26.719999" ; NC_CHAR :latnorth = "37.000000" ; NC_CHAR :latsouth = "5.100000" ; NC_CHAR :verbose = "0" ; NC_CHAR :unit_wgt = "0" ; NC_CHAR :median = "0" ; NC_CHAR :deflate = "5" ; NC_CHAR :composite_prod = "" ; NC_CHAR :composite_scheme = "" ; NC_CHAR :doi = "" ; } // group input_parameters } // group processing_control }

尝试堆叠 netcdf 文件:

尝试1:

chla1<-terra::rast(files)

错误信息

Error: [rast] cannot open this file as a SpatRaster: /Documents/GIS_Data/CHL-A/AQUA_MODIS.20120101.L3b.DAY.CHL.x.nc In addition: Warning message: `Documents/GIS_Data/CHL-A/AQUA_MODIS.20120101.L3b.DAY.CHL.x.nc' not recognized as a supported file format. (GDAL error 4)

尝试2:

chla1<-terra::rast(nc)

错误信息:

Error in methods::as(x, "SpatRaster") : no method or default for coercing “NetCDF” to “SpatRaster”

尝试3:

chl4<-raster::stack(files)

错误信息

Error in ncvar_type_to_string(rv$precint) : Error, unrecognized type code of variable supplied: -1

我的 R 环境的屏幕截图

enter image description here

我的目录中的一些文件的屏幕截图

enter image description here

r gis netcdf terra
1个回答
0
投票
terra

raster
都不会读取该内容,甚至
ncdf4
也会报告错误。据我所知,唯一可以打开文件而不会出现错误的软件包是
ncdfCF
,但即使这样也无法识别每个文件中包含的数据集。不过,您可以读出原始数据,然后自行处理。
library(ncdfCF)

(chl <- open_ncdf(<<your_file.nc>>))
# <Dataset> AQUA_MODIS.20030101.L3b.DAY.CHL 
# Resource   : /my_data_dir/AQUA_MODIS.20030101.L3b.DAY.CHL.nc 
# Format     : netcdf4 
# Conventions: CF-1.6 ACDD-1.3 
# Keep open  : FALSE 
# Has groups : TRUE 

(vars <- lf7$root$unused())
# $`level-3_binned_data.BinList`
# <netCDF variable> [0] BinList
# Group        : /level-3_binned_data 
# Data type    : binListType 
# Dimension ids: 0 
# 
# $`level-3_binned_data.chlor_a`
# <netCDF variable> [1] chlor_a
# Group        : /level-3_binned_data 
# Data type    : binDataType 
# Dimension ids: 1 
# 
# $`level-3_binned_data.BinIndex`
# <netCDF variable> [2] BinIndex
# Group        : /level-3_binned_data 
# Data type    : binIndexType 
# Dimension ids: 2 

原始数据位于 
level-3_binned_data.chlor_a

中,但您将需要其他两个变量来对网格单元进行地理定位。为此,您应该查找

文档
中的 L3b 数据。
    

© www.soinside.com 2019 - 2024. All rights reserved.