Orienting Yourself

Image: @jakevdp

How to install packages using conda

If you're using anaconda, you probably already have most (if not all) of these installed. If you installed miniconda:

conda install numpy

Conda also has channels which allows anybody to distribute their own conda packages. There is an "astropy" channel for AstroPy affiliated packages. You can do:

conda install -c astropy astroml

To check if a package is available on conda:

conda search numpy

How to install packages using pip

Many smaller packages are not available via the conda package manager. For these, use pip:

pip install --no-deps corner

Why prefer conda?

conda is an actual package manager that will take care of resolving dependencies optimally.

NumPy


In [1]:
from __future__ import print_function

import math
import numpy as np

If you use Python for any amount of time, you'll quickly find that there are some things it is not so good at. In particular, performing repeated operations via loops is one of its weaknesses.

For example, in pure Python:


In [2]:
def add_one(x):
    return [xi + 1 for xi in x]

In [3]:
x = list(range(1000000))
%timeit add_one(x)


10 loops, best of 3: 65 ms per loop

Using numpy we would do:


In [4]:
x = np.arange(1000000)
%timeit np.add(x, 1)


1000 loops, best of 3: 1.23 ms per loop

Why is pure Python so slow?

Image: @jakevdp

Operations in NumPy are faster than Python functions involving loops, because

  • The data type can be checked just once
  • The looping then happens in compiled code

Using NumPy efficiently

The name of the game is moving all array-oriented code into vectorized NumPy operations.


In [5]:
# Point coordinates
x = np.random.rand(100000)
y = np.random.rand(100000)

In [7]:
%%timeit
dist = np.empty(len(x))
for i in range(len(x)):
    dist[i] = math.sqrt(x[i]**2 + y[i]**2)


10 loops, best of 3: 84.4 ms per loop

In [9]:
%%timeit
dist = np.sqrt(x**2 + y**2)


1000 loops, best of 3: 514 µs per loop

Aside: How many arrays are created in the above cell?

Sometimes you have to get a little creative to "vectorize" things:


In [12]:
x = np.arange(10)**2
x


Out[12]:
array([ 0,  1,  4,  9, 16, 25, 36, 49, 64, 81])

In [14]:
# difference between adjacent elements
x[1:] - x[:-1]


Out[14]:
array([ 1,  3,  5,  7,  9, 11, 13, 15, 17])

In [16]:
# by the way, this is basically the implementation of `np.ediff1d`
np.ediff1d??

Some interesting properties of numpy functions

Functions that operate element-wise on arrays are known as universal functions ("UFuncs").

UFuncs have some methods built-in, which allow for some very interesting, flexible, and fast operations:


In [17]:
x = np.arange(5)
y = np.arange(1, 6)
x + y


Out[17]:
array([1, 3, 5, 7, 9])

All operators (like +) actuall call an underlying numpy function: in this case np.add:


In [18]:
np.add(x, y)


Out[18]:
array([1, 3, 5, 7, 9])

These ufuncs have some interesting and useful properties:


In [19]:
np.add.accumulate(x)


Out[19]:
array([ 0,  1,  3,  6, 10])

In [20]:
np.multiply.accumulate(x)


Out[20]:
array([0, 0, 0, 0, 0])

In [21]:
np.multiply.accumulate(y)


Out[21]:
array([  1,   2,   6,  24, 120])

In [24]:
x


Out[24]:
array([0, 1, 2, 3, 4])

In [28]:
np.maximum.accumulate(x[::-1])


Out[28]:
array([4, 4, 4, 4, 4])

In [29]:
np.multiply.identity


Out[29]:
1

In [30]:
np.add.outer(x, x)


Out[30]:
array([[0, 1, 2, 3, 4],
       [1, 2, 3, 4, 5],
       [2, 3, 4, 5, 6],
       [3, 4, 5, 6, 7],
       [4, 5, 6, 7, 8]])

In [31]:
np.multiply.outer(x, x)


Out[31]:
array([[ 0,  0,  0,  0,  0],
       [ 0,  1,  2,  3,  4],
       [ 0,  2,  4,  6,  8],
       [ 0,  3,  6,  9, 12],
       [ 0,  4,  8, 12, 16]])

