Skip to content

Conversation

@pvanlaake
Copy link
Contributor

This PR is in response to #756. It adds two new S3 methods, as mentioned in the title.

Additionally, it fixes two other issues:

  1. The refsys "CFtime" was changed to include the CF calendar like "CFtime_noleap". This created problems with testing for string equality of the refsys in three locations.
  2. There was a simple error in test-ncproxy.R, line 107: "GMT" changed to "UTC".

edzer added a commit that referenced this pull request Oct 5, 2025
@edzer edzer merged commit d076814 into r-spatial:main Oct 5, 2025
6 checks passed
@edzer
Copy link
Member

edzer commented Oct 5, 2025

Great, thanks; time handling is now done in create_dimension(), my commit also passes on units in dimension values.

@edzer
Copy link
Member

edzer commented Oct 5, 2025

However, following R-CF/ncdfCF#13 this doesn't work:

library(ncdfCF)
library(stars)
# Loading required package: abind
# Loading required package: sf
# Linking to GEOS 3.12.2, GDAL 3.11.3, PROJ 9.4.1; sf_use_s2() is TRUE
ds <- open_ncdf("TEMPO_O3PROF_L2_V04_20250921T210803Z_S012G02.nc")
# There were 22 warnings (use warnings() to see them)
vars <- ds$var_names
op <- ds[[ vars[1L] ]]
class(op)
# [1] "CFVariable" "CFObject"   "R6"        
(op_ll <- op$subset(longitude = NA, latitude = NA, layer = 24, .resolution = 0.04))
# <Variable> ozone_profile 

# Values: [-0.156455 ... 13.96814] DU
#     NA: 542558 (77.3%)

# Axes:
#  axis name      long_name                  length values                     
#  X    longitude pixel index along slit      649   [-71.691716 ... -45.771716]
#  Y    latitude  scan mirror position index 1081   [17.398387 ... 60.598387]  
#       layer                                   1   [24]                       
#  unit         
#  degrees_east 
#  degrees_north
#               

# Attributes:
#  name         type     length value                         
#  comment      NC_CHAR  23     retrieved ozone profile       
#  units        NC_CHAR   2     DU                            
#  valid_min    NC_FLOAT  1     -100                          
#  valid_max    NC_FLOAT  1     100                           
#  _FillValue   NC_FLOAT  1     -1.26765060022823e+30         
#  coordinates  NC_CHAR  50     time ozone_profile_pressure...
#  actual_range NC_FLOAT  2     -0.156455, 13.968141          
s = st_as_stars(op_ll)
s
# Error in dim.stars(x) : length(d) == length(dim(x[[1]])) is not TRUE
# Calls: <Anonymous> ... print.stars -> cat -> dim -> dim.stars -> stopifnot
# Execution halted

because

> dim(s[[1]])
[1]  649 1081

and

> st_dimensions(s)
          from   to offset delta    refsys x/y
longitude    1  649 -71.71  0.04 OGC:CRS84 [x]
latitude     1 1081  17.38  0.04 OGC:CRS84 [y]
layer        1    1     24    NA        NA    

don't match: dim(s[[1]]) needs to be c(649,1081,1) or layer needs to be dropped:

> st_dimensions(s) = st_dimensions(s)[1:2]
> s
stars object with 2 dimensions and 1 attribute
attribute(s):
                         Min.  1st Qu.   Median    Mean  3rd Qu.     Max.
ozone_profile [DU] -0.1564551 6.509749 7.033861 7.18038 8.031126 13.96814
                     NA's
ozone_profile [DU] 542558
dimension(s):
          from   to offset delta    refsys x/y
longitude    1  649 -71.71  0.04 OGC:CRS84 [x]
latitude     1 1081  17.38  0.04 OGC:CRS84 [y]
s

edzer added a commit that referenced this pull request Oct 5, 2025
@pvanlaake
Copy link
Contributor Author

Ok, I know where this goes wrong. Degenerate dimensions in the data array are dropped and the corresponding dimension should thus not be created. I'll work on a solution.

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

Successfully merging this pull request may close these issues.

2 participants