Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- ES-CL: the ITACyL server is https-only, the 2025 shapefiles sit in province subfolders, and C_REFREC is the identifier
- A test refuses a fixture above 5 MB, committed or merely lying in the fixture folder, because a failing convert test downloads the real source there
- ES-MD: find RECINTO.shp wherever the archive puts it
- BE-WAL: match the crop by name where EuroCrops' table leaves the code empty, which covered 6.79% of the collection
- Update vecorel-cli to v0.2.17:
- GeoJSON is read as UTF-8 as the format mandates, instead of the platform locale (cp1252 on Windows mangled umlauts)
- GeoJSON files with a byte order mark no longer fail to read
Expand Down
3 changes: 3 additions & 0 deletions fiboa_cli/datasets/be_wal.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class Converter(AdminConverterMixin, AddHCATMixin, FiboaBaseConverter):
"determination:datetime": "determination:datetime",
}
ec_mapping_csv = "be_wal_all_years.csv"
# 208 of that table's 298 rows carry no code, only the crop name, so every
# crop whose coded row is missing went unmapped: 23,216 fields over 59 codes.
ec_mapping_name_fallback = True
column_additions = {
"determination:datetime": "2022-01-01T00:00:00Z",
}
Expand Down
17 changes: 17 additions & 0 deletions fiboa_cli/datasets/commons/hcat.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class AddHCATMixin:
"""

ec_mapping_csv: Optional[str] = None # TODO rename to hcat_mapping_csv
# Match on the crop name where the table has no row for the code:
# be_wal_all_years.csv leaves original_code empty in 208 of its 298 rows.
ec_mapping_name_fallback = False
mapping_file = None
ec_mapping: Optional[list[dict]] = None # TODO rename to hcat_mapping

Expand Down Expand Up @@ -70,12 +73,26 @@ def add_hcat(self, gdf):
def map_to(attribute):
return {e[from_code]: e[attribute] or None for e in self.ec_mapping}

name_col = None
if self.ec_mapping_name_fallback and from_code == "original_code":
name_col = self.get_code_column(gdf, "crop:name")

def map_by_name(attribute):
# Three Walloon crops carry a trailing space in the table.
return {
(e["original_name"] or "").strip(): e[attribute] or None
for e in self.ec_mapping
if not (e["original_code"] or "").strip()
}

col = None
for k, v in zip(
self.hcat_columns.keys(), ("translated_name", "HCAT3_name", "HCAT3_code")
):
if v in self.ec_mapping[0]:
col = crop_code_col.map(map_to(v))
if name_col is not None:
col = col.fillna(name_col.str.strip().map(map_by_name(v)))
gdf[k] = col
assert np.unique(col[~col.isna()]).size > 1, "No HCAT crops mapped"

Expand Down
Loading