In [1]:
%matplotlib inline
import om10,os
import numpy as np
db = om10.DB(catalog=os.path.expandvars("$OM10_DIR/data/qso_mock.fits"))
db.paint(Nmax=10)
db.get_sky_positions()
db.assign_sky_positions()


size is  15658
['LENSID', 'FLAGTYPE', 'NIMG', 'ZLENS', 'VELDISP', 'ELLIP', 'PHIE', 'GAMMA', 'PHIG', 'ZSRC', 'XSRC', 'YSRC', 'MAGI_IN', 'MAGI', 'IMSEP', 'XIMG', 'YIMG', 'MAG', 'DELAY', 'KAPPA', 'FSTAR', 'DD', 'DDLUM', 'ABMAG_I', 'APMAG_I', 'KCORR', 'DS', 'DDS', 'SIGCRIT', 'DSLUM', 'L_I', 'REFF', 'REFF_T']
setup done
analysing lens 0
analysing lens 1
analysing lens 2
analysing lens 3
analysing lens 4
analysing lens 5
analysing lens 6
analysing lens 7
analysing lens 8
analysing lens 9
om10.DB: read in LRG sky position data from  /Users/mbaumer/pybin/OM10/data/CFHTLS_LRGs.txt
Mean LRG RA,DEC,z,i =  34.3807307408 -7.09643979181 0.612498 21.63331883
om10.DB: number of LRGs stored =  10000
15658
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-1-1a3581a78516> in <module>()
      5 db.paint(Nmax=10)
      6 db.get_sky_positions()
----> 7 db.assign_sky_positions()

/Users/mbaumer/pybin/OM10/om10/db.py in assign_sky_positions(self)
    406             if len(i) == 0:
    407                 if reallyverbose: print "WARNING: Lens ",k," has no matching LRG..."
--> 408                 self.lenses.RA[k]       = -99
    409                 self.lenses.DEC[k]      = -99
    410                 pass

/Users/mbaumer/anaconda/lib/python2.7/site-packages/pyfits/fitsrec.pyc in __getattribute__(self, attr)
    466             return object.__getattribute__(self, attr)
    467         else:
--> 468             return super(FITS_rec, self).__getattribute__(attr)
    469 
    470     def __setattr__(self, attr, value):

/Users/mbaumer/anaconda/lib/python2.7/site-packages/numpy/core/records.pyc in __getattribute__(self, attr)
    416             res = fielddict[attr][:2]
    417         except (TypeError, KeyError):
--> 418             raise AttributeError("record array has no attribute %s" % attr)
    419         obj = self.getfield(*res)
    420         # if it has fields return a recarray, otherwise return

AttributeError: record array has no attribute RA

In [19]:
print db.lenses.SDSS_FLAG_SRC


[ 2.  2.  1. ...,  0.  0.  0.]

In [5]:
db.get_sky_positions()
db.assign_sky_positions()


om10.DB: read in LRG sky position data from  /Users/mbaumer/pybin/OM10/data/CFHTLS_LRGs.txt
Mean LRG RA,DEC,z,i =  34.3807307408 -7.09643979181 0.612498 21.63331883
om10.DB: number of LRGs stored =  10000
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-5-70d28b964933> in <module>()
      1 db.get_sky_positions()
----> 2 db.assign_sky_positions()

/Users/mbaumer/pybin/OM10/om10/db.py in assign_sky_positions(self)
    387         orig_cols = self.lenses.columns
    388         new_cols = pyfits.ColDefs(cols)
--> 389         self.lenses = pyfits.FITS_rec.from_columns(orig_cols + new_cols)
    390 
    391         # First digitize the lenses to the same bins as the LRGs:

/Users/mbaumer/anaconda/lib/python2.7/site-packages/pyfits/fitsrec.pyc in from_columns(cls, columns, nrows, fill)
    329                     nrows = dim
    330 
--> 331         raw_data = np.empty(columns.dtype.itemsize * nrows, dtype=np.uint8)
    332         raw_data.fill(ord(columns._padding_byte))
    333         data = np.recarray(nrows, dtype=columns.dtype, buf=raw_data).view(cls)

/Users/mbaumer/anaconda/lib/python2.7/site-packages/pyfits/util.pyc in __get__(self, obj, owner)
    122             return obj.__dict__[self._key]
    123         except KeyError:
--> 124             val = self._fget(obj)
    125             obj.__dict__[self._key] = val
    126             return val

/Users/mbaumer/anaconda/lib/python2.7/site-packages/pyfits/column.pyc in dtype(self)
   1135         names = [n for idx, n in enumerate(self.names)
   1136                  if not self[idx]._phantom]
-> 1137         return np.rec.format_parser(formats, names, None).dtype
   1138 
   1139     @lazyproperty

/Users/mbaumer/anaconda/lib/python2.7/site-packages/numpy/core/records.pyc in __init__(self, formats, names, titles, aligned, byteorder)
    144     def __init__(self, formats, names, titles, aligned=False, byteorder=None):
    145         self._parseFormats(formats, aligned)
--> 146         self._setfieldnames(names, titles)
    147         self._createdescr(byteorder)
    148         self.dtype = self._descr

/Users/mbaumer/anaconda/lib/python2.7/site-packages/numpy/core/records.pyc in _setfieldnames(self, names, titles)
    192         _dup = find_duplicate(self._names)
    193         if _dup:
--> 194             raise ValueError("Duplicate field names: %s" % _dup)
    195 
    196         if (titles):

