Skip to content

Implement core ML bridging utilities - #14

Open
ysims wants to merge 1 commit into
mainfrom
feature/ml-samples-integration
Open

Implement core ML bridging utilities#14
ysims wants to merge 1 commit into
mainfrom
feature/ml-samples-integration

Conversation

@ysims

@ysims ysims commented Aug 4, 2026

Copy link
Copy Markdown
Owner

Replace the NotImplementedError placeholders in earthrs.ml.core with real, optional-dependency-guarded implementations:

  • to_numpy: converts Samples, row-mapping lists, or column-oriented mappings to (array, column_names); plain array-likes convert to a bare array. Falls back to dtype=object when values aren't numeric so nothing is lost.
  • prepare_training_data: splits a Samples table into aligned (X, y) via to_numpy, accepting either a label column name or a separate aligned label sequence, with optional NA-row dropping (None/NaN, matching the None-for-missing convention already used in earthrs.processing.core).
  • to_torch_dataset / to_tensorflow_dataset: wrap features/labels in a TensorDataset / tf.data.Dataset via numpy.
  • tile_scene: splits a Scene's band grids into tile_size x tile_size windows (stride defaults to tile_size), cropping partial edge tiles, offsetting scene.transform per tile, and preserving crs/sensor/ acquisition_time/history plus a tile_offset in metadata.
  • raster_predict: tiles a scene, stacks each tile's bands into a numpy array, batches tiles, and calls model.predict/model(), returning (tile, prediction) pairs so callers can reconstruct the full raster.

Add ml / ml-torch / ml-tensorflow optional-dependency extras to pyproject.toml, and tests/test_ml.py covering all six functions (numpy/ torch/tensorflow paths use pytest.importorskip so the suite stays green without those installed).

Replace the NotImplementedError placeholders in earthrs.ml.core with real,
optional-dependency-guarded implementations:

- to_numpy: converts Samples, row-mapping lists, or column-oriented mappings
  to (array, column_names); plain array-likes convert to a bare array.
  Falls back to dtype=object when values aren't numeric so nothing is lost.
- prepare_training_data: splits a Samples table into aligned (X, y) via
  to_numpy, accepting either a label column name or a separate aligned
  label sequence, with optional NA-row dropping (None/NaN, matching the
  None-for-missing convention already used in earthrs.processing.core).
- to_torch_dataset / to_tensorflow_dataset: wrap features/labels in a
  TensorDataset / tf.data.Dataset via numpy.
- tile_scene: splits a Scene's band grids into tile_size x tile_size
  windows (stride defaults to tile_size), cropping partial edge tiles,
  offsetting scene.transform per tile, and preserving crs/sensor/
  acquisition_time/history plus a tile_offset in metadata.
- raster_predict: tiles a scene, stacks each tile's bands into a numpy
  array, batches tiles, and calls model.predict/model(), returning
  (tile, prediction) pairs so callers can reconstruct the full raster.

Add ml / ml-torch / ml-tensorflow optional-dependency extras to
pyproject.toml, and tests/test_ml.py covering all six functions (numpy/
torch/tensorflow paths use pytest.importorskip so the suite stays green
without those installed).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant