[AstroPy] Practical Python for Astronomers web tutorial

Tom Aldcroft aldcroft at head.cfa.harvard.edu
Wed May 25 00:55:39 EDT 2011


Hi Joe,

Thanks for the detailed review and comments on the tutorial site, this
is very helpful!  In general I agree with your points and we'll plan
to tweak the content accordingly.

> 1. Don't use:
>
> from whatever import *
>
> or any shortcuts like 'ipython -pylab' that do that.  It's poor style
> and against the practice of the numpy community in all its docs and
> demos.  Remember that the numpy, scipy, and matplotlib developers can
> in the future put anything they want in their namespaces, and a new
> release could break your working code because of a namespace conflict
> that doesn't exist when you write it.  While that may not bite you for
> your workshops, it will eventually bite anyone who writes enough code
> like that.  Those problems can be hard to find.

Now I'm going risk being branded as a heretic or lazy or a bad
influence, or all of the above...

The decision to use "pylab" was a deliberate one based on the desire
to present Python as a simple and easy tool for the research
astronomers that participated in the workshops.  For a first look at
Python for analysis there is a real advantage to reducing the visual
and conceptual noise in the form of package prefix names everywhere.
For astronomers who have been using IDL or Matlab for 20 years this
would make Python seem far less attractive.  In our workshops the
majority of people were already fluent in some analysis environment
but few had much experience with Python.

On the topic of rigorously avoiding the implicit "import *", the
workshops tend to follow the Zen of "practicality beats purity".  Most
astronomers I know write only simple programs and are highly focused
on getting an answer quickly so they can have results for their talk
next week.  In that regime I think a "pylab" approach is not only
acceptable but the most efficient.  Of course there is no question
that for a package module or longer program that will get re-used
later, one needs to worry about namespaces and following best
practices.  And this would be a perfect topic for a new workshop
chapter "Beyond one-off scripts: writing real programs in Python"
Volunteers? :-).  You're right that interactive analysis is not the
whole story.

I should note that I never use "import *" in any scripts and do not
endorse ever using that construct explicitly in a script.  For
interactive plotting and analysis I use "ipython -pylab" and typing
plus execfile(), otherwise always explicit import statements.

> Also, the title of each workshop has the first word on the end of a
> breadcrumb trail and the rest on a second line.  Maybe put in a line
> break before the title.

I don't understand what this means.  Is the HTML rendering differently
for you or ??

Thanks, Tom



More information about the AstroPy mailing list