numpy aggregates

Aggregates are functions that take an array and return a smaller-dimension array.


In [32]:
z = np.arange(10, dtype=np.float64).reshape((2, 5))
z


Out[32]:
array([[ 0.,  1.,  2.,  3.,  4.],
       [ 5.,  6.,  7.,  8.,  9.]])

In [40]:
np.sum(z, axis=0)


Out[40]:
array([  5.,   7.,   9.,  11.,  13.])

In [34]:
# alternate spelling:
z.sum()


Out[34]:
45.0

In [36]:
np.mean(z)


Out[36]:
4.5

In [38]:
np.min(z), np.max(z)


Out[38]:
(0.0, 9.0)

In [44]:
np.sum(z, axis=0)


Out[44]:
array([  5.,   7.,   9.,  11.,  13.])

In [41]:
# could also use ufunc 
np.add.reduce(z, axis=0)


Out[41]:
array([  5.,   7.,   9.,  11.,  13.])

Indexing

Slice indexing


In [45]:
x = np.arange(15)
x


Out[45]:
array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14])

In [46]:
x[0:5]


Out[46]:
array([0, 1, 2, 3, 4])

In [47]:
x[0:10:2]  # with a stride


Out[47]:
array([0, 2, 4, 6, 8])

In [48]:
x[10:0:-2]  # reversed


Out[48]:
array([10,  8,  6,  4,  2])

This sort of indexing does not make a copy:


In [49]:
y = x[0:10:2]
y[0] = 100.  # modify y
y


Out[49]:
array([100,   2,   4,   6,   8])

In [50]:
# x is modified:
x


Out[50]:
array([100,   1,   2,   3,   4,   5,   6,   7,   8,   9,  10,  11,  12,
        13,  14])

Indexing with indicies


In [51]:
x = np.arange(15)
y = x[[1, 2, 4]]
y


Out[51]:
array([1, 2, 4])

In [52]:
y[0] = 100
y


Out[52]:
array([100,   2,   4])

In [53]:
# x is not modified
x


Out[53]:
array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14])

Indexing with booleans


In [54]:
x = np.arange(5)
x


Out[54]:
array([0, 1, 2, 3, 4])

In [55]:
mask = np.array([True, True, False, True, False])
x[mask]


Out[55]:
array([0, 1, 3])

In [56]:
# creates a copy
y = x[mask]
y[0] = 100.
print(y)
print(x)


[100   1   3]
[0 1 2 3 4]

How do you remember which type of indexing creates a copy?

NumPy arrays are stored as a chunk of data and a set of strides in each dimension. Boolean and arbitrary indicies cannot be represented this way, so numpy must make a copy.

More on masking

All indexing operations also work in assigning to an array. Here we demonstrate assignment with booleans.

For example, imagine you have an array of data where negative values indicate some kind of error.


In [57]:
x = np.array([1, 2, 3, -999, 2, 4, -999])

How might you clean this array, setting all negative values to, say, zero?


In [58]:
for i in range(len(x)):
    if x[i] < 0:
        x[i] = 0
x


Out[58]:
array([1, 2, 3, 0, 2, 4, 0])

In [59]:
x = np.array([1, 2, 3, -999, 2, 4, -999])

mask = (x < 0)
mask


Out[59]:
array([False, False, False,  True, False, False,  True], dtype=bool)

And the mask can be used directly to set the value you desire:


In [60]:
x[mask] = 0
x


Out[60]:
array([1, 2, 3, 0, 2, 4, 0])

Often you'll see this done in a separate step:


In [62]:
x = np.array([1, 2, 3, -999, 2, 4, -999])
x[x < 0] = 0
x


Out[62]:
array([1, 2, 3, 0, 2, 4, 0])

In [68]:
# additional boolean operations: invert
x = np.array([1, 2, 3, -999, 2, 4, -999])
x[~(x < 0)] = 0
x


Out[68]:
array([   0,    0,    0, -999,    0,    0, -999])

In [71]:
x = np.array([1, 2, 3, -999, 2, 4, -999])
x[(x < 0) | (x > 3)] = 0
x


Out[71]:
array([1, 2, 3, 0, 2, 0, 0])

