|
1 |
| -from dagster import asset, Field, get_dagster_logger |
| 1 | +from dagster import asset, get_dagster_logger, Config, AssetExecutionContext |
| 2 | +from pydantic import Field |
2 | 3 |
|
3 | 4 | from bag3d.core.assets.ahn.core import partition_definition_ahn
|
4 |
| - |
| 5 | +from bag3d.core.assets.ahn.download import LAZDownload |
5 | 6 |
|
6 | 7 | logger = get_dagster_logger("ahn.index")
|
7 | 8 |
|
8 | 9 |
|
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 | + ) |
33 | 23 |
|
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 |
37 | 29 | cmd_list = [
|
38 | 30 | "{exe}",
|
39 | 31 | "-i {local_path}",
|
40 |
| - "-append", |
41 | 32 | "-tile_size",
|
42 |
| - str(context.op_execution_context.op_config["tile_size"]), |
| 33 | + str(config.tile_size), |
43 | 34 | ]
|
44 |
| - if context.op_execution_context.op_config["force"] is False: |
| 35 | + if not config.force: |
45 | 36 | cmd_list.append("-dont_reindex")
|
46 | 37 | 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 |
48 | 39 | )
|
49 | 40 |
|
50 | 41 |
|
51 | 42 | @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 |
| - }, |
70 | 43 | required_resource_keys={"lastools"},
|
71 | 44 | partitions_def=partition_definition_ahn,
|
72 | 45 | )
|
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 | +): |
74 | 63 | """Append a spatial index to the AHN4 LAZ file, using LASTools's `lasindex`.
|
75 | 64 |
|
76 | 65 | See https://lastools.osgeo.org/download/lasindex_README.txt.
|
77 | 66 | """
|
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) |
91 | 68 |
|
92 | 69 |
|
93 | 70 | @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 |
| - }, |
112 | 71 | required_resource_keys={"lastools"},
|
113 | 72 | partitions_def=partition_definition_ahn,
|
114 | 73 | )
|
115 |
| -def lasindex_ahn5(context, laz_files_ahn5): |
| 74 | +def lasindex_ahn5( |
| 75 | + context: AssetExecutionContext, config: LasIndexConfig, laz_files_ahn5: LAZDownload |
| 76 | +): |
116 | 77 | """Append a spatial index to the AHN5 LAZ file, using LASTools's `lasindex`.
|
117 | 78 |
|
118 | 79 | See https://lastools.osgeo.org/download/lasindex_README.txt.
|
119 | 80 | """
|
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