使用R从netcdf中提取SST值

使用R从netcdf中提取SST值,r,R,我想用R软件从Netcdf文件中提取SST值。我从“”下载了温度数据。我需要提取特定区域的温度值(经度在-2到10之间;纬度在35到40之间),并按年份组织它们,然后计算每个月的平均值 我不知道怎么做,因为我不知道怎么读公历 我尝试应用脚本,但: > library(ncdf4) > rm(list=ls()) > fn <- "D:/logiciel/KHAMES/OISST_HR_NRT-GOS-L4-MED-v2.0.nc" > cdf<- nc_ope

我想用R软件从Netcdf文件中提取SST值。我从“”下载了温度数据。我需要提取特定区域的温度值(经度在-2到10之间;纬度在35到40之间),并按年份组织它们,然后计算每个月的平均值

我不知道怎么做,因为我不知道怎么读公历

我尝试应用脚本,但:

> library(ncdf4)
> rm(list=ls())
> fn <- "D:/logiciel/KHAMES/OISST_HR_NRT-GOS-L4-MED-v2.0.nc"
> cdf<- nc_open(fn)
> nc
lat <- ncdf4::ncvar_get(cdf, varid="lat")
lon <- ncdf4::ncvar_get(cdf, varid="lon")
time <- ncdf4::ncvar_get(cdf, varid="time")
sst <- ncdf4::ncvar_get(cdf, varid="analysed_sst")
time_d <- as.Date(time, format="%j", origin=as.Date("1981-01-01"))
time_years <- format(time_d, "%Y")
time_months <- format(time_d, "%m")
time_year_months <- format(time_d, "%Y-%
>库(ncdf4)
>rm(list=ls())
>fn cdf nc

lat我假设您已经正确地从netcdf文件中提取了数据,并且您正在努力计算每个月的平均sst

以下是对我有用的,也可能是你想要的:

lon <- sample(1:5, size = 200, replace = TRUE)
lat <- sample(35:40, size = 200, replace = TRUE)
sst <- 1:200
time_years <- rep(rep(1:10, each = 10), 2)
time_months <- rep(rep(1:10, times = 10), 2)
time_year_months <- paste(time_years, time_months, sep = "-")
library(dplyr)
tibble(lat = as.numeric(lat), lon = as.numeric(lon), sst = as.numeric(sst), time_years, time_months, time_year_months) %>%
  filter(lon > -2, lon < 10, lat > 35, lat < 40) %>%
  group_by(time_year_months) %>%
  summarise(mean_sst = mean(sst))

lon什么是
sst
?是温度吗?