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

Beginning in the FixedTarget and Observer classes #11

Merged
merged 12 commits into from
Jun 26, 2015

Conversation

bmorris3
Copy link
Contributor

No description provided.

@@ -25,8 +40,10 @@ class Observer(object):
Some comments.
"""

def __init__(self, name, longitude, latitude, elevation, pressure,
relative_humidity, temperature, timezone, description=None):
def __init__(self, name=None, location=None, latitude=None, longitude=None,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we instead use the **kwargs syntax and then kwargs.get or kwargs.pop the keywords one at a time?

Copy link
Member

Choose a reason for hiding this comment

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

I think my preference is no to kwargs -- if the arguments are spelled out, it is easier to quickly see what is expected from the documentation of the call sequence.

Copy link
Member

Choose a reason for hiding this comment

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

👍 to @adrn here. Also makes it easier to see what the default is.

@cdeil
Copy link
Member

cdeil commented Jun 19, 2015

@bmorris3 – When you make pull requests, we get a notification, but we don't know whether you want us to review them at this point or not. In Astropy and generally on Github, people do this differently, you could:

Another important thing to know (which you probably do) is that Github doesn't send notifications when you push new commits to a branch. So if there has been review, and then you've addressed the comments, and want something to be merged or a second round of review, you have to leave a comment saying so.

location : `~astropy.coordinates.EarthLocation`
The location (latitude, longitude, elevation) of the observatory.

longitude : str or `~astropy.units.quantity`
Copy link
Member

Choose a reason for hiding this comment

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

quantity needs to be Quantity or the Sphinx link won't work.
You probably know this, but just in case ... the commands to check the docs locally are:

python setup.py build_sphinx
open _docs/_build/html/index.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gah, I should have caught that!

@eteq
Copy link
Member

eteq commented Jun 19, 2015

@bmorris3 - something else is confusing me about this PR: it appears to have some (all?) of the commits from #4. Did you mean to do that? I'm guessing not, because it looks like this is only supposed to include some changes in core.py, and you have a commit where you removed the API doc. This doesn't actually remove it from history, and if you merge this after the API is merged, this will delete that document, which I don't think is what you want.

So maybe you want to rebase this against master.

git checkout initclasses # you might already be on this branch
git branch initclasses-backup # insurance in case you screw up something -- you'll  always back it all out by doing git reset --hard initclasses-backup
git fetch upstream  # this might actually be "astroplanners" depending on how your remotes are set up.  I try to avoid ever having an "origin"/"upstream" because I find it confusing, so I always use the same names as github assigns.  But YMMV.
git rebase -i upstream/master

this will bring up an editor showing you all the commits between master and this branch. You'll want to delete the top 3 (which are from the API branch). Then when you close your editor it will give you an error about The previous cherry-pick is now empty, possibly due to conflict resolution. Just do git rebase --continue and everything will be fine. Once you've done that, you'll see that this branch is just the two commits you wanted and nothing else. So you can do git push origin initclasses -f and all should be good.

@bmorris3
Copy link
Contributor Author

Just to leave a note here – @eteq helped me do the rebase, they won't appear in the PR.

Those were not the commits you were looking for.
– Obi Eteq

@@ -2,6 +2,21 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)

from astropy.coordinates import (EarthLocation, Latitude, Longitude, SkyCoord,
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't either, maybe @eteq can give us some hints on how to read these logs on Monday or in the Hangout on Tuesday.

Copy link
Member

Choose a reason for hiding this comment

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

I still don't understand why that line gave an error on travis-ci:

ImportError: No module named astropy.coordinates

But if you fix the other errors mentioned below and python setup.py test (which imports this file) works locally, it should work on travis-ci, too.

Copy link
Member

Choose a reason for hiding this comment

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

Just adding a line note to remind us that this was resolved by a later commit -- the issue was a missing indentation in astroplan/__init__.py for a line that was importing from astroplan.core.

@eteq
Copy link
Member

eteq commented Jun 23, 2015

A quick note: that missing indent that fixed the tests that @bmorris3 added in the last commit at @adrn's suggestion was not a problem with the package template, because there's no core module in the package template. (no action required, just an FYI about why it happened)

# positions due to leap seconds.
tolerance = 30*u.arcsec
assert (abs(pyephem_altitude - astroplan_altitude) < tolerance and
abs(pyephem_azimuth - astroplan_azimuth) < tolerance)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@astroplanners/astroplanners-contributors : Leap seconds will make comparison with PyEphem tricky in our tests, since PyEphem uses old Earth orientation standards and astroplan uses up-to-date IERS tables. Any ideas on how to handle the differences in apparent positions of targets as a result?

Here I use a very broad tolerance in the accepted difference in altitude/azimuth between astroplan and PyEphem (30 arcsec). In the above test, the differences are significantly smaller than this tolerance:

>>> (pyephem_altitude - astroplan_altitude).to('arcsec')
<Angle 0.10845603317193309 arcsec>

>>> (pyephem_azimuth - astroplan_azimuth).to('arcsec')
<Angle 7.0463692237353825 arcsec>

Copy link
Member

Choose a reason for hiding this comment

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

There's not much you can do. Either make the tolerance so large that it's OK (and document in a comment or somewhere that the difference is understood). Or test against another software package, e.g. does Skyfield have this functionality?

location=location,
**environment_kwargs)

assert obs1.location == obs2.location, ('Locations not parsed equivalently')
Copy link
Member

Choose a reason for hiding this comment

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

I'm -1 on adding descriptions of assert fails.
Over time it adds up to significance work and amount of text we have to write / discuss, with IMO no benefit.
When tests fail pytest will give a very good error message (line number, values, traceback).
Usually one will have to look at the test and code anyways, and then the description on the assert adds nothing useful.

Copy link
Member

Choose a reason for hiding this comment

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

@cdeil What do you mean here? I think assert tests are useful to have for things that must be true, but haven't really thought about it...

Copy link
Member

Choose a reason for hiding this comment

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

@adrn – I'm not sure I understand what you mean with "assert fails".
All asserts in tests should always be true, no?

I mean that here , ('Locations not parsed equivalently') can be removed because it's useless.

Copy link
Member

Choose a reason for hiding this comment

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

I think I mean "assert tests"... and I read you as saying "assert tests" as well! But now I see what you mean...oops

Copy link
Member

Choose a reason for hiding this comment

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

I don't see the problem here in a general sense, @cdeil : leaving a useful note about what you're trying to test with the assert is sort of self-documenting code in my mind. You could instead put in a comment just above, but I think this works just as well.

That said, that particular string is not terribly informative in that it says something you could guess pretty much right away from the fact that it failed. I'd go with something more like “using latitude/longitude/elvation keywords gave a different answer from passing in an EarthLocation directly".

Copy link
Member

Choose a reason for hiding this comment

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

@eteq – I agree leaving a note on the purpose of a given test / assert can be useful.
So far I have been doing this in docstrings or comments in tests, usually not at the place of the assert, but higher up where I start a new test. As far as I can see that's also the common thing to do in Astropy:
https://github.com/astropy/astropy/search?p=1&q=assert&utf8=%E2%9C%93

Another disadvantage if putting this note after the assert is that often you're almost at the end of the line, and then you have to wrap a lot (see the examples below in this PR).

But my main point is that asserts, for written and debugged code will very rarely fail, and thus it's just not worth to implement extra notes for every assert. If someone has a test failure, it's always worth reporting.
The user should copy & paste the console output into the issue report or a gist, and then a developer / maintainer will look at the test code anyways.

But bottom line: this is probably partly a matter of taste, and @bmorris3, if you like it this way, we'll still merge this tomorrow latest. :-)

If time zone (local or otherwise) requested, then uses `datetime.datetime`
and pytz.timezone to convert from UTC.
else:
raise TypeError('Observatory location must be specified with '
Copy link
Member

Choose a reason for hiding this comment

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

Make me happy, and put EarthLocation as the 1st option here :) -- we want to encourage the OOP!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Anything to make you happy, @adrn!

@@ -22,109 +38,152 @@

class Observer(object):
"""
Some comments.
A container for information about an observatory's location and environment.
Copy link
Member

