Skip to content

Commit 5f3edd1

Browse files
Jammy2211Jammy2211
authored andcommitted
removed more zoom stuf
1 parent 107e470 commit 5f3edd1

3 files changed

Lines changed: 6 additions & 343 deletions

File tree

autoarray/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
from .mask.derive.mask_2d import DeriveMask2D
5353
from .mask.derive.grid_1d import DeriveGrid1D
5454
from .mask.derive.grid_2d import DeriveGrid2D
55+
from .mask.derive.zoom_2d import Zoom2D
5556
from .mask.mask_1d import Mask1D
5657
from .mask.mask_2d import Mask2D
5758
from .operators.transformer import TransformerDFT

autoarray/mask/mask_2d.py

Lines changed: 5 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
from pathlib import Path
66
from typing import TYPE_CHECKING, Dict, List, Tuple, Union
77

8-
9-
from autoconf import cached_property
10-
118
from autoarray.structures.abstract_structure import Structure
129

1310
if TYPE_CHECKING:
@@ -24,6 +21,7 @@
2421
from autoarray.mask.derive.mask_2d import DeriveMask2D
2522
from autoarray.mask.derive.grid_2d import DeriveGrid2D
2623
from autoarray.mask.derive.indexes_2d import DeriveIndexes2D
24+
from autoarray.mask.derive.zoom_2d import Zoom2D
2725

2826
from autoarray.structures.arrays import array_2d_util
2927
from autoarray.geometry import geometry_util
@@ -255,6 +253,10 @@ def derive_mask(self) -> DeriveMask2D:
255253
def derive_grid(self) -> DeriveGrid2D:
256254
return DeriveGrid2D(mask=self)
257255

256+
@property
257+
def zoom(self) -> Zoom2D:
258+
return Zoom2D(mask=self)
259+
258260
@classmethod
259261
def all_false(
260262
cls,
@@ -815,95 +817,6 @@ def resized_from(self, new_shape, pad_value: int = 0.0) -> Mask2D:
815817
origin=self.origin,
816818
)
817819

