Skip to content

Commit

Permalink
Initial support for loading NLD/GSF from disk
Browse files Browse the repository at this point in the history
  • Loading branch information
vetlewi committed Jul 22, 2020
1 parent 3f32d82 commit 0fba72a
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions ompy/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from contextlib import redirect_stdout
from uncertainties import unumpy
import os
import fnmatch

from pathlib import Path
from typing import Optional, Union, Any, Tuple, List
Expand Down Expand Up @@ -557,6 +558,33 @@ def __getstate__(self):
pass
return state

@staticmethod
def load(path: Union[str, Path]):
""" Load an ensemble of from disk.
Args:
path: Path to folder with ensemble
Returns:
extractor object with gSF and NLD set.
"""
if path is None:
raise ValueError("path must be given")
path = Path(path)

# Count number of files with name gsf_*.npy
num_gsf = len(fnmatch.filter(next(os.walk(path))[2], 'gsf_*.npy'))
num_nld = len(fnmatch.filter(next(os.walk(path))[2], 'nld_*.npy'))

assert num_gsf == num_nld, \
"The number of gsf files and nld files should be the same."
extractor = Extractor(path=path)
for i in range(num_gsf):
gsf_path = path / f'gsf_{i}.npy'
extractor.gsf.append(Vector(path=gsf_path))
for i in range(num_nld):
nld_path = path / f'nld_{i}.npy'
extractor.nld.append(Vector(path=nld_path))
return extractor


def normalize(mat: Matrix,
std: Optional[Matrix]) -> Tuple[np.ndarray, np.ndarray]:
Expand Down

0 comments on commit 0fba72a

Please sign in to comment.