Skip to content

Commit 28cbbb3

Browse files
committed
Set lasindex tile_size default 10; Refactor asset config
1 parent 92c2ace commit 28cbbb3

File tree

1 file changed

+29
-67
lines changed
  • packages/core/src/bag3d/core/assets/ahn

1 file changed

+29
-67
lines changed

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

Lines changed: 29 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,128 +1,90 @@
1-
from dagster import asset, Field, get_dagster_logger
1+
from dagster import asset, get_dagster_logger, Config
2+
from pydantic import Field
23

34
from bag3d.core.assets.ahn.core import partition_definition_ahn
45

56

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

89

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+
)
23+
24+
925
@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-
},
2826
required_resource_keys={"lastools"},
2927
partitions_def=partition_definition_ahn,
3028
)
31-
def lasindex_ahn3(context, laz_files_ahn3):
29+
def lasindex_ahn3(context, config: LasIndexConfig, laz_files_ahn3):
3230
"""Append a spatial index to the AHN3 LAZ file, using LASTools's `lasindex`.
3331
3432
See https://lastools.osgeo.org/download/lasindex_README.txt.
3533
"""
36-
silent = not context.op_execution_context.op_config["verbose"]
34+
silent = not config.verbose
3735
cmd_list = [
3836
"{exe}",
3937
"-i {local_path}",
4038
"-tile_size",
41-
str(context.op_execution_context.op_config["tile_size"]),
39+
str(config.tile_size),
4240
]
43-
if context.op_execution_context.op_config["force"] is False:
41+
if not config.force:
4442
cmd_list.append("-dont_reindex")
4543
context.resources.lastools.app.execute(
4644
"lasindex", " ".join(cmd_list), local_path=laz_files_ahn3.path, silent=silent
4745
)
4846

4947

5048
@asset(
51-
config_schema={
52-
"tile_size": Field(
53-
int,
54-
default_value=250,
55-
description="Set smallest spatial area indexed to tile_size by tile_size units.",
56-
),
57-
"force": Field(
58-
bool,
59-
default_value=False,
60-
description="Force the re-index the file, even if it is already indexed.",
61-
),
62-
"verbose": Field(
63-
bool,
64-
default_value=False,
65-
is_required=False,
66-
description="Output stdout/stderr from lasindex",
67-
),
68-
},
6949
required_resource_keys={"lastools"},
7050
partitions_def=partition_definition_ahn,
7151
)
72-
def lasindex_ahn4(context, laz_files_ahn4):
52+
def lasindex_ahn4(context, config: LasIndexConfig, laz_files_ahn4):
7353
"""Append a spatial index to the AHN4 LAZ file, using LASTools's `lasindex`.
7454
7555
See https://lastools.osgeo.org/download/lasindex_README.txt.
7656
"""
77-
silent = not context.op_execution_context.op_config["verbose"]
57+
silent = not config.verbose
7858
cmd_list = [
7959
"{exe}",
8060
"-i {local_path}",
8161
"-tile_size",
82-
str(context.op_execution_context.op_config["tile_size"]),
62+
str(config.tile_size),
8363
]
84-
if context.op_execution_context.op_config["force"] is False:
64+
if not config.force:
8565
cmd_list.append("-dont_reindex")
8666
context.resources.lastools.app.execute(
8767
"lasindex", " ".join(cmd_list), local_path=laz_files_ahn4.path, silent=silent
8868
)
8969

9070

9171
@asset(
92-
config_schema={
93-
"tile_size": Field(
94-
int,
95-
default_value=250,
96-
description="Set smallest spatial area indexed to tile_size by tile_size units.",
97-
),
98-
"force": Field(
99-
bool,
100-
default_value=False,
101-
description="Force the re-index the file, even if it is already indexed.",
102-
),
103-
"verbose": Field(
104-
bool,
105-
default_value=False,
106-
is_required=False,
107-
description="Output stdout/stderr from lasindex",
108-
),
109-
},
11072
required_resource_keys={"lastools"},
11173
partitions_def=partition_definition_ahn,
11274
)
113-
def lasindex_ahn5(context, laz_files_ahn5):
75+
def lasindex_ahn5(context, config: LasIndexConfig, laz_files_ahn5):
11476
"""Append a spatial index to the AHN5 LAZ file, using LASTools's `lasindex`.
11577
11678
See https://lastools.osgeo.org/download/lasindex_README.txt.
11779
"""
118-
silent = not context.op_execution_context.op_config["verbose"]
80+
silent = not config.verbose
11981
cmd_list = [
12082
"{exe}",
12183
"-i {local_path}",
12284
"-tile_size",
123-
str(context.op_execution_context.op_config["tile_size"]),
85+
str(config.tile_size),
12486
]
125-
if context.op_execution_context.op_config["force"] is False:
87+
if not config.force:
12688
cmd_list.append("-dont_reindex")
12789
context.resources.lastools.app.execute(
12890
"lasindex", " ".join(cmd_list), local_path=laz_files_ahn5.path, silent=silent

0 commit comments

Comments
 (0)