Skip to content

Commit

Permalink
darts_export: untested export module
Browse files Browse the repository at this point in the history
  • Loading branch information
iona5 committed Oct 10, 2024
1 parent beba287 commit a7a6b63
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 12 deletions.
3 changes: 2 additions & 1 deletion darts-export/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ version = "0.1.0"
description = "Dataset export for the DARTS dataset."
dependencies = [
"numpy>=1.26.3, <2",
"xarray>=2024.9.0",
"xarray>=2024",
"rasterio>=1.4.0",
"rioxarray>=0.17.0",
"h5netcdf>=1.3.0",
"geopandas>=1.0.1",
"pytest"
]
readme = "README.md"
requires-python = ">= 3.11"
Expand Down
11 changes: 0 additions & 11 deletions darts-export/src/darts_export/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +0,0 @@
"""Dataset export for the DARTS dataset."""


def hello() -> str:
"""Say hello to the user.
Returns:
str: Greating message.
"""
return "Hello from darts-export!"
22 changes: 22 additions & 0 deletions darts-export/src/darts_export/inference.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from pathlib import Path

Check failure on line 1 in darts-export/src/darts_export/inference.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (D100)

darts-export/src/darts_export/inference.py:1:1: D100 Missing docstring in public module
import xarray
import rioxarray

Check failure on line 3 in darts-export/src/darts_export/inference.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (F401)

darts-export/src/darts_export/inference.py:3:8: F401 `rioxarray` imported but unused

class InferenceResultWriter:

Check failure on line 5 in darts-export/src/darts_export/inference.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (I001)

darts-export/src/darts_export/inference.py:1:1: I001 Import block is un-sorted or un-formatted

Check failure on line 5 in darts-export/src/darts_export/inference.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (E302)

darts-export/src/darts_export/inference.py:5:1: E302 Expected 2 blank lines, found 1

Check failure on line 5 in darts-export/src/darts_export/inference.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (D101)

darts-export/src/darts_export/inference.py:5:7: D101 Missing docstring in public class

def __init__(self, ds) -> None:

Check failure on line 7 in darts-export/src/darts_export/inference.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (D107)

darts-export/src/darts_export/inference.py:7:9: D107 Missing docstring in `__init__`
self.ds:xarray.Dataset = ds

Check failure on line 8 in darts-export/src/darts_export/inference.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (E231)

darts-export/src/darts_export/inference.py:8:16: E231 Missing whitespace after ':'

def export_probabilities(self, path:Path, filename="pred_probabilities.tif", tags=dict()):

Check failure on line 10 in darts-export/src/darts_export/inference.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (D102)

darts-export/src/darts_export/inference.py:10:9: D102 Missing docstring in public method

Check failure on line 10 in darts-export/src/darts_export/inference.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (E231)

darts-export/src/darts_export/inference.py:10:40: E231 Missing whitespace after ':'

# write the probability layer from the raster to a GeoTiff
self.ds.probabilities.rio.to_raster(path / filename, driver="GTiff", tags=tags, compress="LZW")

def export_binarized(self, path:Path, filename="pred_binarized.tif", tags=dict()):

self.ds.binarized_segmentation.rio.to_raster(path / filename, driver="GTiff", tags=tags, compress="LZW")


def export_vectors(self, path:Path, filename_prefix="pred_segments"):
pass

15 changes: 15 additions & 0 deletions darts-export/test/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pytest
import xarray, numpy as np
import rioxarray

@pytest.fixture
def probabilities():

xds = xarray.DataArray(np.randint(0, 100, 16**2),
dims=("y", "x"),
coords={"x": range(500000, 500016), "y": range(4500000, 4500016)},
)
xds.rio.write_crs("EPSG:32601", inplace=True)
xds.rio.set_spatial_dims(x_dim='x', y_dim='y', inplace=True)
xds.rio.write_transform(inplace=True)
return xds
5 changes: 5 additions & 0 deletions darts-export/test/test_inference.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#import


def test_writeProbabilities(probabilities):
pass

0 comments on commit a7a6b63

Please sign in to comment.