Skip to content

Commit 2135ffd

Browse files
committed
Add "total_fish_shellfish_landings" table to populated places layer
1 parent 37cf11f commit 2135ffd

4 files changed

Lines changed: 78 additions & 0 deletions

File tree

qgreenland/config/cfg-lock.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2109,6 +2109,13 @@
21092109
"https://bank.stat.gl:443/sq/e38caec2-e806-4a9d-9a01-59f021282b56"
21102110
],
21112111
"verify_tls": true
2112+
},
2113+
"total_landings_fish_shellfish": {
2114+
"id": "total_landings_fish_shellfish",
2115+
"urls": [
2116+
"https://bank.stat.gl:443/sq/c4ce17d8-2dec-4889-887b-9e34f42e28ed"
2117+
],
2118+
"verify_tls": true
21122119
}
21132120
},
21142121
"id": "statbank",
@@ -3920,6 +3927,14 @@
39203927
"id": "statbank"
39213928
}
39223929
},
3930+
{
3931+
"asset": {
3932+
"id": "total_landings_fish_shellfish"
3933+
},
3934+
"dataset": {
3935+
"id": "statbank"
3936+
}
3937+
},
39233938
{
39243939
"asset": {
39253940
"id": "only"

qgreenland/config/datasets/statbank.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@
3434
# This URL returns a csv file `FIXFLEET.csv` that has data for 2020-2025
3535
urls=["https://bank.stat.gl:443/sq/0cfea73a-81bd-4d47-b98b-36148097173c"],
3636
),
37+
# This asset from the "Total landings of fish and shellfish by district
38+
# and vessel segment" table.
39+
HttpAsset(
40+
id="total_landings_fish_shellfish",
41+
# This URL returns a csv file `FIX012.csv` that has monthly data for 2012-2026
42+
urls=["https://bank.stat.gl:443/sq/c4ce17d8-2dec-4889-887b-9e34f42e28ed"],
43+
),
3744
],
3845
metadata={
3946
"title": "Statistics Greenland",

qgreenland/config/helpers/layers/populated_places.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,48 @@ def prepare_fishing_vessels(*, input_dir: str, places):
303303
return fishing_vessels
304304

305305

306+
def prepare_total_fish_shellfish_landings(*, input_dir: str, places):
307+
from pathlib import Path
308+
309+
import geopandas as gpd
310+
311+
fs_landings = gpd.read_file(Path(input_dir) / "FIX012.csv")
312+
313+
# Add start/end date cols
314+
fs_landings = _start_and_end_date_cols_for_monthly_data(fs_landings)
315+
316+
# Rename count col
317+
fs_landings = fs_landings.rename(
318+
columns={
319+
"Total landings of fish and shellfish": "landings_fish_and_shellfish_tonnes",
320+
}
321+
)
322+
# Ensure count is cast as int
323+
fs_landings["landings_fish_and_shellfish_tonnes"] = fs_landings[
324+
"landings_fish_and_shellfish_tonnes"
325+
].astype(int)
326+
327+
# Drop unnecessary enhed (units) col
328+
fs_landings = fs_landings.drop(columns=["enhed"])
329+
330+
# Setup place mapping
331+
districts = set(fs_landings["district"])
332+
district_place_mapping = {}
333+
for district in districts:
334+
matches = places[
335+
(places["label"].str.lower() == district.lower())
336+
# Filter for towns, which are the seat of each district and should match
337+
# the District name given in the fishing vessels data.
338+
& (places["category"] == "town")
339+
]
340+
assert len(matches) == 1
341+
district_place_mapping[district] = int(matches.id.values[0])
342+
343+
fs_landings["place_id"] = fs_landings["district"].map(district_place_mapping)
344+
345+
return fs_landings
346+
347+
306348
def process_populated_places(*, input_dir: str, output_dir: str):
307349
"""Combine populated places data with statistics from statbank.
308350
@@ -328,6 +370,10 @@ def process_populated_places(*, input_dir: str, output_dir: str):
328370

329371
fishing_vessels = prepare_fishing_vessels(input_dir=input_dir, places=places)
330372

373+
fs_landings = prepare_total_fish_shellfish_landings(
374+
input_dir=input_dir, places=places
375+
)
376+
331377
# postprocess places to remove some columns we no longer need
332378
# ("Indbyggertal_2016" - the population in 2016 - is used by
333379
# `prepare_cruise_passengers`).
@@ -359,3 +405,8 @@ def process_populated_places(*, input_dir: str, output_dir: str):
359405
"fishing_vessels",
360406
conn,
361407
)
408+
409+
fs_landings.to_sql(
410+
"total_fish_shellfish_landings",
411+
conn,
412+
)

qgreenland/config/layers/Places/populated_places.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@
5454
dataset=statbank,
5555
asset=statbank.assets["fishing_vessels"],
5656
),
57+
# This input provides numbers fish/shellfish caught
58+
LayerInput(
59+
dataset=statbank,
60+
asset=statbank.assets["total_landings_fish_shellfish"],
61+
),
5762
# This input provides a multipolygon of municipalities and gives us the
5863
# municipality name for each populated place. (gpkg)
5964
LayerInput(

0 commit comments

Comments
 (0)