Skip to content

Commit e48e4c4

Browse files
committed
Refactor lasindex runner
1 parent 28cbbb3 commit e48e4c4

File tree

1 file changed

+28
-38
lines changed
  • packages/core/src/bag3d/core/assets/ahn

1 file changed

+28
-38
lines changed
Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from dagster import asset, get_dagster_logger, Config
1+
from dagster import asset, get_dagster_logger, Config, AssetExecutionContext
22
from pydantic import Field
33

44
from bag3d.core.assets.ahn.core import partition_definition_ahn
5-
5+
from bag3d.core.assets.ahn.download import LAZDownload
66

77
logger = get_dagster_logger("ahn.index")
88

@@ -22,15 +22,9 @@ class LasIndexConfig(Config):
2222
)
2323

2424

25-
@asset(
26-
required_resource_keys={"lastools"},
27-
partitions_def=partition_definition_ahn,
28-
)
29-
def lasindex_ahn3(context, config: LasIndexConfig, laz_files_ahn3):
30-
"""Append a spatial index to the AHN3 LAZ file, using LASTools's `lasindex`.
31-
32-
See https://lastools.osgeo.org/download/lasindex_README.txt.
33-
"""
25+
def run_lasindex(
26+
context: AssetExecutionContext, config: LasIndexConfig, lazdownload: LAZDownload
27+
):
3428
silent = not config.verbose
3529
cmd_list = [
3630
"{exe}",
@@ -41,51 +35,47 @@ def lasindex_ahn3(context, config: LasIndexConfig, laz_files_ahn3):
4135
if not config.force:
4236
cmd_list.append("-dont_reindex")
4337
context.resources.lastools.app.execute(
44-
"lasindex", " ".join(cmd_list), local_path=laz_files_ahn3.path, silent=silent
38+
"lasindex", " ".join(cmd_list), local_path=lazdownload.path, silent=silent
4539
)
4640

4741

4842
@asset(
4943
required_resource_keys={"lastools"},
5044
partitions_def=partition_definition_ahn,
5145
)
52-
def lasindex_ahn4(context, config: LasIndexConfig, laz_files_ahn4):
46+
def lasindex_ahn3(
47+
context: AssetExecutionContext, config: LasIndexConfig, laz_files_ahn3: LAZDownload
48+
):
49+
"""Append a spatial index to the AHN3 LAZ file, using LASTools's `lasindex`.
50+
51+
See https://lastools.osgeo.org/download/lasindex_README.txt.
52+
"""
53+
run_lasindex(context, config, laz_files_ahn3)
54+
55+
56+
@asset(
57+
required_resource_keys={"lastools"},
58+
partitions_def=partition_definition_ahn,
59+
)
60+
def lasindex_ahn4(
61+
context: AssetExecutionContext, config: LasIndexConfig, laz_files_ahn4: LAZDownload
62+
):
5363
"""Append a spatial index to the AHN4 LAZ file, using LASTools's `lasindex`.
5464
5565
See https://lastools.osgeo.org/download/lasindex_README.txt.
5666
"""
57-
silent = not config.verbose
58-
cmd_list = [
59-
"{exe}",
60-
"-i {local_path}",
61-
"-tile_size",
62-
str(config.tile_size),
63-
]
64-
if not config.force:
65-
cmd_list.append("-dont_reindex")
66-
context.resources.lastools.app.execute(
67-
"lasindex", " ".join(cmd_list), local_path=laz_files_ahn4.path, silent=silent
68-
)
67+
run_lasindex(context, config, laz_files_ahn4)
6968

7069

7170
@asset(
7271
required_resource_keys={"lastools"},
7372
partitions_def=partition_definition_ahn,
7473
)
75-
def lasindex_ahn5(context, config: LasIndexConfig, laz_files_ahn5):
74+
def lasindex_ahn5(
75+
context: AssetExecutionContext, config: LasIndexConfig, laz_files_ahn5: LAZDownload
76+
):
7677
"""Append a spatial index to the AHN5 LAZ file, using LASTools's `lasindex`.
7778
7879
See https://lastools.osgeo.org/download/lasindex_README.txt.
7980
"""
80-
silent = not config.verbose
81-
cmd_list = [
82-
"{exe}",
83-
"-i {local_path}",
84-
"-tile_size",
85-
str(config.tile_size),
86-
]
87-
if not config.force:
88-
cmd_list.append("-dont_reindex")
89-
context.resources.lastools.app.execute(
90-
"lasindex", " ".join(cmd_list), local_path=laz_files_ahn5.path, silent=silent
91-
)
81+
run_lasindex(context, config, laz_files_ahn5)

0 commit comments

Comments
 (0)