eliocamp / metR

Tools for Easier Analysis of Meteorological Fields
https://eliocamp.github.io/metR/
142 stars 22 forks source link

WaveFlux invalid type (list) Error #119

Closed jonathonprc closed 4 years ago

jonathonprc commented 4 years ago

Hello,

I just started working with a couple of the packages that you've put together and they've been great!

I'm running into the following error when trying to apply the WaveFlux function:

Error in model.frame.default(terms(formula, lhs = lhs, rhs = rhs, data = data, : invalid type (list) for variable 'psi.dx'

I attempted to work through the source code and I believe the chunk of code below is causing the problem. It appears that Derivate() outputs a list of nrow elements in the first line, which is then causing the error when 'psi.dx' is used as an argument for Derivate() in the last line.

Derivadas

dt[, `:=`(psi.dx  = Derivate(psi ~ lonrad, cyclical = TRUE),
          psi.dxx = Derivate(psi ~ lonrad, 2), cyclical = TRUE), by = lat]
dt[, `:=`(psi.dy  = Derivate(psi ~ latrad, cyclical = FALSE),
          psi.dyy = Derivate(psi ~ latrad, 2, cyclical = FALSE),
          psi.dxy = Derivate(psi.dx ~ latrad, cyclical = FALSE)), by = lon]
eliocamp commented 4 years ago

Thanks! It should be fixed now in the development version. You can install it with

devtools::install_github("eliocamp/metR@dev")

Can you tell me if it works now?

jonathonprc commented 4 years ago

I'm still receiving the same error. The updated line of code (below) still assigns a list object to the new column 'psi.dx', where each row of the resulting column contains an element with a length equal to the length of the longitude dimension of the input dataset (361 for my data which is at 1 degree resolution).

dt[, :=(psi.dx = Derivate(psi ~ lonrad, cyclical = TRUE)[[1]], psi.dxx = Derivate(psi ~ lonrad, 2, cyclical = TRUE)[[1]]), by = lat]

eliocamp commented 4 years ago

Hi, @jonathonprc . This is now working on the development version (remotes::install_github("eliocamp/metR@dev"))

library(metR)
geo <- geopotential[date == date[1]][, c("u", "v") := GeostrophicWind(gh, lon, lat)]
geo[, c("wx", "wy") := WaveFlux(gh, u, v, lon, lat, lev = 700)]

I would be grateful if you could run your code and tell me if it works on your end. If not, can you post a reproducible example so I can test if further?