Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with ncdf files #729

Open
ramiromagno opened this issue Jan 9, 2025 · 1 comment
Open

Error with ncdf files #729

ramiromagno opened this issue Jan 9, 2025 · 1 comment

Comments

@ramiromagno
Copy link

ramiromagno commented Jan 9, 2025

Hi Edzer!,

Thanks for the stars package!

I am struggling with reading an NC file. Could you take a look, please? I tried my best to sort the issue myself...

Download the file (1.1G) from Google Drive: https://drive.google.com/file/d/1GGt68l6HOo5Q4aGuX4ZLIRTRXgZSDKs3/view?usp=sharing.

With:

nc_file <- "chl_Omon_MPI-ESM1-2-HR_ssp245_r1i1p1f1_gn_201501-201912.nc"
nc <- stars::read_ncdf(.x = nc_file)
stars::st_as_stars(nc)

I get this error:

Error in seq.default(dims$start[ic], length = dims$count[ic]) : 
  'from' must be a finite number

I managed to narrowed it down to the fact that dims gets an NA in start at this location:

stars/R/ncdf.R

Line 165 in 76df605

dims <- .update_dims(dims, proxy_dimensions, coords, tdim)

# A tibble: 4 × 9
     id name  length unlim coord_dim coord_var axis  start count
  <int> <chr>  <dbl> <lgl> <lgl>     <chr>     <chr> <dbl> <dbl>
1     3 i        802 FALSE TRUE      ""        ""        2   802
2     2 j        404 FALSE TRUE      ""        ""        2   404
3     1 lev       40 FALSE TRUE      "lev"     "Z"      NA    40
4     0 time      60 TRUE  TRUE      "time"    "T"       1    60
@edzer
Copy link
Member

edzer commented Jan 9, 2025

I can reproduce that, but managed to read the file using

> nc <- stars::read_stars(.x = nc_file)
There were 22 warnings (use warnings() to see them)
> nc
stars object with 4 dimensions and 1 attribute
attribute(s), summary of first 1e+05 cells:
                                                Min.      1st Qu.      Median
Mass Concentration of Total... [kg/m^3] 1.837166e-07 7.611779e-07 1.62674e-06
                                                Mean      3rd Qu.        Max.
Mass Concentration of Total... [kg/m^3] 3.080384e-06 4.044461e-06 3.34308e-05
                                         NA's
Mass Concentration of Total... [kg/m^3] 18119
dimension(s):
     from  to  refsys                                      values x/y
x       1 802      NA          [802x404] 0.005916 [°],...,360 [°] [x]
y       1 404      NA          [802x404] -78.72 [°],...,89.76 [°] [y]
lev     1  40 udunits              [6,17) [m],...,[5720,6270) [m]    
time    1  60 POSIXct 2015-01-16 12:00:00,...,2019-12-16 12:00:00    
curvilinear grid

and

> x = read_mdim(nc_file)
> x
stars object with 4 dimensions and 1 attribute
attribute(s), summary of first 1e+05 cells:
                     Min.      1st Qu.       Median         Mean      3rd Qu.
chl [kg/m^3] 6.839074e-10 2.858014e-09 1.985313e-07 2.226392e-07 3.982834e-07
                     Max.  NA's
chl [kg/m^3] 4.758287e-06 65786
dimension(s):
     from  to   offset delta  refsys                    values x/y
i       1 802 -0.5 [1] 1 [1] udunits                      NULL [x]
j       1 404 -0.5 [1] 1 [1] udunits                      NULL [y]
lev     1  40       NA    NA      NA    [0,12),...,[5420,6020)    
time    1  60       NA    NA    Date 2015-01-16,...,2019-12-16    

The difference in summary statistics of the first 1e5 cells is, I guess, caused by a different dimension ordering of the two interfaces. As the lon/lat "cells" are defined by 4 corners, I'm not sure they are read in sensibly by read_stars. Another worry is the difference in lev intervals from both interfaces.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants