knitr::opts_chunk$set(echo = TRUE)

ROMS grid

Regional Ocean MOdelling System (ROMS) uses a horizontal curvilinear coordinate sytem, which needs special care for use in Cartesian or other coordinate systems.

The material discussed here is sourced from this: discussion on 'Curvlinear Coordinates' on the Ocean Modeling Discussion forum.

##This file contains a subset of a ROMs model. 
romsfile <- file.path(getOption("default.datadir"), 
                      "data_local", "acecrc.org.au", 
                      "ROMS", "s_corney", 
                      "cpolar", "ocean_his_3101_uvwtempsalt.nc")
##This file contains all Mertz, on RDSI, mounted on ace-ecostats
romsfile <- file.path("/mnt/mertzdata/mdl/mer015_1", "mer_his_0001.nc")
library(raadtools)

## print out the ncdump header
# sink(sprintf("%s_dump", basename(romsfile)))
# print(raster(romsfile))
# sink(NULL)

A tidier (than ncdump -h) summary can be obtained with the rancid package.

The most important variables for this discussion are lon_u, lat_u, angle.

library(rancid)
roms <- NetCDF(romsfile)
library(dplyr)
## what vars?
vars(roms) %>% filter(name == "temp") %>% dplyr::select(name, ndims, units, longname ,id) %>% 
  inner_join(roms$vardim) %>% select(dimids) %>% inner_join(dims(roms), c("dimids" = "id"))



plot(brick(romsfile, varname = "temp", level = 1, dims = c(2, 3, 1))[[1]], asp = "")



dims(roms)
atts(roms, "angle")

Obtain the lon_u, lat_u and angle variables as RasterLayer objects.

library(angstroms)
lon_u <- romsdata(romsfile, "lon_u")
lat_u <- romsdata(romsfile, "lat_u")

angle <- romsdata(romsfile, "angle")
u <- romsdata(romsfile, "u", slice = c(1, 1))
v <- romsdata(romsfile, "v", slice = c(1, 1))

mesh <- as.matrix(crop(brick(lon_u, lat_u, u, v, angle), extent(400, 600, 30, 180)))
plot(mesh, pch = ".")


mdsumner/oms documentation built on April 20, 2020, 8:51 p.m.