Skip to content

Commit 0388e96

Browse files
committed
Update PartitionDefinitionAHN
To new style of partitiondefintion
1 parent f000360 commit 0388e96

File tree

4 files changed

+26
-21
lines changed

4 files changed

+26
-21
lines changed

packages/core/src/bag3d/core/assets/ahn/core.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88

99
logger = get_dagster_logger("ahn")
1010

11-
12-
class PartitionDefinitionAHN(StaticPartitionsDefinition):
13-
def __init__(self):
14-
super().__init__(partition_keys=sorted(list(AHN_TILE_IDS)))
11+
partition_definition_ahn = StaticPartitionsDefinition(sorted(list(AHN_TILE_IDS)))
1512

1613

1714
def format_laz_log(fpath: Path, msg: str) -> str:

packages/core/src/bag3d/core/assets/ahn/download.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88
from bag3d.common.utils.requests import download_file, download_as_str
99
from bag3d.core.assets.ahn.core import (
10-
PartitionDefinitionAHN,
1110
format_laz_log,
1211
download_ahn_index,
1312
ahn_laz_dir,
13+
partition_definition_ahn,
1414
)
1515

1616
logger = get_dagster_logger("ahn.download")
@@ -141,7 +141,7 @@ def tile_index_ahn(context):
141141

142142
@asset(
143143
required_resource_keys={"file_store"},
144-
partitions_def=PartitionDefinitionAHN(),
144+
partitions_def=partition_definition_ahn,
145145
)
146146
def laz_files_ahn3(context, md5_ahn3, tile_index_ahn):
147147
"""AHN3 LAZ files as they are downloaded from PDOK.
@@ -196,7 +196,7 @@ def laz_files_ahn3(context, md5_ahn3, tile_index_ahn):
196196

197197
@asset(
198198
required_resource_keys={"file_store"},
199-
partitions_def=PartitionDefinitionAHN(),
199+
partitions_def=partition_definition_ahn,
200200
)
201201
def laz_files_ahn4(context, md5_ahn4, tile_index_ahn):
202202
"""AHN4 LAZ files as they are downloaded from PDOK.
@@ -254,7 +254,7 @@ def laz_files_ahn4(context, md5_ahn4, tile_index_ahn):
254254

255255
@asset(
256256
required_resource_keys={"file_store"},
257-
partitions_def=PartitionDefinitionAHN(),
257+
partitions_def=partition_definition_ahn,
258258
)
259259
def laz_files_ahn5(context, sha256_ahn5, tile_index_ahn):
260260
"""AHN5 LAZ files as they are downloaded from PDOK.
@@ -322,8 +322,11 @@ def get_checksums(url: str) -> Mapping[str, str]:
322322

323323

324324
def download_ahn_laz(
325-
fpath: Path, url_laz: str = None, url_base: str = None, verify_ssl: bool = False,
326-
nr_retries: int = 5
325+
fpath: Path,
326+
url_laz: str = None,
327+
url_base: str = None,
328+
verify_ssl: bool = False,
329+
nr_retries: int = 5,
327330
) -> LAZDownload:
328331
"""Download an AHN LAZ file from the input url to the given path,
329332
if the file does not exists.
@@ -350,7 +353,10 @@ def download_ahn_laz(
350353
for i in range(nr_retries):
351354
try:
352355
fpath = download_file(
353-
url=url, target_path=fpath, chunk_size=1024 * 1024, verify=verify_ssl
356+
url=url,
357+
target_path=fpath,
358+
chunk_size=1024 * 1024,
359+
verify=verify_ssl,
354360
)
355361
if fpath is None:
356362
# Download failed
@@ -366,10 +372,10 @@ def download_ahn_laz(
366372
file_size = round(fpath.stat().st_size / 1e6, 2)
367373
break
368374
except ConnectionError as e:
369-
if i==4:
375+
if i == 4:
370376
raise e
371377
else:
372-
logger.warning(f"Retrying ({i+1}/5) due to {e}")
378+
logger.warning(f"Retrying ({i + 1}/5) due to {e}")
373379
else: # pragma: no cover
374380
logger.info(format_laz_log(fpath, "File already downloaded"))
375381
success = True

packages/core/src/bag3d/core/assets/ahn/index.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from dagster import asset, Field, get_dagster_logger
22

3-
from bag3d.core.assets.ahn.core import PartitionDefinitionAHN
3+
from bag3d.core.assets.ahn.core import partition_definition_ahn
4+
45

56
logger = get_dagster_logger("ahn.index")
67

8+
79
@asset(
810
config_schema={
911
"tile_size": Field(
@@ -18,7 +20,7 @@
1820
),
1921
},
2022
required_resource_keys={"lastools"},
21-
partitions_def=PartitionDefinitionAHN(),
23+
partitions_def=partition_definition_ahn,
2224
)
2325
def lasindex_ahn3(context, laz_files_ahn3):
2426
"""Append a spatial index to the AHN3 LAZ file, using LASTools's `lasindex`.
@@ -53,7 +55,7 @@ def lasindex_ahn3(context, laz_files_ahn3):
5355
),
5456
},
5557
required_resource_keys={"lastools"},
56-
partitions_def=PartitionDefinitionAHN(),
58+
partitions_def=partition_definition_ahn,
5759
)
5860
def lasindex_ahn4(context, laz_files_ahn4):
5961
"""Append a spatial index to the AHN4 LAZ file, using LASTools's `lasindex`.
@@ -88,7 +90,7 @@ def lasindex_ahn4(context, laz_files_ahn4):
8890
),
8991
},
9092
required_resource_keys={"lastools"},
91-
partitions_def=PartitionDefinitionAHN(),
93+
partitions_def=partition_definition_ahn,
9294
)
9395
def lasindex_ahn5(context, laz_files_ahn5):
9496
"""Append a spatial index to the AHN5 LAZ file, using LASTools's `lasindex`.

packages/core/src/bag3d/core/assets/ahn/metadata.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from bag3d.common.utils.geodata import pdal_info
1010
from bag3d.common.utils.database import create_schema, load_sql
11-
from bag3d.core.assets.ahn.core import PartitionDefinitionAHN
11+
from bag3d.core.assets.ahn.core import partition_definition_ahn
1212

1313

1414
@asset(required_resource_keys={"db_connection"})
@@ -41,7 +41,7 @@ def metadata_table_ahn5(context):
4141
),
4242
},
4343
required_resource_keys={"pdal", "db_connection"},
44-
partitions_def=PartitionDefinitionAHN(),
44+
partitions_def=partition_definition_ahn,
4545
)
4646
def metadata_ahn3(context, laz_files_ahn3, metadata_table_ahn3, tile_index_ahn):
4747
"""Metadata of the AHN3 LAZ file, retrieved from the PDOK tile index and
@@ -64,7 +64,7 @@ def metadata_ahn3(context, laz_files_ahn3, metadata_table_ahn3, tile_index_ahn):
6464
),
6565
},
6666
required_resource_keys={"pdal", "db_connection"},
67-
partitions_def=PartitionDefinitionAHN(),
67+
partitions_def=partition_definition_ahn,
6868
)
6969
def metadata_ahn4(context, laz_files_ahn4, metadata_table_ahn4, tile_index_ahn):
7070
"""Metadata of the AHN4 LAZ file, retrieved from the PDOK tile index and
@@ -87,7 +87,7 @@ def metadata_ahn4(context, laz_files_ahn4, metadata_table_ahn4, tile_index_ahn):
8787
),
8888
},
8989
required_resource_keys={"pdal", "db_connection"},
90-
partitions_def=PartitionDefinitionAHN(),
90+
partitions_def=partition_definition_ahn,
9191
)
9292
def metadata_ahn5(context, laz_files_ahn5, metadata_table_ahn5, tile_index_ahn):
9393
"""Metadata of the AHN5 LAZ file, retrieved from the PDOK tile index and

0 commit comments

Comments
 (0)