alan-turing-institute / deepsensor

A Python package for tackling diverse environmental prediction tasks with NPs.
https://alan-turing-institute.github.io/deepsensor/
MIT License
94 stars 16 forks source link

PR to make model agnostic to coordinate directions #127

Closed MartinSJRogers closed 3 months ago

MartinSJRogers commented 3 months ago

Changes to model.py and loader.py to allow patching during inference, irrespective of whether x1 and x2 increase or decrease from the top left corner. In particular, the code is modified to overcome the error deriving from xr.combine_by_coords that the coordinates are not monotonic in direction. Summary of changes:

data/loader.py

  1. Add new method, self._compute_x1x2_direction(), to calculate x1 and x2 direction
  2. Add additional if/else statements to sample_sliding_window(), so the top left corner is always the first part of the image to be patched, irrespective of coordinate direction. This can probably be simplified.

Other minor change in loader.py

  1. sample_sliding_window() sometimes produces duplicate entries, so code added in this method to remove these.

model/model.py

  1. Identify direction of x1 and x2 in main body of patch_predict() (line 985-997)
  2. Add x1_ascend and x2_ascend as arguments to get_patch_overlap(), so overlap between patches can be calculated irrespective of coordinate direction
  3. Add x1_ascend and x2_ascend as arguments to stitch_clipped_predictions() and add additional if/else statements to make stitching agnostic to x1 and x2 direction

Other minor changes in model.py:

  1. Change all references of x and y to x2 and x1 respectively
  2. change reference of unnorm_coords['x1'] to orig_x1_name

Prediction when patching (stride = 0.25, patch = 0.5): image

Prediction when patching (stride = 0.05, patch = 0.1): image

Prediction when not patching: image

Difference between prediction when patching/not patching- todo-resolve line!!: image

review-notebook-app[bot] commented 3 months ago

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB