Skip to content

Commit bf3e85e

Browse files
authored
Merge pull request #297 from 3DBAG/fix/lasindex-append-tile-size
Refactor and optimize lasindex behavior
2 parents 12a986c + e48e4c4 commit bf3e85e

File tree

1 file changed

+46
-97
lines changed
  • packages/core/src/bag3d/core/assets/ahn

1 file changed

+46
-97
lines changed
Lines changed: 46 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,132 +1,81 @@
1-
from dagster import asset, Field, get_dagster_logger
1+
from dagster import asset, get_dagster_logger, Config, AssetExecutionContext
2+
from pydantic import Field
23

34
from bag3d.core.assets.ahn.core import partition_definition_ahn
4-
5+
from bag3d.core.assets.ahn.download import LAZDownload
56

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

89

9-
@asset(
10-
config_schema={
11-
"tile_size": Field(
12-
int,
13-
default_value=250,
14-
description="Set smallest spatial area indexed to tile_size by tile_size units.",
15-
),
16-
"force": Field(
17-
bool,
18-
default_value=False,
19-
description="Force the re-index the file, even if it is already indexed.",
20-
),
21-
"verbose": Field(
22-
bool,
23-
default_value=False,
24-
is_required=False,
25-
description="Output stdout/stderr from lasindex",
26-
),
27-
},
28-
required_resource_keys={"lastools"},
29-
partitions_def=partition_definition_ahn,
30-
)
31-
def lasindex_ahn3(context, laz_files_ahn3):
32-
"""Append a spatial index to the AHN3 LAZ file, using LASTools's `lasindex`.
10+
class LasIndexConfig(Config):
11+
tile_size: int = Field(
12+
default=10,
13+
description="Set smallest spatial area indexed to tile_size by tile_size units.",
14+
)
15+
force: bool = Field(
16+
default=False,
17+
description="Force re-index the file, even if it is already indexed.",
18+
)
19+
verbose: bool = Field(
20+
default=False,
21+
description="Output stdout/stderr from lasindex",
22+
)
3323

34-
See https://lastools.osgeo.org/download/lasindex_README.txt.
35-
"""
36-
silent = not context.op_execution_context.op_config["verbose"]
24+
25+
def run_lasindex(
26+
context: AssetExecutionContext, config: LasIndexConfig, lazdownload: LAZDownload
27+
):
28+
silent = not config.verbose
3729
cmd_list = [
3830
"{exe}",
3931
"-i {local_path}",
40-
"-append",
4132
"-tile_size",
42-
str(context.op_execution_context.op_config["tile_size"]),
33+
str(config.tile_size),
4334
]
44-
if context.op_execution_context.op_config["force"] is False:
35+
if not config.force:
4536
cmd_list.append("-dont_reindex")
4637
context.resources.lastools.app.execute(
47-
"lasindex", " ".join(cmd_list), local_path=laz_files_ahn3.path, silent=silent
38+
"lasindex", " ".join(cmd_list), local_path=lazdownload.path, silent=silent
4839
)
4940

5041

5142
@asset(
52-
config_schema={
53-
"tile_size": Field(
54-
int,
55-
default_value=250,
56-
description="Set smallest spatial area indexed to tile_size by tile_size units.",
57-
),
58-
"force": Field(
59-
bool,
60-
default_value=False,
61-
description="Force the re-index the file, even if it is already indexed.",
62-
),
63-
"verbose": Field(
64-
bool,
65-
default_value=False,
66-
is_required=False,
67-
description="Output stdout/stderr from lasindex",
68-
),
69-
},
7043
required_resource_keys={"lastools"},
7144
partitions_def=partition_definition_ahn,
7245
)
73-
def lasindex_ahn4(context, 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+
):
7463
"""Append a spatial index to the AHN4 LAZ file, using LASTools's `lasindex`.
7564
7665
See https://lastools.osgeo.org/download/lasindex_README.txt.
7766
"""
78-
silent = not context.op_execution_context.op_config["verbose"]
79-
cmd_list = [
80-
"{exe}",
81-
"-i {local_path}",
82-
"-append",
83-
"-tile_size",
84-
str(context.op_execution_context.op_config["tile_size"]),
85-
]
86-
if context.op_execution_context.op_config["force"] is False:
87-
cmd_list.append("-dont_reindex")
88-
context.resources.lastools.app.execute(
89-
"lasindex", " ".join(cmd_list), local_path=laz_files_ahn4.path, silent=silent
90-
)
67+
run_lasindex(context, config, laz_files_ahn4)
9168

9269

9370
@asset(
94-
config_schema={
95-
"tile_size": Field(
96-
int,
97-
default_value=250,
98-
description="Set smallest spatial area indexed to tile_size by tile_size units.",
99-
),
100-
"force": Field(
101-
bool,
102-
default_value=False,
103-
description="Force the re-index the file, even if it is already indexed.",
104-
),
105-
"verbose": Field(
106-
bool,
107-
default_value=False,
108-
is_required=False,
109-
description="Output stdout/stderr from lasindex",
110-
),
111-
},
11271
required_resource_keys={"lastools"},
11372
partitions_def=partition_definition_ahn,
11473
)
115-
def lasindex_ahn5(context, laz_files_ahn5):
74+
def lasindex_ahn5(
75+
context: AssetExecutionContext, config: LasIndexConfig, laz_files_ahn5: LAZDownload
76+
):
11677
"""Append a spatial index to the AHN5 LAZ file, using LASTools's `lasindex`.
11778
11879
See https://lastools.osgeo.org/download/lasindex_README.txt.
11980
"""
120-
silent = not context.op_execution_context.op_config["verbose"]
121-
cmd_list = [
122-
"{exe}",
123-
"-i {local_path}",
124-
"-append",
125-
"-tile_size",
126-
str(context.op_execution_context.op_config["tile_size"]),
127-
]
128-
if context.op_execution_context.op_config["force"] is False:
129-
cmd_list.append("-dont_reindex")
130-
context.resources.lastools.app.execute(
131-
"lasindex", " ".join(cmd_list), local_path=laz_files_ahn5.path, silent=silent
132-
)
81+
run_lasindex(context, config, laz_files_ahn5)

0 commit comments

Comments
 (0)