Skip to content

Commit 71e018e

Browse files
author
EmmaCartuyvels1
committed
Also download order and genus
1 parent 016fe27 commit 71e018e

File tree

2 files changed

+45
-17
lines changed

2 files changed

+45
-17
lines changed

source/R/Prepare_data_10km.Rmd

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Load and save unstructured data at 10km² grid.
4343
The ABV data is downloaded as a cube from GBIF.org.
4444
The zip file is stored under *./data/raw*.
4545

46-
> GBIF.org (15 April 2025) GBIF Occurrence Download https://doi.org/10.15468/dl.hdwm9t
46+
> GBIF.org (01 September 2025) GBIF Occurrence Download https://doi.org/10.15468/dl.97pdjf
4747
4848
```{r}
4949
# nolint start: line_length_linter.
@@ -53,10 +53,14 @@ query_abv <- "SELECT
5353
COALESCE(coordinateUncertaintyInMeters, 1000)) AS mgrsCode,
5454
speciesKey,
5555
species,
56+
\"order\",
5657
family,
58+
genus,
5759
COUNT(*) AS n,
5860
MIN(COALESCE(coordinateUncertaintyInMeters, 1000)) AS minCoordinateUncertaintyInMeters,
59-
IF(ISNULL(family), NULL, SUM(COUNT(*)) OVER (PARTITION BY family)) AS familyCount
61+
IF(ISNULL(\"order\"), NULL, SUM(COUNT(*)) OVER (PARTITION BY \"order\")) AS orderCount,
62+
IF(ISNULL(family), NULL, SUM(COUNT(*)) OVER (PARTITION BY family)) AS familyCount,
63+
IF(ISNULL(genus), NULL, SUM(COUNT(*)) OVER (PARTITION BY genus)) AS genusCount
6064
FROM
6165
occurrence
6266
WHERE
@@ -78,7 +82,9 @@ query_abv <- "SELECT
7882
\"year\",
7983
mgrsCode,
8084
speciesKey,
85+
\"order\",
8186
family,
87+
genus,
8288
species
8389
ORDER BY
8490
\"year\" ASC,
@@ -106,7 +112,7 @@ glimpse(abv_data_total)
106112
The cube data is downloaded from GBIF.org.
107113
The zip file is stored under *./data/raw*.
108114

109-
> GBIF.org (15 April 2025) GBIF Occurrence Download https://doi.org/10.15468/dl.75hgxm
115+
> GBIF.org (01 September 2025) GBIF Occurrence Download https://doi.org/10.15468/dl.5grehw
110116
111117
```{r}
112118
# nolint start: line_length_linter.
@@ -116,10 +122,14 @@ query_birdcube <- "SELECT
116122
COALESCE(coordinateUncertaintyInMeters, 10000)) AS mgrsCode,
117123
speciesKey,
118124
species,
125+
\"order\",
119126
family,
127+
genus,
120128
COUNT(*) AS n,
121129
MIN(COALESCE(coordinateUncertaintyInMeters, 10000)) AS minCoordinateUncertaintyInMeters,
122-
IF(ISNULL(family), NULL, SUM(COUNT(*)) OVER (PARTITION BY family)) AS familyCount
130+
IF(ISNULL(\"order\"), NULL, SUM(COUNT(*)) OVER (PARTITION BY \"order\")) AS orderCount,
131+
IF(ISNULL(family), NULL, SUM(COUNT(*)) OVER (PARTITION BY family)) AS familyCount,
132+
IF(ISNULL(genus), NULL, SUM(COUNT(*)) OVER (PARTITION BY genus)) AS genusCount
123133
FROM
124134
occurrence
125135
WHERE
@@ -141,7 +151,9 @@ query_birdcube <- "SELECT
141151
\"year\",
142152
mgrsCode,
143153
speciesKey,
154+
\"order\",
144155
family,
156+
genus,
145157
species
146158
ORDER BY
147159
\"year\" ASC,
@@ -266,13 +278,15 @@ We select the columns we want in a logical order:
266278

267279
```{r}
268280
abv_data_out_sf <- abv_data_total_sf %>%
269-
select("mgrscode", "year", "specieskey", "species", "family", "n",
270-
"mincoordinateuncertaintyinmeters", "familycount", "geometry")
281+
select("mgrscode", "year", "specieskey", "species", "order", "family",
282+
"genus", "n", "mincoordinateuncertaintyinmeters",
283+
"ordercount", "familycount", "genuscount", "geometry")
271284
abv_data_out <- st_drop_geometry(abv_data_out_sf)
272285
273286
birdcube_data_out_sf <- birdcube_data_total_sf %>%
274-
select("mgrscode", "year", "specieskey", "species", "family", "n",
275-
"mincoordinateuncertaintyinmeters", "familycount", "geometry")
287+
select("mgrscode", "year", "specieskey", "species", "order", "family",
288+
"genus", "n", "mincoordinateuncertaintyinmeters",
289+
"ordercount", "familycount", "genuscount", "geometry")
276290
birdcube_data_out <- st_drop_geometry(birdcube_data_out_sf)
277291
```
278292

source/R/prepare_abv_data.Rmd

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ head(sampling_framework_abv)
7575
The ABV data is downloaded as a cube from GBIF.org. We set the randomization to zero, since the monitoring takes place in specific squares.
7676
The zip file is stored under *./data/raw*.
7777

78-
> GBIF.org (15 April 2025) GBIF Occurrence Download https://doi.org/10.15468/dl.ddzhrc
78+
> GBIF.org (01 September 2025) GBIF Occurrence Download https://doi.org/10.15468/dl.bjzbrv
7979
8080
```{r}
8181
# nolint start: line_length_linter.
@@ -84,10 +84,14 @@ query_abv <- "SELECT
8484
GBIF_MGRSCode(1000, decimalLatitude, decimalLongitude, 0) AS mgrsCode,
8585
speciesKey,
8686
species,
87+
\"order\",
8788
family,
89+
genus,
8890
COUNT(*) AS n,
8991
MIN(COALESCE(coordinateUncertaintyInMeters, 0)) AS minCoordinateUncertaintyInMeters,
90-
IF(ISNULL(family), NULL, SUM(COUNT(*)) OVER (PARTITION BY family)) AS familyCount
92+
IF(ISNULL(\"order\"), NULL, SUM(COUNT(*)) OVER (PARTITION BY \"order\")) AS orderCount,
93+
IF(ISNULL(family), NULL, SUM(COUNT(*)) OVER (PARTITION BY family)) AS familyCount,
94+
IF(ISNULL(genus), NULL, SUM(COUNT(*)) OVER (PARTITION BY genus)) AS genusCount
9195
FROM
9296
occurrence
9397
WHERE
@@ -109,7 +113,9 @@ query_abv <- "SELECT
109113
\"year\",
110114
mgrsCode,
111115
speciesKey,
116+
\"order\",
112117
family,
118+
genus,
113119
species
114120
ORDER BY
115121
\"year\" ASC,
@@ -137,7 +143,7 @@ glimpse(abv_data_total)
137143
The cube data is downloaded as a cube from GBIF.org.
138144
The zip file is stored under *./data/raw*.
139145

140-
> GBIF.org (15 April 2025) GBIF Occurrence Download https://doi.org/10.15468/dl.mn4ybb
146+
> GBIF.org (01 September 2025) GBIF Occurrence Download https://doi.org/10.15468/dl.vvqewm
141147
142148
```{r}
143149
# nolint start: line_length_linter.
@@ -147,10 +153,14 @@ query_birdcube <- "SELECT
147153
COALESCE(coordinateUncertaintyInMeters, 1000)) AS mgrsCode,
148154
speciesKey,
149155
species,
156+
\"order\",
150157
family,
158+
genus,
151159
COUNT(*) AS n,
152-
MIN(COALESCE(coordinateUncertaintyInMeters, 1000)) AS minCoordinateUncertaintyInMeters,
153-
IF(ISNULL(family), NULL, SUM(COUNT(*)) OVER (PARTITION BY family)) AS familyCount
160+
MIN(COALESCE(coordinateUncertaintyInMeters, 0)) AS minCoordinateUncertaintyInMeters,
161+
IF(ISNULL(\"order\"), NULL, SUM(COUNT(*)) OVER (PARTITION BY \"order\")) AS orderCount,
162+
IF(ISNULL(family), NULL, SUM(COUNT(*)) OVER (PARTITION BY family)) AS familyCount,
163+
IF(ISNULL(genus), NULL, SUM(COUNT(*)) OVER (PARTITION BY genus)) AS genusCount
154164
FROM
155165
occurrence
156166
WHERE
@@ -172,7 +182,9 @@ query_birdcube <- "SELECT
172182
\"year\",
173183
mgrsCode,
174184
speciesKey,
185+
\"order\",
175186
family,
187+
genus,
176188
species
177189
ORDER BY
178190
\"year\" ASC,
@@ -338,8 +350,9 @@ We select the columns we want in a logical order:
338350

339351
```{r}
340352
abv_data_out_sf <- abv_data_total_sf %>%
341-
select("mgrscode", "year", "specieskey", "species", "family", "n",
342-
"mincoordinateuncertaintyinmeters", "familycount", "geometry")
353+
select("mgrscode", "year", "specieskey", "species", "order", "family",
354+
"genus", "n", "mincoordinateuncertaintyinmeters",
355+
"ordercount", "familycount", "genuscount", "geometry")
343356
abv_data_out <- st_drop_geometry(abv_data_out_sf)
344357
345358
colnames(sampling_framework_abv_sf) <- tolower(
@@ -351,8 +364,9 @@ sampling_framework_out_sf <- sampling_framework_abv_sf %>%
351364
sampling_framework_out <- st_drop_geometry(sampling_framework_out_sf)
352365
353366
birdcube_data_out_sf <- birdcube_data_total_sf %>%
354-
select("mgrscode", "year", "specieskey", "species", "family", "n",
355-
"mincoordinateuncertaintyinmeters", "familycount", "geometry")
367+
select("mgrscode", "year", "specieskey", "species", "order", "family",
368+
"genus", "n", "mincoordinateuncertaintyinmeters",
369+
"ordercount", "familycount", "genuscount", "geometry")
356370
birdcube_data_out <- st_drop_geometry(birdcube_data_out_sf)
357371
```
358372

0 commit comments

Comments
 (0)