Choose a reason for hiding this comment

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

(minor quibble) maybe "a container class" instead of just "a container"?

Copy link
Member

Choose a reason for hiding this comment

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

also, maybe "observer" instead of "observatory"? After all, it could just be a person outside with their eyes...

@eteq
Copy link
Member

eteq commented Jun 26, 2015

I left a few more comments @bmorris3, but all but the last are phrasing/polish bits on the docs, nothing substantial on the code itself. The last one is an important subtlety, though, that I think needs to be addressed (fortunately, it's easy to fix).

@bmorris3
Copy link
Contributor Author

@eteq : thanks for the comments! They've been addressed in the latest commit.

@cdeil cdeil added this to the 0.1 release milestone Jun 26, 2015
@cdeil
Copy link
Member

cdeil commented Jun 26, 2015

@eteq @adrn – Does one of you have time for a final review and hitting the merge button for this PR later today?

@adrn
Copy link
Member

adrn commented Jun 26, 2015

This looks good to me -- way to go @bmorris3! I'm going to fire away and merge this.

adrn added a commit that referenced this pull request Jun 26, 2015
Beginning in the FixedTarget and Observer classes
@adrn adrn merged commit a3eee9a into astropy:master Jun 26, 2015
@cdeil
Copy link
Member

cdeil commented Jun 26, 2015

🎈

Have a nice weekend, everyone!

@bmorris3
Copy link
Contributor Author

🎊 One of many reasons to celebrate today!

@adrn
Copy link
Member

adrn commented Jun 26, 2015

I merged this for 🌈 !

@bmorris3 bmorris3 deleted the initclasses branch August 10, 2015 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants