Last updated: 2021-10-12

Checks: 7 0

Knit directory: emlr_obs_preprocessing/

This reproducible R Markdown analysis was created with workflowr (version 1.6.2). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20200707) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 730f19a. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    data/

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/read_Gruber_2019.Rmd) and HTML (docs/read_Gruber_2019.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd 730f19a jens-daniel-mueller 2021-10-12 prepare G19 data for RECCAP2
html 2dad8c7 jens-daniel-mueller 2021-10-12 Build site.
Rmd 1268707 jens-daniel-mueller 2021-10-12 prepare G19 data for RECCAP2
html 6cef0b0 jens-daniel-mueller 2021-09-26 Build site.
Rmd 984ccac jens-daniel-mueller 2021-09-26 read all Gruber 2019 cases
html e49875a jens-daniel-mueller 2021-07-07 Build site.
html 6312bd4 jens-daniel-mueller 2021-07-07 Build site.
Rmd 4905409 jens-daniel-mueller 2021-07-07 rerun with new setup_obs.Rmd file
html 58bc706 jens-daniel-mueller 2021-07-06 Build site.
Rmd 0db89e1 jens-daniel-mueller 2021-07-06 rerun with revised variable names

1 Data source

2 Read nc files

Here, we use the standard case V101 for public and raw data sets.

2.1 Public data sets

The publicly available data sets contain only positive Cant estimates.

2.1.1 3d fields

# open file
dcant <- tidync(paste(
  path_gruber_2019,
  "dcant_emlr_cstar_gruber_94-07_vs1.nc",
  sep = ""
))

# read gamma field as tibble
dcant <- dcant %>%  activate(GAMMA_DENS)
dcant_gamma <- dcant %>% hyper_tibble()

# read delta cant field
dcant <- dcant %>%  activate(DCANT_01)
dcant <- dcant %>% hyper_tibble()

# join cant and gamma fields
dcant <- left_join(dcant, dcant_gamma)

# harmonize column names and coordinates
dcant <- dcant %>% 
  rename(lon = LONGITUDE,
         lat = LATITUDE,
         depth = DEPTH,
         gamma = GAMMA_DENS,
         dcant_pos = DCANT_01) %>% 
  mutate(lon = if_else(lon < 20, lon + 360, lon))

rm(dcant_gamma)

2.1.2 Column inventories

dcant_inv <- tidync(paste(
  path_gruber_2019,
  "inv_dcant_emlr_cstar_gruber_94-07_vs1.nc",
  sep = ""
))

dcant_inv <- dcant_inv %>%  activate(DCANT_INV01)
dcant_inv <- dcant_inv %>% hyper_tibble()

# harmonize column names and coordinates
dcant_inv <- dcant_inv %>% 
  rename(lon = LONGITUDE,
         lat = LATITUDE,
         dcant_pos = DCANT_INV01) %>% 
  mutate(lon = if_else(lon < 20, lon + 360, lon))
dcant_inv_all <- read_ncdf(
  paste(
    path_gruber_2019,
    "inv_dcant_emlr_cstar_gruber_94-07_vs1.nc",
    sep = ""
  ),
  var = sprintf("DCANT_INV%02d", seq(1, 14, 1)),
  make_units = FALSE
)

dcant_inv_all <- dcant_inv_all %>% as_tibble()

dcant_inv_all <- dcant_inv_all %>% 
  pivot_longer(DCANT_INV01:DCANT_INV14,
               names_to = "Version_ID",
               values_to = "dcant_pos",
               names_prefix = "DCANT_INV")

# harmonize column names and coordinates
dcant_inv_all <- dcant_inv_all %>%
  rename(lon = LONGITUDE,
         lat = LATITUDE) %>%
  mutate(lon = if_else(lon < 20, lon + 360, lon))

2.2 Raw data

Internally available data sets also contain negative Cant estimates, as they are generated in the “raw” output of the eMLR mapping step.

# open v 101 file
V101 <- tidync(paste(path_gruber_2019,
                     "Cant_V101new.nc",
                     sep = ""))

# create tibble
V101 <- V101 %>%  activate(Cant)
V101 <- V101 %>% hyper_tibble()

# harmonize column names and coordinates
V101 <- V101 %>% 
  rename(lon = longitude,
         lat = latitude,
         dcant = Cant) %>% 
  filter(dcant != -999) %>% 
  mutate(lon = if_else(lon < 20, lon + 360, lon))

3 Apply basin mask

# use only three basin to assign general basin mask
# ie this is not specific to the MLR fitting
basinmask <- basinmask %>% 
  filter(MLR_basins == "2") %>% 
  select(lat, lon, basin_AIP)

dcant <- inner_join(dcant, basinmask)
dcant_inv_publ <- inner_join(dcant_inv, basinmask)
dcant_inv_all <- inner_join(dcant_inv_all, basinmask)
V101 <- inner_join(V101, basinmask)

4 Join pos and all delta Cant

# join files
dcant_3d <- inner_join(dcant, V101)

rm(dcant, V101)

5 Zonal mean section

dcant_zonal <- m_zonal_mean_sd(dcant_3d)

6 Column inventory

6.1 Calculation

dcant_inv_layers <- m_dcant_inv(dcant_3d)

dcant_inv <- dcant_inv_layers %>% 
  filter(inv_depth == params_global$inventory_depth_standard)

6.2 Plots

6.2.1 All Cant

p_map_cant_inv(
  df = dcant_inv,
  var = "dcant",
  col = "divergent")

Version Author Date
6cef0b0 jens-daniel-mueller 2021-09-26
58bc706 jens-daniel-mueller 2021-07-06

6.2.2 Pos Cant

p_map_cant_inv(
  df = dcant_inv,
  var = "dcant_pos")

Version Author Date
2dad8c7 jens-daniel-mueller 2021-10-12
6cef0b0 jens-daniel-mueller 2021-09-26
58bc706 jens-daniel-mueller 2021-07-06
p_map_cant_inv(
  df = dcant_inv_all %>% mutate(dcant_pos = dcant_pos*(10/13)),
  var = "dcant_pos") +
  facet_wrap(~ Version_ID, ncol = 2)

Version Author Date
2dad8c7 jens-daniel-mueller 2021-10-12
6cef0b0 jens-daniel-mueller 2021-09-26

6.2.3 Published inventories

p_map_cant_inv(
  df = dcant_inv,
  var = "dcant_pos")

Version Author Date
2dad8c7 jens-daniel-mueller 2021-10-12
6cef0b0 jens-daniel-mueller 2021-09-26
58bc706 jens-daniel-mueller 2021-07-06

6.2.4 Published vs calculated

# join published and calculated data sets
dcant_inv_offset <- inner_join(
  dcant_inv %>% rename(dcant_re = dcant_pos),
  dcant_inv_publ %>% rename(dcant_pub = dcant_pos)
)

# calculate offset
dcant_inv_offset <- dcant_inv_offset %>% 
  mutate(dcant_offset = dcant_re - dcant_pub)

# plot map
p_map_cant_inv(
  df = dcant_inv_offset,
  var = "dcant_offset",
  col = "divergent",
  breaks = seq(-3, 3, 0.25)
)

Version Author Date
6cef0b0 jens-daniel-mueller 2021-09-26
58bc706 jens-daniel-mueller 2021-07-06
rm(dcant_inv_offset, dcant_inv_publ)

7 Horizontal plane maps

7.1 All Cant

p_map_climatology(
  df = dcant_3d,
  var = "dcant",
  col = "divergent")

Version Author Date
58bc706 jens-daniel-mueller 2021-07-06

7.2 Positive Cant

p_map_climatology(
  df = dcant_3d,
  var = "dcant_pos")

Version Author Date
58bc706 jens-daniel-mueller 2021-07-06

7.3 Neutral density

p_map_climatology(
  df = dcant_3d,
  var = "gamma")

Version Author Date
58bc706 jens-daniel-mueller 2021-07-06

8 Zonal mean section plot

8.1 Positive Cant

dcant_zonal %>%
  group_split(basin_AIP) %>%
  head(1) %>%
  map(
    ~ p_section_zonal(
      df = .x,
      var = "dcant_pos_mean",
      plot_slabs = "n",
      subtitle_text = paste("Basin:", unique(.x$basin_AIP))
    )
  )
[[1]]

Version Author Date
6cef0b0 jens-daniel-mueller 2021-09-26
58bc706 jens-daniel-mueller 2021-07-06

9 Global sections plot

9.1 All Cant

p_section_global(
  df = dcant_3d,
  var = "dcant",
  col = "divergent")

Version Author Date
58bc706 jens-daniel-mueller 2021-07-06

9.2 Positive Cant

p_section_global(
  df = dcant_3d,
  var = "dcant_pos")

Version Author Date
58bc706 jens-daniel-mueller 2021-07-06

10 Sections at regular longitudes

10.1 All Cant

p_section_climatology_regular(
  df = dcant_3d,
  var = "dcant",
  col = "divergent")

Version Author Date
58bc706 jens-daniel-mueller 2021-07-06

10.2 Positive Cant

p_section_climatology_regular(
  df = dcant_3d,
  var = "dcant_pos")

Version Author Date
58bc706 jens-daniel-mueller 2021-07-06

10.3 Neutral density

p_section_climatology_regular(
  df = dcant_3d,
  var = "gamma")

Version Author Date
58bc706 jens-daniel-mueller 2021-07-06

11 Write files

dcant_3d %>%
  write_csv(paste(path_preprocessing,
                  "G19_dcant_3d.csv",
                  sep = ""))

dcant_inv %>%
  write_csv(paste(path_preprocessing,
                  "G19_dcant_inv.csv",
                  sep = ""))

dcant_inv_all %>%
  write_csv(paste(path_preprocessing,
                  "G19_dcant_inv_all.csv",
                  sep = ""))

dcant_zonal %>%
  write_csv(paste(path_preprocessing,
                  "G19_dcant_zonal.csv",
                  sep = ""))

12 RECCAP2-ocean

# extract coordinate reference system
G19_raster <- raster::brick(paste0(
  path_gruber_2019,
  "dcant_emlr_cstar_gruber_94-07_vs1.nc"))

coord_ref <- raster::crs(G19_raster)
rm(G19_raster)

# open nc file for data extraction
dcant_nc <- tidync(paste(
  path_gruber_2019,
  "dcant_emlr_cstar_gruber_94-07_vs1.nc",
  sep = ""
))

# read delta cant field
dcant <- dcant_nc %>%
  activate(DCANT_01) %>%
  hyper_tibble(na.rm = FALSE)

# read delta cant field
gamma <- dcant_nc %>%
  activate(GAMMA_DENS) %>%
  hyper_tibble(na.rm = FALSE)

# join gamma and dcant
dcant <- full_join(dcant, gamma)
rm(gamma)

# harmonize column names and coordinates
dcant <- dcant %>% 
  rename(lon = LONGITUDE,
         lat = LATITUDE,
         depth = DEPTH,
         dcant = DCANT_01,
         gamma = GAMMA_DENS) %>% 
  mutate(gamma = if_else(is.na(dcant), NaN, gamma))

# convert dcant unit from "µmol kg-1" to "mol m-3"
dcant <- dcant %>% 
  mutate(dens = (1000 + gamma) / 1000,
         dcant = dcant * dens * 1e-3)

# create volume grid
dcant <- dcant %>% 
  m_layer_thickness() %>% 
  mutate(surface_area = marelac::earth_surf(lat, lon),
         volume = layer_thickness * surface_area,
         volume = if_else(is.na(dcant), NaN, volume))
Error in get(genname, envir = envir) : object 'testthat_print' not found
# check total volume
dcant %>% 
  summarise(total_ocean_volume = sum(volume, na.rm = TRUE))
# A tibble: 1 × 1
  total_ocean_volume
               <dbl>
1            1.25e18
# check total dcant
dcant %>% 
  filter(depth <= 3000) %>% 
  mutate(dcant_inv = dcant * volume) %>% 
  summarise(total_dcant = sum(dcant_inv, na.rm = TRUE)*12*1e-15)
# A tibble: 1 × 1
  total_dcant
        <dbl>
1        31.8
# select relevant columns
dcant <- dcant %>% 
  select(lon, lat, depth, dcant, volume)

# create raster objects
volume_raster <- dcant %>% 
  select(lon, lat, volume) %>%
  base::split(dcant$depth) %>% 
  lapply(raster::rasterFromXYZ) %>% 
  raster::brick() %>% 
  raster::setZ(z = unique(dcant$depth), name = "volume")

dcant_raster <- dcant %>% 
  select(lon, lat, dcant) %>%
  base::split(dcant$depth) %>% 
  lapply(raster::rasterFromXYZ) %>% 
  raster::brick() %>% 
  raster::setZ(z = unique(dcant$depth), name = "dcant")

# assign coordinate reference system
raster::crs(dcant_raster) <- coord_ref
raster::crs(volume_raster) <- coord_ref

# assign NA values
raster::NAvalue(dcant_raster) <- -9999
raster::NAvalue(dcant_raster)
[1] -9999
raster::NAvalue(volume_raster) <- -9999
raster::NAvalue(volume_raster)
[1] -9999
# check object
dim(dcant_raster)
[1] 180 360  33
raster::nbands(dcant_raster)
[1] 1
raster::nlayers(dcant_raster)
[1] 33
names(dcant_raster) #get the names of layers
 [1] "X0"    "X10"   "X20"   "X30"   "X50"   "X75"   "X100"  "X125"  "X150" 
[10] "X200"  "X250"  "X300"  "X400"  "X500"  "X600"  "X700"  "X800"  "X900" 
[19] "X1000" "X1100" "X1200" "X1300" "X1400" "X1500" "X1750" "X2000" "X2500"
[28] "X3000" "X3500" "X4000" "X4500" "X5000" "X5500"
raster::getZ(dcant_raster)
 [1]    0   10   20   30   50   75  100  125  150  200  250  300  400  500  600
[16]  700  800  900 1000 1100 1200 1300 1400 1500 1750 2000 2500 3000 3500 4000
[31] 4500 5000 5500
# write netcdf file
raster::writeRaster(
  dcant_raster,
  filename = paste0(path_preprocessing,
                    "dcant_Gruber2019_1994-2007_v20211012.nc"),
  overwrite = T
)

raster::writeRaster(
  volume_raster,
  filename = paste0(path_preprocessing,
                    "volume_Gruber2019_1994-2007_v20211012.nc"),
  overwrite = T
)


# modify created netcdf files
library(ncdf4)

# dcant file

# open file in writing mode
dcant_reopen <- nc_open(
  paste0(path_preprocessing,
         "dcant_Gruber2019_1994-2007_v20211012.nc"),
  write = TRUE)

dcant_reopen
File /nfs/kryo/work/jenmueller/emlr_cant/observations/preprocessing/dcant_Gruber2019_1994-2007_v20211012.nc (NC_FORMAT_CLASSIC):

     2 variables (excluding dimension variables):
        int crs[]   
            proj4: +proj=longlat +datum=WGS84 +no_defs
        float dcant[longitude,latitude,z]   
            _FillValue: -3.39999995214436e+38
            grid_mapping: crs
            proj4: +proj=longlat +datum=WGS84 +no_defs
            min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
            max: 0.0248421741701018
             max: 0.0263988532810143
             max: 0.0259323226992999
             max: 0.0468319294577161
             max: 0.0539228878337458
             max: 0.0579115449847562
             max: 0.0591300899669754
             max: 0.0595068498539064
             max: 0.0591967236903614
             max: 0.0622757641709907
             max: 0.0701156483511376
             max: 0.0822125437177265
             max: 0.0895806756023294
             max: 0.0465109463416744
             max: 0.0447200492198721
             max: 0.022305883055381
             max: 0.0186725092366003
             max: 0.0160326506043697
             max: 0.0148016268892587
             max: 0.011432505514404
             max: 0.0127706811725398
             max: 0.0131554593368835
             max: 0.0110274898367661
             max: 0.0123063573857286
             max: 0.0129442649462616
             max: 0.00788267650599191
             max: 0.00889479200777699
             max: 0.00910296888252653
             max: 0.016749840595237
             max: 0.0143819581236115
             max: 0.0205526824791368
             max: 0.0269090482439296
             max: 0.0229962165359498

     3 dimensions:
        longitude  Size:360
            units: degrees_east
            long_name: longitude
        latitude  Size:180
            units: degrees_north
            long_name: latitude
        z  Size:33   *** is unlimited ***
            units: unknown
            long_name: z

    3 global attributes:
        Conventions: CF-1.4
        created_by: R, packages ncdf4 and raster (version 3.4-5)
        date: 2021-10-12 16:58:27
print(dcant_reopen)
File /nfs/kryo/work/jenmueller/emlr_cant/observations/preprocessing/dcant_Gruber2019_1994-2007_v20211012.nc (NC_FORMAT_CLASSIC):

     2 variables (excluding dimension variables):
        int crs[]   
            proj4: +proj=longlat +datum=WGS84 +no_defs
        float dcant[longitude,latitude,z]   
            _FillValue: -3.39999995214436e+38
            grid_mapping: crs
            proj4: +proj=longlat +datum=WGS84 +no_defs
            min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
             min: 0
            max: 0.0248421741701018
             max: 0.0263988532810143
             max: 0.0259323226992999
             max: 0.0468319294577161
             max: 0.0539228878337458
             max: 0.0579115449847562
             max: 0.0591300899669754
             max: 0.0595068498539064
             max: 0.0591967236903614
             max: 0.0622757641709907
             max: 0.0701156483511376
             max: 0.0822125437177265
             max: 0.0895806756023294
             max: 0.0465109463416744
             max: 0.0447200492198721
             max: 0.022305883055381
             max: 0.0186725092366003
             max: 0.0160326506043697
             max: 0.0148016268892587
             max: 0.011432505514404
             max: 0.0127706811725398
             max: 0.0131554593368835
             max: 0.0110274898367661
             max: 0.0123063573857286
             max: 0.0129442649462616
             max: 0.00788267650599191
             max: 0.00889479200777699
             max: 0.00910296888252653
             max: 0.016749840595237
             max: 0.0143819581236115
             max: 0.0205526824791368
             max: 0.0269090482439296
             max: 0.0229962165359498

     3 dimensions:
        longitude  Size:360
            units: degrees_east
            long_name: longitude
        latitude  Size:180
            units: degrees_north
            long_name: latitude
        z  Size:33   *** is unlimited ***
            units: unknown
            long_name: z

    3 global attributes:
        Conventions: CF-1.4
        created_by: R, packages ncdf4 and raster (version 3.4-5)
        date: 2021-10-12 16:58:27
names(dcant_reopen$var)
[1] "crs"   "dcant"
# add units
ncatt_get(dcant_reopen, varid = "dcant")
$`_FillValue`
[1] -3.4e+38

$grid_mapping
[1] "crs"

$proj4
[1] "+proj=longlat +datum=WGS84 +no_defs"

$min
 [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

$max
 [1] 0.024842174 0.026398853 0.025932323 0.046831929 0.053922888 0.057911545
 [7] 0.059130090 0.059506850 0.059196724 0.062275764 0.070115648 0.082212544
[13] 0.089580676 0.046510946 0.044720049 0.022305883 0.018672509 0.016032651
[19] 0.014801627 0.011432506 0.012770681 0.013155459 0.011027490 0.012306357
[25] 0.012944265 0.007882677 0.008894792 0.009102969 0.016749841 0.014381958
[31] 0.020552682 0.026909048 0.022996217
ncatt_put(dcant_reopen, varid = "dcant",
          attname = "units", attval = "mol m-3")

ncatt_get(dcant_reopen, varid = "z")
$units
[1] "unknown"

$long_name
[1] "z"
ncatt_put(dcant_reopen, varid = "z",
          attname = "units", attval = "metres")

nc_close(dcant_reopen)


# volume file

# open file in writing mode
volume_reopen <- nc_open(
  paste0(path_preprocessing,
         "volume_Gruber2019_1994-2007_v20211012.nc"),
  write = TRUE)

volume_reopen
File /nfs/kryo/work/jenmueller/emlr_cant/observations/preprocessing/volume_Gruber2019_1994-2007_v20211012.nc (NC_FORMAT_CLASSIC):

     2 variables (excluding dimension variables):
        int crs[]   
            proj4: +proj=longlat +datum=WGS84 +no_defs
        float volume[longitude,latitude,z]   
            _FillValue: -3.39999995214436e+38
            grid_mapping: crs
            proj4: +proj=longlat +datum=WGS84 +no_defs
            min: 13557913860.915
             min: 27115827721.8299
             min: 27115827721.8299
             min: 40673741582.7449
             min: 61010612374.1174
             min: 67789569304.5748
             min: 67789569304.5748
             min: 67789569304.5748
             min: 101684353956.862
             min: 135579138609.15
             min: 135579138609.15
             min: 203368707913.725
             min: 271158277218.299
             min: 271158277218.299
             min: 271158277218.299
             min: 314515048709.952
             min: 314515048709.952
             min: 314515048709.952
             min: 314515048709.952
             min: 314515048709.952
             min: 314515048709.952
             min: 314515048709.952
             min: 314515048709.952
             min: 550401335242.417
             min: 786287621774.881
             min: 1179431432662.32
             min: 1572575243549.76
             min: 1777833760784.07
             min: 1878515185661.79
             min: 1979171773639.54
             min: 2079803524717.3
             min: 2482082160028.49
             min: 1631799437103.27
            max: 62002375113.084
             max: 124004750226.168
             max: 124004750226.168
             max: 186007125339.252
             max: 279010688008.878
             max: 310011875565.42
             max: 310011875565.42
             max: 310011875565.42
             max: 465017813348.13
             max: 620023751130.84
             max: 620023751130.84
             max: 930035626696.26
             max: 1240047502261.68
             max: 1240047502261.68
             max: 1240047502261.68
             max: 1240047502261.68
             max: 1240047502261.68
             max: 1240047502261.68
             max: 1240047502261.68
             max: 1240047502261.68
             max: 1240047502261.68
             max: 1240047502261.68
             max: 1240047502261.68
             max: 2170083128957.94
             max: 3100118755654.2
             max: 4650178133481.3
             max: 6200237511308.4
             max: 6200237511308.4
             max: 6200237511308.4
             max: 6200237511308.4
             max: 6200237511308.4
             max: 6200237511308.4
             max: 3100118755654.2

     3 dimensions:
        longitude  Size:360
            units: degrees_east
            long_name: longitude
        latitude  Size:180
            units: degrees_north
            long_name: latitude
        z  Size:33   *** is unlimited ***
            units: unknown
            long_name: z

    3 global attributes:
        Conventions: CF-1.4
        created_by: R, packages ncdf4 and raster (version 3.4-5)
        date: 2021-10-12 16:58:27
print(volume_reopen)
File /nfs/kryo/work/jenmueller/emlr_cant/observations/preprocessing/volume_Gruber2019_1994-2007_v20211012.nc (NC_FORMAT_CLASSIC):

     2 variables (excluding dimension variables):
        int crs[]   
            proj4: +proj=longlat +datum=WGS84 +no_defs
        float volume[longitude,latitude,z]   
            _FillValue: -3.39999995214436e+38
            grid_mapping: crs
            proj4: +proj=longlat +datum=WGS84 +no_defs
            min: 13557913860.915
             min: 27115827721.8299
             min: 27115827721.8299
             min: 40673741582.7449
             min: 61010612374.1174
             min: 67789569304.5748
             min: 67789569304.5748
             min: 67789569304.5748
             min: 101684353956.862
             min: 135579138609.15
             min: 135579138609.15
             min: 203368707913.725
             min: 271158277218.299
             min: 271158277218.299
             min: 271158277218.299
             min: 314515048709.952
             min: 314515048709.952
             min: 314515048709.952
             min: 314515048709.952
             min: 314515048709.952
             min: 314515048709.952
             min: 314515048709.952
             min: 314515048709.952
             min: 550401335242.417
             min: 786287621774.881
             min: 1179431432662.32
             min: 1572575243549.76
             min: 1777833760784.07
             min: 1878515185661.79
             min: 1979171773639.54
             min: 2079803524717.3
             min: 2482082160028.49
             min: 1631799437103.27
            max: 62002375113.084
             max: 124004750226.168
             max: 124004750226.168
             max: 186007125339.252
             max: 279010688008.878
             max: 310011875565.42
             max: 310011875565.42
             max: 310011875565.42
             max: 465017813348.13
             max: 620023751130.84
             max: 620023751130.84
             max: 930035626696.26
             max: 1240047502261.68
             max: 1240047502261.68
             max: 1240047502261.68
             max: 1240047502261.68
             max: 1240047502261.68
             max: 1240047502261.68
             max: 1240047502261.68
             max: 1240047502261.68
             max: 1240047502261.68
             max: 1240047502261.68
             max: 1240047502261.68
             max: 2170083128957.94
             max: 3100118755654.2
             max: 4650178133481.3
             max: 6200237511308.4
             max: 6200237511308.4
             max: 6200237511308.4
             max: 6200237511308.4
             max: 6200237511308.4
             max: 6200237511308.4
             max: 3100118755654.2

     3 dimensions:
        longitude  Size:360
            units: degrees_east
            long_name: longitude
        latitude  Size:180
            units: degrees_north
            long_name: latitude
        z  Size:33   *** is unlimited ***
            units: unknown
            long_name: z

    3 global attributes:
        Conventions: CF-1.4
        created_by: R, packages ncdf4 and raster (version 3.4-5)
        date: 2021-10-12 16:58:27
names(volume_reopen$var)
[1] "crs"    "volume"
# add units
ncatt_get(volume_reopen, varid = "volume")
$`_FillValue`
[1] -3.4e+38

$grid_mapping
[1] "crs"

$proj4
[1] "+proj=longlat +datum=WGS84 +no_defs"

$min
 [1] 1.355791e+10 2.711583e+10 2.711583e+10 4.067374e+10 6.101061e+10
 [6] 6.778957e+10 6.778957e+10 6.778957e+10 1.016844e+11 1.355791e+11
[11] 1.355791e+11 2.033687e+11 2.711583e+11 2.711583e+11 2.711583e+11
[16] 3.145150e+11 3.145150e+11 3.145150e+11 3.145150e+11 3.145150e+11
[21] 3.145150e+11 3.145150e+11 3.145150e+11 5.504013e+11 7.862876e+11
[26] 1.179431e+12 1.572575e+12 1.777834e+12 1.878515e+12 1.979172e+12
[31] 2.079804e+12 2.482082e+12 1.631799e+12

$max
 [1] 6.200238e+10 1.240048e+11 1.240048e+11 1.860071e+11 2.790107e+11
 [6] 3.100119e+11 3.100119e+11 3.100119e+11 4.650178e+11 6.200238e+11
[11] 6.200238e+11 9.300356e+11 1.240048e+12 1.240048e+12 1.240048e+12
[16] 1.240048e+12 1.240048e+12 1.240048e+12 1.240048e+12 1.240048e+12
[21] 1.240048e+12 1.240048e+12 1.240048e+12 2.170083e+12 3.100119e+12
[26] 4.650178e+12 6.200238e+12 6.200238e+12 6.200238e+12 6.200238e+12
[31] 6.200238e+12 6.200238e+12 3.100119e+12
ncatt_put(volume_reopen, varid = "volume",
          attname = "units", attval = "m3")

ncatt_get(volume_reopen, varid = "z")
$units
[1] "unknown"

$long_name
[1] "z"
ncatt_put(volume_reopen, varid = "z",
          attname = "units", attval = "metres")

nc_close(volume_reopen)



# final check dcant

dcant_reopen <- tidync(
  paste0(path_preprocessing,
         "dcant_Gruber2019_1994-2007_v20211012.nc")) %>% 
  hyper_tibble()

dcant_reopen %>% 
  filter(z == 0) %>% 
  ggplot(aes(longitude, latitude, fill=dcant)) +
  geom_raster() +
  scale_fill_viridis_c()

Version Author Date
2dad8c7 jens-daniel-mueller 2021-10-12
dcant_reopen %>% 
  filter(longitude == 200.5) %>% 
  ggplot(aes(latitude, z, z=dcant)) +
  scale_y_reverse() +
  geom_contour_filled() +
  scale_fill_viridis_d()

Version Author Date
2dad8c7 jens-daniel-mueller 2021-10-12
dcant_reopen <- read_ncdf(
  paste0(path_preprocessing,
         "dcant_Gruber2019_1994-2007_v20211012.nc"))
Error in UseMethod("GPFN") : 
  no applicable method for 'GPFN' applied to an object of class "list"
plot(dcant_reopen,
     axes = TRUE)

Version Author Date
2dad8c7 jens-daniel-mueller 2021-10-12
# final check volume

volume_reopen <- tidync(
  paste0(path_preprocessing,
         "volume_Gruber2019_1994-2007_v20211012.nc")) %>% 
  hyper_tibble()

volume_reopen %>% 
  filter(z == 0) %>% 
  ggplot(aes(longitude, latitude, fill=volume)) +
  geom_raster() +
  scale_fill_viridis_c()

Version Author Date
2dad8c7 jens-daniel-mueller 2021-10-12
volume_reopen %>% 
  filter(longitude == 200.5) %>% 
  ggplot(aes(latitude, z, z=volume)) +
  scale_y_reverse() +
  geom_contour_filled() +
  scale_fill_viridis_d()

Version Author Date
2dad8c7 jens-daniel-mueller 2021-10-12
volume_reopen <- read_ncdf(
  paste0(path_preprocessing,
         "volume_Gruber2019_1994-2007_v20211012.nc"))
Error in UseMethod("GPFN") : 
  no applicable method for 'GPFN' applied to an object of class "list"
plot(volume_reopen,
     axes = TRUE)

Version Author Date
2dad8c7 jens-daniel-mueller 2021-10-12

sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: openSUSE Leap 15.2

Matrix products: default
BLAS:   /usr/local/R-4.0.3/lib64/R/lib/libRblas.so
LAPACK: /usr/local/R-4.0.3/lib64/R/lib/libRlapack.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] ncdf4_1.17      stars_0.5-2     sf_0.9-8        abind_1.4-5    
 [5] tidync_0.2.4    ggforce_0.3.3   metR_0.9.0      scico_1.2.0    
 [9] patchwork_1.1.1 collapse_1.5.0  forcats_0.5.0   stringr_1.4.0  
[13] dplyr_1.0.5     purrr_0.3.4     readr_1.4.0     tidyr_1.1.3    
[17] tibble_3.1.3    ggplot2_3.3.5   tidyverse_1.3.0 workflowr_1.6.2

loaded via a namespace (and not attached):
 [1] colorspace_2.0-2         RcppEigen_0.3.3.7.0      ellipsis_0.3.2          
 [4] class_7.3-17             rgdal_1.5-18             rprojroot_2.0.2         
 [7] RcppArmadillo_0.10.1.2.0 fs_1.5.0                 rstudioapi_0.13         
[10] farver_2.0.3             fansi_0.4.1              lubridate_1.7.9         
[13] xml2_1.3.2               codetools_0.2-16         knitr_1.33              
[16] polyclip_1.10-0          jsonlite_1.7.1           gsw_1.0-5               
[19] broom_0.7.9              dbplyr_1.4.4             compiler_4.0.3          
[22] httr_1.4.2               backports_1.1.10         assertthat_0.2.1        
[25] Matrix_1.2-18            cli_3.0.1                later_1.2.0             
[28] tweenr_1.0.2             htmltools_0.5.1.1        tools_4.0.3             
[31] gtable_0.3.0             glue_1.4.2               Rcpp_1.0.5              
[34] cellranger_1.1.0         jquerylib_0.1.4          RNetCDF_2.4-2           
[37] raster_3.4-5             vctrs_0.3.8              lwgeom_0.2-5            
[40] xfun_0.25                testthat_2.3.2           rvest_0.3.6             
[43] lifecycle_1.0.0          ncmeta_0.3.0             oce_1.2-0               
[46] MASS_7.3-53              scales_1.1.1             hms_0.5.3               
[49] promises_1.1.1           parallel_4.0.3           yaml_2.2.1              
[52] sass_0.4.0               stringi_1.5.3            highr_0.8               
[55] e1071_1.7-4              checkmate_2.0.0          shape_1.4.5             
[58] rlang_0.4.11             pkgconfig_2.0.3          evaluate_0.14           
[61] lattice_0.20-41          labeling_0.4.2           tidyselect_1.1.0        
[64] seacarb_3.2.14           magrittr_1.5             R6_2.5.0                
[67] generics_0.1.0           DBI_1.1.0                pillar_1.6.2            
[70] haven_2.3.1              whisker_0.4              withr_2.3.0             
[73] units_0.6-7              sp_1.4-4                 modelr_0.1.8            
[76] crayon_1.3.4             KernSmooth_2.23-17       utf8_1.1.4              
[79] rmarkdown_2.10           grid_4.0.3               readxl_1.3.1            
[82] isoband_0.2.2            data.table_1.14.0        blob_1.2.1              
[85] git2r_0.27.1             reprex_0.3.0             digest_0.6.27           
[88] classInt_0.4-3           httpuv_1.5.4             munsell_0.5.0           
[91] viridisLite_0.3.0        bslib_0.2.5.1            marelac_2.1.10