Accessing CEFI data with R#
The following notebook is a quick demostration on how to use R to access the OPeNDAP server data. This is designed for users that prefer the programing interface to be R. There are already couple of great resource related to preprocessing and visualizing data in R. Therefore, the notebook will not repeat that part of the code but focusing on how to accessing the data from a R interface. The resources is listed below
http://cran.nexr.com/web/packages/rerddap/vignettes/Using_rerddap.html (A detail introduction of rerddap package and show the visualization in many different datasets)
https://ioos.github.io/ioos_code_lab/content/code_gallery/data_access_notebooks/2017-08-01-xtractoR.html (use a different package called xtractomatic to access the ERDDAP data)
Launch R in Jupyterlab
In addition to the standard R code demonstrated below, our current interface leverages JupyterLab to execute R code using the R kernel. To enable this functionality, we utilize the environment.yml file to create a Conda/Mamba environment. The primary objective is to install the r-irkernel package within this environment.This installation of r-irkernel through Conda/Mamba ensures that the R kernel becomes available as an option when launching JupyterLab. Selecting the R kernel empowers users to utilize the JupyterLab interface for running R code effortlessly.
Packages used#
To use R to access the OPeNDAP server directly from your R script or R-notebook, you will need
ncdf4
There are couple of ways to install the packages, here we provide two popular ways below
In the R environment,
install.packages('<package name>')
In the conda/mamba environment for package version control,
conda install r-<package name>
ormamba install r-<package name>
(many r package can be install this way by adding “r-” in front of the package name)
Import R packages#
The way to import packages to the current R environment is to use the require
or library
functions
Both functions will import the package but with subtle different of
The require() and library() functions can both be used to load packages in R, but they have one subtle difference:
require() will output a warning if a package is not installed and then continue to execute the code.
library() will output an error and stop the execution of the code.
Detail explanation can be find here
library("ncdf4")
Direct OPeNDAP server data access#
With the help of the ncdf4 package we are able to load the data that is hosted on the OPeNDAP server and grab the coordinate and attribute without the need to downloading the entire dataset.
first we need to find the URL that can provide the OPeNDAP access for R (this can be find on the THREDDS server here)
click on OPeNDAP option when clicking on any of the netcdf files
on top of the OPeNDAP form there is a URL for accessing the data
Tip
Understanding of the OPeNDAP server and what it provides is highly recommended before reading the following intructions.
Link to data source (regular gridded product)#
# Specify the OPeNDAP server URL (using regular grid output)
url <- "http://psl.noaa.gov/thredds/dodsC/Projects/CEFI/regional_mom6/northwest_atlantic/hist_run/regrid/ocean_monthly.199301-201912.sos.nc"
# Open a NetCDF file lazily and remotely
ncopendap <- nc_open(url)
Load the data to local memory#
Warning
There is a 500MB limit per request so making sure the data request each time is not over the limit. For loop to seperate the request is one of the solution to avoid the single time request becoming to large.
Here we only request a single slice in the time domain but the whole northeast Atlantic domain in the regional mom6 model. Since this is the part that actually downloading the data. It would takes a bit longer.
# Read the data into memory
timeslice = 1
lon <- ncvar_get(ncopendap, "lon")
lat <- ncvar_get(ncopendap, "lat")
time <- ncvar_get(ncopendap, "time",start = c(timeslice), count = c(1))
# Read a slice of the data into memory
sos <- ncvar_get(ncopendap, "sos", start = c(1, 1, timeslice), count = c(-1, -1, 1))
# the matrix output of sea surface salinity
sos
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋱ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ |
NA | 36.06681 | 36.06974 | 36.07292 | 36.07632 | 36.07998 | 36.08291 | 36.08522 | 36.08725 | 36.08934 | ⋯ | 34.73696 | 34.73539 | 34.73647 | 34.74131 | 34.74666 | 34.75334 | 34.75716 | 34.75456 | NA | NA |
NA | 36.06295 | 36.06661 | 36.07045 | 36.07452 | 36.07897 | 36.08310 | 36.08648 | 36.08923 | 36.09155 | ⋯ | 34.74045 | 34.73808 | 34.73823 | 34.74231 | 34.74707 | 34.75413 | 34.75976 | 34.75694 | NA | NA |
NA | 36.05849 | 36.06314 | 36.06780 | 36.07257 | 36.07759 | 36.08237 | 36.08672 | 36.09046 | 36.09347 | ⋯ | 34.74746 | 34.74201 | 34.74012 | 34.74227 | 34.74576 | 34.75234 | 34.75902 | 34.75777 | NA | NA |
NA | 36.05369 | 36.05925 | 36.06476 | 36.07031 | 36.07592 | 36.08116 | 36.08618 | 36.09076 | 36.09464 | ⋯ | 34.75548 | 34.74885 | 34.74416 | 34.74366 | 34.74535 | 34.75097 | 34.75755 | 34.75734 | NA | NA |
NA | 36.04902 | 36.05526 | 36.06161 | 36.06792 | 36.07402 | 36.07977 | 36.08530 | 36.09044 | 36.09501 | ⋯ | 34.76160 | 34.75608 | 34.75015 | 34.74781 | 34.74790 | 34.75181 | 34.75766 | 34.75819 | 34.75734 | NA |
NA | 36.04408 | 36.05053 | 36.05745 | 36.06454 | 36.07141 | 36.07781 | 36.08392 | 36.08958 | 36.09463 | ⋯ | 34.76550 | 34.76152 | 34.75721 | 34.75390 | 34.75283 | 34.75468 | 34.75901 | 34.76021 | 34.75845 | NA |
NA | 36.04190 | 36.04766 | 36.05413 | 36.06111 | 36.06828 | 36.07522 | 36.08199 | 36.08827 | 36.09380 | ⋯ | 34.76876 | 34.76551 | 34.76207 | 34.75816 | 34.75706 | 34.75796 | 34.76087 | 34.76239 | 34.76061 | NA |
NA | 36.04018 | 36.04603 | 36.05214 | 36.05864 | 36.06561 | 36.07269 | 36.07980 | 36.08659 | 36.09266 | ⋯ | 34.76980 | 34.76541 | 34.76189 | 34.75913 | 34.75877 | 34.76064 | 34.76353 | 34.76416 | 34.76292 | NA |
NA | 36.03717 | 36.04394 | 36.05040 | 36.05678 | 36.06345 | 36.07047 | 36.07769 | 36.08479 | 36.09132 | ⋯ | 34.76788 | 34.76265 | 34.75869 | 34.75768 | 34.75938 | 34.76270 | 34.76633 | 34.76665 | 34.76496 | NA |
NA | 36.03350 | 36.04106 | 36.04810 | 36.05481 | 36.06152 | 36.06849 | 36.07570 | 36.08286 | 36.08960 | ⋯ | 34.76396 | 34.76099 | 34.76042 | 34.76034 | 34.76133 | 34.76479 | 34.76829 | 34.76902 | 34.76764 | NA |
NA | 36.02943 | 36.03791 | 36.04574 | 36.05303 | 36.06005 | 36.06709 | 36.07425 | 36.08128 | 36.08791 | ⋯ | 34.76386 | 34.76818 | 34.77166 | 34.77100 | 34.76776 | 34.76808 | 34.76986 | 34.77100 | 34.77069 | NA |
NA | 36.02458 | 36.03363 | 36.04208 | 36.05010 | 36.05777 | 36.06527 | 36.07266 | 36.07973 | 36.08626 | ⋯ | 34.76764 | 34.77813 | 34.78325 | 34.78295 | 34.77775 | 34.77345 | 34.77206 | 34.77309 | 34.77344 | NA |
NA | 36.01963 | 36.02950 | 36.03859 | 36.04711 | 36.05532 | 36.06328 | 36.07097 | 36.07821 | 36.08479 | ⋯ | 34.76589 | 34.77855 | 34.78933 | 34.79220 | 34.78659 | 34.77967 | 34.77597 | 34.77587 | 34.77601 | NA |
NA | 36.01572 | 36.02608 | 36.03551 | 36.04424 | 36.05259 | 36.06091 | 36.06899 | 36.07661 | 36.08349 | ⋯ | 34.75874 | 34.77301 | 34.78843 | 34.79423 | 34.79357 | 34.78385 | 34.78009 | 34.77915 | 34.77828 | NA |
NA | 36.01262 | 36.02339 | 36.03323 | 36.04221 | 36.05057 | 36.05886 | 36.06705 | 36.07491 | 36.08214 | ⋯ | 34.75564 | 34.77016 | 34.78686 | 34.79307 | 34.79391 | 34.78737 | 34.78199 | 34.78096 | 34.78004 | NA |
NA | 36.00889 | 36.01962 | 36.02956 | 36.03890 | 36.04763 | 36.05627 | 36.06479 | 36.07304 | 36.08072 | ⋯ | 34.75578 | 34.77051 | 34.78710 | 34.79151 | 34.79279 | 34.78922 | 34.78222 | 34.78127 | 34.78144 | NA |
NA | 36.00357 | 36.01318 | 36.02231 | 36.03156 | 36.04055 | 36.04980 | 36.05910 | 36.06818 | 36.07665 | ⋯ | 34.75756 | 34.77338 | 34.78811 | 34.78880 | 34.78954 | NA | NA | NA | NA | NA |
NA | 35.99727 | 36.00686 | 36.01548 | 36.02365 | 36.03199 | 36.04065 | 36.04974 | 36.05908 | 36.06821 | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | 35.99375 | 36.00301 | 36.01150 | 36.01948 | 36.02755 | 36.03580 | 36.04436 | 36.05302 | 36.06137 | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | 35.99067 | 35.99976 | 36.00843 | 36.01677 | 36.02492 | 36.03313 | 36.04148 | 36.04988 | 36.05798 | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | 35.98929 | 35.99733 | 36.00493 | 36.01240 | 36.02032 | 36.02892 | 36.03785 | 36.04679 | 36.05525 | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | 35.98853 | 35.99566 | 36.00272 | 36.00967 | 36.01695 | 36.02480 | 36.03326 | 36.04210 | 36.05079 | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | 35.98984 | 35.99562 | 36.00151 | 36.00760 | 36.01403 | 36.02109 | 36.02871 | 36.03672 | 36.04471 | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | 35.99236 | 35.99694 | 36.00180 | 36.00718 | 36.01291 | 36.01927 | 36.02615 | 36.03342 | 36.04070 | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | 35.99572 | 35.99891 | 36.00230 | 36.00635 | 36.01140 | 36.01728 | 36.02369 | 36.03047 | 36.03728 | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | 35.99943 | 36.00193 | 36.00453 | 36.00752 | 36.01143 | 36.01679 | 36.02267 | 36.02894 | 36.03537 | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | 36.00339 | 36.00506 | 36.00668 | 36.00868 | 36.01175 | 36.01678 | 36.02245 | 36.02861 | 36.03501 | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | 36.00587 | 36.00730 | 36.00890 | 36.01093 | 36.01387 | 36.01844 | 36.02397 | 36.03017 | 36.03662 | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | 36.00937 | 36.01059 | 36.01206 | 36.01410 | 36.01703 | 36.02140 | 36.02668 | 36.03267 | 36.03910 | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
36.00972 | 36.01036 | 36.01167 | 36.01402 | 36.01757 | 36.02230 | 36.02740 | 36.03313 | 36.03950 | 36.04632 | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
Converting time array to datetime#
The origial time would be only in the unit of time “days since 1993-01-01”. In order to understand what is the actual time. We need to grab the time unit and the time number and convert to a datetime object.
# Get the units
tunits <- ncatt_get(ncopendap, "time", "units")
datesince <- tunits$value
datesince <- substr(datesince, nchar(datesince)-9, nchar(datesince))
datesince
# convert the number to datetime (input should be in second while the time is in unit of days)
datetime_var <- as.POSIXct(time*86400, origin=datesince, tz="UTC")
datetime_var
[1] "1993-01-16 12:00:00 UTC"
Quick view of the data#
Convert the matrix to dataframe#
df <- expand.grid(X = lon, Y = lat)
data <- as.vector(t(sos))
df$Data <- data
names(df) <- c("lon", "lat", "sos")
df
lon | lat | sos |
---|---|---|
<dbl[1d]> | <dbl[1d]> | <dbl> |
261.5577 | 5.272542 | NA |
261.6384 | 5.272542 | NA |
261.7191 | 5.272542 | NA |
261.7998 | 5.272542 | NA |
261.8804 | 5.272542 | NA |
261.9611 | 5.272542 | NA |
262.0418 | 5.272542 | NA |
262.1225 | 5.272542 | NA |
262.2031 | 5.272542 | NA |
262.2838 | 5.272542 | NA |
262.3645 | 5.272542 | NA |
262.4452 | 5.272542 | NA |
262.5258 | 5.272542 | NA |
262.6065 | 5.272542 | NA |
262.6872 | 5.272542 | NA |
262.7679 | 5.272542 | NA |
262.8485 | 5.272542 | NA |
262.9292 | 5.272542 | NA |
263.0099 | 5.272542 | NA |
263.0906 | 5.272542 | NA |
263.1713 | 5.272542 | NA |
263.2519 | 5.272542 | NA |
263.3326 | 5.272542 | NA |
263.4133 | 5.272542 | NA |
263.4940 | 5.272542 | NA |
263.5746 | 5.272542 | NA |
263.6553 | 5.272542 | NA |
263.7360 | 5.272542 | NA |
263.8167 | 5.272542 | NA |
263.8973 | 5.272542 | NA |
⋮ | ⋮ | ⋮ |
321.5804 | 58.16076 | NA |
321.6611 | 58.16076 | NA |
321.7418 | 58.16076 | NA |
321.8224 | 58.16076 | NA |
321.9031 | 58.16076 | NA |
321.9838 | 58.16076 | NA |
322.0645 | 58.16076 | NA |
322.1451 | 58.16076 | NA |
322.2258 | 58.16076 | NA |
322.3065 | 58.16076 | NA |
322.3872 | 58.16076 | NA |
322.4679 | 58.16076 | NA |
322.5485 | 58.16076 | NA |
322.6292 | 58.16076 | NA |
322.7099 | 58.16076 | NA |
322.7906 | 58.16076 | NA |
322.8712 | 58.16076 | NA |
322.9519 | 58.16076 | NA |
323.0326 | 58.16076 | NA |
323.1133 | 58.16076 | NA |
323.1939 | 58.16076 | NA |
323.2746 | 58.16076 | NA |
323.3553 | 58.16076 | NA |
323.4360 | 58.16076 | NA |
323.5166 | 58.16076 | NA |
323.5973 | 58.16076 | NA |
323.6780 | 58.16076 | NA |
323.7587 | 58.16076 | NA |
323.8393 | 58.16076 | NA |
323.9200 | 58.16076 | NA |
Link to data source (Raw gridded product)#
Let’s proceed to load a more complex data structure, specifically the raw grid structure from the regional MOM6 output. This time besides the data itself we also need to load the grid structure that is stored in another file
# Specify the OPeNDAP server URL (using regular grid output)
url <- "http://psl.noaa.gov/thredds/dodsC/Projects/CEFI/regional_mom6/northwest_atlantic/hist_run/ocean_monthly.199301-201912.sos.nc"
url_static <- "http://psl.noaa.gov/thredds/dodsC/Projects/CEFI/regional_mom6/northwest_atlantic/hist_run/ocean_static.nc"
# Open a NetCDF file lazily and remotely
ncopendap <- nc_open(url)
ncstaticopendap <- nc_open(url_static)
Load the data to local memory#
# Read the data into memory
timeslice = 1
lon <- ncvar_get(ncstaticopendap, "geolon")
lat <- ncvar_get(ncstaticopendap, "geolat")
x <- ncvar_get(ncopendap, "xh")
y <- ncvar_get(ncopendap, "yh")
time <- ncvar_get(ncopendap, "time",start = c(timeslice), count = c(1))
# Read a slice of the data into memory
sos <- ncvar_get(ncopendap, "sos", start = c(1, 1, timeslice), count = c(-1, -1, 1))
# the matrix output of sea surface salinity in raw grid
sos
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ⋯ | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA |
⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋱ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ |
36.06316 | 36.06666 | 36.07069 | 36.07516 | 36.08017 | 36.08429 | 36.08701 | 36.08958 | 36.09265 | 36.09607 | ⋯ | 34.80659 | 34.81098 | 34.81022 | 34.79948 | 34.79108 | 34.78642 | 34.78243 | 34.77775 | 34.77651 | 34.77795 |
36.05833 | 36.06303 | 36.06798 | 36.07320 | 36.07905 | 36.08459 | 36.08875 | 36.09180 | 36.09468 | 36.09760 | ⋯ | 34.80303 | 34.80756 | 34.80666 | 34.79648 | 34.78674 | 34.78220 | 34.77971 | 34.77703 | 34.77509 | 34.77502 |
36.05238 | 36.05880 | 36.06493 | 36.07114 | 36.07767 | 36.08385 | 36.08942 | 36.09361 | 36.09667 | 36.09941 | ⋯ | 34.79466 | 34.79580 | 34.79778 | 34.79187 | 34.78111 | 34.77416 | 34.77547 | 34.77576 | 34.77447 | 34.77347 |
36.04670 | 36.05423 | 36.06145 | 36.06870 | 36.07599 | 36.08271 | 36.08915 | 36.09451 | 36.09829 | 36.10128 | ⋯ | 34.78625 | 34.78665 | 34.78574 | 34.78183 | 34.77693 | 34.77106 | 34.77203 | 34.77369 | 34.77409 | 34.77260 |
36.04206 | 36.04967 | 36.05793 | 36.06623 | 36.07409 | 36.08150 | 36.08850 | 36.09461 | 36.09937 | 36.10255 | ⋯ | 34.77374 | 34.77227 | 34.77102 | 34.76943 | 34.76948 | 34.76999 | 34.77063 | 34.77155 | 34.77229 | 34.77136 |
36.03751 | 36.04457 | 36.05320 | 36.06246 | 36.07140 | 36.07964 | 36.08738 | 36.09401 | 36.09956 | 36.10316 | ⋯ | 34.75886 | 34.75692 | 34.75567 | 34.75788 | 34.76315 | 34.76784 | 34.76936 | 34.77008 | 34.77065 | 34.77069 |
36.03690 | 36.04289 | 36.05040 | 36.05908 | 36.06821 | 36.07714 | 36.08578 | 36.09309 | 36.09896 | 36.10265 | ⋯ | 34.74899 | 34.74711 | 34.74578 | 34.74976 | 34.75845 | 34.76456 | 34.76727 | 34.76911 | 34.76947 | 34.77027 |
36.03389 | 36.04147 | 36.04893 | 36.05691 | 36.06567 | 36.07469 | 36.08382 | 36.09188 | 36.09810 | 36.10144 | ⋯ | 34.74152 | 34.73811 | 34.73778 | 34.74155 | 34.74957 | 34.75737 | 34.76272 | 34.76721 | 34.76850 | 34.77018 |
36.02908 | 36.03862 | 36.04719 | 36.05520 | 36.06360 | 36.07252 | 36.08185 | 36.09048 | 36.09711 | 36.10019 | ⋯ | 34.72876 | 34.72907 | 34.73158 | 34.73658 | 34.74427 | 34.75083 | 34.75873 | 34.76292 | 34.76661 | 34.76955 |
36.02460 | 36.03511 | 36.04457 | 36.05318 | 36.06172 | 36.07058 | 36.07988 | 36.08864 | 36.09586 | 36.09876 | ⋯ | 34.72097 | 34.72352 | 34.72813 | 34.73433 | 34.74120 | 34.74810 | 34.75660 | 34.76035 | 34.76415 | 34.76849 |
36.01945 | 36.03128 | 36.04193 | 36.05140 | 36.06038 | 36.06933 | 36.07845 | 36.08698 | 36.09431 | 36.09684 | ⋯ | 34.72031 | 34.72313 | 34.72760 | 34.73323 | 34.73876 | 34.74477 | 34.75047 | 34.75623 | 34.76080 | 34.76653 |
36.01379 | 36.02654 | 36.03770 | 36.04814 | 36.05801 | 36.06760 | 36.07694 | 36.08535 | 36.09263 | 36.09438 | ⋯ | 34.72471 | 34.72692 | 34.73055 | 34.73436 | 34.73807 | 34.74279 | 34.74618 | 34.75154 | 34.75659 | 34.76956 |
36.00798 | 36.02188 | 36.03411 | 36.04510 | 36.05561 | 36.06577 | 36.07540 | 36.08394 | 36.09105 | 36.09171 | ⋯ | 34.73067 | 34.73273 | 34.73616 | 34.73895 | 34.74172 | 34.74531 | 34.74725 | 34.75043 | 34.75504 | 34.77031 |
36.00372 | 36.01831 | 36.03104 | 36.04225 | 36.05287 | 36.06348 | 36.07367 | 36.08267 | 36.08979 | 36.08950 | ⋯ | 34.73488 | 34.73708 | 34.74036 | 34.74347 | 34.74659 | 34.75022 | 34.75229 | 34.75226 | 34.75223 | 34.76383 |
36.00056 | 36.01539 | 36.02872 | 36.04037 | 36.05098 | 36.06148 | 36.07182 | 36.08131 | 36.08853 | 36.08773 | ⋯ | 34.73723 | 34.73918 | 34.74294 | 34.74615 | 34.74986 | 34.75451 | 34.75743 | 34.75720 | 34.75408 | 34.75927 |
35.99664 | 36.01163 | 36.02472 | 36.03681 | 36.04795 | 36.05896 | 36.06976 | 36.07986 | 36.08741 | 36.08676 | ⋯ | 34.73930 | 34.74003 | 34.74292 | 34.74564 | 34.74959 | 34.75540 | 34.75964 | 34.76072 | 34.75602 | 34.75869 |
35.99162 | 36.00603 | 36.01719 | 36.02898 | 36.04042 | 36.05228 | 36.06422 | 36.07539 | 36.08396 | 36.08456 | ⋯ | 34.74349 | 34.74224 | 34.74293 | 34.74451 | 34.74821 | 34.75348 | 34.75851 | 34.76070 | 34.75645 | 34.75818 |
35.98555 | 35.99961 | 36.01112 | 36.02127 | 36.03176 | 36.04269 | 36.05448 | 36.06649 | 36.07556 | 36.07706 | ⋯ | 34.74929 | 34.74654 | 34.74561 | 34.74589 | 34.74827 | 34.75297 | 34.75723 | 34.75896 | 34.75603 | 34.75731 |
35.98346 | 35.99615 | 36.00750 | 36.01759 | 36.02781 | 36.03825 | 36.04925 | 36.05998 | 36.06851 | 36.06985 | ⋯ | 34.75634 | 34.75341 | 34.75164 | 34.75051 | 34.75143 | 34.75467 | 34.75814 | 34.75930 | 34.75674 | 34.75726 |
35.98092 | 35.99297 | 36.00430 | 36.01498 | 36.02534 | 36.03577 | 36.04643 | 36.05700 | 36.06501 | 36.06565 | ⋯ | 34.76123 | 34.75815 | 34.75695 | 34.75602 | 34.75595 | 34.75776 | 34.76007 | 34.76100 | 34.75890 | 34.75813 |
35.98059 | 35.99152 | 36.00132 | 36.01055 | 36.02058 | 36.03160 | 36.04319 | 36.05429 | 36.06256 | 36.06384 | ⋯ | 34.76117 | 34.75938 | 34.75889 | 34.75835 | 34.75936 | 34.76068 | 34.76204 | 34.76286 | 34.76182 | 34.75990 |
35.98170 | 35.99031 | 35.99942 | 36.00812 | 36.01730 | 36.02724 | 36.03833 | 36.04968 | 36.05844 | 36.06092 | ⋯ | 34.75763 | 34.75748 | 34.75853 | 34.75976 | 34.76191 | 34.76455 | 34.76491 | 34.76450 | 34.76379 | 34.76223 |
35.98421 | 35.99146 | 35.99870 | 36.00626 | 36.01436 | 36.02333 | 36.03328 | 36.04361 | 36.05179 | 36.05465 | ⋯ | 34.76080 | 34.75982 | 34.75965 | 34.76126 | 34.76426 | 34.76712 | 34.76796 | 34.76727 | 34.76568 | 34.76424 |
35.98772 | 35.99378 | 35.99940 | 36.00607 | 36.01331 | 36.02139 | 36.03040 | 36.03983 | 36.04719 | 36.04960 | ⋯ | 34.77341 | 34.77015 | 34.76644 | 34.76521 | 34.76710 | 34.76883 | 34.76965 | 34.76968 | 34.76838 | 34.76686 |
35.99235 | 35.99681 | 36.00060 | 36.00535 | 36.01172 | 36.01925 | 36.02767 | 36.03650 | 36.04350 | 36.04580 | ⋯ | 34.78518 | 34.78251 | 34.77713 | 34.77214 | 34.77108 | 34.77065 | 34.77133 | 34.77184 | 34.77138 | 34.77016 |
35.99693 | 36.00026 | 36.00334 | 36.00682 | 36.01173 | 36.01867 | 36.02637 | 36.03470 | 36.04137 | 36.04403 | ⋯ | 34.79337 | 34.79287 | 34.78571 | 34.77971 | 34.77736 | 34.77376 | 34.77381 | 34.77420 | 34.77405 | 34.77278 |
36.00138 | 36.00405 | 36.00594 | 36.00813 | 36.01199 | 36.01858 | 36.02609 | 36.03439 | 36.04110 | 36.04403 | ⋯ | 34.79374 | 34.79575 | 34.79308 | 34.78400 | 34.78144 | 34.77864 | 34.77738 | 34.77721 | 34.77664 | 34.77501 |
36.00448 | 36.00630 | 36.00809 | 36.01041 | 36.01413 | 36.02010 | 36.02768 | 36.03600 | 36.04306 | 36.04640 | ⋯ | 34.79247 | 34.79409 | 34.79383 | 34.78801 | 34.78362 | 34.78125 | 34.78088 | 34.78065 | 34.77849 | 34.77674 |
36.00802 | 36.00977 | 36.01124 | 36.01357 | 36.01729 | 36.02298 | 36.03021 | 36.03839 | 36.04640 | 36.05140 | ⋯ | 34.79107 | 34.79212 | 34.79312 | 34.78963 | 34.78327 | 34.78130 | 34.78089 | 34.78209 | 34.77966 | 34.77679 |
36.00972 | 36.01054 | 36.01251 | 36.01666 | 36.02267 | 36.02918 | 36.03686 | 36.04556 | 36.05394 | 36.05979 | ⋯ | 34.78788 | 34.78782 | 34.79068 | 34.78967 | 34.78308 | 34.78175 | 34.78161 | 34.78364 | 34.78035 | 34.77749 |
Converting time array to datetime#
The origial time would be only in the unit of time “days since 1993-01-01”. In order to understand what is the actual time. We need to grab the time unit and the time number and convert to a datetime object.
# Get the units
tunits <- ncatt_get(ncopendap, "time", "units")
datesince <- tunits$value
datesince <- substr(datesince, nchar(datesince)-18, nchar(datesince)-8)
datesince
# convert the number to datetime (input should be in second while the time is in unit of days)
datetime_var <- as.POSIXct(time*86400, origin=datesince, tz="UTC")
datetime_var
[1] "1993-01-16 12:00:00 UTC"
Quick view of the data#
Convert the matrix to dataframe#
Since we might want the dataframe to represent the lon lat data structure. We can convert the lon, lat,(not xh,yh which represents the grid number and not the actual lon lat) and data matrix to the dataframe.
X <- as.vector(t(lon))
Y <- as.vector(t(lat))
data <- as.vector(t(sos))
df <- data.frame(
"lon" = X,
"lat" = Y,
"sos" = data
)
df
lon | lat | sos |
---|---|---|
<dbl> | <dbl> | <dbl> |
-98 | 5.272542 | NA |
-98 | 5.352199 | NA |
-98 | 5.431845 | NA |
-98 | 5.511480 | NA |
-98 | 5.591105 | NA |
-98 | 5.670719 | NA |
-98 | 5.750322 | NA |
-98 | 5.829914 | NA |
-98 | 5.909494 | NA |
-98 | 5.989064 | NA |
-98 | 6.068621 | NA |
-98 | 6.148167 | NA |
-98 | 6.227701 | NA |
-98 | 6.307223 | NA |
-98 | 6.386733 | NA |
-98 | 6.466230 | NA |
-98 | 6.545714 | NA |
-98 | 6.625186 | NA |
-98 | 6.704646 | NA |
-98 | 6.784092 | NA |
-98 | 6.863526 | NA |
-98 | 6.942946 | NA |
-98 | 7.022352 | NA |
-98 | 7.101746 | NA |
-98 | 7.181125 | NA |
-98 | 7.260490 | NA |
-98 | 7.339842 | NA |
-98 | 7.419179 | NA |
-98 | 7.498502 | NA |
-98 | 7.577811 | NA |
⋮ | ⋮ | ⋮ |
-36.93195 | 56.94660 | 34.74023 |
-36.94019 | 56.98895 | 34.74160 |
-36.94849 | 57.03125 | 34.74315 |
-36.95685 | 57.07353 | 34.74638 |
-36.96524 | 57.11577 | 34.74915 |
-36.97369 | 57.15798 | 34.74821 |
-36.98215 | 57.20015 | 34.74909 |
-36.99069 | 57.24229 | 34.75011 |
-36.99927 | 57.28439 | 34.75198 |
-37.00787 | 57.32647 | 34.75169 |
-37.01654 | 57.36850 | 34.74945 |
-37.02524 | 57.41050 | 34.74542 |
-37.03397 | 57.45247 | 34.74216 |
-37.04276 | 57.49440 | 34.74070 |
-37.05161 | 57.53630 | 34.74549 |
-37.06049 | 57.57817 | 34.75808 |
-37.06940 | 57.62000 | 34.76130 |
-37.07837 | 57.66180 | 34.77727 |
-37.08740 | 57.70356 | 34.78886 |
-37.09647 | 57.74529 | 34.78878 |
-37.10556 | 57.78699 | 34.78788 |
-37.11472 | 57.82865 | 34.78782 |
-37.12390 | 57.87028 | 34.79068 |
-37.13315 | 57.91188 | 34.78967 |
-37.14243 | 57.95344 | 34.78308 |
-37.15176 | 57.99497 | 34.78175 |
-37.16113 | 58.03646 | 34.78161 |
-37.17056 | 58.07793 | 34.78364 |
-37.18005 | 58.11936 | 34.78035 |
-37.18954 | 58.16076 | 34.77749 |