Skip to content

Commit

Permalink
Added "Load data" macro command (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
melund authored Jul 9, 2024
1 parent c16a39d commit 99c2ee5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# AnyPyTools Change Log


## v1.13.0

**Added:**
* Added a "LoadData" macro command can generate the macro for loading h5 files.

## v1.12.2

**Fixed:**
Expand Down
2 changes: 2 additions & 0 deletions anypytools/macro_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
UpdateValues,
OperationRun,
SaveData,
LoadData,
)

__all__ = [
Expand All @@ -33,4 +34,5 @@
"UpdateValues",
"OperationRun",
"SaveData",
"LoadData",
]
30 changes: 29 additions & 1 deletion anypytools/macroutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,8 @@ class SaveData(MacroCommand):
operation : str
Operation to save the h5 from
filename : str
The anyset file to save the values to
The h5 file to save the values to. This must be given a
file name without extension or with a ".anydata.h5" extension.
Examples
--------
Expand All @@ -475,6 +476,33 @@ def get_macro(self, index, **kwarg):
return macro_str.format(self.opeation, self.filename)


class LoadData(MacroCommand):
"""Create a "Load data" classoperation macro command.
This macro operation will load all data from a HDF5 file into a study.
Parameters
----------
operation : str
Operation to load the h5 data into
filename : str
The h5 file to load the data from.
Examples
--------
>>> LoadData('Main.Study', 'output.anydata.h5')
classoperation Main.Study.Output "Load data" --file="output.anydata.h5"
"""

def __init__(self, operation, filename):
self.filename = filename
self.opeation = operation

def get_macro(self, index, **kwarg):
macro_str = 'classoperation {}.Output "Load data" --file="{}"'
return macro_str.format(self.opeation, self.filename)


class LoadValues(MacroCommand):
"""Create a Load Values classoperation macro command.
Expand Down
6 changes: 6 additions & 0 deletions tests/test_macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ def test_savedata():
== 'classoperation Main.MyStudy.Output "Save data" --type="Deep" --file="output.anydata.h5"'
)

def test_loaddata():
c = mc.LoadData("Main.MyStudy", "output.anydata.h5")
assert (
c.get_macro(0)
== 'classoperation Main.MyStudy.Output "Load data" --file="output.anydata.h5"'
)

def test_loadvalues():
c = mc.LoadValues("c:/design.anyset")
Expand Down

0 comments on commit 99c2ee5

Please sign in to comment.