Skip to content

Commit

Permalink
fix mineportal requirements for new pyvista version
Browse files Browse the repository at this point in the history
  • Loading branch information
dc-devops committed Nov 23, 2021
1 parent 3865420 commit 2f96bb1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 23 deletions.
49 changes: 31 additions & 18 deletions pyvista/core/dataobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def save(self, filename: str, binary=True, texture=None):
texture array will be saved as ``'RGBA'``
.. note::
This feature is only available when saving PLY files.
This feature is only available when saving PLY files.
Notes
-----
Expand Down Expand Up @@ -328,7 +328,7 @@ def add_field_data(self, array: np.ndarray, name: str, deep=True):
Add field data to a UniformGrid dataset.
>>> mesh = pyvista.UniformGrid((2, 2, 1))
>>> mesh.add_field_data(['I could', 'write', 'notes', 'here'],
>>> mesh.add_field_data(['I could', 'write', 'notes', 'here'],
... 'my-field-data')
>>> mesh['my-field-data']
array(['I could', 'write', 'notes', 'here'], dtype='<U7')
Expand Down Expand Up @@ -496,28 +496,41 @@ def copy_attributes(self, dataset: _vtk.vtkDataSet):
def __getstate__(self):
"""Support pickle. Serialize the VTK object to ASCII string."""
state = self.__dict__.copy()
writer = _vtk.vtkDataSetWriter()
writer.SetInputDataObject(self)
writer.SetWriteToOutputString(True)
writer.SetFileTypeToBinary()
writer.Write()
to_serialize = writer.GetOutputStdString()
try:
from dcpipe.vtktools import to_bytes
to_serialize = to_bytes(self)
except:
writer = _vtk.vtkDataSetWriter()
writer.SetInputDataObject(self)
writer.SetCompressorTypeToLZ4()
writer.SetWriteToOutputString(True)
writer.SetFileTypeToBinary()
writer.Write()
to_serialize = writer.GetOutputStdString()
state['vtk_serialized'] = to_serialize
return state

def __setstate__(self, state):
"""Support unpickle."""
vtk_serialized = state.pop('vtk_serialized')
self.__dict__.update(state)
reader = _vtk.vtkDataSetReader()
reader.ReadFromInputStringOn()
if isinstance(vtk_serialized, bytes):
reader.SetBinaryInputString(vtk_serialized, len(vtk_serialized))
elif isinstance(vtk_serialized, str):
reader.SetInputString(vtk_serialized)
reader.Update()
mesh = pyvista.wrap(reader.GetOutput())
try:
from dcpipe.vtktools import from_bytes
mesh = from_bytes(vtk_serialized)
except:
reader = _vtk.vtkDataSetReader()
reader.ReadFromInputStringOn()
if isinstance(vtk_serialized, bytes):
reader.SetBinaryInputString(vtk_serialized, len(vtk_serialized))
elif isinstance(vtk_serialized, str):
reader.SetInputString(vtk_serialized)
reader.Update()
mesh = pyvista.wrap(reader.GetOutput())

# copy data
self.copy_structure(mesh)
self.copy_attributes(mesh)
if hasattr(self, 'CopyStructure'):
self.copy_structure(mesh)
if hasattr(self, 'CopyAttributes'):
self.copy_attributes(mesh)
elif hasattr(self, 'ShallowCopy'):
self.ShallowCopy(mesh)
10 changes: 5 additions & 5 deletions pyvista/core/datasetattributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,9 @@ def _datacloud_prepare_array(self, narray: Union[Sequence[Number], Number, np.nd
if narray is None:
raise TypeError('narray cannot be None.')

if isinstance(narray, Iterable):
narray = pyvista_ndarray(narray)

if isinstance(narray, pd.Series):
if np.issubdtype(narray.dtype, np.object):
narray = narray.convert_dtypes()
Expand All @@ -554,9 +557,6 @@ def _datacloud_prepare_array(self, narray: Union[Sequence[Number], Number, np.nd
else:
narray = narray.to_numpy()

if isinstance(narray, Iterable):
narray = pyvista_ndarray(narray)

if categorical_to_ints:
if not (type(self.VTKObject).__vtkname__ in ['vtkFieldData']):
if np.issubdtype(narray.dtype, np.str_) or np.issubdtype(narray.dtype, np.string_):
Expand All @@ -570,7 +570,7 @@ def _datacloud_prepare_array(self, narray: Union[Sequence[Number], Number, np.nd
# narray = np.searchsorted(unique_values, narray).astype(float)
# narray[nans] = np.nan

self.dataset.add_field_array(unique_values, name)
self.dataset.field_data[name] = unique_values

return narray

Expand Down Expand Up @@ -637,7 +637,7 @@ def set_array(self, data: Union[Sequence[Number], Number, np.ndarray],
scalars.
"""
vtk_arr = self._datacloud_prepare_array(data, name, categorical_to_ints=categorical_to_ints, string_na_value=string_na_value)
data = self._datacloud_prepare_array(data, name, categorical_to_ints=categorical_to_ints, string_na_value=string_na_value)
vtk_arr = self._prepare_array(data, name, deep_copy)
self.VTKObject.AddArray(vtk_arr)
self.VTKObject.Modified()
Expand Down

0 comments on commit 2f96bb1

Please sign in to comment.