ValueError: Duplicate field names: ['RA', 'DEC']

In [7]:
print db.lenses.names


['LENSID', 'FLAGTYPE', 'NIMG', 'ZLENS', 'VELDISP', 'ELLIP', 'PHIE', 'GAMMA', 'PHIG', 'ZSRC', 'XSRC', 'YSRC', 'MAGI_IN', 'MAGI', 'IMSEP', 'XIMG', 'YIMG', 'MAG', 'DELAY', 'KAPPA', 'FSTAR', 'DD', 'DDLUM', 'ABMAG_I', 'APMAG_I', 'KCORR', 'DS', 'DDS', 'SIGCRIT', 'DSLUM', 'L_I', 'REFF', 'REFF_T', 'RA   ', 'DEC   ', 'MAGG_LENS   ', 'MAGR_LENS   ', 'MAGI_LENS   ', 'MAGZ_LENS   ', 'MAGW1_LENS   ', 'MAGW2_LENS   ', 'MAGW3_LENS   ', 'MAGW4_LENS   ', 'MAGG_SRC   ', 'MAGR_SRC   ', 'MAGI_SRC   ', 'MAGZ_SRC   ', 'MAGW1_SRC   ', 'MAGW2_SRC   ', 'MAGW3_SRC   ', 'MAGW4_SRC   ', 'SDSS_FLAG_LENS   ', 'SDSS_FLAG_SRC   ']

In [39]:
print db.lenses.MAGW3_SRC[2], db.lenses.MAGI_IN[2], db.lenses.MAGI[2]


2.76681086013 22.51 21.93714

In [23]:
db.lenses.MAGG_SRC[10]


Out[23]:
0.0

In [1]:
print db.lenses.DEC[20]


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-548cc8cb8ad6> in <module>()
----> 1 print db.lenses.DEC[20]

NameError: name 'db' is not defined

In [3]:
db.paint(Nmax=10)


size is  15658
setup done
analysing lens 0
analysing lens 1
analysing lens 2
analysing lens 3
analysing lens 4
analysing lens 5
analysing lens 6
analysing lens 7
analysing lens 8
analysing lens 9

In [29]:
len(db.lenses)


Out[29]:
15658

In [26]:
import pandas as pd
arr = db.lenses.
print type(arr), arr.shape, db.lenses.shape
pd.DataFrame(arr,columns=db.lenses.names)


 <class 'pyfits.fitsrec.FITS_rec'> (15658,) (15658,)
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-26-02956bf4d815> in <module>()
      2 arr = db.lenses.ravel()
      3 print type(arr), arr.shape, db.lenses.shape
----> 4 pd.DataFrame(arr,columns=db.lenses.names)

/Users/mbaumer/anaconda/lib/python2.7/site-packages/pandas/core/frame.pyc in __init__(self, data, index, columns, dtype, copy)
    224                 if columns is None:
    225                     columns = data_columns
--> 226                 mgr = self._init_dict(data, index, columns, dtype=dtype)
    227             elif getattr(data, 'name', None):
    228                 mgr = self._init_dict({data.name: data}, index, columns,

/Users/mbaumer/anaconda/lib/python2.7/site-packages/pandas/core/frame.pyc in _init_dict(self, data, index, columns, dtype)
    321 
    322         return _arrays_to_mgr(arrays, data_names, index, columns,
--> 323                               dtype=dtype)
    324 
    325     def _init_ndarray(self, values, index, columns, dtype=None,

/Users/mbaumer/anaconda/lib/python2.7/site-packages/pandas/core/frame.pyc in _arrays_to_mgr(arrays, arr_names, index, columns, dtype)
   4466 
   4467     # don't force copy because getting jammed in an ndarray anyway
-> 4468     arrays = _homogenize(arrays, index, dtype)
   4469 
   4470     # from BlockManager perspective

/Users/mbaumer/anaconda/lib/python2.7/site-packages/pandas/core/frame.pyc in _homogenize(data, index, dtype)
   4775 
   4776             v = _sanitize_array(v, index, dtype=dtype, copy=False,
-> 4777                                 raise_cast_failure=False)
   4778 
   4779         homogenized.append(v)

/Users/mbaumer/anaconda/lib/python2.7/site-packages/pandas/core/series.pyc in _sanitize_array(data, index, dtype, copy, raise_cast_failure)
   2598     elif subarr.ndim > 1:
   2599         if isinstance(data, pa.Array):
-> 2600             raise Exception('Data must be 1-dimensional')
   2601         else:
   2602             subarr = _asarray_tuplesafe(data, dtype=dtype)

Exception: Data must be 1-dimensional

In [1]:
from astropy.table import Table
import numpy as np

arr = np.arange(15).reshape(5, 3)
t = Table(arr, names=('a', 'b', 'c'), meta={'keywords': {'key1': 'val1'}})

In [11]:
row = t[2]
print t['a'][2]


6

In [18]:
t[0]['d'] = 3

In [20]:
print t


 a   b   c   d 
--- --- --- ---
  0   1   2   3
  3   4   5   1
  6   7   8   1
  9  10  11   1
 12  13  14   1

In [21]:
arr = Table()

In [22]:
arr['bees'] = np.array([1,2,3])

In [23]:
print arr


bees
----
   1
   2
   3

In [25]:
a = 0.0
type(a)


Out[25]:
float

In [27]:



---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-27-3e11ce4b0fdf> in <module>()
----> 1 (a).to_bytes()

AttributeError: 'float' object has no attribute 'to_bytes'

In [ ]: