Skip to content

Commit

Permalink
fix: adding value point save.
Browse files Browse the repository at this point in the history
TODO there should be a base class for points to share methods
  • Loading branch information
lachlangrose committed Jun 5, 2024
1 parent c8641a6 commit 2093f4e
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions LoopStructural/datatypes/_point.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from dataclasses import dataclass
import numpy as np

from typing import Optional


@dataclass
class ValuePoints:
locations: np.ndarray
values: np.ndarray
name: str
properties: Optional[dict] = None

def to_dict(self):
return {
Expand All @@ -22,12 +25,40 @@ def vtk(self):
points["values"] = self.values
return points

def save(self, filename):
filename = str(filename)
ext = filename.split('.')[-1]
if ext == 'json':
import json

with open(filename, 'w') as f:
json.dump(self.to_dict(), f)
elif ext == 'vtk':
self.vtk().save(filename)

elif ext == 'geoh5':
from LoopStructural.export.geoh5 import add_points_to_geoh5

add_points_to_geoh5(filename, self)
elif ext == 'pkl':
import pickle

with open(filename, 'wb') as f:
pickle.dump(self, f)
elif ext == 'vs':
from LoopStructural.export.gocad import _write_pointset

_write_pointset(self, filename)
else:
raise ValueError(f'Unknown file extension {ext}')


@dataclass
class VectorPoints:
locations: np.ndarray
vectors: np.ndarray
name: str
properties: Optional[dict] = None

def to_dict(self):
return {
Expand Down

0 comments on commit 2093f4e

Please sign in to comment.