Skip to content

st_warp() with curvilinear grid part 2 #618

@Rapsodia86

Description

@Rapsodia86

Greetings,
I am continuing #513 issue because warping curvilinear grid gives me some problems.

So, I am exploring Sentinel 3 L2 LST (spatial res 1km) data which come in separate *.nc files.
I have followed the tutorial (https://cran.r-project.org/web/packages/stars/vignettes/stars4.html) and those steps: (#54 (comment))
to have them displayed. That is ok.
But I am getting trouble with warping to have them at the end exported to tif. See the examples later in the post.
Does anyone have any experience with those data? I am well aware of SNAP software, but I would like to avoid it as much as possible. Here is an example of processing this data using vrt in gdal (https://github.com/jgomezdans/s3_olci/blob/master/s3_olci/s3_pre_processor.py) that gives me data in tiff format (spat res: 0.009884033). I have also been exploring xarray or pyresample & kdt (based on: https://git.earthdata.nasa.gov/projects/LPDUR/repos/ecostress_swath2grid/browse/ECOSTRESS_swath2grid.py) but was never able to match SNAP output. That is why I wanted to try starts in R. Any suggestion how to properly transform to grid and export to tif using stars? Thanks!

library(stars)
> Loading required package: abind
> Loading required package: sf
> Linking to GEOS 3.9.3, GDAL 3.5.2, PROJ 8.2.1; sf_use_s2() is TRUE

packageVersion("stars")
>‘0.6.0’
ll_in <- ("geodetic_in.nc")
lst_in <- ("LST_in.nc")

lon <- read_stars(ll_in, sub=5) %>% adrop
lat <- read_stars(ll_in, sub=3) %>% adrop
lst <- read_stars(lst_in, sub=1) %>% adrop
ll = setNames(c(lon, lat), c("x", "y"))
temp.c = st_as_stars(lst, curvilinear = ll)
st_crs(temp.c) <- 4326

> temp.c
stars object with 2 dimensions and 1 attribute
attribute(s), summary of first 1e+05 cells:
           Min. 1st Qu.  Median     Mean 3rd Qu.   Max. NA's
LST [K] 257.794 314.068 316.592 316.0953 319.404 330.82 4101
dimension(s):
  from   to refsys                                  values x/y
x    1 1500 WGS 84 [1500x1200] 58.2526 [°],...,77.2557 [°] [x]
y    1 1200 WGS 84 [1500x1200] 28.6775 [°],...,41.9878 [°] [y]
curvilinear grid

plot(temp.c, breaks = "equal", reset = FALSE, axes = TRUE, as_points = FALSE, border = NA)

This looks ok!
image

#warp1 no cellsize provided
w = st_warp(temp.c, crs = 4326, no_data_value = -32768)
Warning message:
In transform_grid_grid(st_as_stars(src), st_dimensions(dest), threshold) :
  using Euclidean distance measures on geodetic coordinates
> w
stars object with 2 dimensions and 1 attribute
attribute(s), summary of first 1e+05 cells:
          Min. 1st Qu.  Median     Mean 3rd Qu.    Max.
LST [K] 247.34  304.19 315.336 313.9428 327.496 332.056
         NA's
LST [K] 11458
dimension(s):
  from   to  offset      delta refsys x/y
x    1 1580 58.2526  0.0120283 WGS 84 [x]
y    1 1140 42.3817 -0.0120283 WGS 84 [y]

Here we have an issue
image

#warp2 use cellsize from the previous warp1
w2 = st_warp(temp.c, crs = 4326, no_data_value = -32768, cellsize=0.012)
Warning message:
In transform_grid_grid(st_as_stars(src), st_dimensions(dest), threshold) :
  using Euclidean distance measures on geodetic coordinates
> w2
stars object with 2 dimensions and 1 attribute
attribute(s), summary of first 1e+05 cells:
           Min. 1st Qu. Median     Mean 3rd Qu.    Max.
LST [K] 294.876 317.572 325.27 322.5213 327.152 330.104
         NA's
LST [K] 97983
dimension(s):
  from   to  offset  delta refsys x/y
x    1 1584 58.2526  0.012 WGS 84 [x]
y    1 1143 42.3817 -0.012 WGS 84 [y]

That one also does not work
image

S3A_SL_2_LST.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions