0

I downloaded temperature data from https://www.nodc.noaa.gov/cgi-bin/OC5/woa18/woa18.pl

and I opened it in R. I am trying to create a data frame Temp where all the temperature, depth and date information are merged into a single data frame .

I can do this for a single time point depth_Temp <- data.frame(Temp_Jan@z) where I get temperature by depth

Is it possible to get depth and date from Jan - May and merge them together?

 library(raster)
 library(ncdf4)

 Temp_Jan <- brick("woa18_decav_t01_01.nc", stopIfNotEqualSpaced = FALSE, varname = "t_an", lvar=4)
 Temp_Feb <- brick("woa18_decav_t02_01.nc", stopIfNotEqualSpaced = FALSE, varname = "t_an", lvar=4)
 Temp_Mar <- brick("woa18_decav_t03_01.nc", stopIfNotEqualSpaced = FALSE, varname = "t_an", lvar=4)
 Temp_Apr <- brick("woa18_decav_t04_01.nc", stopIfNotEqualSpaced = FALSE, varname = "t_an", lvar=4)
 Temp_May <- brick("woa18_decav_t05_01.nc", stopIfNotEqualSpaced = FALSE, varname = "t_an", lvar=4)


 depth_Temp <- data.frame(Temp_Jan@z)

 Temp <- rbind(Temp_Jan, Temp_Feb, Temp_Mar, Temp_Apr, Temp_May)

Also I am importing each file individually Temp_Jan <- brick("woa18_decav_t01_01.nc", stopIfNotEqualSpaced = FALSE, varname = "t_an", lvar=4). Is it possible to import all the files using one line of code or is it safer/easier to do them individually?

L55
  • 117
  • 8

1 Answers1

2

You should be able to solve this easily using tidync:

df <- tidync::tidync("woa18_decav_t01_01.nc") %>% 
  tidync::hyper_tibble()
Robert Wilson
  • 3,192
  • 11
  • 19
  • Thank you. That did open a data frame and interestingly time is just one value through the entire data frame (373.5). Im not good in ncdf files. If it says ```time Size:1 standard_name: time long_name: time units: months since 1955-01-01 00:00:00 axis: T climatology: climatology_bounds``` Does it mean that it is just one value for the entire month of January? So there is no time component in the file? – L55 Sep 15 '20 at 08:01
  • 1
    you should only have one time as the WOA is just an average, not values for individual months – Robert Wilson Sep 15 '20 at 08:04