Broadcasting


In [72]:
x = np.arange(4)
x


Out[72]:
array([0, 1, 2, 3])

In [73]:
x + 3


Out[73]:
array([3, 4, 5, 6])


In [74]:
x = np.array([[0,  0,  0],
              [10, 10, 10],
              [20, 20, 20],
              [30, 30, 30]])
y = np.array([0, 1, 2])
print("x shape:", x.shape)
print("y shape:   ", y.shape)


x shape: (4, 3)
y shape:    (3,)

In [75]:
# If x and y are different dimensions, shape is padded on left with 1s
# before broadcasting.
x + y


Out[75]:
array([[ 0,  1,  2],
       [10, 11, 12],
       [20, 21, 22],
       [30, 31, 32]])


In [76]:
x = np.array([[0],
              [10],
              [20],
              [30]])
y = np.array([0, 1, 2])
print("x shape:", x.shape)
print("y shape:   ", y.shape)


x shape: (4, 1)
y shape:    (3,)

In [81]:
x + y


Out[81]:
array([[ 0,  1,  2],
       [10, 11, 12],
       [20, 21, 22],
       [30, 31, 32]])

Broadcasting rules:

  1. If the two arrays differ in their number of dimensions, the shape of the array with fewer dimensions is padded with ones on its leading (left) side.

  2. If the shape of the two arrays does not match in any dimension, the array with shape equal to 1 in that dimension is stretched to match the other shape.

  3. If in any dimension the sizes disagree and neither is equal to 1, an error is raised.

Mini exercises

Assume you have $N$ points in $D$ dimensions, represented by an array of shape (N, D), where there are some mising values scattered throughout the points.

  1. Count the number of points (rows) with no missing values, using np.any or np.all.

  2. Clean the array of the points with missing values.

  3. Construct the matrix M, the centered and normalized version of the X array: $$ M_{ij} = (X_{ij} - \mu_j) / \sigma_j $$ using np.mean and np.std. This is one version of whitening the array.


In [83]:
np.random.seed(0)
X = np.random.rand(5000)
X[np.random.randint(0, 5000, size=500)] = np.nan  # ~10% missing
X = X.reshape((1000, 5))  # 1000 points in 5 dimensions

In [112]:
# 1. Compute the number of points (rows) with no missing values, using `np.any` or `np.all`.
mask = np.all(~np.isnan(X), axis=1)
mask.sum()


Out[112]:
612

In [96]:
# 2. Clean the array, leaving only rows with no missing values
Y = X[mask]
Y.shape


Out[96]:
(612, 5)

In [99]:
# 3. Compute the whitened version of the array using np.mean and np.std.
(Y - np.mean(Y, axis=0)) / np.std(Y, axis=0)


Out[99]:
array([[ 1.06529173,  0.09242815,  0.28895283,  1.37495433, -1.51438865],
       [-1.41794214, -1.64994524,  1.22435157,  0.88599369,  1.20944498],
       [ 0.53028299, -1.22817041,  1.62049802,  0.03598805, -0.34291462],
       ..., 
       [ 1.53325011,  0.58772122, -0.90299997,  1.0223077 , -0.32292258],
       [-1.03929087, -0.96220483, -0.88700535, -1.18773479,  0.60570199],
       [-0.95616059, -0.91269895, -1.02149246, -0.37245591,  1.51143122]])

What else is in NumPy?

  • numpy.random: Random number generation
  • numpy.linalg: Some linear algebra routines
  • numpy.fft: Fast Fourier Transform

In [ ]:
print(np.random.__doc__)

SciPy

Interestingly, scipy predates numpy by more than half a decade (circa 1999), even though it is built on top of numpy.

Originally "scipack", a collection of wrappers for Fortran NetLib libraries.


In [101]:
# contents of scipy:
import scipy
print(scipy.__doc__)


SciPy: A scientific computing package for Python
================================================

Documentation is available in the docstrings and
online at http://docs.scipy.org.

Contents
--------
SciPy imports all the functions from the NumPy namespace, and in
addition provides:

Subpackages
-----------
Using any of these subpackages requires an explicit import.  For example,
``import scipy.cluster``.

