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
Added a angular_radius
convenience property to Helioprojective
#5191
Conversation
Hello @Anubhav1107! Thanks for updating this PR.
Comment last updated at 2021-06-02 17:06:03 UTC |
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.
Thanks for the PR! In addition to my comments, also remove a bunch of the empty newlines.
hey, is it ok now ? |
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.
hey, is it ok now ?
Heh, no, it doesn't even run because you didn't import the _angular_radius()
function.
This PR will also need a unit test.
Ahh, So sorry, I totally forgot it ! |
Hi @Anubhav1107, we would really like to get this into sunpy 3.0, so were wondering if you could update this in the next few days? If not, would you be okay with someone else finishing it off? |
Hey @dstansby, I am sorry to be this late, sure. I will try to finish it soon, if not I will tell you! |
hey @ayshih, this line you added If I try to call this function as
It gives My qsn is how do you calculate the angular_radius, If I try to insert a value in them. It gives error |
In this case, the command line is telling you that Tho it does have the "@Property" which I thought dealt with that? EDIT: I ran the code, the issue is that the frame you created with I am not sure if the frames are meant to be called directly? (This is beyond my area). But to get a working example you can do: import astropy.units as u
from astropy.coordinates import SkyCoord
from sunpy.coordinates import frames # Not sure if we need this but maybe to register the frames?
sc = SkyCoord(0*u.deg, 0*u.deg, 5*u.km,obstime="2010/01/01T00:00:00", observer="earth", frame="helioprojective")
sc.angular_radius
<Angle 975.51961541 arcsec> |
That's correct: The
Using >>> import astropy.units as u
>>> from sunpy.coordinates import Helioprojective
>>> h = Helioprojective(0*u.deg, 0*u.deg, obstime='2010-01-01', observer='earth')
>>> h.angular_radius
<Angle 975.51961541 arcsec>
Yes, an import is needed for |
test_ex.txt |
It will need some work but if you can add it to the PR, we can work on it. |
sure, I tried this because when I was doing test with pytest and assert, it started giving error as |
Err, sounds like it could be. I am not sure what needs to be done to fix it, maybe you need to reinstall sunpy? |
sunpy/map/frames_test.py
Outdated
@@ -0,0 +1,36 @@ | |||
import astropy.units as u |
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.
Things to do:
- This code should go into https://github.com/sunpy/sunpy/blob/main/sunpy/coordinates/tests/test_frames.py not a new file
- You do not need most of these imports at all and should be removed.
- The test should be something like:
def test_angular_radius():
coord = frames.Helioprojective(0*u.deg,0*u.deg,5*u.km,obstime="2010/01/01T00:00:00", observer="earth")
sc = SkyCoord(0*u.deg, 0*u.deg, 5*u.km,obstime="2010/01/01T00:00:00", observer="earth", frame="helioprojective")
assert coord.angular_radius==sc.angular_radius
Thanks much, I changed it. The amount of push and pull req is a little confusing |
I don't quite understand what you mean. |
coord = Helioprojective(0*u.deg, 0*u.deg, 5*u.km, obstime="2010/01/01T00:00:00", observer="earth") | ||
sc = SkyCoord(0*u.deg, 0*u.deg, 5*u.km, obstime="2010/01/01T00:00:00", observer="earth", frame="helioprojective") | ||
assert coord.angular_radius==sc.angular_radius |
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.
This test has low value as written. sc.angular_radius
simply calls Helioprojective.angular_radius
, so the equality check will always succeed, as long as Heliprojective.angular_radius
returns a value without an error. However, the value could be wildly wrong.
A better test would be a consistency check that coord.angular_radius
is equal* to the return value of sunpy.coordinates.sun.angular_radius(coord.obstime)
. We have accuracy checks for the sunpy.coordinates.sun
functions against The Astronomical Almanac, so that would implicitly check the accuracy as well.
* Incidentally, don't literally use ==
. You should use assert_quantity_allclose()
.
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.
Sure, thanks!
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.
Hey, I am getting this output after the code
AssertionError:
Not equal to tolerance rtol=1e-07, atol=0
Mismatch: 100%
Max absolute difference: 2.37443473
Max relative difference: 0.00243402
x: array(973.145181)
y: array(975.519615)
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.
I can't really debug this if you don't show the code as well. The 975.519615 arcseconds is correct for this observation time. I can't guess what code is returning 973.145181 arcseconds.
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.
Ooh,this is the code
def test_angular_radius():
coord = frames.Helioprojective(0*u.deg, 0*u.deg, 5*u.km, obstime="2010/01/01T00:00:00", observer="earth")
print(coord.angular_radius)
print(sunpy.coordinates.sun.angular_radius(coord.obstime))
assert_quantity_allclose(coord.angular_radius,sunpy.coordinates.sun.angular_radius(coord.obstime))
when the observer is earth it works fine, but if changed to moon it was giving error
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.
Well, that's because sunpy.coordinates.sun.angular_radius()
is expressly for an Earth observer. An observer on the Moon would be a different distance from the Sun, so the angular radius is different from what is returned by sunpy.coordinates.sun.angular_radius()
.
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.
Sure, I have added the cases along with the changes
@@ -427,3 +428,20 @@ def test_skycoord_hpc(args, kwargs): | |||
hgs = sc.transform_to("heliographic_stonyhurst") | |||
|
|||
assert isinstance(hgs.frame, HeliographicStonyhurst) | |||
|
|||
|
|||
def test1_ang_rad(): |
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.
Can you fix the names of these tests?
@@ -3,6 +3,7 @@ | |||
|
|||
import numpy as np | |||
import pytest | |||
import sunpy |
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.
Why was this imported?
assert_quantity_allclose(coord.angular_radius, sun.angular_radius(coord.obstime)) | ||
|
||
|
||
def test3_ang_radius_no_obstime(): |
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.
Forgot this one?
angular_radius
convenience property to Helioprojective
374bf6d
to
bfebec8
Compare
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.
Looks good to me
Description
Fixes #5182