-
Notifications
You must be signed in to change notification settings - Fork 3
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
Feature/visualize fpr value #42
Changes from all commits
7815845
67ee4e1
66d2e62
ada1579
7b8aa4d
9a6a0e7
0e7637d
4c1504e
6b1ca4f
a7ac60b
a9f4b98
4259be6
a69024a
15bbfc9
c1bfbfe
92c0466
858accd
aacf6ff
0bd214f
7ec4ea9
a7ad10b
a2a1ae3
3a1584e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,10 @@ class ImagingCIException(Exception): | |
pass | ||
|
||
|
||
class ExtractException(Exception): | ||
pass | ||
Comment on lines
+17
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Docs? |
||
|
||
|
||
class LayoutException(Exception): | ||
pass | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
class Extract1D: | ||
def __init__( | ||
self, | ||
shape_1d: Optional[Tuple[int]] = None, | ||
region_list: Optional[aa.type.Region1DList] = None, | ||
prescan: Optional[aa.type.Region1DLike] = None, | ||
overscan: Optional[aa.type.Region1DLike] = None, | ||
|
@@ -22,6 +23,9 @@ def __init__( | |
region_list | ||
Integer pixel coordinates specifying the corners of signal (x0, x1). | ||
""" | ||
|
||
self.shape_1d = shape_1d | ||
|
||
self.region_list = ( | ||
list(map(aa.Region1D, region_list)) if region_list is not None else None | ||
) | ||
|
@@ -42,11 +46,29 @@ def total_pixels_min(self) -> int: | |
""" | ||
return np.min([region.total_pixels for region in self.region_list]) | ||
|
||
def region_list_from(self, pixels: Tuple[int, int]) -> List[aa.Region2D]: | ||
@property | ||
def parallel_rows_between_regions(self): | ||
return [ | ||
self.region_list[i + 1].x0 - self.region_list[i].x1 | ||
for i in range(len(self.region_list) - 1) | ||
] | ||
Comment on lines
+51
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can also do [second.x0 - first.x1 for first, second in zip(self.region_list, self.region_list[1:])] |
||
|
||
@property | ||
def trail_size_to_array_edge(self): | ||
return self.shape_1d[0] - np.max([region.x1 for region in self.region_list]) | ||
|
||
def region_list_from( | ||
self, | ||
pixels: Optional[Tuple[int, int]] = None, | ||
pixels_from_end: Optional[int] = None, | ||
) -> List[aa.Region2D]: | ||
raise NotImplementedError | ||
|
||
def array_1d_list_from( | ||
self, array: aa.Array1D, pixels: Tuple[int, int] | ||
self, | ||
array: aa.Array1D, | ||
pixels: Optional[Tuple[int, int]] = None, | ||
pixels_from_end: Optional[int] = None, | ||
) -> List[aa.Array1D]: | ||
""" | ||
Extract a specific region from every region on the line dataset and return as a list of 1D arrays. | ||
|
@@ -66,11 +88,16 @@ def array_1d_list_from( | |
|
||
arr_list = [ | ||
array.native[region.slice] | ||
for region in self.region_list_from(pixels=pixels) | ||
for region in self.region_list_from( | ||
pixels=pixels, pixels_from_end=pixels_from_end | ||
) | ||
] | ||
|
||
mask_1d_list = [ | ||
array.mask[region.slice] for region in self.region_list_from(pixels=pixels) | ||
array.mask[region.slice] | ||
for region in self.region_list_from( | ||
pixels=pixels, pixels_from_end=pixels_from_end | ||
) | ||
] | ||
|
||
return [ | ||
|
@@ -79,7 +106,10 @@ def array_1d_list_from( | |
] | ||
|
||
def stacked_array_1d_from( | ||
self, array: aa.Array1D, pixels: Tuple[int, int] | ||
self, | ||
array: aa.Array1D, | ||
pixels: Optional[Tuple[int, int]] = None, | ||
pixels_from_end: Optional[int] = None, | ||
) -> aa.Array1D: | ||
""" | ||
Extract a region (e.g. the FPR) of every region on the line dataset and stack them by taking their mean. | ||
|
@@ -102,13 +132,18 @@ def stacked_array_1d_from( | |
|
||
arr_list = [ | ||
np.ma.array(data=array.native[region.slice], mask=array.mask[region.slice]) | ||
for region in self.region_list_from(pixels=pixels) | ||
for region in self.region_list_from( | ||
pixels=pixels, pixels_from_end=pixels_from_end | ||
) | ||
] | ||
|
||
stacked_array_1d = np.ma.mean(np.ma.asarray(arr_list), axis=0) | ||
|
||
mask_1d_list = [ | ||
array.mask[region.slice] for region in self.region_list_from(pixels=pixels) | ||
array.mask[region.slice] | ||
for region in self.region_list_from( | ||
pixels=pixels, pixels_from_end=pixels_from_end | ||
) | ||
] | ||
|
||
return aa.Array1D( | ||
|
@@ -117,7 +152,11 @@ def stacked_array_1d_from( | |
).native | ||
|
||
def add_to_array( | ||
self, new_array: aa.Array1D, array: aa.Array1D, pixels: Tuple[int, int] | ||
self, | ||
new_array: aa.Array1D, | ||
array: aa.Array1D, | ||
pixels: Optional[Tuple[int, int]] = None, | ||
pixels_from_end: Optional[int] = None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess that decorator I mentioned in the other PR would also be applicable here |
||
) -> aa.Array1D: | ||
""" | ||
Extracts the region (e.g. the FPRs) from the line dataset and adds them to a line dataset. | ||
|
@@ -132,9 +171,13 @@ def add_to_array( | |
The row pixel index which determines the region extracted (e.g. `pixels=(0, 3)` will compute the region | ||
corresponding to the 1st, 2nd and 3rd pixels). | ||
""" | ||
region_list = self.region_list_from(pixels=pixels) | ||
region_list = self.region_list_from( | ||
pixels=pixels, pixels_from_end=pixels_from_end | ||
) | ||
|
||
array_1d_list = self.array_1d_list_from(array=array, pixels=pixels) | ||
array_1d_list = self.array_1d_list_from( | ||
array=array, pixels=pixels, pixels_from_end=pixels_from_end | ||
) | ||
|
||
for arr, region in zip(array_1d_list, region_list): | ||
new_array[region.x0 : region.x1] += arr | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe assign 10 to a constant so it's clear what it means rather than just being an arbitrary integer value?