-
Notifications
You must be signed in to change notification settings - Fork 51
Dithering utils - WIP #735
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
Open
wtgee
wants to merge
35
commits into
panoptes:develop
Choose a base branch
from
wtgee:dithering-utils
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
48e3ccb
Add the dither pattern util from AstroHuntsman with some minor changes:
wtgee c83e5ef
Base commit of dither testing
wtgee 01afd6e
Mostly just rearranging to get within line-width limits
wtgee 3eee887
Adding the plot utility function for the dither
wtgee bd0389a
Adding an option to put a finder chart on the back of the dither
wtgee 0de12d7
Simplifying the plot to only require the generated positions
wtgee d805bed
Cleaning up docstrings
wtgee 3628a45
Adding doctest examples
wtgee 2e40488
Changing variable name and cleaning up based on review
wtgee 7089e89
Fixing param name
wtgee 582415a
Small change to hit some split coverage
wtgee 7f46494
Fixing helper function (it's not a method)
wtgee 27feb38
Merge branch 'develop' of https://github.com/panoptes/POCS into dithe…
wtgee 0f091b6
Merge branch 'dithering-utils' of github.com:wtgee/POCS into ditherin…
wtgee c88f01b
Dithering Utils
wtgee d0bea7e
Add baseline plots
wtgee c360d7d
Restoring the normal tolerance on the mpl image comparison.
wtgee e787017
Attemping to upload bad images after test failure
wtgee 32fdcb0
More trying to get images to work.
wtgee 64bf586
Adding in the actual save path to make it work
wtgee 594bc4c
Trying an alternative temporary image upload location
wtgee 46a8179
Minor typos (sigh)
wtgee 4674d1d
I sure do love testing things on travis one upload at a time!
wtgee dc484d2
Still trying to simply output the url
wtgee 6210dcc
Seriously though. This is my last attempt. This is why people leave t…
wtgee 2b54e19
Ok, I lied. I'm trying agian.
wtgee 462d4fe
How about not removint the text?
wtgee 8411178
Making tolerance on diff image high enough to not fail, which basically
wtgee a7721e1
Put failed image upload directly in travis
wtgee b153f77
Try new script (will fail) with no tolerance. This means at least two
wtgee aa7e765
And yet here I am, still working on it...
wtgee cc57754
Deep breaths...
wtgee 45dc0cb
Revert "Put failed image upload directly in travis"
wtgee 76d7375
Changing back the tolerance, which makes it so it is not really being…
wtgee 7d41d0e
Adding comment about test
wtgee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,191 @@ | ||
| import pytest | ||
| import astropy.units as u | ||
| from astropy.coordinates import SkyCoord | ||
| from astropy.coordinates import Angle | ||
|
|
||
| from pocs.utils import dither | ||
|
|
||
|
|
||
| def test_dice9_SkyCoord(): | ||
| base = SkyCoord("16h52m42.2s -38d37m12s") | ||
|
|
||
| positions = dither.get_dither_positions(base_position=base, | ||
| num_positions=12, | ||
| pattern=dither.dice9, | ||
| pattern_offset=30 * u.arcminute) | ||
|
|
||
| assert isinstance(positions, SkyCoord) | ||
| assert len(positions) == 12 | ||
| # postion 0 should be the base position | ||
| assert positions[0].separation(base) < Angle(1e12 * u.degree) | ||
| # With no random offset positions 9, 10, 11 should be the same as 0, 1, 2 | ||
| assert positions[0:3].to_string() == positions[9:12].to_string() | ||
| # Position 1 should be 30 arcminute offset from base, in declination direction only | ||
| assert base.spherical_offsets_to( | ||
| positions[1])[0].radian == pytest.approx(Angle(0 * u.degree).radian) | ||
| assert base.spherical_offsets_to( | ||
| positions[1])[1].radian == pytest.approx(Angle(0.5 * u.degree).radian) | ||
| # Position 3 should be 30 arcminute offset from base in RA only. | ||
| assert base.spherical_offsets_to( | ||
| positions[3])[0].radian == pytest.approx(Angle(0.5 * u.degree).radian) | ||
| assert base.spherical_offsets_to( | ||
| positions[3])[1].radian == pytest.approx(Angle(0 * u.degree).radian) | ||
|
|
||
|
|
||
| def test_dice9_string(): | ||
| base = "16h52m42.2s -38d37m12s" | ||
|
|
||
| positions = dither.get_dither_positions(base_position=base, | ||
| num_positions=12, | ||
| pattern=dither.dice9, | ||
| pattern_offset=30 * u.arcminute) | ||
|
|
||
| base = SkyCoord(base) | ||
|
|
||
| assert isinstance(positions, SkyCoord) | ||
| assert len(positions) == 12 | ||
| # postion 0 should be the base position | ||
| assert positions[0].separation(base) < Angle(1e12 * u.degree) | ||
| # With no random offset positions 9, 10, 11 should be the same as 0, 1, 2 | ||
| assert positions[0:3].to_string() == positions[9:12].to_string() | ||
| # Position 1 should be 30 arcminute offset from base, in declination direction only | ||
| assert base.spherical_offsets_to( | ||
| positions[1])[0].radian == pytest.approx(Angle(0 * u.degree).radian) | ||
| assert base.spherical_offsets_to( | ||
| positions[1])[1].radian == pytest.approx(Angle(0.5 * u.degree).radian) | ||
| # Position 3 should be 30 arcminute offset from base in RA only. | ||
| assert base.spherical_offsets_to( | ||
| positions[3])[0].radian == pytest.approx(Angle(0.5 * u.degree).radian) | ||
| assert base.spherical_offsets_to( | ||
| positions[3])[1].radian == pytest.approx(Angle(0 * u.degree).radian) | ||
|
|
||
|
|
||
| def test_dice9_bad_base_position(): | ||
| with pytest.raises(ValueError): | ||
| dither.get_dither_positions(base_position=42, | ||
| num_positions=42, | ||
| pattern=dither.dice9, | ||
| pattern_offset=300 * u.arcsecond) | ||
|
|
||
|
|
||
| def test_dice9_random(): | ||
| base = SkyCoord("16h52m42.2s -38d37m12s") | ||
|
|
||
| # Offsets don't have units so added as arcseconds | ||
| positions = dither.get_dither_positions(base_position=base, | ||
| num_positions=12, | ||
| pattern=dither.dice9, | ||
| pattern_offset=30 * 60, | ||
| random_offset=30) | ||
|
|
||
| assert isinstance(positions, SkyCoord) | ||
| assert len(positions) == 12 | ||
| # postion 0 should be the base position | ||
| assert positions[0].separation(base) < Angle(30 * 2**0.5 * u.arcsecond) | ||
|
|
||
| angle_0 = Angle(0 * u.degree).radian | ||
| angle_05 = Angle(0.5 * u.degree).radian | ||
| angle_30 = Angle(30 * u.arcsecond).radian | ||
| position_1_offset = base.spherical_offsets_to(positions[1]) | ||
| position_3_offset = base.spherical_offsets_to(positions[3]) | ||
|
|
||
| # Position 1 should be 30 arcminute offset from base, in declination direction only | ||
| assert position_1_offset[0].radian == pytest.approx(angle_0, abs=angle_30) | ||
| assert position_1_offset[1].radian == pytest.approx(angle_05, abs=angle_30) | ||
|
|
||
| # Position 3 should be 30 arcminute offset from base in RA only. | ||
| assert position_3_offset[0].radian == pytest.approx(angle_05, abs=angle_30) | ||
| assert position_3_offset[1].radian == pytest.approx(angle_0, abs=angle_30) | ||
|
|
||
|
|
||
| def test_random(): | ||
| base = SkyCoord("16h52m42.2s -38d37m12s") | ||
|
|
||
| positions = dither.get_dither_positions(base_position=base, | ||
| num_positions=12, | ||
| random_offset=30 * u.arcsecond) | ||
| assert isinstance(positions, SkyCoord) | ||
| assert len(positions) == 12 | ||
|
|
||
| angle_0 = Angle(0 * u.degree).radian | ||
| angle_30 = Angle(30 * u.arcsecond).radian | ||
| position_0_offset = base.spherical_offsets_to(positions[0]) | ||
| position_1_offset = base.spherical_offsets_to(positions[1]) | ||
|
|
||
| assert position_0_offset[0].radian == pytest.approx(angle_0, abs=angle_30) | ||
| assert position_0_offset[1].radian == pytest.approx(angle_0, abs=angle_30) | ||
|
|
||
| assert position_1_offset[0].radian == pytest.approx(angle_0, abs=angle_30) | ||
| assert position_1_offset[1].radian == pytest.approx(angle_0, abs=angle_30) | ||
|
|
||
|
|
||
| def test_dice5(): | ||
| base = SkyCoord("16h52m42.2s -38d37m12s") | ||
|
|
||
| positions = dither.get_dither_positions(base_position=base, | ||
| num_positions=12, | ||
| pattern=dither.dice5, | ||
| pattern_offset=30 * u.arcminute) | ||
|
|
||
| assert isinstance(positions, SkyCoord) | ||
| assert len(positions) == 12 | ||
| # postion 0 should be the base position | ||
| assert positions[0].separation(base) < Angle(1e12 * u.degree) | ||
| # With no random offset positions 5, 6, 7 should be the same as 0, 1, 2 | ||
| assert positions[0:3].to_string() == positions[5:8].to_string() | ||
| # Position 1 should be 30 arcminute offset from base, in RA and dec | ||
| assert base.spherical_offsets_to( | ||
| positions[1])[0].radian == pytest.approx(Angle(0.5 * u.degree).radian) | ||
| assert base.spherical_offsets_to( | ||
| positions[1])[1].radian == pytest.approx(Angle(0.5 * u.degree).radian) | ||
| # Position 3 should be 30 arcminute offset from base in RA and dec | ||
| assert base.spherical_offsets_to(positions[3])[0].radian == pytest.approx( | ||
| Angle(-0.5 * u.degree).radian) | ||
| assert base.spherical_offsets_to(positions[3])[1].radian == pytest.approx( | ||
| Angle(-0.5 * u.degree).radian) | ||
|
|
||
|
|
||
| def test_custom_pattern(): | ||
| base = SkyCoord("16h52m42.2s -38d37m12s") | ||
| cross = ((0, 0), | ||
| (0, 1), | ||
| (1, 0), | ||
| (0, -1), | ||
| (-1, 0)) | ||
|
|
||
| positions = dither.get_dither_positions(base_position=base, | ||
| num_positions=12, | ||
| pattern=cross, | ||
| pattern_offset=1800 * u.arcsecond) | ||
|
|
||
| assert isinstance(positions, SkyCoord) | ||
| assert len(positions) == 12 | ||
| # postion 0 should be the base position | ||
| assert positions[0].separation(base) < Angle(1e12 * u.degree) | ||
| # With no random offset positions 5, 6, 7 should be the same as 0, 1, 2 | ||
| assert positions[0:3].to_string() == positions[5:8].to_string() | ||
| # Position 3 should be 30 arcminute offset from base, in declination direction only | ||
| assert base.spherical_offsets_to( | ||
| positions[3])[0].radian == pytest.approx(Angle(0 * u.degree).radian) | ||
| assert base.spherical_offsets_to(positions[3])[1].radian == pytest.approx( | ||
| Angle(-0.5 * u.degree).radian) | ||
| # Position 4 should be 30 arcminute offset from base in RA only. | ||
| assert base.spherical_offsets_to(positions[4])[0].radian == pytest.approx( | ||
| Angle(-0.5 * u.degree).radian) | ||
| assert base.spherical_offsets_to( | ||
| positions[4])[1].radian == pytest.approx(Angle(0 * u.degree).radian) | ||
|
|
||
|
|
||
| # Note that the tolerance is way to high for this to be an effective test but | ||
| # we are waiting on some clarity from the module. | ||
| # https://github.com/matplotlib/pytest-mpl/issues/81 | ||
| @pytest.mark.mpl_image_compare(baseline_dir='baseline_images', tolerance=15) | ||
| def test_plot_dither(tmpdir): | ||
| base = SkyCoord("16h52m42.2s -38d37m12s") | ||
| positions = dither.get_dither_positions(base_position=base, | ||
| num_positions=12, | ||
| pattern=dither.dice9, | ||
| pattern_offset=30 * u.arcminute) | ||
|
|
||
| dither_figure = dither.plot_dither_pattern(positions) | ||
| return dither_figure |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@jamessynge when you get a chance I would appreciate your thoughts on this.