Repository navigation
Moon phase/illumination functions begun with PyEphem implementation - #39
Conversation
|
A topic for discussion: looking at all of these functions that start with |
|
@ejeschke Sorry, I missed it in the doctoring! |
There was a problem hiding this comment.
I don't quite understand why here (and in moon_phase) you have the moon and sun keywords. Doesn't it make more sense to just use time? Otherwise the user might pass in moon/sun objects that don't correctly match time, and then all kinds of stuff might go bonkers (without an error). After all, one of the Zen of python elements is "Errors should never pass silently."...
If this is a performance thing, I would instead suggest caching. I.e. something like:
# somewhere you'll have to create self._cached_moons... in __init__ is probably the easiest
if time in self._cached_moons: # this might need to be time.jd? Not sure if `Time` objects are hashable
moon = self._cached_moons[time]
else:
moon = get_moon(time, self.location, self.pressure)
self._cached_moons[time] = moon
# similar for the sun
There was a problem hiding this comment.
It was meant to be a performance thing, since you're likely to ask for the illumination and position of the moon at the same time. I'll remove that feature for now and hold onto caching for discussion later – there are bunch of other places where we could cache too.
|
@bmorris3: I'm a bit confused by how this is now implemented. As I recall from one of your notebooks, the astropy/jplephem approach got the (GCRS) RA/Dec right (at least insofar as it matched pyephem), but it was only the GCRS->AltAz conversion that featured a bug. But the code you have here uses pyephem to compute the ra and dec but not the alt/az. Or am I misunderstanding something? So I was thinking this would make it so that |
|
@eteq You're right, the I (somehow) didn't realize you could initialize a |
There was a problem hiding this comment.
You'll need to pass in all the other elements of the altaz frame that apply for this observer. The easiest/most interanlly consistent way is probably:
SkyCoord(alt=moon_alt*u.rad, az=moon_az*u.rad, frame=self.altaz(time))|
Ok gotcha. But one reason I was asking: Here, I think what you're doing in |
|
@bmorris3 - I figured out what’s up with the recursion thing. So that brings in the reason for why So the work-around for now is to have |
|
@eteq, I'm still getting the recursion depth error even after making the from astroplan.moon import get_moon
from astropy.coordinates import SkyCoord, EarthLocation, AltAz, get_sun
from astropy.time import Time
time = Time.now()
location = EarthLocation('-122d', '47d')
moon = get_moon(time, location)
sun = get_sun(time).transform_to(AltAz(location=location, obstime=time))
print(moon.separation(sun)) # Fails
print(sun.separation(moon)) # Fails |
|
@bmorris3 - ok, now I think we've reached a bug in astropy rather than a problem with what frames are being compared. I suggest this as a work-around: from astropy.coordinates import Angle
from astropy.coordinates.angle_utilities import angular_separation
moonsph = moon.spherical
sunsph = moon.spherical
sep = Angle(angular_separation(moonsph.lon, moonsph.lat, sunsph.lon, sunsph.lat), u.deg)that's basically the same as the guts of |
|
@eteq / @cdeil I think this is as far as this PR is going to go until a few related astropy-related issues (astropy/astropy#4033, astropy/astropy#3998, astropy/astropy#3938, astropy/astropy#3920) are sorted out, and we can replace the PyEphem placeholders with the long-term jplephem equivalents. |
|
I'm +1 to remove the
Otherwise 👍 |
|
@cdeil I left the |
|
I'm +0 on @cdeil's suggestion - it's fine to either remove the However, I think it's not that important either way, because those functions are not to be part of the public API, right? Rather, they're internal functions used by Which reminds me of one additional (easy) change you need, @bmorris3: |
|
If the function and method basically do the same thing, it's good if they have the same name, no? |
There was a problem hiding this comment.
This still says moon/sun instead of time/location (same below in moon_illumination)
|
Alright, looks good. Merging! |
Moon phase/illumination functions begun with PyEphem implementation
As per Issue #35 , the machinery for computing the position of the moon with jplephem is on the back burner until a bug in astropy is resolved. In the mean time, I've implemented some of the lunar convenience functions using PyEphem, with intentions to swap it out in favor of our permanent jplephem solution when the astropy bug is corrected.
I also implemented
moon_altaz()with tests, but commented them out, since these the routines are affected by the aforementioned bug.