-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path_1-galah.qmd
390 lines (290 loc) · 9.74 KB
/
_1-galah.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
# {galah} {#galah .galah-breaks data-menu-title="galah" background-color="#e9317f"}
::: {.notes}
The first project I wanted to introduce is the {galah} package, which acts as an interface to the
biodiversity data in the ALA. The majority of these data consist of species occurrence records...
:::
## {#sp-occ .galah data-menu-title="Species Occurrence"}
#### 2020-09-23
{.absolute top="20px" left="380px" width="700px"}
{.absolute bottom="200px" left="1000px" height="500px"}
::: {.notes}
...so, evidence of a taxon in a particular time and place. It's possible to get these records through the website, but one of the main advantages of using {galah} is that it makes the query reproducible. It's also implemented in both R and Python- the R version currently has more functionality but a fully-fledged Python release is going to be happening very soon.
:::
## Counts of records {#counts .galah data-menu-title="atlas_counts()"}
::: {.columns .v-center-container}
::: {.column width="100%"}
::: {.panel-tabset}
```{r}
#| echo: false
#| message: false
#| warning: false
library(galah)
galah_config(email = Sys.getenv("email"), verbose = FALSE)
```
### R
```{r}
#| echo: true
#| eval: true
#| code-line-numbers: "|1|3|4|"
#| output-location: column-fragment
library(galah)
galah_call() |>
atlas_counts()
```
### Python
```{python}
#| echo: true
#| eval: false
#| code-line-numbers: "|"
import galah
galah.atlas_counts()
```
:::
:::
:::
::: {.notes}
I'll run through some examples using the R syntax, but the Python code is here in this tab, and these slides are available online.
So, start by loading the package, and every query begins with galah_call(),
which tells the API what we want. A lot of the syntax is similar to using dplyr, so if you're familiar with the tidyverse this will be quite straightforward. The next line specifies what we want - here, atlas_counts() will retrieve counts of records. Voila, we're told that there are just over 113 million records in the ALA. But we don't always want everything, everywhere, all at once. So here are some functions that allow us to construct more specific queries
:::
## Identify taxa {#identify .galah data-menu-title="galah_identify()"}
::: {.columns .v-center-container}
::: {.column width="100%"}
::: {.panel-tabset}
### R
```{r}
#| echo: true
#| eval: true
#| code-line-numbers: "|4|"
#| output-location: column-fragment
library(galah)
galah_call() |>
galah_identify("pardalotus") |>
atlas_counts()
```
### Python
```{python}
#| echo: true
#| eval: false
#| code-line-numbers: "|"
import galah
galah.atlas_counts(taxa="pardalotus")
```
:::
{.absolute bottom="50px" right="100px" height="150px"}
{.absolute bottom="50px" right="300px" height="150px"}
{.absolute bottom="50px" right="500px" height="150px"}
{.absolute bottom="50px" right="700px" height="150px"}
:::
:::
::: {.notes}
galah_identify() lets us specify one or more taxa - here, I've asked for the
genus pardalotus. Over a million pardalote records
:::
## Filter records {#filter .galah data-menu-title="galah_filter()"}
::: {.columns .v-center-container}
::: {.column width="100%"}
::: {.panel-tabset}
### R
```{r}
#| echo: true
#| eval: true
#| code-line-numbers: "|5-6|"
#| output-location: column-fragment
library(galah)
galah_call() |>
galah_identify("pardalotus") |>
galah_filter(year >= 2020,
stateProvince == "Tasmania") |>
atlas_counts()
```
### Python
```{python}
#| echo: true
#| eval: false
#| code-line-numbers: "|"
import galah
galah.atlas_counts(
taxa="pardalotus",
filters=["year >= 2020", "stateProvince == Tasmania"]
)
```
:::
{.absolute bottom="50px" right="100px" height="150px"}
{.absolute bottom="50px" right="300px" height="150px"}
{.absolute bottom="50px" right="500px" height="150px"}
:::
:::
::: {.notes}
galah_filter() applies filters to different fields - here, I've specified records
from 2020 onwards, from Tasmania. Down to 7000 records. But maybe you want to know if there are different species in there, or if the counts change over the years...
:::
## Group counts {#group .galah data-menu-title="galah_group_by()"}
::: {.columns .v-center-container}
::: {.column width="100%"}
::: {.panel-tabset}
### R
```{r}
#| echo: true
#| eval: true
#| code-line-numbers: "|7|"
#| output-location: column-fragment
library(galah)
galah_call() |>
galah_identify("pardalotus") |>
galah_filter(year >= 2020,
stateProvince == "Tasmania") |>
galah_group_by(year, species) |>
atlas_counts()
```
### Python
```{python}
#| echo: true
#| eval: false
#| code-line-numbers: "|"
import galah
galah.atlas_counts(
taxa="pardalotus",
filters=["year >= 2020", "stateProvince == Tasmania"],
group_by=["year","species"]
)
```
:::
{.absolute bottom="50px" left="100px" height="150px"}
{.absolute bottom="50px" left="300px" height="150px"}
{.absolute bottom="50px" left="500px" height="150px"}
:::
:::
::: {.notes}
group_by() lets you group counts by the fields you specify - here, year and species. We can see that there are 3 species, and there's quite a difference in the number of records.
:::
## Download occurrences {#download .galah data-menu-title="atlas_occurrences()"}
::: {.columns .v-center-container}
::: {.column width="100%"}
::: {.panel-tabset}
### R
```{r}
#| echo: true
#| eval: true
#| code-line-numbers: "|2,8|"
#| output-location: column-fragment
library(galah)
galah_config(email = "[email protected]")
galah_call() |>
galah_identify("pardalotus") |>
galah_filter(year >= 2020,
stateProvince == "Tasmania") |>
atlas_occurrences()
```
### Python
```{python}
#| echo: true
#| eval: false
#| code-line-numbers: "|"
import galah
galah.galah_config(email="[email protected]")
galah.atlas_occurrences(
taxa="pardalotus",
filters=["year >= 2020", "stateProvince == Tasmania"]
)
```
:::
{.absolute bottom="50px" left="100px" height="150px"}
{.absolute bottom="50px" left="300px" height="150px"}
{.absolute bottom="50px" left="500px" height="150px"}
:::
:::
::: {.notes}
To download these records and have a look at them in more detail,
we can switch from atlas_counts() to atlas_occurrences(). Downloading records also
requires that we provide the email we used to register with the ALA. This is a bit truncated, but we can see that the download consists of 7000+ rows and 8 columns.
:::
## Select fields {#select .galah data-menu-title="galah_select()"}
::: {.columns .v-center-container}
::: {.column width="100%"}
::: {.panel-tabset}
### R
```{r}
#| echo: true
#| eval: true
#| code-line-numbers: "|8-10|"
#| output-location: column-fragment
library(galah)
galah_config(email = "[email protected]")
galah_call() |>
galah_identify("pardalotus") |>
galah_filter(year >= 2020,
stateProvince == "Tasmania") |>
galah_select(species,
year,
dataResourceName) |>
atlas_occurrences()
```
### Python
```{python}
#| echo: true
#| eval: false
#| code-line-numbers: "|"
import galah
galah.galah_config(email="[email protected]")
galah.atlas_occurrences(
taxa="pardalotus",
filters=["year >= 2020", "stateProvince == Tasmania"],
fields=["species","year","decimalLatitude","decimalLongitude"]
)
```
:::
{.absolute bottom="50px" left="100px" height="150px"}
{.absolute bottom="50px" left="300px" height="150px"}
{.absolute bottom="50px" left="500px" height="150px"}
:::
:::
::: {.notes}
We might not want all the columns that are included in the default download, or we might want some different ones; we can specify this with galah_select() - here, we have records with information about species, year, and the data provider.
:::
## Geolocate {#geolocate .galah data-menu-title="galah_geolocate()"}
::: {.columns .v-center-container}
::: {.column width="100%"}
::: {.panel-tabset}
### R
```{r}
#| echo: true
#| eval: true
#| code-line-numbers: "|1-2|4-6|8-11|"
#| output-location: column-fragment
library(galah)
library(sf)
melb <- st_read("data/metro_region.shp",
quiet = TRUE) |>
st_simplify(dTolerance = 1000)
galah_call() |>
galah_identify("pardalotus") |>
galah_geolocate(melb) |>
atlas_counts()
```
{.absolute bottom="10px" right="10px"}
### Python
Watch this space!
:::
:::
:::
::: {.notes}
{galah} also lets you search within a bespoke location; with galah_geolocate, you
can provide a shapefile, well known text string, bounding box, or simple features object. In this example here, we load the {sf} package, then read in a shapefile of the melbourne metro region. Then it's' just a case of providing this as an argument to galah_geolocate, and we have 93 thousand pardalotes ever recorded in Melbourne.
:::
## {#galah-url .links data-menu-title="{galah} URL"}
::: {.columns .v-center-container}
::: {.column width="10%"}
:::
::: {.column width="15%"}

:::
::: {.column width="50%"}
[galah.ala.org.au](https://galah.ala.org.au)
:::
:::
::: {.notes}
This is just some of the functionality of the package, there's lots of other cool
things that you can do with it, like apply data quality profiles, or query other
living atlases, and that's all documented on the website.
:::