Skip to content

Commit

Permalink
Various modernization / py3 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
taldcroft committed Feb 7, 2015
1 parent a84d01d commit 7129fe2
Show file tree
Hide file tree
Showing 7 changed files with 897 additions and 47 deletions.
870 changes: 870 additions & 0 deletions source/downloads/fermi_agn.dat

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion source/files/asciifiles.rst
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,9 @@ rewrite the same code every time when it is already done!). Instead just use `a

.. admonition:: Exercise: scraping table data from the web

*Note: this exercise only works on Python 2 due to BeautifulSoup doing something
differently in Python 3. Five cheers to the person who can fix this!*

To do this exercise you must first install the `BeautifulSoup
<http://www.crummy.com/software/BeautifulSoup/>`_ package which will parse
HTML pages into nice data structures. **QUIT** your IPython session and from the command line do::
Expand Down Expand Up @@ -586,7 +589,9 @@ Here is a more complicated example, that is actually useful::
The resulting plot clearly shows the inverse first ionization potential effect.
That means, that elements of a large FIP are enhanced in the corona.

The second command ``np.genfromtxt`` is more versatile. It can fill missing values in a table, read column names, exclude some columns etc. Here is an example::
The second command ``np.genfromtxt`` is more versatile. It can fill missing
values in a table, read column names, exclude some columns etc. Here is an
example (which only works in Python 2 as of Numpy 1.9)::

d = StringIO('''
#element abund error FIP
Expand Down
18 changes: 1 addition & 17 deletions source/files/binaryfiles.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,27 +76,11 @@ What can you do?
1. Convert your collegue to use a different file format.
2. Read that file in python.

If you have a relatively recent version (at least 0.9) of ``scipy`` then this is a matter of two lines::
With any relatively recent version ``scipy`` (at least 0.9) then this is a matter of two lines::
from scipy.io.idl import readsav
data = readsav('myidlfile.sav')

If your scipy is older, then you need to install the package `idlsave <http://astrofrog.github.com/idlsave/>`_ yourself.
(Go back to :doc:`../installation/packages` for details on package installation.)

In a normal terminal (outside ``ipython``) do::
pip install --upgrade idlsave
or, if you install packages as root user on your system::
sudo pip install --upgrade idlsave

Then import the package and read the data::
import idlsave
data = idlsave.read('myidlfile.sav')
.. admonition:: Exercise: Where is your data?

``idlsave`` already prints some information on the screen while reading the file. Inspect the object ``data``, find out how you use it and plot
Expand Down
4 changes: 4 additions & 0 deletions source/fitting/fitting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Workshop goals are to use Sherpa to:

- Fit the MAST 3C 273 data using the low-level API

.. Note::

Sherpa currently does not support Python 3.

**Agenda**

.. toctree::
Expand Down
2 changes: 1 addition & 1 deletion source/fitting/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Sherpa Installation

In order to follow along with the Sherpa examples presented in this
workshop, you can use
`Sherpa in CIAO 4.4 <http://cxc.harvard.edu/ciao/download/>`_,
`Sherpa in CIAO <http://cxc.harvard.edu/ciao/download/>`_,
or install the stand-alone version described below.

.. Note::
Expand Down
17 changes: 4 additions & 13 deletions source/python/objects.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,10 @@ remember object methods!**
::

In [17]: a.<TAB>
a.__add__ a.__ge__ a.__iter__ a.__repr__ a.append
a.__class__ a.__getattribute__ a.__le__ a.__reversed__ a.count
a.__contains__ a.__getitem__ a.__len__ a.__rmul__ a.extend
a.__delattr__ a.__getslice__ a.__lt__ a.__setattr__ a.index
a.__delitem__ a.__gt__ a.__mul__ a.__setitem__ a.insert
a.__delslice__ a.__hash__ a.__ne__ a.__setslice__ a.pop
a.__doc__ a.__iadd__ a.__new__ a.__sizeof__ a.remove
a.__eq__ a.__imul__ a.__reduce__ a.__str__ a.reverse
a.__format__ a.__init__ a.__reduce_ex__ a.__subclasshook__ a.sort

For the most part you can ignore all the ones that begin with ``__`` since
they are generally are internal methods that are not called directly. At
the end you see useful looking functions like ``append`` or ``sort`` which
a.append a.extend a.insert a.remove a.sort
a.count a.index a.pop a.reverse

Here you see useful looking functions like ``append`` or ``sort`` which
you can get help for and use::

a.sort
Expand Down
26 changes: 11 additions & 15 deletions source/python/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Manipulating these behaves the way you would expect, so an operation (``+``, ``-
>>> 8 * complex(-3.3,1)
(-26.4+8j) # int * complex = complex

However, there is one case where this happens but is not desirable, and that you should be aware of, which is the division of two integer numbers::
However, there is one case in Python 2 where this happens but is not desirable, and that you should be aware of, which is the division of two integer numbers::

>>> 3 / 2
1
Expand All @@ -71,6 +71,9 @@ After typing this, we can use the Python 3.x syntax::
>>> 3 // 2
1

If you are writing new code in Python 2 then it's a fine idea to start each
file with ``from __future__ import division`` at the top.

Another way to prevent this is to cast at least one of the integers in the division to a ``float``::

>>> 3 / float(2)
Expand Down Expand Up @@ -240,20 +243,13 @@ This will show the available attributes and methods for the Python list
remember object methods!**
::

In [17]: a.<TAB>
a.__add__ a.__ge__ a.__iter__ a.__repr__ a.append
a.__class__ a.__getattribute__ a.__le__ a.__reversed__ a.count
a.__contains__ a.__getitem__ a.__len__ a.__rmul__ a.extend
a.__delattr__ a.__getslice__ a.__lt__ a.__setattr__ a.index
a.__delitem__ a.__gt__ a.__mul__ a.__setitem__ a.insert
a.__delslice__ a.__hash__ a.__ne__ a.__setslice__ a.pop
a.__doc__ a.__iadd__ a.__new__ a.__sizeof__ a.remove
a.__eq__ a.__imul__ a.__reduce__ a.__str__ a.reverse
a.__format__ a.__init__ a.__reduce_ex__ a.__subclasshook__ a.sort

For the most part you can ignore all the ones that begin with ``__`` since
they are generally are internal methods that are not called directly. At
the end you see useful looking functions like ``append`` or ``sort`` which
::

In [17]: a.<TAB>
a.append a.extend a.insert a.remove a.sort
a.count a.index a.pop a.reverse

Here you see useful looking functions like ``append`` or ``sort`` which
you can get help for and use::

a.sort
Expand Down

0 comments on commit 7129fe2

Please sign in to comment.