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): ...@@ -69,9 +69,9 @@ class DataArrayLine(DataArray):
if dtype_expression is None: if dtype_expression is None:
dtype = np.dtype(array_view.dtype) dtype = np.dtype(array_view.dtype)
else: else:
dtype = evaluateExpressionFromString( dtype = np.dtype(evaluateExpressionFromString(
createExpressionContext(None, portal=getindex), createExpressionContext(None, portal=getindex),
dtype_expression) dtype_expression))
dtype.names = name_list dtype.names = name_list
return array_view.view(dtype=dtype) return array_view.view(dtype=dtype)
return array_view return array_view
...@@ -51,27 +51,28 @@ class DataArrayViewLine(DataArray): ...@@ -51,27 +51,28 @@ class DataArrayViewLine(DataArray):
""" """
Get numpy view of Parent Data Array according to index. Get numpy view of Parent Data Array according to index.
""" """
zbigarray = self.getPredecessorValue().getArray()
getindex = GetIndex("getindex") getindex = GetIndex("getindex")
index_expression = self.getIndexExpression()
dtype_expression = self.getDtypeExpression()
name_list = self.getNameList()
index = evaluateExpressionFromString( index = evaluateExpressionFromString(
createExpressionContext(None, portal=getindex), createExpressionContext(None, portal=getindex),
"python: portal[%s]" %self.getIndexExpression() "python: portal[%s]" %index_expression
) )
zbigarray = self.getPredecessorValue().getArray()
try: try:
array_view = zbigarray[index] array_view = zbigarray[index]
except TypeError: except TypeError:
array = zbigarray[:] array = zbigarray[:]
new_dtype = np.dtype({name:array.dtype.fields[name] for name in index}) 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) 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:
if dtype_expression is not None or name_list: dtype = np.dtype(evaluateExpressionFromString(
if dtype_expression is None: createExpressionContext(None, portal=getindex), dtype_expression))
dtype = np.dtype(array_view.dtype) if name_list:
else:
dtype = evaluateExpressionFromString(
createExpressionContext(None, portal=getindex),
dtype_expression)
dtype.names = name_list dtype.names = name_list
return array_view.view(dtype=dtype) array_view = array_view.reshape(array_view.size,).view(dtype)
else:
array_view = array_view
return 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