Skip to content

Commit f59901a

Browse files
authored
Merge pull request #844 from rafaqz/la/resample_continue
resample cellarea continue
2 parents 9bc60db + e50815c commit f59901a

File tree

12 files changed

+587
-23
lines changed

12 files changed

+587
-23
lines changed

docs/Project.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,23 @@ DocumenterVitepress = "4710194d-e776-4893-9690-8d956a29c365"
1111
GBIF2 = "dedd4f52-e074-43bf-924d-d6bce14ad628"
1212
GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
1313
GeoInterface = "cf35fbd7-0cd7-5166-be24-54bfbe79505f"
14+
GeoMakie = "db073c08-6b98-4ee5-b6a4-5efafb3259c6"
1415
HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
1516
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
1617
MLJBase = "a7f614a8-145f-11e9-1d2a-a57a1082229d"
1718
MLJGLMInterface = "caf8df21-4939-456d-ac9c-5fefbfb04c0c"
1819
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
1920
Maxnet = "81f79f80-22f2-4e41-ab86-00c11cf0f26f"
2021
NCDatasets = "85f8d34a-cbdd-5861-8df4-14fed0d494ab"
22+
NaNStatistics = "b946abbf-3ea7-4610-9019-9858bfdeaf2d"
23+
NaturalEarth = "436b0209-26ab-4e65-94a9-6526d86fea76"
2124
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
25+
Proj = "c94c279d-25a6-4763-9509-64d165bea63e"
2226
RasterDataSources = "3cb90ccd-e1b6-4867-9617-4276c8b2ca36"
2327
Rasters = "a3a2b9e3-a471-40c9-b274-f788e487c689"
2428
Shapefile = "8e980c4a-a4fe-5da2-b3a7-4b4b0353a2f4"
2529
SpeciesDistributionModels = "3ef73bbf-0321-4d3b-9a2e-5fbebc8e35da"
30+
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
2631

2732
[sources]
2833
SpeciesDistributionModels = {url = "https://github.com/tiemvanderdeure/SpeciesDistributionModels.jl/"}

docs/src/.vitepress/config.mts

