Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaqz committed Jul 8, 2024
1 parent cd934ad commit f4dd9bb
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 27 deletions.
87 changes: 64 additions & 23 deletions index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,19 @@ execute:

## Read/Write Backends

- Netcdf/hdf5
- GeoTIFF and other GDAL compatible formats
- Gribb (read only)
- Zarr (PR nearly done!)
- R grd (simple mmapped data from R)
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
GeoTIFF and everything else | ArchGDAL.jl


## Backend detection

From filename extension:

```julia
# Single array
rast = Raster("myrasterfile.ext")
Expand All @@ -59,20 +64,25 @@ rast = Raster(filename; lazy=true)

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

## Change chunk patterned for more efficient lazy reads:
\
Reads from disk only on `getindex`:
```julia
write("rechunked.tif", raster; chunks=(256, 256))
rast10[X=100 .. 135, Y=20 .. 40]
```

Or `read`:
```julia

RasterStack("myrasterstack.ext")
read(rast10)
```

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

## RasterDataSources.jl integration

Expand All @@ -84,19 +94,21 @@ ENV["RASTERDATASOURCES_PATH"] = "/home/raf/Data/Raster";
Load a raster the standard way, from a filename:

```{julia}
using Rasters, ArchGDAL, RasterDataSources, CairoMakie
using Rasters, RasterDataSources, ArchGDAL
bioclim_filename = RasterDataSources.getraster(WorldClim{BioClim}, 5)
bioclim5 = Raster(bioclim_filename);
```
\
Or use RasterDataSources syntax directly:
Or just use RasterDataSources syntax directly:

```{julia}
bioclim_filename = Raster(WorldClim{BioClim}, 5);
```

# Plotting

Always the right way up!

## Plots.jl

```{julia}
Expand Down Expand Up @@ -127,19 +139,42 @@ Makie.heatmap!(ga, bioclim5; colormap=:isoluminant_cgo_70_c39_n256)
fig
```


# Common GIS methods

---
## Native rasterization engine

- accepts all GeoInterface.jl geometries
- extremely fast + threaded
- usually an order of magnitude faster than other packages
- detailed correctness warnings
- consistent behaviour and syntax for:
- `rasterize`
- `coverage`
- `mask`
- `boolmask`/`missingmask`
- `zonal`

## Other common methods

- extract
- crop/extend
- trim
- mosaic
- aggregate
- resample

## `mask`, `trim`
## `mask` + `trim`

```{julia}
#| echo: false
using Rasters, RasterDataSources, ArchGDAL, NaturalEarth, Plots, Dates, DataFrames
using Rasters: trim
```

Mask climate data wth Norway border (from NaturalEarth.jl), and trim:

```{julia}
using NaturalEarth, Dates, DataFrames
countries = DataFrame(naturalearth("ne_10m_admin_0_countries"))
norway_border = subset(countries, :NAME => ByRow(==("Norway"))).geometry[1]
climate = RasterStack(WorldClim{Climate}, (:tmin, :tmax, :prec, :wind); month=July)
Expand All @@ -153,27 +188,33 @@ Extract climate data at species occurrence points:

```{julia}
#| code-overflow: scroll
using Rasters, GBIF2, RasterDataSources
records = GBIF2.occurrence_search("Burramys parvus")
A = RasterStack(WorldClim{BioClim})
climate = extract(A, records; name=(:bio1, :bio4, :bio7)) |> DataFrame
using GBIF2
occurrences = GBIF2.occurrence_search("Burramys parvus")
climate = RasterStack(WorldClim{BioClim})
extract(climate, occurrences; name=(:bio1, :bio4, :bio7)) |> DataFrame
```

## `zonal` statistics

Hottest and coldest countries in July:

```{julia}
#| echo: false
using Rasters, RasterDataSources, ArchGDAL, Dates, DataFrames, NaturalEarth, Statistics
```

Find the hottest and coldest countries in July:

```{julia}
countries = DataFrame(naturalearth("ne_10m_admin_0_countries"))
clim = Raster(WorldClim{Climate}, :tmax; month=July)
countries.july_maxtemp = zonal(Statistics.mean, clim;
of=countries, boundary=:touches, progress=false
)
sort!(subset(countries, :july_maxtemp => ByRow(!isnan)), :july_maxtemp).NAME
filtered = subset(countries, :july_maxtemp => ByRow(!isnan))
sort!(filtered, :july_maxtemp).NAME
```

# Thanks!

Any problems, make github issues at\https://github.com/rafaqz/Rasters.jl
\
But please include all files in a MWE!
8 changes: 4 additions & 4 deletions style.scss
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/*-- scss:rules --*/

.div sourceCode {
.sourceCode {
margin-top: 10px;
margin-bottom: 10px;
}

.div dataframe {
.dataframe {
font-size: 20px;
}

.div cell-output {
font-size: 16;
.cell-output {
font-size: 20px;
}

0 comments on commit f4dd9bb

Please sign in to comment.