Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XY refactor #11

Merged
merged 17 commits into from Feb 8, 2022
Merged

XY refactor #11

merged 17 commits into from Feb 8, 2022

Conversation

Kirill888
Copy link
Member

@Kirill888 Kirill888 commented Feb 4, 2022

There were a bunch of places where it was not clear whether some tuple contains X,Y or Y,X data. It's confusing on the interface and confusing when reading code. This PR adds an XY[T] type and a bunch of constructor methods that make it easy to understand what order x,y parameters are added.

Instead of using plain tuples those new types are used instead. On the input shape= parameters are still allowed to be supplied as plain (int, int) tuples and are equivalent to iyx_(y, x). Internally those properties are kept in XY[int] form. Similarly a 2d index is also allowed to be supplied as (int, int), as this is what allows some_thing[ix, iy] or some_thing[row, col] syntax, order depends on use case, but should be clearly stated in the docs.

Resolution input parameters are allowed to be a single float, but plain tuples are not allowed as this causes order confusion. Single value resolution is equivalent to resyx_(-value, value).

Change GeoBox constructor to accept shape

Geobox(width, height, ...) interface is problematic for several
reasons:

  1. not compatible with ndarray, where shape is used instead
  2. no type-safety, easy to get order wrong
  3. two parameters to configure single property

Replacing width, height with a single parameter shape. This could be a simple (int, int) tuple for easier interop with ndarray. But one can choose to use more typesafe XY[int].

Example of the change at call site

   # before change:
   GeoBox(512, 256, A, "espg:4326")

   # becomes
   ## if array order is "native" at call-site
   GeoBox((256, 512), A, "epsg:4326")
   ## if width/height orded is preferred
   GeoBox(ixy_(512, 256), A, "epsg:4326")

Plan is stop using tuples that might contain X,Y or Y,X ordered values
and instead be explicit about the order during construction and use.
@codecov
Copy link

codecov bot commented Feb 4, 2022

Codecov Report

Merging #11 (5455163) into develop (d6aca73) will increase coverage by 0.31%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop      #11      +/-   ##
===========================================
+ Coverage    97.13%   97.44%   +0.31%     
===========================================
  Files           13       14       +1     
  Lines         1639     1841     +202     
===========================================
+ Hits          1592     1794     +202     
  Misses          47       47              
Impacted Files Coverage Δ
odc/geo/testutils.py 100.00% <ø> (ø)
odc/geo/__init__.py 100.00% <100.00%> (ø)
odc/geo/_xr_interop.py 100.00% <100.00%> (ø)
odc/geo/geobox.py 100.00% <100.00%> (ø)
odc/geo/geom.py 100.00% <100.00%> (ø)
odc/geo/gridspec.py 100.00% <100.00%> (ø)
odc/geo/types.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d6aca73...5455163. Read the comment docs.

@github-actions
Copy link

github-actions bot commented Feb 4, 2022

`Geobox(width, height, ...)` interface is problematic for several
reasons:

1. not compatible with `ndarray`, where shape is used instead
2. no type-safety, easy to get order wrong
3. two parameters to configure single property

Replacing `width, height` with a single parameter `shape`. This could
be a simple `(int, int)` tuple for easier interop with `ndarray`. But
one can choose to use more typesafe `XY[int]`.

Example of the change at call site

```python
   # before change:
   GeoBox(512, 256, A, "espg:4326")

   # becomes
   ## if array order is "native" at call-site
   GeoBox((256, 512), A, "epsg:4326")
   ## if width/height orded is preferred
   GeoBox(ixy_(512, 256), A, "epsg:4326")
```
Allow conversion from tuples and passthrough of output types.
Instead of using plain tuples use XY classes.
@github-actions
Copy link

github-actions bot commented Feb 4, 2022

Use XY[] objects internally and stop indexing with
`[0|1]`.

Do not accept plain tuples for Resolution/Alignment
Report resolution/alignment as Resolution/XY objects
@github-actions
Copy link

github-actions bot commented Feb 4, 2022

@Kirill888 Kirill888 marked this pull request as ready for review February 4, 2022 08:47
odc/geo/geobox.py Outdated Show resolved Hide resolved
odc/geo/geobox.py Outdated Show resolved Hide resolved
odc/geo/gridspec.py Outdated Show resolved Hide resolved
odc/geo/gridspec.py Outdated Show resolved Hide resolved
After change to XY[] comments about axis order are no longer relevant.
nx,ny instead of W,H
s{x,y}, t{x,y} for Affine matrix components
adding some clarification comments.
@github-actions
Copy link

github-actions bot commented Feb 8, 2022

- using x twice instead of x,y
- adding test with non-square tiles
It behavse like a tuple of ny,nx int values, but also is XY[int]
@github-actions
Copy link

github-actions bot commented Feb 8, 2022

geobox/gridspec use Shape2d now
@github-actions
Copy link

github-actions bot commented Feb 8, 2022

add work around for crs<->geom dependency.
enable warnings are errors mode for doc building.
@Kirill888
Copy link
Member Author

@gadomski

since your last review:

  • fixed doc strings that still contained order where it no longer made sense
  • fixed error in GridSpec and added test that would have caught it
  • Added Shape2d(XY[int]) class
    • it behaves just like a Tuple[int, int] would: can be unpacked, indexed, iterated, is a sequence, can be concatenated with other tuples on both sides, can be passed into np.zeros(shape=<>, ...).
    • So it's not safe on "use-site" unless you choose to use it in a "safe" way, but you can use it with use-site readable order since it is XY[int]
    • The default order for the unsafe use is Y,X to match numpy
  • Switched over (most?) interfaces to Shape2d
  • Adding new methods/classes to api docs
  • Fixed docs building warning and enabled strict doc building mode.

@github-actions
Copy link

github-actions bot commented Feb 8, 2022

@github-actions
Copy link

github-actions bot commented Feb 8, 2022

@Kirill888 Kirill888 merged commit ef4721f into develop Feb 8, 2022
@Kirill888 Kirill888 deleted the xy-refactor branch February 17, 2022 23:08
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.

None yet

2 participants