Skip to content

Commit

Permalink
Updated the createStoredObjects script to include SSH and use teh new…
Browse files Browse the repository at this point in the history
…, single SST data file. Original data files are not going to be posted, so that will be up to the user to download. Also updated the readme.
  • Loading branch information
brianburkenoaa committed Oct 30, 2024
1 parent f69ed79 commit fcdecdd
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 25 deletions.
48 changes: 48 additions & 0 deletions R/createStoredObjects.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
# This code creates those datasets and saves them as RData files
# This only has to be run to update the data, not each time you want to use the code



# LAND --------------------------------------------------------------------


#********************************************************
# get the land for plotting (wrap across antimeridian)
#********************************************************
Expand All @@ -13,9 +18,16 @@ rest_of_world <- land[!land$region_un=='Americas',]
land <- rbind(pacified_amer, rest_of_world)
save("land", file = "data/land.Rdata")



# ERSST -------------------------------------------------------------------


#********************************************************
# THIS IS TO CREATE THE GLOBAL SST DATA (RDATA FILE)
#********************************************************
source("R/getOceanData.R")

dataSet='ERSST'
# Full globe
min.lon=0
Expand All @@ -38,3 +50,39 @@ oceanData_ERSST<-getOceanData(dataSet=dataSet,
save(x = "oceanData_ERSST", file = 'data/oceanSSTData.RData')
load('data/oceanSSTData.RData')


# SSH ---------------------------------------------------------------------

#********************************************************
# THIS IS TO CREATE THE GLOBAL SSH DATA (RDATA FILE)
#********************************************************
source("R/getOceanData.R")

# The compiled SSH data (referred to as oceanSSHData.RData)
# is too large to store in github. Please download the original data
# files here: https://psl.noaa.gov/data/gridded/data.godas.html
# and create the file with the code below.

dataSet='SSH'
# Full globe
# SSH longitude goes from 0.5 to 359.5, by 1
min.lon=0
max.lon=360
# SSH latitude goes from -74 to 65, by 1/3?
min.lat=-90
max.lat=90
years=seq(1980, 2023, 1)
months=seq(1,12,1)
removeBering=FALSE
returnDataType='anom'
returnObjectType='array'

oceanData_SSH<-getOceanData(dataSet=dataSet,
returnDataType=returnDataType, returnObjectType=returnObjectType,
min.lon=min.lon, max.lon=max.lon,
min.lat=min.lat, max.lat=max.lat,
years = years, months = months,
removeBering = removeBering)
save(x = "oceanData_SSH", file = 'data/oceanSSHData.RData')
load('data/oceanSSHData.RData')

51 changes: 26 additions & 25 deletions R/create_OceanData_Object.R → R/getOceanData.R
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
# Extract data from global data sets
# User sets extent and return object type


#*****************************************
#*****************************************
# Not needed by most users. The resulting data
# have been stored in RData files, which will
# be updated annually by Brian Burke
#*****************************************
#*****************************************

# To run this code, you will need to download the original data files
# and store them in data/SST/ or data/SSH

# SST data are from ERSST (https://www.ncei.noaa.gov/pub/data/cmb/ersst/v5/netcdf/)
# But I obtained them where they have been reposted in a slightly different format here:
# https://psl.noaa.gov/data/gridded/data.noaa.ersst.v5.html
# ERSST is a 2x2 degree gloabal dataset

# references: Huang et al, 2017: Extended Reconstructed Sea Surface Temperatures Version 5 (ERSSTv5): Upgrades, Validations, and Intercomparisons. Journal of Climate, https://doi.org/10.1175/JCLI-D-16-0836.1
# climatology: Climatology is based on 1971-2000 SST, Xue, Y., T. M. Smith, and R. W. Reynolds, 2003: Interdecadal changes of 30-yr SST normals during 1871.2000. Journal of Climate, 16, 1601-1612.
# acknowledgment: The NOAA Extended Reconstructed Sea Surface Temperature (ERSST) data are provided by the NOAA National Centers for Environmental Information(NCEI)

# SSH Data from: https://psl.noaa.gov/data/gridded/data.godas.html
# Or maybe here: https://downloads.psl.noaa.gov/Datasets/godas/

library(ncdf4)

Expand Down Expand Up @@ -48,15 +42,15 @@ getOceanData<-function(dataSet='ERSST',

# open a (any) netCDF file to extract lats and longs
if (dataSet == 'ERSST') {
#ncfname <- "data/../../data/SST/ersst.v5.202001.nc"
ncfname <- "data/SST/ersst.v5.202001.nc"
ncfname <- "data/SST/sst.mon.ltm.1991-2020.nc"
#ncfname <- "data/SST/sst.mon.ltm.1981-2010.nc"
ncin <- nc_open(ncfname)
lons <- ncvar_get(ncin,"lon")
lats <- ncvar_get(ncin,"lat",verbose=F)
sst.ltm <- ncvar_get(ncin,"sst")
nc_close(ncin)
}
if (dataSet == 'SSH') {
#ncfname <- "data/../../data/SSH/sshg.mon.ltm.1991-2020.nc"
ncfname <- "data/SSH/sshg.mon.ltm.1991-2020.nc"
ncin <- nc_open(ncfname) # open it
lons <- ncvar_get(ncin,"lon")
Expand All @@ -71,7 +65,7 @@ getOceanData<-function(dataSet='ERSST',
#***************************************************************

# Index the locations in the file
lon.index<-which(lons > min.lon & lons < max.lon)
lon.index<-which(lons >= min.lon & lons < max.lon)
lat.index<-which(lats > min.lat & lats < max.lat)
lon.subset <- lons[lon.index]
lat.subset <- lats[lat.index]
Expand All @@ -82,22 +76,29 @@ getOceanData<-function(dataSet='ERSST',
dimnames = list(lon.subset, lat.subset, year_mo$label))

if (dataSet == 'ERSST') {
# Loop over files and get sst data
for (ym in 1:nrow(year_mo)) {
#ncfname <- paste0("data/../../data/SST/ersst.v5.",year_mo$year[ym],sprintf("%02d",year_mo$month[ym]),".nc")
ncfname <- paste0("data/SST/ersst.v5.",year_mo$year[ym],sprintf("%02d",year_mo$month[ym]),".nc")
ncin <- nc_open(ncfname)
if (returnDataType=="anom") sst <- ncvar_get(ncin,"ssta")
if (returnDataType=="raw") sst <- ncvar_get(ncin,"sst")
returnData[,,ym]<-sst[lon.index, lat.index]
nc_close(ncin)
# All of the sst data are in one file
ncfname <- "data/SST/sst.mnmean.nc"
ncin <- nc_open(ncfname)
sst <- ncvar_get(ncin,"sst") #float sst[lon,lat,time]
psl.time <- ncvar_get(ncin,"time")
dates <- format(as.Date("1800-01-01") + psl.time, "%Y_%m")
dates <- sub("(.+)_0?(.+)", "\\1_\\2", dates)
dimnames(sst) <- list(seq(0,358,2), seq(-88,88,2), dates)
# get anomaly, if requested
for (mo in 1:nrow(year_mo)) {
if (returnDataType == 'anom') {
sst.temp <- sst[,, dates == year_mo$label[mo]] - sst.ltm[,, year_mo$month[mo]]
} else sst.temp <- sst[,, dates == year_mo$label[mo]]
returnData[, , mo]<-sst.temp
}
nc_close(ncin)
returnData <- returnData[,89:1,] # I think this would fix the reversed latitude
}
if (dataSet == 'SSH') {
# Loop over files and get ssh data
# Loop over files (one per year) and get ssh data
for (ym in 1:nrow(year_mo)) {
if (year_mo$month[ym]==1) {
ncfname <- paste0("data/../../data/SSH/sshg.",year_mo$year[ym],".nc")
ncfname <- paste0("data/SSH/sshg.",year_mo$year[ym],".nc")
ncin <- nc_open(ncfname)
ssh.temp <- ncvar_get(ncin,"sshg")
}
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,23 @@

This repository is a scientific product and is not official communication of the National Oceanic and Atmospheric Administration, or the United States Department of Commerce. All NOAA GitHub project content is provided on an "as is" basis and the user assumes responsibility for its use. Any claims against the Department of Commerce or Department of Commerce bureaus stemming from the use of this GitHub project will be governed by all applicable Federal law. Any reference to specific commercial products, processes, or services by service mark, trademark, manufacturer, or otherwise, does not constitute or imply their endorsement, recommendation or favoring by the Department of Commerce. The Department of Commerce seal and logo, or the seal and logo of a DOC bureau, shall not be used in any manner to imply endorsement of any commercial product or activity by DOC or the United States Government.


## Data sources

To update the data files:
- land.RData
- oceanSSTData.RData
- oceanSSHData.RData
- responseData.RData
you will need to download the data files, store them in the data folder (use SST and SSH subfolders for SST and SSH data), and run the code in createStoredObjects.R

SST data are from ERSST (https://www.ncei.noaa.gov/pub/data/cmb/ersst/v5/netcdf/)
But I obtained them where they have been reposted in a slightly different format here:
https://psl.noaa.gov/data/gridded/data.noaa.ersst.v5.html
ERSST is a 2x2 degree gloabal dataset

references: Huang et al, 2017: Extended Reconstructed Sea Surface Temperatures Version 5 (ERSSTv5): Upgrades, Validations, and Intercomparisons. Journal of Climate, https://doi.org/10.1175/JCLI-D-16-0836.1
acknowledgment: The NOAA Extended Reconstructed Sea Surface Temperature (ERSST) data are provided by the NOAA National Centers for Environmental Information(NCEI)

SSH Data from: https://psl.noaa.gov/data/gridded/data.godas.html

0 comments on commit fcdecdd

Please sign in to comment.