Skip to content

notes on xarray/MDIM #145

@mdsumner

Description

@mdsumner

here's the basics of how we could return an xarray object (sometimes you'll want the date from the fileset, sometimes it will be in the object already)

library(reticulate)
xarray <- import("xarray")
pandas <- import("pandas")

ftodate <- function(x) pandas$DatetimeIndex(list(
  format(as.Date(stringr::str_extract(basename(x), "[0-9]{8}"), "%Y%m%d"))
))

da <- function(x) {
  ds <- xarray$open_dataset(x)
  ds$expand_dims(time = ftodate(x))
}
files <- raadtools::read_par(returnfiles = TRUE)
ds <- xarray$concat(lapply(files$fullname[1:100], da), dim = "time")

<xarray.Dataset> Size: 15GB
Dimensions:  (time: 100, lat: 4320, lon: 8640, rgb: 3, eightbitcolor: 256)
Coordinates:
  * time     (time) datetime64[ns] 800B 2002-07-04 2002-07-12 ... 2004-08-28
  * lat      (lat) float32 17kB 89.98 89.94 89.9 89.85 ... -89.9 -89.94 -89.98
  * lon      (lon) float32 35kB -180.0 -179.9 -179.9 ... 179.9 179.9 180.0
Dimensions without coordinates: rgb, eightbitcolor
Data variables:
    par      (time, lat, lon) float32 15GB dask.array<chunksize=(1, 44, 87), meta=np.ndarray>
    palette  (time, rgb, eightbitcolor) uint8 77kB dask.array<chunksize=(1, 3, 256), meta=np.ndarray>
Attributes: (12/62)
    product_name:                     AQUA_MODIS.20020704_20020711.L3m.8D.PAR...
    instrument:                       MODIS
    title:                            MODISA Level-3 Standard Mapped Image
    project:                          Ocean Biology Processing Group (NASA/GS...
    platform:                         Aqua
    source:                           satellite observations from MODIS-Aqua
    ...                               ...
    cdm_data_type:                    grid
    keywords:                         Earth Science > Oceans > Ocean Optics >...
    keywords_vocabulary:              NASA Global Change Master Directory (GC...
    data_bins:                        20363532
    data_minimum:                     0.018797303
    data_maximum:                     66.28954
>

Don't yet know how to specify what the time is (interval or start or middle or whatever)

I think this could avoid the actual calls to open datasets by using kerchunk ...

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