-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathrectangular_rotated_spline.py
More file actions
72 lines (61 loc) · 2.34 KB
/
Copy pathrectangular_rotated_spline.py
File metadata and controls
72 lines (61 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"""Rotated-CDF variant of the spline rectangular interpolator.
Used by :class:`RectangularRotatedAdaptImage`. The mesh class rotates
``data_grid`` into a brightness-weighted PCA frame before constructing this
interpolator; everything else (bilinear scatter, CDF spline, mappings/sizes/
weights) runs unchanged inside that frame.
The only behavioural difference vs the parent
:class:`InterpolatorRectangularSpline` is the geometry: ``mesh_geometry`` is
replaced by :class:`MeshGeometryRectangularRotated`, which un-rotates the
CDF-warped edges back into the source frame for plotting.
"""
from typing import Optional
import numpy as np
from autonerves import cached_property
from autoarray.inversion.mesh.interpolator.rectangular_spline import (
SPLINE_CDF_DEFAULT_DEG,
InterpolatorRectangularSpline,
)
class InterpolatorRectangularRotatedSpline(InterpolatorRectangularSpline):
"""Spline-CDF rectangular interpolator with brightness-weighted PCA rotation.
Constructed by :class:`RectangularRotatedAdaptImage` with a pre-rotated
``data_grid`` shim. Carries the rotation matrix and centroid so the
rotated geometry can un-rotate edges for plotting.
"""
def __init__(
self,
mesh,
mesh_grid,
data_grid,
mesh_weight_map,
rotation_matrix,
rotation_centroid,
adapt_data: Optional[np.ndarray] = None,
spline_deg: int = SPLINE_CDF_DEFAULT_DEG,
xp=np,
):
super().__init__(
mesh=mesh,
mesh_grid=mesh_grid,
data_grid=data_grid,
mesh_weight_map=mesh_weight_map,
adapt_data=adapt_data,
spline_deg=spline_deg,
xp=xp,
)
self.rotation_matrix = rotation_matrix
self.rotation_centroid = rotation_centroid
@cached_property
def mesh_geometry(self):
from autoarray.inversion.mesh.mesh_geometry.rectangular_rotated import (
MeshGeometryRectangularRotated,
)
return MeshGeometryRectangularRotated(
mesh=self.mesh,
mesh_grid=self.mesh_grid,
data_grid=self.data_grid,
mesh_weight_map=self.mesh_weight_map,
spline_deg=self.spline_deg,
rotation_matrix=self.rotation_matrix,
rotation_centroid=self.rotation_centroid,
xp=self._xp,
)