::

 cluster                      --- Vector Quantization / Kmeans
 fftpack                      --- Discrete Fourier Transform algorithms
 integrate                    --- Integration routines
 interpolate                  --- Interpolation Tools
 io                           --- Data input and output
 linalg                       --- Linear algebra routines
 linalg.blas                  --- Wrappers to BLAS library
 linalg.lapack                --- Wrappers to LAPACK library
 misc                         --- Various utilities that don't have
                                  another home.
 ndimage                      --- n-dimensional image package
 odr                          --- Orthogonal Distance Regression
 optimize                     --- Optimization Tools
 signal                       --- Signal Processing Tools
 sparse                       --- Sparse Matrices
 sparse.linalg                --- Sparse Linear Algebra
 sparse.linalg.dsolve         --- Linear Solvers
 sparse.linalg.dsolve.umfpack --- :Interface to the UMFPACK library:
                                  Conjugate Gradient Method (LOBPCG)
 sparse.linalg.eigen          --- Sparse Eigenvalue Solvers
 sparse.linalg.eigen.lobpcg   --- Locally Optimal Block Preconditioned
                                  Conjugate Gradient Method (LOBPCG)
 spatial                      --- Spatial data structures and algorithms
 special                      --- Special functions
 stats                        --- Statistical Functions

Utility tools
-------------
::

 test              --- Run scipy unittests
 show_config       --- Show scipy build configuration
 show_numpy_config --- Show numpy build configuration
 __version__       --- Scipy version string
 __numpy_version__ --- Numpy version string


Note the overlap:

  • numpy.fft / scipy.fft
  • numpy.linalg / scipy.linalg

Why the duplication? The scipy routines are based on Fortran libraries, whereas numpy is C-only.

AstroPy

Project started in 2011, in response to increasing duplication in Python astronomy ecosystem.

Initially brought together several existing Python packages:

  • astropy.io.fits (formerly pyfits)
  • astropy.io.ascii (formerly asciitable)
  • astropy.wcs (formerly pywcs)
  • astropy.cosmology (formerly cosmolopy)

Now also contains:

  • astropy.table (Table class and table operations)
  • astropy.units (Quantity: arrays with units)
  • astropy.coordinates (astronomical coordinate systems)
  • astropy.time (UTC, UT, MJD, etc)
  • astropy.stats (additional stats not in scipy)
  • astropy.modeling (simple model fitting)
  • astropy.vo (virtual observatory)
  • astropy.io.votable
  • astropy.analytic_functions

Example: Coordinates


In [102]:
from astropy import coordinates as coords
from astropy import units as u


/home/kyle/.conda/lib/python3.4/site-packages/IPython/kernel/__init__.py:13: ShimWarning: The `IPython.kernel` package has been deprecated. You should import from ipykernel or jupyter_client instead.
  "You should import from ipykernel or jupyter_client instead.", ShimWarning)

In [103]:
ra = 360. * np.random.rand(100)
dec = -90. + 180. * np.random.rand(100)
print("RA:", ra[:5], "...")
print("Dec:", dec[:5], "...")


RA: [  22.26271521  183.12057268  245.43571113  135.14011884   46.60902808] ...
Dec: [  0.84336721  71.28940527  67.98133383 -57.76496669  62.82170868] ...

In [104]:
c = coords.SkyCoord(ra, dec, unit=(u.deg, u.deg))
c


