Skip to content

Commit

Permalink
Implement a working native pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
relativityhd committed Oct 18, 2024
1 parent 77bac8a commit 950bc2d
Show file tree
Hide file tree
Showing 29 changed files with 467 additions and 678 deletions.
10 changes: 10 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Note: The sub-headings / sections are optional and are removed from the config parser anyway. The only important thing is the [darts] heading
[darts.paths]
input-data-dir = "data/input"
output-data-dir = "data/output"
model-dir = "models"

[darts.segmentation]
patch-size = 1024
overlap = 128
batch-size = 2
4 changes: 3 additions & 1 deletion darts-export/src/darts_export/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# noqa: D104
"""Dataset export for the DARTS dataset."""

from darts_export.inference import InferenceResultWriter as InferenceResultWriter
Empty file.
55 changes: 0 additions & 55 deletions darts-nextgen/src/darts_nextgen/native.py

This file was deleted.

109 changes: 0 additions & 109 deletions darts-nextgen/src/darts_nextgen/run.py

This file was deleted.

5 changes: 3 additions & 2 deletions darts-postprocessing/src/darts_postprocessing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
def hello() -> str:
return "Hello from darts-postprocessing!"
"""Postprocessing steps for the DARTS dataset."""

from darts_postprocessing.prepare_export import prepare_export as prepare_export
10 changes: 1 addition & 9 deletions darts-preprocessing/src/darts_preprocessing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
"""Data preprocessing and feature engineering for the DARTS dataset."""


def hello() -> str:
"""Say hello to the user.
Returns:
str: Greating message.
"""
return "Hello from darts-preprocessing!"
from darts_preprocessing.preprocess import load_and_preprocess_planet_scene as load_and_preprocess_planet_scene
52 changes: 52 additions & 0 deletions darts-preprocessing/src/darts_preprocessing/data_sources/planet.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,55 @@ def load_planet_scene(fpath: str | Path) -> xr.Dataset:
ds_planet = xr.merge(datasets)
logger.debug(f"Loaded Planet scene in {time.time() - start_time} seconds.")
return ds_planet


def load_planet_masks(fpath: str | Path) -> xr.Dataset:
"""Load the valid and quality data masks from a Planet scene.
Args:
fpath (str | Path): The file path to the Planet scene from which to derive the masks.
Raises:
FileNotFoundError: If no matching UDM-2 TIFF file is found in the specified path.
Returns:
xr.Dataset: A merged xarray Dataset containing two data masks:
- 'valid_data_mask': A mask indicating valid (1) and no data (0).
- 'quality_data_mask': A mask indicating high quality (1) and low quality (0).
Notes:
- The function utilizes the `get_planet_udm2path_from_planet_scene_path`
to obtain the path to the UDM (User Data Model) file.
- It uses `rasterio` to read the UDM file and `xarray` for handling
"""
start_time = time.time()
logger.debug(f"Loading data masks from {fpath}")
# Convert to Path object if a string is provided
fpath = fpath if isinstance(fpath, str) else Path(fpath)

# Get imagepath
udm_path = next(fpath.glob("*_udm2.tif"))
if not udm_path:
raise FileNotFoundError(f"No matching UDM-2 TIFF files found in {fpath} (.glob('*_udm2.tif'))")

da_udm = xr.open_dataarray(udm_path)

# valid data mask: valid data = 1, no data = 0
valid_data_mask = (
(da_udm.sel(band=8) == 0)
.assign_attrs({"data_source": "planet", "long_name": "Valid data mask"})
.to_dataset(name="valid_data_mask")
.drop_vars("band")
)

# quality data mask: high quality = 1, low quality = 0
quality_data_mask = (
(da_udm.sel(band=[2, 3, 4, 5, 6]).max(axis=0) != 1)
.assign_attrs({"data_source": "planet", "long_name": "Quality data mask"})
.to_dataset(name="quality_data_mask")
)

qa_ds = xr.merge([valid_data_mask, quality_data_mask])
logger.debug(f"Loaded data masks in {time.time() - start_time} seconds.")
return qa_ds

This file was deleted.

Loading

0 comments on commit 950bc2d

Please sign in to comment.