[AstroPy] Vector Quantities in QTable

Jeffrey Brent McBeth mcbeth at broggs.org
Thu Apr 13 07:52:13 EDT 2017


I'm trying to carry around state vectors for measurements I'm making.
Some of these measurements come in a large vector that I need to transform easily as a bulk later (calibration)
I'm struggling to get these measurements to load into QTable (which I assumed would be the right structure for this)

#+begin_src python
from astropy.table import QTable
import astropy.units as u
import numpy as np

# I've significantly reduced the number of objects in state1 to keep things simple
foo = QTable(names=('state1','mass'),dtype=('(3,1)f8','f8'))
foo['state1'].unit = u.K
foo['mass'].unit = u.mg

s0 = [235,240,245]*u.K
m0 = 5*u.g

try:
        foo.add_row((s0,m0)) # Incorrect length for column state1 after inserting [ 235.  240.  245.] K (expected 3,
got 1)
except Exception as e:
        print e

try:
        foo.add_row((s0[:,np.newaxis],m0)) # could not broadcast input array from shape (3,1) into shape (3)
except Exception as e:
        print e

print foo
#+end_src

-- 
"The man who does not read good books has no advantage over 
 the man who cannot read them."
 -- not Mark Twain, maybe a southen librarian in 1910



More information about the AstroPy mailing list