Out[104]:
<SkyCoord (ICRS): (ra, dec) in deg
    [(22.26271521, 0.84336721), (183.12057268, 71.28940527),
     (245.43571113, 67.98133383), (135.14011884, -57.76496669),
     (46.60902808, 62.82170868), (5.5463205, 1.75300981),
     (139.22724099, -70.89876917), (267.38584817, -33.93293061),
     (356.59862418, 33.6502332), (166.70614453, 70.81810387),
     (106.17018389, -70.4970478), (124.80006278, 19.73757575),
     (33.09518851, 32.06320665), (162.04076361, -40.28813887),
     (225.7663043, 46.19530728), (224.48786841, -71.40090351),
     (4.5968499, -46.85816015), (228.14350723, -89.91162652),
     (239.64711432, 0.49282502), (180.72883022, -42.58152806),
     (340.15654779, -75.94785495), (92.8961079, 68.55866164),
     (306.68972711, -54.24030273), (62.71976297, 12.11756194),
     (94.30386281, -41.13622255), (73.76355903, 17.54992362),
     (318.71501869, 27.77339407), (285.66924461, 40.60643253),
     (162.17415904, -36.76930584), (136.08830588, -81.49407869),
     (4.64446431, 64.30889663), (252.69825187, 84.47288164),
     (347.3777251, 69.52044938), (280.2669565, -75.13019124),
     (83.90758544, 51.32451507), (95.22073131, -2.51937637),
     (152.20903157, 23.78184064), (146.78340593, 20.10874512),
     (83.64156533, 6.30563222), (284.98240361, 31.51402911),
     (282.99085196, 20.93785713), (254.32950052, 13.83134106),
     (1.78581656, -64.29158404), (330.25618742, 65.68874076),
     (121.52091784, 45.62917606), (10.37475192, 83.58645599),
     (229.47085232, 52.51374062), (265.53574626, 14.85382878),
     (241.54596526, 75.0901592), (140.72984933, 27.76728755),
     (310.01976019, -34.17665585), (128.34306374, -58.40938547),
     (193.77297, 18.77540026), (331.83235418, 42.51134429),
     (262.04231582, 58.34918428), (34.08059625, -38.6481709),
     (279.76991069, 72.36002549), (324.60875408, 14.03482972),
     (297.13978196, 40.15674984), (171.63550278, 55.46390996),
     (297.05320486, 77.63075714), (27.22647275, -37.80173752),
     (91.52158026, -19.35600865), (312.07208258, 71.99411499),
     (14.89961203, 60.20570492), (143.2994469, -18.15547608),
     (309.76915887, -5.87911215), (160.50771678, 39.08657269),
     (30.46347675, -78.9750637), (165.28050836, -23.8826492),
     (263.59773577, -52.87856396), (113.90111071, 3.38313306),
     (326.35113069, 48.97843671), (338.68670438, -66.61352401),
     (60.39560909, 87.61220229), (33.61911774, -5.91989213),
     (107.7684492, 49.14300366), (168.85535304, -26.56505755),
     (56.52506585, -2.13537993), (86.96459271, 83.6755635),
     (335.98755118, 34.24718827), (257.35680774, -85.38242037),
     (215.26055807, -48.24321599), (254.8640582, -43.33306374),
     (0.98131284, 82.60324643), (52.3876921, 48.5223606),
     (249.03008076, 32.15351108), (257.38865925, -77.46286704),
     (307.07025181, 54.68661457), (210.79808225, -57.29881293),
     (200.61001583, -63.21951458), (143.14958607, 66.39298266),
     (293.96018895, -89.09331409), (306.72829877, -78.60962086),
     (162.57346671, 75.493078), (135.21343018, -44.72002254),
     (18.14583323, 49.38088939), (285.14756737, 28.29117374),
     (242.30053801, -69.79817479), (158.11270946, 53.0872026)]>

In [105]:
# convert to galactic
g = c.galactic
g


Out[105]:
<SkyCoord (Galactic): (l, b) in deg
    [(142.37028781, -60.60101337), (127.37230118, 45.50149802),
     (100.49884144, 38.71850453), (275.87053715, -7.5951703),
     (137.6665351, 3.87813007), (108.06497461, -60.27162952),
     (287.10403859, -14.9623307), (356.15234471, -3.29831988),
     (107.72578741, -27.29362883), (134.52292868, 43.88003306),
     (281.46855763, -24.37217664), (203.80955011, 27.83935091),
     (142.27463499, -27.75021987), (278.84553583, 16.74828645),
     (78.02777848, 57.8109045), (312.74161612, -10.9804884),
     (319.01590877, -69.22446783), (302.98924546, -27.05610163),
     (10.25291144, 37.82692152), (293.49026089, 19.39890292),
     (312.59812132, -38.62184719), (145.71418151, 21.60079545),
     (343.95068476, -35.46134659), (180.53815112, -27.72519608),
     (248.59233783, -23.55871339), (182.99565049, -15.97021682),
     (75.16627147, -14.40484285), (71.10929272, 15.2873244),
     (277.16460109, 19.88635456), (295.2489923, -22.26134368),
     (119.37897502, 1.66406845), (117.42508474, 29.79729391),
     (114.18005303, 8.3993656), (319.43162298, -25.4918569),
     (159.8258784, 10.0995378), (211.69193909, -7.9455871),
     (208.87177497, 53.29988496), (212.17417162, 47.43588807),
     (198.19156249, -13.95124905), (62.30981967, 12.13642734),
     (51.79074719, 9.26739816), (33.01879165, 31.45029927),
     (310.73787241, -52.16014571), (106.57051623, 8.3867858),
     (174.05492536, 31.67449869), (122.63526923, 20.720434),
     (86.03553116, 52.80489599), (38.92746275, 21.90380285),
     (109.06000508, 36.28540938), (199.49015343, 44.09616228),
     (8.93071087, -36.31700832), (274.15184992, -10.82569324),
     (308.86627869, 81.60501453), (93.42409172, -10.7659707),
     (86.83008336, 33.6509553), (251.30642995, -68.86325801),
     (103.13637159, 26.68461494), (68.12213634, -27.6679297),
     (74.63146094, 7.25424395), (145.56809294, 57.77485968),
     (109.84415954, 23.4939854), (257.9934367, -73.88500449),
     (225.74535602, -18.43370669), (106.50634039, 17.42065631),
     (123.94656633, -2.64996479), (250.60303651, 23.98314356),
     (40.26328397, -26.57592625), (180.67510179, 60.58335906),
     (298.74705856, -37.57473158), (272.81858615, 32.45962212),
     (338.37443145, -10.74260514), (214.95784695, 11.36533281),
     (94.4446611, -3.32554999), (321.41139411, -45.29973077),
     (124.88338323, 25.50276295), (169.6250365, -61.02098579),
     (168.11543601, 23.24739239), (277.65622699, 31.55142316),
     (189.68011317, -41.32615602), (129.65816277, 25.23667075),
     (91.20966037, -19.3851468), (307.53285974, -25.06558446),
     (317.96983218, 11.99492145), (342.89465867, -0.51816913),
     (121.31723339, 19.88090491), (148.03593022, -6.49003792),
     (53.12910329, 41.46421685), (315.06803174, -21.22484069),
     (90.64339893, 9.27123397), (312.53678562, 4.22874672),
     (306.41578296, -0.55766695), (146.58474094, 40.41331607),
     (303.93317115, -27.29926864), (315.12198596, -31.20660739),
     (132.33334152, 39.34275309), (266.03776428, 1.00670149),
     (126.46623087, -13.34569525), (59.38841784, 10.65104759),
     (318.56417117, -13.18478465), (158.05947175, 53.49363349)]>

In [106]:
# access longitude or latitude
g.l


Out[106]:
[$142^\circ22{}^\prime13.0361{}^{\prime\prime}$ $127^\circ22{}^\prime20.2843{}^{\prime\prime}$ $100^\circ29{}^\prime55.8292{}^{\prime\prime}$ $275^\circ52{}^\prime13.9337{}^{\prime\prime}$ $137^\circ39{}^\prime59.5263{}^{\prime\prime}$ $108^\circ03{}^\prime53.9086{}^{\prime\prime}$ $287^\circ06{}^\prime14.5389{}^{\prime\prime}$ $356^\circ09{}^\prime08.441{}^{\prime\prime}$ $107^\circ43{}^\prime32.8347{}^{\prime\prime}$ $134^\circ31{}^\prime22.5432{}^{\prime\prime}$ $281^\circ28{}^\prime06.8075{}^{\prime\prime}$ $203^\circ48{}^\prime34.3804{}^{\prime\prime}$ $142^\circ16{}^\prime28.686{}^{\prime\prime}$ $278^\circ50{}^\prime43.929{}^{\prime\prime}$ $78^\circ01{}^\prime40.0025{}^{\prime\prime}$ $312^\circ44{}^\prime29.818{}^{\prime\prime}$ $319^\circ00{}^\prime57.2716{}^{\prime\prime}$ $302^\circ59{}^\prime21.2837{}^{\prime\prime}$ $10^\circ15{}^\prime10.4812{}^{\prime\prime}$ $293^\circ29{}^\prime24.9392{}^{\prime\prime}$ $312^\circ35{}^\prime53.2368{}^{\prime\prime}$ $145^\circ42{}^\prime51.0534{}^{\prime\prime}$ $343^\circ57{}^\prime02.4651{}^{\prime\prime}$ $180^\circ32{}^\prime17.344{}^{\prime\prime}$ $248^\circ35{}^\prime32.4162{}^{\prime\prime}$ $182^\circ59{}^\prime44.3418{}^{\prime\prime}$ $75^\circ09{}^\prime58.5773{}^{\prime\prime}$ $71^\circ06{}^\prime33.4538{}^{\prime\prime}$ $277^\circ09{}^\prime52.5639{}^{\prime\prime}$ $295^\circ14{}^\prime56.3723{}^{\prime\prime}$ $119^\circ22{}^\prime44.3101{}^{\prime\prime}$ $117^\circ25{}^\prime30.3051{}^{\prime\prime}$ $114^\circ10{}^\prime48.1909{}^{\prime\prime}$ $319^\circ25{}^\prime53.8427{}^{\prime\prime}$ $159^\circ49{}^\prime33.1623{}^{\prime\prime}$ $211^\circ41{}^\prime30.9807{}^{\prime\prime}$ $208^\circ52{}^\prime18.3899{}^{\prime\prime}$ $212^\circ10{}^\prime27.0178{}^{\prime\prime}$ $198^\circ11{}^\prime29.625{}^{\prime\prime}$ $62^\circ18{}^\prime35.3508{}^{\prime\prime}$ $51^\circ47{}^\prime26.6899{}^{\prime\prime}$ $33^\circ01{}^\prime07.6499{}^{\prime\prime}$ $310^\circ44{}^\prime16.3407{}^{\prime\prime}$ $106^\circ34{}^\prime13.8584{}^{\prime\prime}$ $174^\circ03{}^\prime17.7313{}^{\prime\prime}$ $122^\circ38{}^\prime06.9692{}^{\prime\prime}$ $86^\circ02{}^\prime07.9122{}^{\prime\prime}$ $38^\circ55{}^\prime38.8659{}^{\prime\prime}$ $109^\circ03{}^\prime36.0183{}^{\prime\prime}$ $199^\circ29{}^\prime24.5523{}^{\prime\prime}$ $8^\circ55{}^\prime50.5591{}^{\prime\prime}$ $274^\circ09{}^\prime06.6597{}^{\prime\prime}$ $308^\circ51{}^\prime58.6033{}^{\prime\prime}$ $93^\circ25{}^\prime26.7302{}^{\prime\prime}$ $86^\circ49{}^\prime48.3001{}^{\prime\prime}$ $251^\circ18{}^\prime23.1478{}^{\prime\prime}$ $103^\circ08{}^\prime10.9377{}^{\prime\prime}$ $68^\circ07{}^\prime19.6908{}^{\prime\prime}$ $74^\circ37{}^\prime53.2594{}^{\prime\prime}$ $145^\circ34{}^\prime05.1346{}^{\prime\prime}$ $109^\circ50{}^\prime38.9743{}^{\prime\prime}$ $257^\circ59{}^\prime36.3721{}^{\prime\prime}$ $225^\circ44{}^\prime43.2817{}^{\prime\prime}$ $106^\circ30{}^\prime22.8254{}^{\prime\prime}$ $123^\circ56{}^\prime47.6388{}^{\prime\prime}$ $250^\circ36{}^\prime10.9314{}^{\prime\prime}$ $40^\circ15{}^\prime47.8223{}^{\prime\prime}$ $180^\circ40{}^\prime30.3665{}^{\prime\prime}$ $298^\circ44{}^\prime49.4108{}^{\prime\prime}$ $272^\circ49{}^\prime06.9101{}^{\prime\prime}$ $338^\circ22{}^\prime27.9532{}^{\prime\prime}$ $214^\circ57{}^\prime28.249{}^{\prime\prime}$ $94^\circ26{}^\prime40.78{}^{\prime\prime}$ $321^\circ24{}^\prime41.0188{}^{\prime\prime}$ $124^\circ53{}^\prime00.1796{}^{\prime\prime}$ $169^\circ37{}^\prime30.1314{}^{\prime\prime}$ $168^\circ06{}^\prime55.5697{}^{\prime\prime}$ $277^\circ39{}^\prime22.4172{}^{\prime\prime}$ $189^\circ40{}^\prime48.4074{}^{\prime\prime}$ $129^\circ39{}^\prime29.386{}^{\prime\prime}$ $91^\circ12{}^\prime34.7773{}^{\prime\prime}$ $307^\circ31{}^\prime58.2951{}^{\prime\prime}$ $317^\circ58{}^\prime11.3958{}^{\prime\prime}$ $342^\circ53{}^\prime40.7712{}^{\prime\prime}$ $121^\circ19{}^\prime02.0402{}^{\prime\prime}$ $148^\circ02{}^\prime09.3488{}^{\prime\prime}$ $53^\circ07{}^\prime44.7719{}^{\prime\prime}$ $315^\circ04{}^\prime04.9143{}^{\prime\prime}$ $90^\circ38{}^\prime36.2362{}^{\prime\prime}$ $312^\circ32{}^\prime12.4282{}^{\prime\prime}$ $306^\circ24{}^\prime56.8186{}^{\prime\prime}$ $146^\circ35{}^\prime05.0674{}^{\prime\prime}$ $303^\circ55{}^\prime59.4161{}^{\prime\prime}$ $315^\circ07{}^\prime19.1495{}^{\prime\prime}$ $132^\circ20{}^\prime00.0295{}^{\prime\prime}$ $266^\circ02{}^\prime15.9514{}^{\prime\prime}$ $126^\circ27{}^\prime58.4311{}^{\prime\prime}$ $59^\circ23{}^\prime18.3042{}^{\prime\prime}$ $318^\circ33{}^\prime51.0162{}^{\prime\prime}$ $158^\circ03{}^\prime34.0983{}^{\prime\prime}$]

