Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions quantities/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def wrapped_function(*args , **kwargs):
#test if the argument is a quantity
if isinstance(args[i], Quantity):
#convert the units to the base units
args[i] = args[i].simplified()
args[i] = args[i].simplified

#view the array as an ndarray
args[i] = args[i].magnitude
Expand Down Expand Up @@ -142,7 +142,7 @@ def wrapped_function(*args , **kwargs):
result[i] = Quantity(
result[i],
handler_quantities[i]
.dimensionality.simplified()
.dimensionality.simplified
)
#now convert the quantity to the appropriate units
result[i] = result[i].rescale(
Expand Down
16 changes: 16 additions & 0 deletions quantities/quantity.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,22 @@ def _reference(self):
def magnitude(self):
return self.view(type=np.ndarray)

@property
def real(self):
return Quantity(self.magnitude.real, self.dimensionality)

@real.setter
def real(self, r):
self.magnitude.real = Quantity(r, self.dimensionality).magnitude

@property
def imag(self):
return Quantity(self.magnitude.imag, self.dimensionality)

@imag.setter
def imag(self, i):
self.magnitude.imag = Quantity(i, self.dimensionality).magnitude

@property
def simplified(self):
rq = 1*unit_registry['dimensionless']
Expand Down
10 changes: 10 additions & 0 deletions quantities/tests/test_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,16 @@ def test_conj(self):
self.assertQuantityEqual((self.q*(1+1j)).conj(), self.q*(1-1j))
self.assertQuantityEqual((self.q*(1+1j)).conjugate(), self.q*(1-1j))

def test_real(self):
test_q = self.q * (1 + 1j)
test_q.real = [[39.3701, 39.3701], [39.3701, 39.3701]] * pq.inch
self.assertQuantityEqual(test_q.real, [[1., 1.], [1., 1.]] * pq.m)

def test_imag(self):
test_q = self.q * (1 + 1j)
test_q.imag = [[39.3701, 39.3701], [39.3701, 39.3701]] * pq.inch
self.assertQuantityEqual(test_q.imag, [[1., 1.], [1., 1.]] * pq.m)

def test_getitem(self):
self.assertRaises(IndexError, self.q.__getitem__, (0,10))
self.assertQuantityEqual(self.q[0], [1,2]*pq.m)
Expand Down