|
1 |
| -from dagster import asset, Field, get_dagster_logger |
| 1 | +from dagster import asset, get_dagster_logger, Config |
| 2 | +from pydantic import Field |
2 | 3 |
|
3 | 4 | from bag3d.core.assets.ahn.core import partition_definition_ahn
|
4 | 5 |
|
5 | 6 |
|
6 | 7 | logger = get_dagster_logger("ahn.index")
|
7 | 8 |
|
8 | 9 |
|
| 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 | + |
9 | 25 | @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 | 26 | required_resource_keys={"lastools"},
|
29 | 27 | partitions_def=partition_definition_ahn,
|
30 | 28 | )
|
31 |
| -def lasindex_ahn3(context, laz_files_ahn3): |
| 29 | +def lasindex_ahn3(context, config: LasIndexConfig, laz_files_ahn3): |
32 | 30 | """Append a spatial index to the AHN3 LAZ file, using LASTools's `lasindex`.
|
33 | 31 |
|
34 | 32 | See https://lastools.osgeo.org/download/lasindex_README.txt.
|
35 | 33 | """
|
36 |
| - silent = not context.op_execution_context.op_config["verbose"] |
| 34 | + silent = not config.verbose |
37 | 35 | cmd_list = [
|
38 | 36 | "{exe}",
|
39 | 37 | "-i {local_path}",
|
40 | 38 | "-tile_size",
|
41 |
| - str(context.op_execution_context.op_config["tile_size"]), |
| 39 | + str(config.tile_size), |
42 | 40 | ]
|
43 |
| - if context.op_execution_context.op_config["force"] is False: |
| 41 | + if not config.force: |
44 | 42 | cmd_list.append("-dont_reindex")
|
45 | 43 | context.resources.lastools.app.execute(
|
46 | 44 | "lasindex", " ".join(cmd_list), local_path=laz_files_ahn3.path, silent=silent
|
47 | 45 | )
|
48 | 46 |
|
49 | 47 |
|
50 | 48 | @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 |
| - }, |
69 | 49 | required_resource_keys={"lastools"},
|
70 | 50 | partitions_def=partition_definition_ahn,
|
71 | 51 | )
|
72 |
| -def lasindex_ahn4(context, laz_files_ahn4): |
| 52 | +def lasindex_ahn4(context, config: LasIndexConfig, laz_files_ahn4): |
73 | 53 | """Append a spatial index to the AHN4 LAZ file, using LASTools's `lasindex`.
|
74 | 54 |
|
75 | 55 | See https://lastools.osgeo.org/download/lasindex_README.txt.
|
76 | 56 | """
|
77 |
| - silent = not context.op_execution_context.op_config["verbose"] |
| 57 | + silent = not config.verbose |
78 | 58 | cmd_list = [
|
79 | 59 | "{exe}",
|
80 | 60 | "-i {local_path}",
|
81 | 61 | "-tile_size",
|
82 |
| - str(context.op_execution_context.op_config["tile_size"]), |
| 62 | + str(config.tile_size), |
83 | 63 | ]
|
84 |
| - if context.op_execution_context.op_config["force"] is False: |
| 64 | + if not config.force: |
85 | 65 | cmd_list.append("-dont_reindex")
|
86 | 66 | context.resources.lastools.app.execute(
|
87 | 67 | "lasindex", " ".join(cmd_list), local_path=laz_files_ahn4.path, silent=silent
|
88 | 68 | )
|
89 | 69 |
|
90 | 70 |
|
91 | 71 | @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 |
| - }, |
110 | 72 | required_resource_keys={"lastools"},
|
111 | 73 | partitions_def=partition_definition_ahn,
|
112 | 74 | )
|
113 |
| -def lasindex_ahn5(context, laz_files_ahn5): |
| 75 | +def lasindex_ahn5(context, config: LasIndexConfig, laz_files_ahn5): |
114 | 76 | """Append a spatial index to the AHN5 LAZ file, using LASTools's `lasindex`.
|
115 | 77 |
|
116 | 78 | See https://lastools.osgeo.org/download/lasindex_README.txt.
|
117 | 79 | """
|
118 |
| - silent = not context.op_execution_context.op_config["verbose"] |
| 80 | + silent = not config.verbose |
119 | 81 | cmd_list = [
|
120 | 82 | "{exe}",
|
121 | 83 | "-i {local_path}",
|
122 | 84 | "-tile_size",
|
123 |
| - str(context.op_execution_context.op_config["tile_size"]), |
| 85 | + str(config.tile_size), |
124 | 86 | ]
|
125 |
| - if context.op_execution_context.op_config["force"] is False: |
| 87 | + if not config.force: |
126 | 88 | cmd_list.append("-dont_reindex")
|
127 | 89 | context.resources.lastools.app.execute(
|
128 | 90 | "lasindex", " ".join(cmd_list), local_path=laz_files_ahn5.path, silent=silent
|
|
0 commit comments