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

Fix Spitzer logic #362

Merged
merged 3 commits into from
Dec 11, 2024
Merged

Fix Spitzer logic #362

merged 3 commits into from
Dec 11, 2024

Conversation

troyraen
Copy link
Contributor

@troyraen troyraen commented Dec 8, 2024

Closes #358

Includes two code changes, explained below.

@troyraen troyraen added bug Something isn't working use case: spectroscopy Spectroscopy use case labels Dec 8, 2024
Comment on lines 48 to 53
# If multiple entries are found, pick the closest.
# Or should we take the average instead??
if len(tab) > 0:
if len(tab) > 1:
print("More than 1 entry found", end="")
if not COMBINESPEC:
print(" - pick the closest")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code change:

  • appears to be what the original author intended. (print("More than 1 entry found")
  • does not change the results but does make the code more efficient. (The code block that finds the closest entry now gets skipped when len(tab) == 1.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense to me that this is a typo and not intentional. I agree with the change.

Along the same lines, do we need the 'else' statement for this 'if' statment? since we have already covered the case where it is 0, it should never get to that else. Which may mean that we can get rid of the whole 'if len(tab)> 1 ...else' and reduce the indentation??? Somehow I can't leave this comment on the appropriate line, sorry.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Along the same lines, do we need the 'else' statement for this 'if' statement?

That code block wasn't getting hit originally but it will now when len(tab) == 1. And/but I agree that this could be made simpler (== easier to follow).

for tt in tab:
for tt in tab_final:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code change does change the results, and appears to be what the author intended. The code block above this produces tab_final which contains the single row from tab that is closest to the target if COMBINESPEC is True, else a full copy of tab. In the original code, tab_final was not ever used, so COMBINESPEC had no effect -- spectra were always combined.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I agree that the original intent of the code is to use COMBINESPEC to determine if the spectra should be combined or chosen based on the nearest, and I agree that is not happening (good catch!). I agree this change you suggest makes sense.

@troyraen troyraen marked this pull request as ready for review December 8, 2024 01:50
Copy link
Contributor

@jkrick jkrick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @troyraen for catching those logic issues. I think your suggested changes are sensible and I left comments on them in response to your comments.

I don't know why I can't leave comments on other places in the code, maybe because I wasn't tagged to review?

Some additional suggestions for the code in addition to the inline comments:

  • line 14: change 'HST' to 'Spitzer' - which makes me think that the HST function should be checked for the same logic problems being fixed in this PR (Hey! I read the doctstring)
  • could simplify the np.nanmin line to be np.nanargmin which returns the index directly - not important at all, but I had to look that one up and found the simpler solution

@afaisst if you have time this week, could you check this logic stuff, but if not, I am pretty confident that the changes are what the code was intended to do.

Comment on lines 48 to 53
# If multiple entries are found, pick the closest.
# Or should we take the average instead??
if len(tab) > 0:
if len(tab) > 1:
print("More than 1 entry found", end="")
if not COMBINESPEC:
print(" - pick the closest")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense to me that this is a typo and not intentional. I agree with the change.

Along the same lines, do we need the 'else' statement for this 'if' statment? since we have already covered the case where it is 0, it should never get to that else. Which may mean that we can get rid of the whole 'if len(tab)> 1 ...else' and reduce the indentation??? Somehow I can't leave this comment on the appropriate line, sorry.

for tt in tab:
for tt in tab_final:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I agree that the original intent of the code is to use COMBINESPEC to determine if the spectra should be combined or chosen based on the nearest, and I agree that is not happening (good catch!). I agree this change you suggest makes sense.

@troyraen
Copy link
Contributor Author

troyraen commented Dec 9, 2024

I don't know why I can't leave comments on other places in the code

You may be running into github's limit on the number of lines above or below an actual change that's being made in the PR.

@troyraen
Copy link
Contributor Author

troyraen commented Dec 9, 2024

Thanks @jkrick. I'll look closer at the two HST and np.nanmin things.

@troyraen
Copy link
Contributor Author

I applied your suggestions @jkrick. Good call on np.nanargmin. The HST logic is different but there were similar problems in the docstrings (probably from me copy/pasting in #356).

I think this is ready but I'll wait a bit to see if @afaisst wants to review.

@troyraen troyraen force-pushed the raen/issues/358/spitzer-bugfix branch from 970dee7 to 7706496 Compare December 11, 2024 20:46
@troyraen
Copy link
Contributor Author

Rebased on top of main to pull in recent changes.

@troyraen
Copy link
Contributor Author

Changes approved by @afaisst. Merging now.

@troyraen troyraen merged commit 0e0cb9a into main Dec 11, 2024
3 checks passed
@troyraen troyraen deleted the raen/issues/358/spitzer-bugfix branch December 11, 2024 23:44
github-actions bot pushed a commit that referenced this pull request Dec 11, 2024
* Fix #358

* Apply @jkrick review comments

* Bugfix: Return a Table instead of a Row 0e0cb9a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working use case: spectroscopy Spectroscopy use case
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SpitzerIRS_get_spec seems to have two bugs
2 participants