Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaqz committed Jul 9, 2024
1 parent 2c12001 commit e017f16
Showing 1 changed file with 87 additions and 31 deletions.
118 changes: 87 additions & 31 deletions index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -14,73 +14,116 @@ format:
revealjs:
theme: [simple, style.scss] # beige blood dark default league moon night serif simple sky solarized
incremental: true
toc: false
toc-depth: 2
toc: true
toc-depth: 1
slide-number: true
overview: true
code-line-numbers: false
highlight-style: ayu
execute:
echo: true
---

## Read/Write Backends
# What is a raster?

. . .

:::: {.columns}

::: {.column width="50%"}
![](https://raw.githubusercontent.com/NEONScience/NEON-Data-Skills/main/graphics/raster-general/raster_concept.png)
:::

::: {.column width="50%"}
- like an image, but not RGB
- values of some variable accross a gridded space
- usually has X/Y spatial dimensions
- (e.g. lattitude/longitude)
- with a coordinate reference system
:::

::::

---

:::: {.columns}

::: {.column width="50%"}
![](https://esd.copernicus.org/articles/11/201/2020/esd-11-201-2020-f03-web.png)
:::

::: {.column width="50%"}
- may be collected in a dataset with multiple variables
- may have more dimensions, like time
:::

::::


# DimensionalData.jl integration

- Rasters extends DimensionalData.jl
- `Raster <: AbstractDimArray` and `RasterStack <: AbstractDimStack`
- This gives is the foundation for spatial work
- Rasters adds:
- coordinate reference systems
- missing value handling
- File IO
- GIS tools

## File Read/Write Backends

File types | Package
------------------------------- | ----------
Netcdf/hdf5 | NCDatasets.jl
Grib (read only) | GRIBDatasets.jl
Zarr (PR nearly done!) | ZarrDatasets.jl
R grd (simple Mmap data from R) | native
grd (simple Mmap data from R) | native
GeoTIFF and everything else | ArchGDAL.jl


## Backend detection

From filename extension:
Backend detected in constructors:

```julia
# Single array
rast = Raster("myrasterfile.ext")
rast = Raster("myraster.tif") # Will use ArchGDAL.jl
rast = Raster("myraster.nc") # Will use NCDatasets

# Multi-array
st = RasterStack("myrasterstack.ext")

# Series of rasters or stacks may be detectable from folders
st = RasterSeries("myrasterfolder", Ti(DateTime))
st = RasterStack("mystack.nc") # Will use NCDatasets.jl
st = RasterStack("mystack.grib") # Will use GRIBDatasets.jl
```

# Lazy loading

For manipulating larger-than-memory data
# DiskArrays.jl integration

## DiskArrays.jl integration
For larger-than-memory data

Loads data lazily:
## Lazy loading

```julia
rast = Raster(filename; lazy=true)
```
. . .

Still lazy after broadcasts:
```julia
rast10 = rast .* 10
```
. . .

Reads from disk/network only on `getindex`:
```julia
rast10[X=100 .. 135, Y=20 .. 40]
```

Or `read`:
```julia
read(rast10)
```
## Chunk patterns

## Change chunk patterns
For more efficient lazy reads:
\
```julia
write("rechunked.tif", raster; chunks=(256, 256))
write("rechunked.tif", mem_rast; chunks=(X(256), Y(256)))
```

## RasterDataSources.jl integration
Expand All @@ -97,6 +140,9 @@ using Rasters, RasterDataSources, ArchGDAL
bioclim_filename = RasterDataSources.getraster(WorldClim{BioClim}, 5)
bioclim5 = Raster(bioclim_filename);
```

. . .

\
Or use RasterDataSources.jl syntax directly:

Expand Down Expand Up @@ -140,27 +186,36 @@ fig


# Common GIS methods
- for working with raster data
- for using vector/geometry data with raster data

## Native rasterization engine

- accepts all GeoInterface.jl geometries
- extremely fast + threaded
- detailed correctness warnings
- consistent behaviour and syntax for:

. . .

::: {.nonincremental}
- `rasterize`
- `coverage`
- `mask`
- `boolmask`/`missingmask`
- `zonal`
:::

## Other common methods

::: {.nonincremental}
- extract
- crop/extend
- trim
- mosaic
- aggregate
- resample
:::

# Examples
\
Expand Down Expand Up @@ -193,19 +248,15 @@ extract(clim, occ; name=(:bio1, :bio4, :bio7)) |> DataFrame

## `mask` + `trim`

Mask climate data wth country border and trim:

---
code-annotations: hover
---
Mask climate rasters wth country border :

```{julia}
#| output-location: fragment
clim = RasterStack(WorldClim{Climate}, (:tmin, :tmax, :prec, :wind); month=July)
countries = naturalearth("ne_10m_admin_0_countries") |> DataFrame
norway = subset(countries, :NAME => ByRow(==("Norway"))).geometry
norway_clim = mask(clim; with=norway)[Y=0 .. 90] |> trim
Plots.plot(norway_clim; size=(800, 400))
finland = subset(countries, :NAME => ByRow(==("Finland"))).geometry
finland_clim = mask(clim; with=finland) |> trim
Plots.plot(finland_clim; size=(800, 400))
```

## `zonal` statistics
Expand All @@ -228,10 +279,15 @@ filtered = subset(countries, :july_maxtemp => ByRow(!isnan))
sort!(filtered, :july_maxtemp).NAME
```

# Thanks!
## Thanks

Especially to Rasters.jl contributors!

![](https://contrib.rocks/image?repo=rafaqz/Rasters.jl)

\
Any problems, make github issues at\
https://github.com/rafaqz/Rasters.jl
\
\
Please include all files in a MWE!
(Please include all files in a MWE!)

0 comments on commit e017f16

Please sign in to comment.