In [107]:
type(g.l)


Out[107]:
astropy.coordinates.angles.Longitude

In [108]:
# get underlying numpy array
g.l.degree


Out[108]:
array([ 142.37028781,  127.37230118,  100.49884144,  275.87053715,
        137.6665351 ,  108.06497461,  287.10403859,  356.15234471,
        107.72578741,  134.52292868,  281.46855763,  203.80955011,
        142.27463499,  278.84553583,   78.02777848,  312.74161612,
        319.01590877,  302.98924546,   10.25291144,  293.49026089,
        312.59812132,  145.71418151,  343.95068476,  180.53815112,
        248.59233783,  182.99565049,   75.16627147,   71.10929272,
        277.16460109,  295.2489923 ,  119.37897502,  117.42508474,
        114.18005303,  319.43162298,  159.8258784 ,  211.69193909,
        208.87177497,  212.17417162,  198.19156249,   62.30981967,
         51.79074719,   33.01879165,  310.73787241,  106.57051623,
        174.05492536,  122.63526923,   86.03553116,   38.92746275,
        109.06000508,  199.49015343,    8.93071087,  274.15184992,
        308.86627869,   93.42409172,   86.83008336,  251.30642995,
        103.13637159,   68.12213634,   74.63146094,  145.56809294,
        109.84415954,  257.9934367 ,  225.74535602,  106.50634039,
        123.94656633,  250.60303651,   40.26328397,  180.67510179,
        298.74705856,  272.81858615,  338.37443145,  214.95784695,
         94.4446611 ,  321.41139411,  124.88338323,  169.6250365 ,
        168.11543601,  277.65622699,  189.68011317,  129.65816277,
         91.20966037,  307.53285974,  317.96983218,  342.89465867,
        121.31723339,  148.03593022,   53.12910329,  315.06803174,
         90.64339893,  312.53678562,  306.41578296,  146.58474094,
        303.93317115,  315.12198596,  132.33334152,  266.03776428,
        126.46623087,   59.38841784,  318.56417117,  158.05947175])

Other astro packages

AstroPy-affiliated packages

PyPI packages with topic "Astronomy"


In [ ]: