问题:
我在R中有一个代码,可以从单个Aqua Modis网络CDF文件中提取每月海面温度(SST)值(见下文)。但是,我在一个文件夹中有一批 59 个 Aqua Modis netCDF 文件。
目的:
我的目标是从所有59个netCDF文件的每个netCDF中提取变量的经度、纬度和SST,使用函数stack::raster()将它们转换为光栅文件,然后处理这些文件。
我的数据框有 650 行,它们是海豚 ID。我想提取 2016-2021 年期间每个海豚 ID 的平均 SST。一旦我提取了每个海豚ID的平均值SST,我想将这些值写入一个名为“ Average_SST”的列的.csv文件中。
不幸的是,由于所有权问题,我无法共享我的数据。
我是一个完全的新手在空间分析,我一直试图解决这个难题近4天通过观看YouTube,阅读教程和堆栈溢出。我现在感到非常困惑,我相信我将不得不循环通过所有的文件来实现我的目标。
如果有人能帮忙,在此提前致谢。
r代码:
从文件夹中打开所有59个Aqua Modis netCDF文件
##Open packages needed for our analysis
library(ncdf4)
library(terra)
library('RNetCDF')
library(raster)
library(sp)
filenames = list.files('~/Documents/Ocean_ColorSST_2016_2021',pattern='*.nc',full.names=TRUE)
##Open the 70 Aqua Modis netCDF files from their folder
SST <- nc_open(filenames[59])
##Print the results for SST
print(SST)
结果:
3 variables (excluding dimension variables):
short sst[lon,lat] (Chunking: [87,44]) (Compression: shuffle,level 4)
long_name: Sea Surface Temperature
scale_factor: 0.00499999988824129
add_offset: 0
units: degree_C
standard_name: sea_surface_temperature
_FillValue: -32767
valid_min: -1000
valid_max: 10000
display_scale: linear
display_min: -2
display_max: 45
unsigned byte qual_sst[lon,lat] (Chunking: [87,44]) (Compression: shuffle,level 4)
long_name: Quality Levels, Sea Surface Temperature
_FillValue: 255
valid_min: 0
valid_max: 5
unsigned byte palette[eightbitcolor,rgb] (Contiguous storage)
4 dimensions:
lat Size:4320
long_name: Latitude
units: degrees_north
standard_name: latitude
_FillValue: -999
valid_min: -90
valid_max: 90
lon Size:8640
long_name: Longitude
units: degrees_east
standard_name: longitude
_FillValue: -999
valid_min: -180
valid_max: 180
rgb Size:3 (no dimvar)
eightbitcolor Size:256 (no dimvar)
[1] ">>>> WARNING <<< attribute data_bins is an 8-byte value, but R"
[1] "does not support this data type. I am returning a double precision"
[1] "floating point, but you must be aware that this could lose precision!"
61 global attributes:
product_name: AQUA_MODIS.20210901_20210930.L3m.MO.SST.sst.4km.nc
instrument: MODIS
title: MODISA Level-3 Standard Mapped Image
project: Ocean Biology Processing Group (NASA/GSFC/OBPG)
platform: Aqua
temporal_range: month
processing_version: R2019.0
date_created: 2021-12-03T08:21:22.000Z
history: l3mapgen par=AQUA_MODIS.20210901_20210930.L3m.MO.SST.sst.4km.nc.param
l2_flag_names: LAND,HISOLZEN
time_coverage_start: 2021-09-01T00:45:00.000Z
time_coverage_end: 2021-10-01T02:55:00.000Z
start_orbit_number: 102808
end_orbit_number: 103246
map_projection: Equidistant Cylindrical
latitude_units: degrees_north
longitude_units: degrees_east
northernmost_latitude: 90
southernmost_latitude: -90
westernmost_longitude: -180
easternmost_longitude: 180
geospatial_lat_max: 90
geospatial_lat_min: -90
geospatial_lon_max: 180
geospatial_lon_min: -180
latitude_step: 0.0416666679084301
longitude_step: 0.0416666679084301
sw_point_latitude: -89.9791641235352
sw_point_longitude: -179.97917175293
spatialResolution: 4.64 km
geospatial_lon_resolution: 0.0416666679084301
geospatial_lat_resolution: 0.0416666679084301
geospatial_lat_units: degrees_north
geospatial_lon_units: degrees_east
number_of_lines: 4320
number_of_columns: 8640
measure: Mean
suggested_image_scaling_minimum: -2
suggested_image_scaling_maximum: 45
suggested_image_scaling_type: LINEAR
suggested_image_scaling_applied: No
_lastModified: 2021-12-03T08:21:22.000Z
Conventions: CF-1.6 ACDD-1.3
institution: NASA Goddard Space Flight Center, Ocean Ecology Laboratory, Ocean Biology Processing Group
standard_name_vocabulary: CF Standard Name Table v36
naming_authority: gov.nasa.gsfc.sci.oceandata
id: AQUA_MODIS.20210901_20210930.L3b.MO.SST.nc/L3/AQUA_MODIS.20210901_20210930.L3b.MO.SST.nc
license: https://science.nasa.gov/earth-science/earth-science-data/data-information-policy/
creator_name: NASA/GSFC/OBPG
publisher_name: NASA/GSFC/OBPG
creator_email: data@oceancolor.gsfc.nasa.gov
publisher_email: data@oceancolor.gsfc.nasa.gov
creator_url: https://oceandata.sci.gsfc.nasa.gov
publisher_url: https://oceandata.sci.gsfc.nasa.gov
processing_level: L3 Mapped
cdm_data_type: grid
keywords: Earth Science > Oceans > Ocean Optics > Sea Surface Temperature
keywords_vocabulary: NASA Global Change Master Directory (GCMD) Science Keywords
data_bins: 20227868
data_minimum: -1.80000007152557
data_maximum: 40.0000038146973
> SST_brick <- brick(list[59], "sst")
Error in h(simpleError(msg, call)) :
error in evaluating the argument 'x' in selecting a method for function 'brick': object of type 'builtin' is not subsettable
> ##Print the results for SST
> print(SST)
File /Users/kirstymedcalf/Documents/DMAD/Publication/DMAD_Maps_Analysis_Publication/Montenegro_Final_Analysis_Folders/Ocean_ColorSST_2016_2021/AQUA_MODIS.20210901_20210930.L3m.MO.SST.sst.4km.nc (NC_FORMAT_NETCDF4):
3 variables (excluding dimension variables):
short sst[lon,lat] (Chunking: [87,44]) (Compression: shuffle,level 4)
long_name: Sea Surface Temperature
scale_factor: 0.00499999988824129
add_offset: 0
units: degree_C
standard_name: sea_surface_temperature
_FillValue: -32767
valid_min: -1000
valid_max: 10000
display_scale: linear
display_min: -2
display_max: 45
unsigned byte qual_sst[lon,lat] (Chunking: [87,44]) (Compression: shuffle,level 4)
long_name: Quality Levels, Sea Surface Temperature
_FillValue: 255
valid_min: 0
valid_max: 5
unsigned byte palette[eightbitcolor,rgb] (Contiguous storage)
4 dimensions:
lat Size:4320
long_name: Latitude
units: degrees_north
standard_name: latitude
_FillValue: -999
valid_min: -90
valid_max: 90
lon Size:8640
long_name: Longitude
units: degrees_east
standard_name: longitude
_FillValue: -999
valid_min: -180
valid_max: 180
rgb Size:3 (no dimvar)
eightbitcolor Size:256 (no dimvar)
[1] ">>>> WARNING <<< attribute data_bins is an 8-byte value, but R"
[1] "does not support this data type. I am returning a double precision"
[1] "floating point, but you must be aware that this could lose precision!"
61 global attributes:
product_name: AQUA_MODIS.20210901_20210930.L3m.MO.SST.sst.4km.nc
instrument: MODIS
title: MODISA Level-3 Standard Mapped Image
project: Ocean Biology Processing Group (NASA/GSFC/OBPG)
platform: Aqua
temporal_range: month
processing_version: R2019.0
date_created: 2021-12-03T08:21:22.000Z
history: l3mapgen par=AQUA_MODIS.20210901_20210930.L3m.MO.SST.sst.4km.nc.param
l2_flag_names: LAND,HISOLZEN
time_coverage_start: 2021-09-01T00:45:00.000Z
time_coverage_end: 2021-10-01T02:55:00.000Z
start_orbit_number: 102808
end_orbit_number: 103246
map_projection: Equidistant Cylindrical
latitude_units: degrees_north
longitude_units: degrees_east
northernmost_latitude: 90
southernmost_latitude: -90
westernmost_longitude: -180
easternmost_longitude: 180
geospatial_lat_max: 90
geospatial_lat_min: -90
geospatial_lon_max: 180
geospatial_lon_min: -180
latitude_step: 0.0416666679084301
longitude_step: 0.0416666679084301
sw_point_latitude: -89.9791641235352
sw_point_longitude: -179.97917175293
spatialResolution: 4.64 km
geospatial_lon_resolution: 0.0416666679084301
geospatial_lat_resolution: 0.0416666679084301
geospatial_lat_units: degrees_north
geospatial_lon_units: degrees_east
number_of_lines: 4320
number_of_columns: 8640
measure: Mean
suggested_image_scaling_minimum: -2
suggested_image_scaling_maximum: 45
suggested_image_scaling_type: LINEAR
suggested_image_scaling_applied: No
_lastModified: 2021-12-03T08:21:22.000Z
Conventions: CF-1.6 ACDD-1.3
institution: NASA Goddard Space Flight Center, Ocean Ecology Laboratory, Ocean Biology Processing Group
standard_name_vocabulary: CF Standard Name Table v36
naming_authority: gov.nasa.gsfc.sci.oceandata
id: AQUA_MODIS.20210901_20210930.L3b.MO.SST.nc/L3/AQUA_MODIS.20210901_20210930.L3b.MO.SST.nc
license: https://science.nasa.gov/earth-science/earth-science-data/data-information-policy/
creator_name: NASA/GSFC/OBPG
publisher_name: NASA/GSFC/OBPG
creator_email: data@oceancolor.gsfc.nasa.gov
publisher_email: data@oceancolor.gsfc.nasa.gov
creator_url: https://oceandata.sci.gsfc.nasa.gov
publisher_url: https://oceandata.sci.gsfc.nasa.gov
processing_level: L3 Mapped
cdm_data_type: grid
keywords: Earth Science > Oceans > Ocean Optics > Sea Surface Temperature
keywords_vocabulary: NASA Global Change Master Directory (GCMD) Science Keywords
data_bins: 20227868
data_minimum: -1.80000007152557
data_maximum: 40.0000038146973
##从每个Aqua Modis文件中提取SST、经度和纬度值,为感兴趣的变量创建59个列表。然而,我认为我只是提取了一个Aqua Modis文件的值[1]
SST_filenames <- ncvar_get(SST, "sst")
lon_filenames <- ncvar_get(SST, "lon")
lat_filenames <- ncvar_get(SST, "lat")
我以为我会尝试 brick() 函数但没有成功,因为我仍然认为我正在从单个 Aqua Modis 文件 [1] 中提取值。.
SST_brick <- brick(filenames[59], "sst")
lon_brick <- brick(filenames[59], "lon")
lat_brick <- brick(filenames[59], "lat")
SST_brick的结果
lass : RasterBrick
dimensions : 4320, 8640, 37324800, 1 (nrow, ncol, ncell, nlayers)
resolution : 0.04166667, 0.04166667 (x, y)
extent : -180, 180, -90.00001, 90 (xmin, xmax, ymin, ymax)
crs : +proj=longlat +datum=WGS84 +no_defs
source : AQUA_MODIS.20210901_20210930.L3m.MO.SST.sst.4km.nc
names : layer
varname : sst
如果我使用对象SST,我想我还是打开了单个Aqua Modis netCDF文件的值[1]
SST_filenames <- ncvar_get(SST, "sst")
lon_filenames <- ncvar_get(SST, "lon")
lat_filenames <- ncvar_get(SST, "lat")
您似乎误解了RasterStack
或SpatRaster
对象是什么。您打印了SST_brick
,它清楚地显示它知道经度和纬度。您不需要其他任何东西。
与
library(terra)
filenames = list.files('~/Documents/Ocean_ColorSST_2016_2021',pattern='*.nc',full.names=TRUE)
假设<code>海豚</code>是一个矩阵或数据。带有变量“经度”和“纬度”的框架,您可以对一个文件这样做:
SST <- rast(filenames[1], "sst")
e <- extract(SST, dolphins[, c("longitude", "latitude")])
但是你可以像这样一蹴而就
SSTs <- rast(filenames, "sst")
e <- extract(SSTs, dolphins[, c("longitude", "latitude")])
问题内容: 我对Json文件很陌生。如果我有一个包含多个json对象的json文件,例如: 我想将所有“时间戳记”和“有用性”提取到一个数据帧中: 有谁知道解决此类问题的一般方法? 问题答案: 使用json数组,格式为: 然后将其导入到您的python代码中 现在,数据的内容是一个带有字典的数组,字典表示每个元素。 您可以轻松访问它,即:
我想使用R从一个数组中读取“when”值。由Google My tracks创建的kml文件(摘录如下): 节点“when”是“与位置相对应的时间值(在gx:coord元素中指定)”。“gx:coord”是“由经度、纬度和高度三个值组成的坐标值”。(https://developers.google.com/kml/documentation/kmlreference#gxtrack) 我想要的值
在我的应用程序中,我下载了Android系统的扩展文件- 我尝试将APK扩展Zip库用作: 但是expansionFile总是空的。这个obb文件是用Jobb创建的,用于文件夹obb/file。拉链
本文向大家介绍如何在R数据帧中提取两个或多个变量的唯一组合?,包括了如何在R数据帧中提取两个或多个变量的唯一组合?的使用技巧和注意事项,需要的朋友参考一下 R数据帧可以具有大量类别变量,并且这些类别形成不同的组合。例如,变量的一个值可以与另一个变量的两个或多个值链接。同样,一个类别变量可以具有所有唯一类别。我们可以根据需要找到尽可能多的变量,并且可以通过独特的功能来完成。 示例 请看以下数据帧-
问题内容: 这是我的第一个文件: 我想要这个配置变量在另一个文件中,所以我在另一个文件中所做的是: 但这给我一个错误。 请提出我该怎么办? 问题答案: 您需要的是module.exports 出口产品 在当前模块的所有实例之间共享并可以通过require()访问的对象。export与module.exports对象相同。有关更多信息,请参见src / node.js。导出实际上不是全局的,而是每个
我正在编写一个Go客户端,通过REST-API创建备份。带有多部分表单数据的REST-API响应到GET请求。因此,响应(类型*http.response)正文的内容如下: 如何从响应正文中提取zip文件? 我试图使用内置(net / http)方法,但这些方法需要一个请求结构。