818-
@property
819-
def zoom_centre(self) -> Tuple[float, float]:
820-
from autoarray.structures.grids.uniform_2d import Grid2D
821-
822-
grid = grid_2d_util.grid_2d_slim_via_mask_from(
823-
mask_2d=np.array(self),
824-
pixel_scales=self.pixel_scales,
825-
origin=self.origin,
826-
)
827-
828-
grid = Grid2D(values=grid, mask=self)
829-
830-
extraction_grid_1d = self.geometry.grid_pixels_2d_from(grid_scaled_2d=grid)
831-
y_pixels_max = np.max(extraction_grid_1d[:, 0])
832-
y_pixels_min = np.min(extraction_grid_1d[:, 0])
833-
x_pixels_max = np.max(extraction_grid_1d[:, 1])
834-
x_pixels_min = np.min(extraction_grid_1d[:, 1])
835-
836-
return (
837-
((y_pixels_max + y_pixels_min - 1.0) / 2.0),
838-
((x_pixels_max + x_pixels_min - 1.0) / 2.0),
839-
)
840-
841-
@property
842-
def zoom_offset_pixels(self) -> Tuple[float, float]:
843-
if self.pixel_scales is None:
844-
return self.geometry.central_pixel_coordinates
845-
846-
return (
847-
self.zoom_centre[0] - self.geometry.central_pixel_coordinates[0],
848-
self.zoom_centre[1] - self.geometry.central_pixel_coordinates[1],
849-
)
850-
851-
@property
852-
def zoom_offset_scaled(self) -> Tuple[float, float]:
853-
return (
854-
-self.pixel_scales[0] * self.zoom_offset_pixels[0],
855-
self.pixel_scales[1] * self.zoom_offset_pixels[1],
856-
)
857-
858-
@property
859-
def zoom_region(self) -> List[int]:
860-
"""
861-
The zoomed rectangular region corresponding to the square encompassing all unmasked values. This zoomed
862-
extraction region is a squuare, even if the mask is rectangular.
863-
864-
This is used to zoom in on the region of an image that is used in an analysis for visualization.
865-
"""
866-
867-
where = np.array(np.where(np.invert(self.astype("bool"))))
868-
y0, x0 = np.amin(where, axis=1)
869-
y1, x1 = np.amax(where, axis=1)
870-
871-
# Have to convert mask to bool for invert function to work.
872-
873-
ylength = y1 - y0
874-
xlength = x1 - x0
875-
876-
if ylength > xlength:
877-
length_difference = ylength - xlength
878-
x1 += int(length_difference / 2.0)
879-
x0 -= int(length_difference / 2.0)
880-
elif xlength > ylength:
881-
length_difference = xlength - ylength
882-
y1 += int(length_difference / 2.0)
883-
y0 -= int(length_difference / 2.0)
884-
885-
return [y0, y1 + 1, x0, x1 + 1]
886-
887-
@property
888-
def zoom_shape_native(self) -> Tuple[int, int]:
889-
region = self.zoom_region
890-
return (region[1] - region[0], region[3] - region[2])
891-
892-
@property
893-
def zoom_mask_unmasked(self) -> "Mask2D":
894-
"""
895-
The scaled-grid of (y,x) coordinates of every pixel.
896-
897-
This is defined from the top-left corner, such that the first pixel at location [0, 0] will have a negative x
898-
value y value in scaled units.
899-
"""
900-
901-
return Mask2D.all_false(
902-
shape_native=self.zoom_shape_native,
903-
pixel_scales=self.pixel_scales,
904-
origin=self.zoom_offset_scaled,
905-
)
906-
907820
@property
908821
def is_circular(self) -> bool:
909822
"""

test_autoarray/mask/test_mask_2d.py

Lines changed: 0 additions & 251 deletions
Original file line numberDiff line numberDiff line change
@@ -489,257 +489,6 @@ def test__resized_from():
489489

490490
assert (mask_resized == mask_resized_manual).all()
491491

492-
493-
def test__zoom_quantities():
494-
mask = aa.Mask2D.all_false(shape_native=(3, 5), pixel_scales=(1.0, 1.0))
495-
assert mask.zoom_centre == (1.0, 2.0)
496-
assert mask.zoom_offset_pixels == (0, 0)
497-
assert mask.zoom_shape_native == (5, 5)
498-
499-
mask = aa.Mask2D.all_false(shape_native=(5, 3), pixel_scales=(1.0, 1.0))
500-
assert mask.zoom_centre == (2.0, 1.0)
501-
assert mask.zoom_offset_pixels == (0, 0)
502-
assert mask.zoom_shape_native == (5, 5)
503-
504-
mask = aa.Mask2D.all_false(shape_native=(4, 6), pixel_scales=(1.0, 1.0))
505-
assert mask.zoom_centre == (1.5, 2.5)
506-
assert mask.zoom_offset_pixels == (0, 0)
507-
assert mask.zoom_shape_native == (6, 6)
508-
509-
mask = aa.Mask2D.all_false(shape_native=(6, 4), pixel_scales=(1.0, 1.0))
510-
assert mask.zoom_centre == (2.5, 1.5)
511-
assert mask.zoom_offset_pixels == (0, 0)
512-
assert mask.zoom_shape_native == (6, 6)
513-
514-
515-
def test__mask_is_single_false__extraction_centre_is_central_pixel():
516-
mask = aa.Mask2D(
517-
mask=np.array([[False, True, True], [True, True, True], [True, True, True]]),
518-
pixel_scales=(1.0, 1.0),
519-
)
520-
assert mask.zoom_centre == (0, 0)
521-
assert mask.zoom_offset_pixels == (-1, -1)
522-
assert mask.zoom_shape_native == (1, 1)
523-
524-
mask = aa.Mask2D(
525-
mask=np.array([[True, True, False], [True, True, True], [True, True, True]]),
526-
pixel_scales=(1.0, 1.0),
527-
)
528-
assert mask.zoom_centre == (0, 2)
529-
assert mask.zoom_offset_pixels == (-1, 1)
530-
assert mask.zoom_shape_native == (1, 1)
531-
532-
mask = aa.Mask2D(
533-
mask=np.array([[True, True, True], [True, True, True], [False, True, True]]),
534-
pixel_scales=(1.0, 1.0),
535-
)
536-
assert mask.zoom_centre == (2, 0)
537-
assert mask.zoom_offset_pixels == (1, -1)
538-
assert mask.zoom_shape_native == (1, 1)
539-
540-
mask = aa.Mask2D(
541-
mask=np.array([[True, True, True], [True, True, True], [True, True, False]]),
542-
pixel_scales=(1.0, 1.0),
543-
)
544-
assert mask.zoom_centre == (2, 2)
545-
assert mask.zoom_offset_pixels == (1, 1)
546-
assert mask.zoom_shape_native == (1, 1)
547-
548-
mask = aa.Mask2D(
549-
mask=np.array([[True, False, True], [True, True, True], [True, True, True]]),
550-
pixel_scales=(1.0, 1.0),
551-
)
552-
assert mask.zoom_centre == (0, 1)
553-
assert mask.zoom_offset_pixels == (-1, 0)
554-
assert mask.zoom_shape_native == (1, 1)
555-
556-
mask = aa.Mask2D(
557-
mask=np.array([[True, True, True], [False, True, True], [True, True, True]]),
558-
pixel_scales=(1.0, 1.0),
559-
)
560-
assert mask.zoom_centre == (1, 0)
561-
assert mask.zoom_offset_pixels == (0, -1)
562-
assert mask.zoom_shape_native == (1, 1)
563-
564-
mask = aa.Mask2D(
565-
mask=np.array([[True, True, True], [True, True, False], [True, True, True]]),
566-
pixel_scales=(1.0, 1.0),
567-
)
568-
assert mask.zoom_centre == (1, 2)
569-
assert mask.zoom_offset_pixels == (0, 1)
570-
assert mask.zoom_shape_native == (1, 1)
571-
572-
mask = aa.Mask2D(
573-
mask=np.array([[True, True, True], [True, True, True], [True, False, True]]),
574-
pixel_scales=(1.0, 1.0),
575-
)
576-
assert mask.zoom_centre == (2, 1)
577-
assert mask.zoom_offset_pixels == (1, 0)
578-
assert mask.zoom_shape_native == (1, 1)
579-
580-
581-
def test__mask_is_x2_false__extraction_centre_is_central_pixel():
582-
mask = aa.Mask2D(
583-
mask=np.array([[False, True, True], [True, True, True], [True, True, False]]),
584-
pixel_scales=(1.0, 1.0),
585-
)
586-
assert mask.zoom_centre == (1, 1)
587-
assert mask.zoom_offset_pixels == (0, 0)
588-
assert mask.zoom_shape_native == (3, 3)
589-
590-
mask = aa.Mask2D(
591-
mask=np.array([[False, True, True], [True, True, True], [False, True, True]]),
592-
pixel_scales=(1.0, 1.0),
593-
)
594-
assert mask.zoom_centre == (1, 0)
595-
assert mask.zoom_offset_pixels == (0, -1)
596-
assert mask.zoom_shape_native == (3, 3)
597-
598-
mask = aa.Mask2D(
599-
mask=np.array([[False, True, False], [True, True, True], [True, True, True]]),
600-
pixel_scales=(1.0, 1.0),
601-
)
602-
assert mask.zoom_centre == (0, 1)
603-
assert mask.zoom_offset_pixels == (-1, 0)
604-
assert mask.zoom_shape_native == (3, 3)
605-
606-
mask = aa.Mask2D(
607-
mask=np.array([[False, False, True], [True, True, True], [True, True, True]]),
608-
pixel_scales=(1.0, 1.0),
609-
)
610-
assert mask.zoom_centre == (0, 0.5)
611-
assert mask.zoom_offset_pixels == (-1, -0.5)
612-
assert mask.zoom_shape_native == (1, 2)
613-
614-
615-
def test__rectangular_mask():
616-
mask = aa.Mask2D(
617-
mask=np.array(
618-
[
619-
[False, True, True, True],
620-
[True, True, True, True],
621-
[True, True, True, True],
622-
]
623-
),
624-
pixel_scales=(1.0, 1.0),
625-
)
626-
627-
assert mask.zoom_centre == (0, 0)
628-
assert mask.zoom_offset_pixels == (-1.0, -1.5)
629-
630-
mask = aa.Mask2D(
631-
mask=np.array(
632-
[
633-
[True, True, True, True],
634-
[True, True, True, True],
635-
[True, True, True, False],
636-
]
637-
),
638-
pixel_scales=(1.0, 1.0),
639-
)
640-
641-
assert mask.zoom_centre == (2, 3)
642-
assert mask.zoom_offset_pixels == (1.0, 1.5)
643-
644-
mask = aa.Mask2D(
645-
mask=np.array(
646-
[
647-
[True, True, True, True, True],
648-
[True, True, True, True, True],
649-
[True, True, True, True, False],
650-
]
651-
),
652-
pixel_scales=(1.0, 1.0),
653-
)
654-
655-
assert mask.zoom_centre == (2, 4)
656-
assert mask.zoom_offset_pixels == (1, 2)
657-
658-
mask = aa.Mask2D(
659-
mask=np.array(
660-
[
661-
[True, True, True, True, True, True, True],
662-
[True, True, True, True, True, True, True],
663-
[True, True, True, True, True, True, False],
664-
]
665-
),
666-
pixel_scales=(1.0, 1.0),
667-
)
668-
669-
assert mask.zoom_centre == (2, 6)
670-
assert mask.zoom_offset_pixels == (1, 3)
671-
672-
mask = aa.Mask2D(
673-
mask=np.array(
674-
[
675-
[True, True, True],
676-
[True, True, True],
677-
[True, True, True],
678-
[True, True, True],
679-
[True, True, False],
680-
]
681-
),
682-
pixel_scales=(1.0, 1.0),
683-
)
684-
685-
assert mask.zoom_centre == (4, 2)
686-
assert mask.zoom_offset_pixels == (2, 1)
687-
688-
mask = aa.Mask2D(
689-
mask=np.array(
690-
[
691-
[True, True, True],
692-
[True, True, True],
693-
[True, True, True],
694-
[True, True, True],
695-
[True, True, True],
696-
[True, True, True],
697-
[True, True, False],
698-
]
699-
),
700-
pixel_scales=(1.0, 1.0),
701-
)
702-
703-
assert mask.zoom_centre == (6, 2)
704-
assert mask.zoom_offset_pixels == (3, 1)
705-
706-
707-
def test__zoom_mask_unmasked():
708-
mask = aa.Mask2D(
709-
mask=np.array(
710-
[
711-
[False, True, True, True],
712-
[True, False, True, True],
713-
[True, True, True, True],
714-
]
715-
),
716-
pixel_scales=(1.0, 1.0),
717-
)
718-
719-
zoom_mask = mask.zoom_mask_unmasked
720-
721-
assert (zoom_mask == np.array([[False, False], [False, False]])).all()
722-
assert zoom_mask.origin == (0.5, -1.0)
723-
724-
mask = aa.Mask2D(
725-
mask=np.array(
726-
[
727-
[False, True, True, True],
728-
[True, False, True, True],
729-
[True, False, True, True],
730-
]
731-
),
732-
pixel_scales=(1.0, 2.0),
733-
)
734-
735-
zoom_mask = mask.zoom_mask_unmasked
736-
737-
assert (
738-
zoom_mask == np.array([[False, False], [False, False], [False, False]])
739-
).all()
740-
assert zoom_mask.origin == (0.0, -2.0)
741-
742-
743492
def test__mask_centre():
744493
mask = np.array(
745494
[

0 commit comments

Comments
 (0)