Lines changed: 68 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,46 @@ const navTemp = {
1818
{ text: 'Get Started', link: '/get_started' },
1919
{ text: 'Manual',
2020
items: [
21-
{ text: 'Methods', link: '/manual/methods' },
22-
{ text: 'Array Operations', link: '/manual/array_operations' },
23-
{ text: 'Data Sources', link: '/manual/data_sources' },
24-
{ text: 'Plots',
21+
{ text: 'Data Sources', link: '/manual/data_sources' },
22+
{ text: 'Methods',
2523
items: [
26-
{ text: 'Plots.jl', link: '/manual/plotting' },
27-
{ text: 'Makie.jl', link: 'manual/plot_makie' },
24+
{ text: 'Overview', link: '/manual/methods' },
25+
{ text: 'rasterize', link: '/api#Rasters.rasterize' },
26+
{ text: 'extract', link: '/api#Rasters.extract' },
27+
{ text: 'zonal', link: '/api#Rasters.zonal-Tuple{Any,%20Union{AbstractRaster,%20AbstractRasterStack}}'},
28+
{ text: 'aggregate', link: '/api#Rasters.aggregate' },
29+
{ text: 'disaggregate', link: '/api#Rasters.disaggregate' },
30+
{ text: 'cellarea', link: '/manual/cellarea' },
31+
{ text: 'mosaic', link: '/api#Rasters.mosaic-Tuple{Function,%20Union{AbstractRaster,%20AbstractRasterStack},%20Vararg{Union{AbstractRaster,%20AbstractRasterStack}}}' },
32+
{ text: 'crop', link: '/api#Rasters.crop' },
33+
{ text: 'extend', link: '/api#Rasters.extend' },
34+
{ text: 'trim', link: '/api#Rasters.trim-Tuple{Union{AbstractRaster,%20AbstractRasterStack}}' },
35+
{ text: 'resample', link: '/api#Rasters.resample-Tuple' },
36+
{ text: 'warp', link: '/api#Rasters.warp-Tuple' },
37+
{ text: 'classify', link: '/api#Rasters.classify' },
38+
{ text: 'mask', link: '/api#Rasters.mask-Tuple{Any}' },
39+
{ text: 'replace_missing', link: '/api#Rasters.replace_missing-Tuple{Any}' },
40+
{ text: 'modify', link: '/api#DimensionalData.modify-Tuple{Any,%20AbstractRasterSeries}' },
41+
{ text: 'read', link: '/api#Base.read-Tuple{Union{AbstractRaster,%20AbstractRasterSeries,%20AbstractRasterStack}}' },
42+
{ text: 'read!', link: '/api#Base.read!-Tuple{AbstractRaster,%20AbstractArray}' },
43+
{ text: 'open', link: '/api#Base.open-Tuple{Function,%20AbstractRaster}' },
44+
{ text: 'write', link: '/api#Base.write-Tuple{AbstractString,%20AbstractRasterSeries}' },
2845
]
29-
},
46+
},
3047
]
3148
},
3249
{ text: 'Tutorials',
3350
items: [
51+
{ text: 'Plotting',
52+
collapsed: true,
53+
items: [
54+
{ text: 'Plots.jl', link: '/tutorials/plotting' },
55+
{ text: 'Makie.jl', link: '/tutorials/plot_makie' },
56+
]
57+
},
58+
{ text: 'Array Operations', link: '/tutorials/array_operations' },
59+
{ text: 'Spatial mean', link: '/tutorials/spatial_mean' },
60+
{ text: 'Reprojection and resampling', link: '/tutorials/resample'},
3461
{ text: 'Species Distribution Modelling', link: '/tutorials/gbif_wflow' },
3562
]
3663
},
@@ -98,19 +125,47 @@ export default defineConfig({
98125
{ text: 'Get Started', link: '/get_started' },
99126
{ text: 'Manual',
100127
items: [
101-
{ text: 'Methods', link: '/manual/methods' },
102-
{ text: 'Array Operations', link: '/manual/array_operations' },
103128
{ text: 'Data Sources', link: '/manual/data_sources' },
104-
{ text: 'Plots',
129+
{ text: 'Methods',
130+
collapsed: true,
105131
items: [
106-
{ text: 'Plots.jl', link: '/manual/plotting' },
107-
{ text: 'Makie.jl', link: '/manual/plot_makie' },
132+
{ text: 'Overview', link: '/manual/methods' },
133+
{ text: 'rasterize', link: '/api#Rasters.rasterize' },
134+
{ text: 'extract', link: '/api#Rasters.extract' },
135+
{ text: 'zonal', link: '/api#Rasters.zonal-Tuple{Any,%20Union{AbstractRaster,%20AbstractRasterStack}}'},
136+
{ text: 'aggregate', link: '/api#Rasters.aggregate' },
137+
{ text: 'disaggregate', link: '/api#Rasters.disaggregate' },
138+
{ text: 'cellarea', link: '/manual/cellarea' },
139+
{ text: 'mosaic', link: '/api#Rasters.mosaic-Tuple{Function,%20Union{AbstractRaster,%20AbstractRasterStack},%20Vararg{Union{AbstractRaster,%20AbstractRasterStack}}}' },
140+
{ text: 'crop', link: '/api#Rasters.crop' },
141+
{ text: 'extend', link: '/api#Rasters.extend' },
142+
{ text: 'trim', link: '/api#Rasters.trim-Tuple{Union{AbstractRaster,%20AbstractRasterStack}}' },
143+
{ text: 'resample', link: '/api#Rasters.resample-Tuple' },
144+
{ text: 'warp', link: '/api#Rasters.warp-Tuple' },
145+
{ text: 'classify', link: '/api#Rasters.classify' },
146+
{ text: 'mask', link: '/api#Rasters.mask-Tuple{Any}' },
147+
{ text: 'replace_missing', link: '/api#Rasters.replace_missing-Tuple{Any}' },
148+
{ text: 'modify', link: '/api#DimensionalData.modify-Tuple{Any,%20AbstractRasterSeries}' },
149+
{ text: 'read', link: '/api#Base.read-Tuple{Union{AbstractRaster,%20AbstractRasterSeries,%20AbstractRasterStack}}' },
150+
{ text: 'read!', link: '/api#Base.read!-Tuple{AbstractRaster,%20AbstractArray}' },
151+
{ text: 'open', link: '/api#Base.open-Tuple{Function,%20AbstractRaster}' },
152+
{ text: 'write', link: '/api#Base.write-Tuple{AbstractString,%20AbstractRasterSeries}' },
108153
]
109-
},
154+
},
110155
]
111156
},
112157
{ text: 'Tutorials',
113158
items: [
159+
{ text: 'Plotting',
160+
collapsed: true,
161+
items: [
162+
{ text: 'Plots.jl', link: '/tutorials/plotting' },
163+
{ text: 'Makie.jl', link: '/tutorials/plot_makie' },
164+
]
165+
},
166+
{ text: 'Array Operations', link: '/tutorials/array_operations' },
167+
{ text: 'Spatial mean', link: '/tutorials/spatial_mean' },
168+
{ text: 'Reprojection and resampling', link: '/tutorials/resample'},
114169
{ text: 'Species Distribution Modelling', link: '/tutorials/gbif_wflow' },
115170
]
116171
},

docs/src/manual/cellarea.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
## `cellarea`
2+
3+
```@meta
4+
CollapsedDocStrings=true
5+
```
6+
7+
```@docs; canonical=false
8+
cellarea
9+
```
10+
11+
Computing the area of each cell in a raster is useful for a number of reasons - if you have a variable like
12+
population per cell, or elevation ([spatially extensive variables](https://r-spatial.org/book/05-Attributes.html#sec-extensiveintensive)),
13+
you'll want to account for the fact that different cells have different areas.
14+
15+
Let's construct a raster and see what this looks like! We'll keep it in memory.
16+
17+
The spherical method relies on the [Proj.jl](https://github.com/JuliaGeo/Proj.jl) package to perform coordinate transformation, so that has to be loaded explicitly.
18+
19+
````@example cellarea
20+
using Rasters, Proj
21+
````
22+
23+
To construct a raster, we'll need to specify the `x` and `y` dimensions. These are called `lookups` in `Rasters.jl.`
24+
25+
````@example cellarea
26+
using Rasters.Lookups
27+
````
28+
29+
We can now construct the x and y lookups. Here we'll use a start-at-one, step-by-five grid.
30+
Note that we're specifying that the "sampling", i.e., what the coordinates actually mean,
31+
is `Intervals(Start())`, meaning that the coordinates are the starting point of each interval.
32+
33+
This is in contrast to `Points()` sampling, where each index in the raster represents the value at a sampling point;
34+
here, each index represents a grid cell, which is defined by the coordinate being at the start.
35+
36+
````@example cellarea
37+
x = X(1:5:30; sampling = Intervals(Start()), crs = EPSG(4326))
38+
y = Y(50:5:80; sampling = Intervals(Start()), crs = EPSG(4326));
39+
nothing # hide
40+
````
41+
42+
I have chosen the y-range here specifically so we can show the difference between spherical and planar `cellarea`.
43+
44+
````@ansi cellarea
45+
ras = Raster(ones(x, y); crs = EPSG(4326))
46+
````
47+
48+
We can just call `cellarea` on this raster, which returns cell areas in meters, on Earth, assuming it's a sphere:
49+
50+
````@ansi cellarea
51+
cellarea(ras)
52+
````
53+
54+
and if we plot it, you can see the difference in cell area as we go from the equator to the poles:
55+
56+
````@example cellarea
57+
using CairoMakie
58+
heatmap(cellarea(ras); axis = (; aspect = DataAspect()))
59+
````
60+
61+
We can also try this using the planar method, which simply computes the area of the rectangle using `area = x_side_length * y_side_length`:
62+
63+
````@ansi cellarea
64+
cellarea(Planar(), ras)
65+
````
66+
67+
Note that this is of course wildly inaccurate for a geographic dataset - but if you're working in a projected coordinate system, like polar stereographic or Mercator, this can be very useful (and a _lot_ faster)!

docs/src/manual/data_sources.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ They are always 3 dimensional, and have `Y`, `X` and [`Band`](@ref) dimensions.
4343
using Rasters
4444
````
4545

46-
````@docs
47-
smapseries
48-
````
49-
5046
## Writing file formats to disk
5147

5248
Files can be written to disk with ArchGDAL.jl and NCDatasets.jl backends using

docs/src/manual/array_operations.md renamed to docs/src/tutorials/array_operations.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Array operations
2+
13
Most base methods work as for regular julia `Array`s, such as `reverse` and
24
rotations like `rotl90`. Base, statistics and linear algebra methods like `mean`
35
that take a `dims` argument can also use the dimension name.

docs/src/tutorials/gbif_wflow.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This example shows a full Species distribution modelling workflow, from loading data, to cleaning it, to fitting an ensemble and generating predictions.
44

5-
It uses GBIF and WorldClim data, which are common datasets in ecology.
5+
It uses GBIF and WorldClim data, which are common datasets in ecology. We'll load occurrences for the Mountain Pygmy Possum species using [GBIF2.jl](https://github.com/rafaqz/GBIF2.jl), an interface to the [Global Biodiversity Information Facility](https://www.gbif.org/), and extract environmental variables using BioClim data from [RasterDataSources.jl](https://github.com/EcoJulia/RasterDataSources.jl).
66

77
## Load Rasters, ArchGDAL, RasterDataSources and GBIF
88
The GBIF2 library is used to download occurrence data, RasterDataSources to conveniently access Bioclim data. ArchGDAL is necessary to load in the Bioclim data.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)