Commit 6252f617 authored by Klaus Wölfel's avatar Klaus Wölfel Committed by Eteri

Data Array View: allow strucutred view of plain array

parent a9895411
......@@ -69,9 +69,9 @@ class DataArrayLine(DataArray):
if dtype_expression is None:
dtype = np.dtype(array_view.dtype)
else:
dtype = evaluateExpressionFromString(
dtype = np.dtype(evaluateExpressionFromString(
createExpressionContext(None, portal=getindex),
dtype_expression)
dtype_expression))
dtype.names = name_list
return array_view.view(dtype=dtype)
return array_view
......@@ -51,27 +51,28 @@ class DataArrayViewLine(DataArray):
"""
Get numpy view of Parent Data Array according to index.
"""
zbigarray = self.getPredecessorValue().getArray()
getindex = GetIndex("getindex")
index_expression = self.getIndexExpression()
dtype_expression = self.getDtypeExpression()
name_list = self.getNameList()
index = evaluateExpressionFromString(
createExpressionContext(None, portal=getindex),
"python: portal[%s]" %self.getIndexExpression()
"python: portal[%s]" %index_expression
)
zbigarray = self.getPredecessorValue().getArray()
try:
array_view = zbigarray[index]
except TypeError:
array = zbigarray[:]
new_dtype = np.dtype({name:array.dtype.fields[name] for name in index})
array_view = np.ndarray(array.shape, new_dtype, array, 0, array.strides)
name_list = self.getNameList()
dtype_expression = self.getDtypeExpression()
if dtype_expression is not None or name_list:
if dtype_expression is None:
dtype = np.dtype(array_view.dtype)
else:
dtype = evaluateExpressionFromString(
createExpressionContext(None, portal=getindex),
dtype_expression)
dtype.names = name_list
return array_view.view(dtype=dtype)
if dtype_expression is not None:
dtype = np.dtype(evaluateExpressionFromString(
createExpressionContext(None, portal=getindex), dtype_expression))
if name_list:
dtype.names = name_list
array_view = array_view.reshape(array_view.size,).view(dtype)
else:
array_view = array_view
return array_view
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment