impactmesh 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,99 @@
1
+ Metadata-Version: 2.4
2
+ Name: impactmesh
3
+ Version: 0.1.0
4
+ Summary: ImpactMesh package for mesh-based impact analysis
5
+ Author-email: Benedikt Blumenstiel <benedikt.blumenstiel@ibm.com>, Paul Höhn <paul.hoehn@dlr.com>
6
+ License: Apache-2.0
7
+ Requires-Python: >=3.8
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: terratorch>=1.1.1
11
+ Requires-Dist: zarr==2.18.0
12
+ Requires-Dist: numcodecs==0.15.1
13
+ Dynamic: license-file
14
+
15
+ [![arXiv](https://img.shields.io/badge/arXiv-comming_soon-b31b1b?logo=arxiv)](https://arxiv.org/abs/todo)
16
+ [![HuggingFace](https://img.shields.io/badge/Hugging_Face-IBM--ESA--Geospaital-FFD21E?logo=huggingface)](https://huggingface.co/datasets/ibm-esa-geospatial/ImpactMesh-Fire)
17
+ [![IBMblog](https://img.shields.io/badge/Blog-IBM-0F62FE)](https://research.ibm.com/blog/todo)
18
+
19
+ # ImpactMesh
20
+
21
+ ImpactMesh is a large-scale multimodal, multitemporal dataset for flood and wildfire mapping.
22
+ It combines Sentinel-1 SAR, Sentinel-2 optical imagery, and Copernicus DEM with high-quality annotations from Copernicus EMS.
23
+ The dataset covers over 400 events globally with four temporal observations per event.
24
+
25
+ ## Dataset
26
+
27
+ Please find the wildfire subset at https://huggingface.co/datasets/ibm-esa-geospatial/ImpactMesh-Fire and the flood samples at https://huggingface.co/datasets/ibm-esa-geospatial/ImpactMesh-FLood.
28
+ The following map gives an overview of events present in ImpactMesh:
29
+
30
+ ![events_world.png](assets/events_world.png)
31
+
32
+ This repository provides code to build the pytorch dataloader or directly fine-tune a model with [TerraTorch](https://terrastackai.github.io/terratorch/stable/).
33
+
34
+ ## Setup
35
+
36
+ Quick start from pypi:
37
+ ```shell
38
+ pip install impactmesh
39
+ ```
40
+
41
+ Alternatively create a new environment and install TerraTorch and the package from source:
42
+ ```shell
43
+ python -m venv venv
44
+ source venv/bin/activate
45
+ pip install --upgrade pip
46
+ pip install git+https://github.com/terrastackai/terratorch.git@multimodal
47
+ pip install zarr==2.18.0 numcodecs==0.15.1
48
+ pip install -e .
49
+ ```
50
+
51
+ ImpactMesh uses Zarr Version 2.
52
+
53
+ ## Fine-tuning
54
+
55
+ Run training using on of the configs provided in [configs/](configs).
56
+ ```shell
57
+ terratorch fit --config configs/terramind_v1_tiny_impactmesh_fire.yaml
58
+ ```
59
+
60
+ Run the evaluation on the test split.
61
+ ```shell
62
+ terratorch test --config configs/terramind_v1_tiny_impactmesh_fire.yaml -- ckpt output/terramind_tiny_impactmesh_fire/1e-4/best_val_loss.ckpt
63
+ ```
64
+
65
+ Run prediction with the following command:
66
+ ```shell
67
+ terratorch predict -c configs/terramind_v1_tiny_impactmesh_fire.yaml --ckpt path/to/ckeckpoint.pt --predict_output_dir output/impactmesh_fire_predictions
68
+
69
+ # TerraTorch automatically uses a tiled inference. It might still lead to OOM errors. In that case, you can use:
70
+ python impactmesh/run_inference.py -c configs/terramind_v1_tiny_impactmesh_fire.yaml --ckpt path/to/ckeckpoint.pt --output_dir output/impactmesh_fire_predictions
71
+ ```
72
+
73
+ ## Citation
74
+
75
+ Our technical report is released soon!
76
+
77
+ [//]: # (If you use ImpactMesh in your research, please cite the [ImpactMesh]&#40;https://arxiv.org/abs/todo&#41; pre-print.)
78
+
79
+ [//]: # (```text)
80
+
81
+ [//]: # (@article{todo})
82
+
83
+ [//]: # (```)
84
+
85
+ ## Acknowledgement
86
+
87
+ ImpactMesh was developed as part of the FAST‑EO project funded by the European Space Agency Φ‑Lab (contract #4000143501/23/I‑DT).
88
+
89
+ Sentinel-2 Level-2A data were downloaded from Microsoft Planetary Computer and are provided under Copernicus Sentinel license conditions (© European Union 2015–2025, ESA) (https://planetarycomputer.microsoft.com/dataset/sentinel-2-l2a).
90
+
91
+ Sentinel-1 Radiometrically Terrain Corrected (RTC) SAR data were retrieved from Microsoft Planetary Computer (calibrated to GRD and terrain-corrected using PlanetDEM) under Copernicus Sentinel license terms (© European Union 2014–2025) (https://planetarycomputer.microsoft.com/dataset/sentinel-1-rtc).
92
+
93
+ The DEM data is produced using Copernicus WorldDEM-30 © DLR e.V. 2010-2014 and © Airbus Defence and Space GmbH 2014-2018 provided under COPERNICUS by the European Union and ESA; all rights reserved.
94
+
95
+ Annotations were sourced from the Copernicus Emergency Management Service (© European Union, 2012–2025), available at https://emergency.copernicus.eu/.
96
+
97
+ ## License
98
+
99
+ The code and models are release under Apache 2.0. The dataset is released under CC-BY 4.0.
@@ -0,0 +1,85 @@
1
+ [![arXiv](https://img.shields.io/badge/arXiv-comming_soon-b31b1b?logo=arxiv)](https://arxiv.org/abs/todo)
2
+ [![HuggingFace](https://img.shields.io/badge/Hugging_Face-IBM--ESA--Geospaital-FFD21E?logo=huggingface)](https://huggingface.co/datasets/ibm-esa-geospatial/ImpactMesh-Fire)
3
+ [![IBMblog](https://img.shields.io/badge/Blog-IBM-0F62FE)](https://research.ibm.com/blog/todo)
4
+
5
+ # ImpactMesh
6
+
7
+ ImpactMesh is a large-scale multimodal, multitemporal dataset for flood and wildfire mapping.
8
+ It combines Sentinel-1 SAR, Sentinel-2 optical imagery, and Copernicus DEM with high-quality annotations from Copernicus EMS.
9
+ The dataset covers over 400 events globally with four temporal observations per event.
10
+
11
+ ## Dataset
12
+
13
+ Please find the wildfire subset at https://huggingface.co/datasets/ibm-esa-geospatial/ImpactMesh-Fire and the flood samples at https://huggingface.co/datasets/ibm-esa-geospatial/ImpactMesh-FLood.
14
+ The following map gives an overview of events present in ImpactMesh:
15
+
16
+ ![events_world.png](assets/events_world.png)
17
+
18
+ This repository provides code to build the pytorch dataloader or directly fine-tune a model with [TerraTorch](https://terrastackai.github.io/terratorch/stable/).
19
+
20
+ ## Setup
21
+
22
+ Quick start from pypi:
23
+ ```shell
24
+ pip install impactmesh
25
+ ```
26
+
27
+ Alternatively create a new environment and install TerraTorch and the package from source:
28
+ ```shell
29
+ python -m venv venv
30
+ source venv/bin/activate
31
+ pip install --upgrade pip
32
+ pip install git+https://github.com/terrastackai/terratorch.git@multimodal
33
+ pip install zarr==2.18.0 numcodecs==0.15.1
34
+ pip install -e .
35
+ ```
36
+
37
+ ImpactMesh uses Zarr Version 2.
38
+
39
+ ## Fine-tuning
40
+
41
+ Run training using on of the configs provided in [configs/](configs).
42
+ ```shell
43
+ terratorch fit --config configs/terramind_v1_tiny_impactmesh_fire.yaml
44
+ ```
45
+
46
+ Run the evaluation on the test split.
47
+ ```shell
48
+ terratorch test --config configs/terramind_v1_tiny_impactmesh_fire.yaml -- ckpt output/terramind_tiny_impactmesh_fire/1e-4/best_val_loss.ckpt
49
+ ```
50
+
51
+ Run prediction with the following command:
52
+ ```shell
53
+ terratorch predict -c configs/terramind_v1_tiny_impactmesh_fire.yaml --ckpt path/to/ckeckpoint.pt --predict_output_dir output/impactmesh_fire_predictions
54
+
55
+ # TerraTorch automatically uses a tiled inference. It might still lead to OOM errors. In that case, you can use:
56
+ python impactmesh/run_inference.py -c configs/terramind_v1_tiny_impactmesh_fire.yaml --ckpt path/to/ckeckpoint.pt --output_dir output/impactmesh_fire_predictions
57
+ ```
58
+
59
+ ## Citation
60
+
61
+ Our technical report is released soon!
62
+
63
+ [//]: # (If you use ImpactMesh in your research, please cite the [ImpactMesh]&#40;https://arxiv.org/abs/todo&#41; pre-print.)
64
+
65
+ [//]: # (```text)
66
+
67
+ [//]: # (@article{todo})
68
+
69
+ [//]: # (```)
70
+
71
+ ## Acknowledgement
72
+
73
+ ImpactMesh was developed as part of the FAST‑EO project funded by the European Space Agency Φ‑Lab (contract #4000143501/23/I‑DT).
74
+
75
+ Sentinel-2 Level-2A data were downloaded from Microsoft Planetary Computer and are provided under Copernicus Sentinel license conditions (© European Union 2015–2025, ESA) (https://planetarycomputer.microsoft.com/dataset/sentinel-2-l2a).
76
+
77
+ Sentinel-1 Radiometrically Terrain Corrected (RTC) SAR data were retrieved from Microsoft Planetary Computer (calibrated to GRD and terrain-corrected using PlanetDEM) under Copernicus Sentinel license terms (© European Union 2014–2025) (https://planetarycomputer.microsoft.com/dataset/sentinel-1-rtc).
78
+
79
+ The DEM data is produced using Copernicus WorldDEM-30 © DLR e.V. 2010-2014 and © Airbus Defence and Space GmbH 2014-2018 provided under COPERNICUS by the European Union and ESA; all rights reserved.
80
+
81
+ Annotations were sourced from the Copernicus Emergency Management Service (© European Union, 2012–2025), available at https://emergency.copernicus.eu/.
82
+
83
+ ## License
84
+
85
+ The code and models are release under Apache 2.0. The dataset is released under CC-BY 4.0.
File without changes
@@ -0,0 +1,226 @@
1
+
2
+ import logging
3
+ import albumentations as A
4
+ import numpy as np
5
+ from pathlib import Path
6
+ from torchgeo.datamodules import NonGeoDataModule
7
+ from .impactmesh_dataset import ImpactMeshDataset
8
+ from terratorch.datamodules.generic_pixel_wise_data_module import Normalize
9
+ from terratorch.datamodules.generic_multimodal_data_module import MultimodalNormalize, wrap_in_compose_is_list
10
+
11
+ # Dataset statisitcs
12
+ impactmesh_wildfire_means = {
13
+ "S2L2A": [801.325, 861.655, 991.636, 1019.702, 1366.43, 2000.191, 2255.338, 2354.884, 2481.838, 2747.908, 2185.777, 1495.209],
14
+ "S1RTC": [-9.838, -15.465],
15
+ "DEM": [412.745],
16
+ }
17
+ impactmesh_wildfire_stds = {
18
+ "S2L2A": [1960.514, 1732.936, 1494.812, 1384.473, 1385.129, 1309.367, 1322.601, 1352.448, 1336.39, 2379.374, 1145.593, 991.566],
19
+ "S1RTC": [3.505, 3.422],
20
+ "DEM": [354.58],
21
+ }
22
+
23
+ impactmesh_flood_means = {
24
+ "S2L2A": [1223.128, 1251.355, 1423.443, 1408.984, 1786.818, 2448.316, 2685.642, 2745.795, 2817.936, 3194.081, 1964.659, 1399.317],
25
+ "S1RTC": [-9.98, -15.968],
26
+ "DEM": [141.786],
27
+ }
28
+ impactmesh_flood_stds = {
29
+ "S2L2A": [2358.709, 2227.598, 2082.363, 2068.519, 2086.682, 2003.085, 2019.494, 2060.309, 2014.732, 2992.644, 1414.951, 1218.357],
30
+ "S1RTC": [4.24, 4.105],
31
+ "DEM": [189.363],
32
+ }
33
+
34
+
35
+ class ImpactMeshDataModule(NonGeoDataModule):
36
+ """NonGeo LightningDataModule implementation for ImpactMesh."""
37
+
38
+ def __init__(
39
+ self,
40
+ data_root: str,
41
+ batch_size: int = 8,
42
+ num_workers: int = 0,
43
+ means: dict[str, list] = None,
44
+ stds: dict[str, list] = None,
45
+ train_split: str = None,
46
+ val_split: str = None,
47
+ test_split: str = None,
48
+ predict_split: str = None,
49
+ modalities: list[str] = None,
50
+ label_dir: str = "MASK",
51
+ image_grep: dict[str, str] = None,
52
+ label_grep: str = None,
53
+ timesteps: list[int] = None,
54
+ concat_bands: bool = False,
55
+ predict_data_root: str = None,
56
+ train_transform: A.Compose | None | list[A.BasicTransform] = None,
57
+ val_transform: A.Compose | None | list[A.BasicTransform] = None,
58
+ test_transform: A.Compose | None | list[A.BasicTransform] = None,
59
+ no_data_value: float = -9999.,
60
+ no_data_replace: float = None,
61
+ rgb_indices: dict[str, list[int]] = None,
62
+ **kwargs,
63
+ ) -> None:
64
+ """
65
+ Initialize ImpactMeshDataModule.
66
+
67
+ Args:
68
+ data_root (str): Root directory of dataset.
69
+ batch_size (int): Batch size for DataLoaders. Default is 8.
70
+ num_workers (int): Number of workers for data loading. Default is 0.
71
+ means (dict[str, list], optional): Per-modality normalization means. Defaults to dataset statistics.
72
+ stds (dict[str, list], optional): Per-modality normalization stds. Defaults to dataset statistics.
73
+ train_split, val_split, test_split, predict_split (str, optional): Split identifiers.
74
+ Otherwise, run all patches in data_root.
75
+ modalities (list[str], optional): List of input modalities. Defaults to ["S2L2A", "S1RTC", "DEM"].
76
+ label_dir (str): Directory name for labels. Default is "MASK".
77
+ image_grep (dict[str, str], optional): Patterns for image file matching. Default to ImpactMesh pattern.
78
+ label_grep (str, optional): Pattern for label file matching. Default to ImpactMesh pattern.
79
+ timesteps (list[int], optional): Temporal indices to include. Defaults to [0, 1, 2, 3].
80
+ concat_bands (bool): Whether to concatenate bands across modalities. If True, concatenate bands of all
81
+ modalities, otherwise load samples as dict {<modality>: <torch.tensor>}. Defaults to False.
82
+ predict_data_root (str, optional): Root for prediction data.
83
+ train_transform, val_transform, test_transform: List of Albumentations transforms. Defaults to ToTensor.
84
+ no_data_value (float): Value representing missing data. Default is -9999.
85
+ no_data_replace (float, optional): Replacement for missing data (NaN and no_data_value). Default is 0.
86
+ rgb_indices (dict[str, list[int]], optional): RGB band indices per modality.
87
+ **kwargs: Additional arguments for parent class.
88
+ """
89
+ super().__init__(
90
+ ImpactMeshDataset,
91
+ batch_size=batch_size,
92
+ num_workers=num_workers,
93
+ **kwargs,
94
+ )
95
+ self.data_root = Path(data_root)
96
+ self.train_split = train_split
97
+ self.val_split = val_split
98
+ self.test_split = test_split
99
+ self.predict_split = predict_split
100
+ self.modalities = modalities or ["S2L2A", "S1RTC", "DEM"]
101
+ self.label_dir = label_dir
102
+ self.predict_data_root = predict_data_root
103
+ if rgb_indices is not None:
104
+ self.rgb_indices = rgb_indices
105
+ elif concat_bands:
106
+ self.rgb_indices = rgb_indices or {"S2L2A": list(range(12)), "S1RTC": [-3, -2], "DEM": [-1]}
107
+ self.rgb_indices = {m: v for m, v in self.rgb_indices.items() if m in self.modalities}
108
+ else:
109
+ self.rgb_indices = rgb_indices or {m: None for m in self.modalities}
110
+
111
+ self.image_grep = image_grep or {"S2L2A": "_S2L2A.zarr.zip", "S1RTC": "_S1RTC.zarr.zip", "DEM": "_DEM.tif"}
112
+ if label_grep is not None:
113
+ self.label_grep = label_grep
114
+ elif "flood" in str(self.data_root).lower():
115
+ self.label_grep = "_annotation_flood.tif"
116
+ elif "fire" in str(self.data_root).lower():
117
+ self.label_grep = "_annotation_wildfire.tif"
118
+ else:
119
+ raise ValueError(f"Unknown label_grep: {label_grep}. "
120
+ f"Specify a label grep or include disaster type in data root {self.data_root}.")
121
+ self.timesteps = timesteps or [0, 1, 2, 3]
122
+ self.concat_bands = concat_bands
123
+ self.no_data_value = no_data_value
124
+ self.no_data_replace = no_data_replace if no_data_replace is not None else 0
125
+
126
+ self.train_transform = wrap_in_compose_is_list(train_transform, image_modalities=self.modalities)
127
+ self.val_transform = wrap_in_compose_is_list(val_transform, image_modalities=self.modalities)
128
+ self.test_transform = wrap_in_compose_is_list(test_transform, image_modalities=self.modalities)
129
+
130
+ if means is not None and stds is not None:
131
+ pass
132
+ elif "flood" in str(self.data_root).lower():
133
+ means = {m: impactmesh_flood_means[m] for m in self.modalities}
134
+ stds = {m: impactmesh_flood_stds[m] for m in self.modalities}
135
+ elif "fire" in str(self.data_root).lower():
136
+ means = {m: impactmesh_wildfire_means[m] for m in self.modalities}
137
+ stds = {m: impactmesh_wildfire_stds[m] for m in self.modalities}
138
+ else:
139
+ raise ValueError(f"Specify means and std or include disaster type in data root {self.data_root}")
140
+
141
+ if self.concat_bands:
142
+ # Concatenate mean and std values
143
+ self.means = np.concatenate([means[m] for m in self.modalities]).tolist()
144
+ self.stds = np.concatenate([stds[m] for m in self.modalities]).tolist()
145
+
146
+ self.aug = Normalize(self.means, self.stds)
147
+ else:
148
+ # Apply standardization per modality
149
+ self.means = {m: means[m] for m in means.keys()}
150
+ self.stds = {m: stds[m] for m in stds.keys()}
151
+
152
+ self.aug = MultimodalNormalize(self.means, self.stds)
153
+
154
+
155
+ def setup(self, stage: str) -> None:
156
+ """Set up datasets.
157
+
158
+ Args:
159
+ stage: Either fit, validate, test, or predict.
160
+ """
161
+ if stage in ["fit"]:
162
+ self.train_dataset = ImpactMeshDataset(
163
+ data_root=self.data_root,
164
+ split_file=self.train_split,
165
+ modalities=self.modalities,
166
+ label_dir=self.label_dir,
167
+ image_grep=self.image_grep,
168
+ label_grep=self.label_grep,
169
+ timesteps=self.timesteps,
170
+ concat_bands=self.concat_bands,
171
+ transform=self.train_transform,
172
+ no_data_value=self.no_data_value,
173
+ no_data_replace=self.no_data_replace,
174
+ rgb_indices=self.rgb_indices,
175
+ aug=self.aug,
176
+ )
177
+ if stage in ["fit", "validate"]:
178
+ self.val_dataset = ImpactMeshDataset(
179
+ data_root=self.data_root,
180
+ split_file=self.val_split,
181
+ modalities=self.modalities,
182
+ label_dir=self.label_dir,
183
+ image_grep=self.image_grep,
184
+ label_grep=self.label_grep,
185
+ timesteps=self.timesteps,
186
+ concat_bands=self.concat_bands,
187
+ transform=self.val_transform,
188
+ no_data_value=self.no_data_value,
189
+ no_data_replace=self.no_data_replace,
190
+ rgb_indices=self.rgb_indices,
191
+ aug=self.aug,
192
+ )
193
+ if stage in ["test"]:
194
+ self.test_dataset = ImpactMeshDataset(
195
+ data_root=self.data_root,
196
+ split_file=self.test_split,
197
+ modalities=self.modalities,
198
+ label_dir=self.label_dir,
199
+ image_grep=self.image_grep,
200
+ label_grep=self.label_grep,
201
+ timesteps=self.timesteps,
202
+ concat_bands=self.concat_bands,
203
+ transform=self.test_transform,
204
+ no_data_value=self.no_data_value,
205
+ no_data_replace=self.no_data_replace,
206
+ rgb_indices=self.rgb_indices,
207
+ aug=self.aug,
208
+ )
209
+ if stage in ["predict"]:
210
+ if self.predict_data_root is None:
211
+ logging.warning(f"predict_data_root is not specified, using default data_root {self.data_root}.")
212
+ self.predict_dataset = ImpactMeshDataset(
213
+ data_root=self.predict_data_root or self.data_root,
214
+ split_file=self.predict_split,
215
+ modalities=self.modalities,
216
+ label_dir=None,
217
+ image_grep=self.image_grep,
218
+ label_grep=None,
219
+ timesteps=self.timesteps,
220
+ concat_bands=self.concat_bands,
221
+ transform=self.test_transform,
222
+ no_data_value=self.no_data_value,
223
+ no_data_replace=self.no_data_replace,
224
+ rgb_indices=self.rgb_indices,
225
+ aug=self.aug,
226
+ )