0

I'm struggling to deal with sentinel-3 data in R, of 300 meters resolution. I would like to extract TSM (Total Suspended Matter concentration) in each cell. Data are provided in a archive, with many different netcdf files (for example, one for coordinates, another one for chlorophyl, etc). Please, find the data here.

I tried this approach:

library(stars)

nc_files <- c("S3B_OL_2_WFR____20230218T101125_20230218T101425_20230219T222151_0179_076_179_2160_MAR_O_NT_003.SEN3/geo_coordinates.nc", "S3B_OL_2_WFR____20230218T101125_20230218T101425_20230219T222151_0179_076_179_2160_MAR_O_NT_003.SEN3/tsm_nn.nc")

lon_lat_tsm <- read_stars(nc_files)

It gives

> lon_lat_tsm
stars object with 2 dimensions and 5 attributes
attribute(s), summary of first 1e+05 cells:
                   Min.   1st Qu.      Median         Mean     3rd Qu.        Max.  NA's
altitude [m]   0.000000 46.000000 330.0000000 438.93277000 889.0000000 1508.000000     0
latitude [°]  39.568894 40.402587  41.0897840  40.99148193  41.6207120   42.046713     0
longitude [°] -7.581946 -3.745773   0.0337230   0.05383067   3.8784562    7.686906     0
TSM_NN        -1.909408 -1.148438  -0.9310176  -0.84433249  -0.5505323    2.438995 56460
TSM_NN_err    -2.000000 -1.963763  -1.8369349  -1.72683826  -1.5832780    1.986036 56460
dimension(s):
  from   to offset delta refsys point values x/y
x    1 4865      0     1     NA    NA   NULL [x]
y    1 4091   4091    -1     NA    NA   NULL [y]

Longitude and latitude are in the attributes of the stars object, and there is no assigned projection.

If i try to plot: moutains above are supposed to be the Pyreneans, and those at the middle left are the Alps (so the true south is north in the plot, and the true west is east in the plot). The bounding box is not correct, but it's not surprising since there is no projection, and the orientation is not good.

I think my major issue is that the geo_coordinates file is not recognized as the reference coordinates for the tsm_nn.nc file.

I'm a bit confused with these data, any help would be appreciate!

Thank you!

1 Answers1

1

It seems that the nc files does not have the right dimensions (i.e. bounding box) and CRS, but we can modify this using stars::st_set_dimensions():


nc_files <- c("data/geo_coordinates.nc", "data/tsm_nn.nc")

library(stars)
lon_lat_tsm <- read_stars(here::here(nc_files))

#> altitude, latitude, longitude, 
#> TSM_NN, TSM_NN_err, 
#> Warning messages:
#> 1: ignoring unrecognized unit: lg(re g.m-3) 
#> 2: ignoring unrecognized unit: lg(re g.m-3) 
#> 3: ignoring unrecognized unit: lg(re g.m-3) 
#> 4: ignoring unrecognized unit: lg(re g.m-3) 
 
lon_lat_tsm

#> stars object with 2 dimensions and 5 attributes
#> attribute(s), summary of first 1e+05 cells:
#>   Min.   1st Qu.      Median         Mean
#> geo_coordinates.nc.altitude [m]   0.000000 46.000000 330.0000000 438.93277000
#> geo_coordinates.nc.latitude [°]  39.568894 40.402587  41.0897840  40.99148193
#> geo_coordinates.nc.longitude [°] -7.581946 -3.745773   0.0337230   0.05383067
#> tsm_nn.nc.TSM_NN                 -1.909408 -1.148438  -0.9310176  -0.84433249
#> tsm_nn.nc.TSM_NN_err             -2.000000 -1.963763  -1.8369349  -1.72683826
#> 3rd Qu.        Max.  NA's
#> geo_coordinates.nc.altitude [m]  889.0000000 1508.000000     0
#> geo_coordinates.nc.latitude [°]   41.6207120   42.046713     0
#> geo_coordinates.nc.longitude [°]   3.8784562    7.686906     0
#> tsm_nn.nc.TSM_NN                  -0.5505323    2.438995 56460
#> tsm_nn.nc.TSM_NN_err              -1.5832780    1.986036 56460
#> dimension(s):
#>   from   to offset delta x/y
#> x    1 4865      0     1 [x]
#> y    1 4091   4091    -1 [y]

# Need to adjust dimensions
lat <- units::drop_units(range(lon_lat_tsm$geo_coordinates.nc.latitude))
lon <- units::drop_units(range(lon_lat_tsm$geo_coordinates.nc.longitude))
 
row_fix <- nrow(lon_lat_tsm)
row_fix
#>    x 
#> 4865 

col_fix <- ncol(lon_lat_tsm)
col_fix
#>    y 
#> 4091 

lon_lat_tsm_fix <- lon_lat_tsm
 
lon_lat_tsm_fix <- st_set_dimensions(
   lon_lat_tsm_fix, "x",
   seq(lon[1], lon[2], l = row_fix)
 )
lon_lat_tsm_fix <- st_set_dimensions(
   lon_lat_tsm_fix, "y",
   seq(lat[1], lat[2], l = col_fix)
 )
 
st_crs(lon_lat_tsm_fix) <- st_crs(4326)
lon_lat_tsm_fix

#> stars object with 2 dimensions and 5 attributes
#> attribute(s), summary of first 1e+05 cells:
#>                                       Min.   1st Qu.      Median         Mean
#> geo_coordinates.nc.altitude [m]   0.000000 46.000000 330.0000000 438.93277000
#> geo_coordinates.nc.latitude [°]  39.568894 40.402587  41.0897840  40.99148193
#> geo_coordinates.nc.longitude [°] -7.581946 -3.745773   0.0337230   0.05383067
#> tsm_nn.nc.TSM_NN                 -1.909408 -1.148438  -0.9310176  -0.84433249
#> tsm_nn.nc.TSM_NN_err             -2.000000 -1.963763  -1.8369349  -1.72683826
#>                                      3rd Qu.        Max.  NA's
#> geo_coordinates.nc.altitude [m]  889.0000000 1508.000000     0
#> geo_coordinates.nc.latitude [°]   41.6207120   42.046713     0
#> geo_coordinates.nc.longitude [°]   3.8784562    7.686906     0
#> tsm_nn.nc.TSM_NN                  -0.5505323    2.438995 56460
#> tsm_nn.nc.TSM_NN_err              -1.5832780    1.986036 56460
#> dimension(s):
#>   from   to   offset      delta refsys x/y
#> x    1 4865 -7.58195 0.00411457 WGS 84 [x]
#> y    1 4091  39.5689  0.0031562 WGS 84 [y]
 
plot(lon_lat_tsm_fix, axes = TRUE, col = terrain.colors(20))

enter image description here

For info, this is the preview included with your data (browse.jpg file):

enter image description here

dieghernan
  • 2,690
  • 8
  • 16