-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
44e9b97
commit c121655
Showing
5 changed files
with
201 additions
and
33 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
darts-preprocessing/src/darts_preprocessing/preprocess_tobi.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"""PLANET scene based preprocessing.""" | ||
|
||
from pathlib import Path | ||
|
||
import xarray as xr | ||
|
||
from darts_preprocessing.utils.data_pre_processing import ( | ||
calculate_ndvi, | ||
load_auxiliary, | ||
load_data_masks, | ||
load_planet_scene, | ||
) | ||
|
||
|
||
def load_and_preprocess_planet_scene(planet_scene_path: Path, elevation_path: Path, slope_path: Path) -> xr.Dataset: | ||
"""Load and preprocess a Planet Scene (PSOrthoTile or PSScene) into an xr.Dataset. | ||
Args: | ||
planet_scene_path (Path): path to the Planet Scene | ||
elevation_path (Path): path to the elevation data | ||
slope_path (Path): path to the slope data | ||
Returns: | ||
xr.Dataset: preprocessed Planet Scene | ||
""" | ||
# load planet scene | ||
ds_planet = load_planet_scene(planet_scene_path) | ||
|
||
# calculate xr.dataset ndvi | ||
ds_ndvi = calculate_ndvi(ds_planet) | ||
|
||
# get xr.dataset for elevation | ||
ds_elevation = load_auxiliary(planet_scene_path, elevation_path, xr_dataset_name="relative_elevation") | ||
|
||
# get xr.dataset for slope | ||
ds_slope = load_auxiliary(planet_scene_path, slope_path, xr_dataset_name="slope") | ||
|
||
# # get xr.dataset for tcvis | ||
# ds_tcvis = load_auxiliary(planet_scene_path, tcvis_path) | ||
|
||
# load udm2 | ||
ds_data_masks = load_data_masks(planet_scene_path) | ||
|
||
# merge to final dataset | ||
ds_merged = xr.merge([ds_planet, ds_ndvi, ds_elevation, ds_slope, ds_data_masks]) | ||
|
||
return ds_merged |
24 changes: 0 additions & 24 deletions
24
darts-segmentation/src/darts_segmentation/hardcoded_stuff.py
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from pathlib import Path\n", | ||
"\n", | ||
"import xarray as xr\n", | ||
"from darts_postprocessing.prepare_export import prepare_export\n", | ||
"from darts_preprocessing.preprocess_tobi import load_and_preprocess_planet_scene\n", | ||
"from darts_segmentation.segment import SMPSegmenter\n", | ||
"from lovely_tensors import monkey_patch\n", | ||
"from rich import traceback\n", | ||
"\n", | ||
"xr.set_options(display_expand_data=False)\n", | ||
"\n", | ||
"monkey_patch()\n", | ||
"traceback.install(show_locals=True)\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"DATA_ROOT = Path(\"../data/input\")\n", | ||
"\n", | ||
"fpath = DATA_ROOT / \"planet/PSOrthoTile/4372514/5790392_4372514_2022-07-16_2459\"\n", | ||
"scene_id = fpath.parent.name\n", | ||
"\n", | ||
"# TODO: change to vrt\n", | ||
"elevation_path = DATA_ROOT / \"ArcticDEM\" / \"relative_elevation\" / f\"{scene_id}_relative_elevation_100.tif\"\n", | ||
"slope_path = DATA_ROOT / \"ArcticDEM\" / \"slope\" / f\"{scene_id}_slope.tif\"\n", | ||
"\n", | ||
"tile = load_and_preprocess_planet_scene(fpath, elevation_path, slope_path)\n", | ||
"tile\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"model = SMPSegmenter(\"../models/RTS_v6_notcvis.pt\")\n", | ||
"tile = model.segment_tile(tile)\n", | ||
"final = prepare_export(tile)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"tile" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": ".venv", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.9" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |