-
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
Add flagging functions for power spectra #157
Changes from 1 commit
02db5c8
dcd400b
424c366
d815ec0
e0fab29
e176c5a
ce9d731
eedee0f
7f41ac2
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 |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import numpy as np | ||
|
||
mask_generator(nsamples, flags, n_threshold, greedy=False, axis, greedy_threshold, retain_flags=True): | ||
""" | ||
Generates a greedy flags mask from input flags and nsamples arrays | ||
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 think it's worth briefly explaining how the algorithm works here. |
||
|
||
Parameters | ||
---------- | ||
nsamples : numpy.ndarray | ||
integer array with number of samples available for each frequency channel at a given LST angle | ||
|
||
flags : numpy.ndarray | ||
binary array with 1 representing flagged, 0 representing unflagged | ||
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. Is this the same as the output of |
||
|
||
n_threshold : int | ||
minimum number of samples needed for a point to remain unflagged | ||
|
||
greedy : bool | ||
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. What if it's False? |
||
greedy flagging is used if true (default is False) | ||
|
||
axis : int | ||
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. This would be better off as a string, and maybe with a name change, e.g. |
||
which axis to flag first if greedy=True (1 is row-first, 0 is col-first) | ||
|
||
greedy_threshold : float | ||
if greedy=True, the threshold used to flag rows or columns if axis=1 or 0, respectively | ||
|
||
retain_flags : bool | ||
LST-Bin Flags are left flagged even if thresholds are not met (default is True) | ||
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. The data going into this are not necessarily LST binned. |
||
|
||
Returns | ||
------- | ||
mask : numpy.ndarray | ||
binary array of the new mask where 1 is flagged, 0 is unflagged | ||
|
||
""" | ||
|
||
shape = nsamples.shape | ||
flags_output = np.zeros(shape) | ||
|
||
num_exactly_equal = 0 | ||
|
||
# comparing the number of samples to the threshold | ||
|
||
for i in range(shape[0]): | ||
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. Can this nested |
||
for j in range(shape[1]): | ||
if nsamples[i, j] < n_threshold: | ||
flags_output[i, j] = 1 | ||
elif nsamples[i, j] > n_threshold: | ||
if retain_flags and flags[i, j] == 1: | ||
flags_output[i, j] = 1 | ||
else: | ||
flags_output[i, j] = 0 | ||
elif nsamples[i, j] == n_threshold: | ||
if retain_flags and flags[i, j] == 1: | ||
flags_output[i, j] = 1 | ||
else: | ||
flags_output[i, j] = 0 | ||
num_exactly_equal += 1 | ||
|
||
# the greedy part | ||
|
||
if axis == 0: | ||
if greedy: | ||
column_flags_counter = 0 | ||
for j in range(shape[1]): | ||
if np.sum(flags_output[:, j])/shape[0] > greedy_threshold: | ||
flags_output[:, j] = np.ones([shape[0]]) | ||
column_flags_counter += 1 | ||
for i in range(shape[0]): | ||
if np.sum(flags_output[i, :]) > column_flags_counter: | ||
flags_output[i, :] = np.ones([shape[1]]) | ||
elif axis == 1: | ||
if greedy: | ||
row_flags_counter = 0 | ||
for i in range(shape[0]): | ||
if np.sum(flags_output[i, :])/shape[1] > greedy_threshold: | ||
flags_output[i, :] = np.ones([shape[1]]) | ||
row_flags_counter += 1 | ||
for j in range(shape[1]): | ||
if np.sum(flags_output[:, j]) > row_flags_counter: | ||
flags_output[:, j] = np.ones([shape[0]]) | ||
|
||
return flags_output |
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 a more descriptive function name, e.g.
construct_factorizable_mask
?