Skip to content
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

Adding unique_pair keyword to obs_nodding_irregular for Issue #11. #12

Merged
merged 2 commits into from
May 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 44 additions & 3 deletions pycrires/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -3964,6 +3964,7 @@ def obs_nodding_irregular(
correct_bad_pixels: bool = True,
extraction_required: bool = True,
check_existing: bool = False,
unique_pairs: bool = False,
) -> None:
"""
Method for running ``cr2res_obs_nodding``.
Expand Down Expand Up @@ -3992,6 +3993,13 @@ def obs_nodding_irregular(
check_existing : bool
Search for existing files in the product
folder. Avoids re-reducing existing files.
unique_pairs : bool
In case of nods with multiple but equal numbers of exposures (e.g. AABB BBAA AABB...),
pair each A uniquely to each B in sequence. So the nth A goes with the nth B and the
nth B goes with the nth A. This will only be carried out if the numbers of nodding
exposures is equal.



Returns
-------
Expand Down Expand Up @@ -4029,6 +4037,12 @@ def obs_nodding_irregular(

print(f"Number of exposures at nod A: {nod_a_count}")
print(f"Number of exposures at nod B: {nod_b_count}")

if nod_a_count != nod_b_count and unique_pairs == True:
warnings.warn(f"Nodding counts are unequal ({nod_a_count} A vs {nod_b_count} B)."
"Reverting to unique_pairs = False.")
unique_pairs = False

# Create SOF file

count_exp_a = 0
Expand All @@ -4037,6 +4051,13 @@ def obs_nodding_irregular(
# Iterate over nod A exposures
a_i_rows = self.header_data.index[nod_a_exp]
b_i_rows = self.header_data.index[nod_b_exp]

if unique_pairs:
#We are going to count A and B frames from the beginning:
A_counter = 0
B_counter = 0
sequence = []

for i_row in science_idx:
nod_ab = self.header_data["SEQ.NODPOS"][i_row]
if nod_ab == "A":
Expand All @@ -4058,9 +4079,21 @@ def obs_nodding_irregular(

file_0 = self.header_data["ORIGFILE"][i_row]
if nod_ab == "A":
closest_i_diffnod = b_i_rows[np.argmin(np.abs(i_row - b_i_rows))]
if not unique_pairs:#This is the default.
closest_i_diffnod = b_i_rows[np.argmin(np.abs(i_row - b_i_rows))]
else:
closest_i_diffnod = b_i_rows[B_counter]
B_counter+=1
elif nod_ab == "B":
closest_i_diffnod = a_i_rows[np.argmin(np.abs(i_row - a_i_rows))]
if not unique_pairs:
closest_i_diffnod = a_i_rows[np.argmin(np.abs(i_row - a_i_rows))]
else:
closest_i_diffnod = a_i_rows[A_counter]
A_counter+=1

if unique_pairs and verbose:#This is for printing the pairing at the end.
sequence.append([i_row,closest_i_diffnod])

file_1 = self.header_data["ORIGFILE"][closest_i_diffnod]

for file in [file_0, file_1]:
Expand Down Expand Up @@ -4201,7 +4234,6 @@ def obs_nodding_irregular(
"spectra in order to maintain the "
"spatial dimension."
)

if verbose:
stdout = None
else:
Expand Down Expand Up @@ -4344,6 +4376,15 @@ def obs_nodding_irregular(
with open(self.json_file, "w", encoding="utf-8") as json_file:
json.dump(self.file_dict, json_file, indent=4)

if unique_pairs and verbose:
print('These were the file IDs of the A frames:')
print(a_i_rows)
print('\n These were the file IDs of the B frames:')
print(b_i_rows)
print('\n This is how they were paired in cr2res_obs_nodding:')
print(sequence)


@typechecked
def molecfit_input(self, nod_ab: str = "A") -> None:
"""
Expand Down