-
Notifications
You must be signed in to change notification settings - Fork 12
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
Experimenting with shapely
RoIs
#390
Conversation
5e52adf
to
e3e43a1
Compare
This PR has definitely scope drifted - mostly my fault because I ended up working on the As such, what I'll do is break up the PR into the following to make reviewing it more manageable:
|
92ba767
to
3a7d56d
Compare
Quality Gate passedIssues Measures |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #390 +/- ##
==========================================
- Coverage 99.80% 99.14% -0.67%
==========================================
Files 15 19 +4
Lines 1048 1175 +127
==========================================
+ Hits 1046 1165 +119
- Misses 2 10 +8 ☔ View full report in Codecov by Sentry. |
Description
What is this PR
Why is this PR needed?
A first step towards addressing #377 - introduces the low-level classes that we will need to represent these in the codebase.
As stated on the issue, we have to use wrapper classes since inheriting from
shapely
classes is problematic. This doesn't really matter too much though - if anything, it is rather helpful for separating the underlying (and rather counter-intuitive at times)shapely
objects from the higher-level analysis functions that we're going to implement.What does this PR do?
roi
submodule, which contains a base class and two derived classes for representing RoIs.make_broadcastable
decorator into theutils
folder. More on this decorator below.make_broadcastable
The data that we will typically be seeing is 2-dimensional in space, but may have multiple other dimensions for time, individuals, etc.
shapely
is not vectorised, so cannot handling broadcasting a single operation across the corresponding dimension of anumpy
array. Furthermore,shapely
also largely depends on casting to it's own internalGeometry
objects before such methods can be applied.make_broadcastable
is a decorator that is designed to help reduce the code bloat that "vectorising" theshapely
operations would need. It turns functions that act on 1D data (notably, theshapely
functions we will be using) into functions that can act along a given axis of aDataArray
input. As an example, we can look at thepoints_are_inside
method that is provided to regions of interest:This method relies on a
shapely
method, so only handles one spatial coordinate per function call. However, by decorating it withmake_broadcastable
, we can now call it by providing aDataArray
instead, as per the corresponding tests intest/test_unit/test_roi/test_points_are_inside.py
in_region
is of the same shape asdata
, but with the"space"
dimension dropped. The values inin_region
arebool
s, corresponding to the output ofpoints_are inside
function as called on each coordinate pair in the"space"
dimension ofdata
.More broadly,
make_broadcastable
is also quite useful to have available publicly to users; they can write functions that assume they're only operating on one "piece" of data (EG one position) and can then use the decorators to extend this in the manner described above.References
Relates to #377 (but does not close). Does introduce the ability to determine if a point is inside an RoI though.
How has this PR been tested?
Addition of local tests for both RoI classes and the new decorator.
Is this a breaking change?
Does this PR require an update to the documentation?
Should maybe consider starting an example that illustrates how to use RoIs. Possibly also a developer example to explain the usage of the new
make_broadcastable
decorator.Checklist: