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

Sub-pixel precision for calculate_fwhm #484

Merged
merged 6 commits into from
Sep 19, 2019

Conversation

danielnperera
Copy link

Improvement to the existing algorithm using linear interpolation to achieve sub-pixel precision.

  • Updated algorithm
  • Updated tests
  • Updated documentation tests

Fixes #378

@danielnperera
Copy link
Author

@nmearl, @eteq suggested this issue as a first time contribution from me. One of the automated tests (Python 3.5) is failing when it tries to access remote data. I'm not sure what I could do to fix that. Would you be able to take a look at this?

Thanks,
Dan

@brechmos-stsci
Copy link

The tests are kinda flaky sometimes. I restarted it twice and the second time it passed :)

argmax = flux_value.argmax()
halfval = flux_value[argmax] / 2
left = flux_value[:argmax] < halfval
right = flux_value[argmax + 1:] < halfval
Copy link
Contributor

Choose a reason for hiding this comment

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

Slices on numpy arrays are none inclusive on the upper range. Are you purposely not including the highest flux value, or did you mean something like this instead:

Suggested change
right = flux_value[argmax + 1:] < halfval
right = flux_value[argmax:] < halfval

Copy link
Author

Choose a reason for hiding this comment

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

Hi, yes - I was excluding it because flux_value[argmax] == halfval, so there's no point in including it during the comparison operation.

Copy link
Author

Choose a reason for hiding this comment

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

sorry, I meant flux_value[argmax] = halfval * 2

@nmearl
Copy link
Contributor

nmearl commented Jul 24, 2019

This looks good, but you'll need to rebase for the latest changes in master.

@danielnperera
Copy link
Author

I'm having some difficulty again with the CI connecting to zenodo.org with 404 not found errors. Is there a way to rerun the tests without closing and reopening the PR?

@danielnperera danielnperera reopened this Jul 26, 2019
@eteq eteq added this to the v0.6 milestone Sep 12, 2019
argmax = np.argmax(flux)
halfval = flux[argmax] / 2
# The .value attribute is used here as the following algorithm does not
# use any array operations and would otherwise introduce a relatively
Copy link
Contributor

@dhomeier dhomeier Sep 17, 2019

Choose a reason for hiding this comment

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

Do you really mean "any array operations" here, or rather "Quantity" or "as a property", because flux.value is a np.ndarray and you are using indexing operations etc.?

# since the maximum value occurs at wavelength=1, and the half-value of
# flux (0.5) occurs at exactly wavelength=2, the result should be
# exactly 1 (2 - 1).
assert result == 1.0*u.um
Copy link
Contributor

Choose a reason for hiding this comment

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

How about modifying that test (or adding another one) so that wavelength=2 is not actually on the grid, to test the interpolation? E.g.
wavelengths = np.linspace(1, 10, 31) * u.um

Copy link
Contributor

Choose a reason for hiding this comment

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

@dhomeier can you open another issue to address expanding on the unit testing? I'd like to merge this PR now for a release and iterate on it over time.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure. Just wanted to note that the PR adds some functionality for which there is no test coverage now, but if it has time I can look into it sometime.

Copy link
Contributor

Choose a reason for hiding this comment

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

@dhomeier, I've gone ahead and included a test for this interpolation case. No need to make a new issue.

@nmearl nmearl merged commit e0cc4e9 into astropy:master Sep 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fwhm could be sub-pixel precise
6 participants