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

Added a angular_radius convenience property to Helioprojective #5191

Merged
merged 1 commit into from Jun 18, 2021

Conversation

Anubhav1107
Copy link
Contributor

Description

Fixes #5182

@Anubhav1107 Anubhav1107 requested a review from a team as a code owner April 6, 2021 13:01
@pep8speaks
Copy link

pep8speaks commented Apr 6, 2021

Hello @Anubhav1107! Thanks for updating this PR.

Line 161:17: W503 line break before binary operator

Line 252:59: W504 line break after binary operator
Line 127:74: W504 line break after binary operator

Comment last updated at 2021-06-02 17:06:03 UTC

@ayshih ayshih marked this pull request as draft April 6, 2021 13:19
@Anubhav1107 Anubhav1107 marked this pull request as ready for review April 6, 2021 13:30
@nabobalis nabobalis marked this pull request as draft April 6, 2021 13:32
@nabobalis nabobalis added coordinates Affects the coordinates submodule No Backport A PR that isn't to be backported to any release branch. (To be used as a flag to other maintainers) labels Apr 6, 2021
Copy link
Member

@ayshih ayshih left a 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.

sunpy/coordinates/frames.py Outdated Show resolved Hide resolved
sunpy/coordinates/frames.py Outdated Show resolved Hide resolved
sunpy/coordinates/frames.py Outdated Show resolved Hide resolved
sunpy/coordinates/frames.py Outdated Show resolved Hide resolved
sunpy/coordinates/frames.py Outdated Show resolved Hide resolved
@Anubhav1107
Copy link
Contributor Author

hey, is it ok now ?

Copy link
Member

@ayshih ayshih left a 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.

sunpy/coordinates/frames.py Outdated Show resolved Hide resolved
sunpy/coordinates/frames.py Outdated Show resolved Hide resolved
sunpy/coordinates/frames.py Outdated Show resolved Hide resolved
@Anubhav1107
Copy link
Contributor Author

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 !

@dstansby
Copy link
Member

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?

@Anubhav1107
Copy link
Contributor Author

Hey @dstansby, I am sorry to be this late, sure. I will try to finish it soon, if not I will tell you!

@Anubhav1107
Copy link
Contributor Author

hey @ayshih, this line you added
_angular_radius(self.rsun, self.observer.radius)

If I try to call this function as

time = frames.Helioprojective()
time.angular_radius
 

It gives
<bound method Helioprojective.angular_radius of <Helioprojective Frame (obstime=None, rsun=695700.0 km, observer=None)>>

My qsn is how do you calculate the angular_radius, If I try to insert a value in them. It gives error
as
AttributeError: 'NoneType' object has no attribute 'radius'

@nabobalis
Copy link
Contributor

nabobalis commented May 13, 2021

In this case, the command line is telling you that angular_radius is a "bound method" and that means you have to call the method with brackets e.g., angular_radius()

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 frames.Helioprojective() has no observer and so goes to get the radius and then errors.

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>

@ayshih
Copy link
Member

ayshih commented May 15, 2021

Tho it does have the "@Property" which I thought dealt with that?

That's correct: The @property decorator must be missing to get that error. I suspect that @Anubhav1107 's local repo does not have the commits as they are in this PR, probably through not fetching commits locally after making changes through GitHub's web interface.

I am not sure if the frames are meant to be called directly? (This is beyond my area).

Using SkyCoord is recommended for most users, but frames will work correctly if called directly. Here's the equivalent without using SkyCoord:

>>> 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>

from sunpy.coordinates import frames # Not sure if we need this but maybe to register the frames?

Yes, an import is needed for SkyCoord to know how to interpret frame="helioprojective", but it can just be import sunpy.coordinates.

sunpy/coordinates/frames.py Show resolved Hide resolved
sunpy/coordinates/frames.py Show resolved Hide resolved
@Anubhav1107
Copy link
Contributor Author

test_ex.txt
Is this an ok unit test example or should how should I change it ?

@nabobalis
Copy link
Contributor

test_ex.txt
Is this an ok unit test example or should how should I change it ?

It will need some work but if you can add it to the PR, we can work on it.

@Anubhav1107
Copy link
Contributor Author

sure, I tried this because when I was doing test with pytest and assert, it started giving error as
warnings._OptionError: invalid module name: 'sunpy.util.exceptions'
It maybe due to env problem so I left it out!

@Anubhav1107 Anubhav1107 marked this pull request as ready for review May 16, 2021 13:32
@Anubhav1107 Anubhav1107 requested a review from a team as a code owner May 16, 2021 13:37
@Anubhav1107 Anubhav1107 requested review from ayshih and removed request for a team May 16, 2021 13:38
@nabobalis
Copy link
Contributor

sure, I tried this because when I was doing test with pytest and assert, it started giving error as
warnings._OptionError: invalid module name: 'sunpy.util.exceptions'
It maybe due to env problem so I left it out!

Err, sounds like it could be. I am not sure what needs to be done to fix it, maybe you need to reinstall sunpy?

@@ -0,0 +1,36 @@
import astropy.units as u
Copy link
Contributor

Choose a reason for hiding this comment

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

Things to do:

  1. This code should go into https://github.com/sunpy/sunpy/blob/main/sunpy/coordinates/tests/test_frames.py not a new file
  2. You do not need most of these imports at all and should be removed.
  3. 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

@Anubhav1107
Copy link
Contributor Author

Thanks much, I changed it. The amount of push and pull req is a little confusing

@nabobalis
Copy link
Contributor

Thanks much, I changed it. The amount of push and pull req is a little confusing

I don't quite understand what you mean.

@nabobalis nabobalis removed the request for review from ayshih May 17, 2021 08:15
@nabobalis nabobalis added the Needs Review Needs reviews before merge label May 17, 2021
Comment on lines 433 to 435
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
Copy link
Member

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().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, thanks!

Copy link
Contributor Author

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)

Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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().

Copy link
Contributor Author

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

changelog/5191.trivial.rst Outdated Show resolved Hide resolved
@@ -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():
Copy link
Contributor

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
Copy link
Contributor

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():
Copy link
Contributor

Choose a reason for hiding this comment

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

Forgot this one?

@ayshih ayshih changed the title added solar_angular_radius Added a angular_radius convenience property to Helioprojective May 18, 2021
@nabobalis nabobalis force-pushed the master branch 2 times, most recently from 374bf6d to bfebec8 Compare June 2, 2021 17:05
@nabobalis nabobalis requested a review from ayshih June 2, 2021 17:53
@nabobalis nabobalis requested review from ayshih and removed request for ayshih June 18, 2021 15:39
Copy link
Member

@ayshih ayshih left a 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

@dstansby dstansby merged commit 9c728e7 into sunpy:main Jun 18, 2021
@dstansby dstansby removed the Needs Review Needs reviews before merge label Jan 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
coordinates Affects the coordinates submodule No Backport A PR that isn't to be backported to any release branch. (To be used as a flag to other maintainers)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add an angular_radius convenience property to Helioprojective
5 participants