eliocamp / metR

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

Receive error with REadNetCDF() #108

Closed jnsroz closed 4 years ago

jnsroz commented 4 years ago

Hi,

First of all, thanks for this great package, it helps me a lot! It's also my first time asking questions at github, so sorry for any errors.

I downloaded data from https://disc.gsfc.nasa.gov/datasets/M2TUNXAER_5.12.4/summary but I'm having trouble opening it with metR::ReadNetCDF().

I am able to open it with ncdf4::nc_open() and I can glance at the file with metr::GlanceNetCDF(), but when I try to open it I receive the following error:

Error in `[.data.table`(nc.df, , `:=`(names(vars)[v], c(nc[[v]])), by = c(missing.dim)) : 
  Supplied 2 items to be assigned to group 1 of size 1 in column 'time_bnds'. The RHS length must either be 1 (single values are ok) or match the LHS length exactly. If you wish to 'recycle' the RHS please use rep() explicitly to make this intent clear to readers of your code

Here's what glance looks like:

>     GlanceNetCDF("MERRA2_300.tavg1_2d_aer_Nx.20100101.SUB.nc")

----- Variables ----- 

SO2SMASS:
    SO2 Surface Mass Concentration __ENSEMBLE__ in kg m-3
    Dimensions: lon by lat by time
time_bnds:
    time_bnds
    Dimensions: bnds by time

----- Dimensions ----- 
  time: 1 values from 2010-01-01 12:00:00 to 2010-01-01 12:00:00 
  lat: 86 values from -35.5 to 7 degrees_north
  lon: 68 values from -74.375 to -32.5 degrees_east
  bnds: 2 values from 1 to 2 

Any idea on what am I doing wrong?

Thanks

eliocamp commented 4 years ago

Yes, that's a common issue that I'm not certain how to address. You are probably trying to read the whole file, but that's two variables (SO2SMASS and time_bnds) which have different dimensions (lon + lat + time vs. bnds + time). You need to explicitly read only the SO2SMASS variable with ReadNetCDF(file, vars = "SO2SMASS").

Let me know if that solves it.

jnsroz commented 4 years ago

Yes, it worked! Thanks a lot.