S3 methods st_as_stars.CFDataset() and st_as_stars.CFVariable()#757
Merged
Conversation
Member
|
Great, thanks; time handling is now done in |
Member
|
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 haltedbecause > dim(s[[1]])
[1] 649 1081and > 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: > 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]
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

This PR is in response to #756. It adds two new S3 methods, as mentioned in the title.
Additionally, it fixes two other issues: