Skip to content

Commit 99c2ee5

Browse files
authored
Added "Load data" macro command (#117)
1 parent c16a39d commit 99c2ee5

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# AnyPyTools Change Log
22

3+
4+
## v1.13.0
5+
6+
**Added:**
7+
* Added a "LoadData" macro command can generate the macro for loading h5 files.
8+
39
## v1.12.2
410

511
**Fixed:**

anypytools/macro_commands.py

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
UpdateValues,
1919
OperationRun,
2020
SaveData,
21+
LoadData,
2122
)
2223

2324
__all__ = [
@@ -33,4 +34,5 @@
3334
"UpdateValues",
3435
"OperationRun",
3536
"SaveData",
37+
"LoadData",
3638
]

anypytools/macroutils.py

+29-1
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,8 @@ class SaveData(MacroCommand):
457457
operation : str
458458
Operation to save the h5 from
459459
filename : str
460-
The anyset file to save the values to
460+
The h5 file to save the values to. This must be given a
461+
file name without extension or with a ".anydata.h5" extension.
461462
462463
Examples
463464
--------
@@ -475,6 +476,33 @@ def get_macro(self, index, **kwarg):
475476
return macro_str.format(self.opeation, self.filename)
476477

477478

479+
class LoadData(MacroCommand):
480+
"""Create a "Load data" classoperation macro command.
481+
482+
This macro operation will load all data from a HDF5 file into a study.
483+
484+
Parameters
485+
----------
486+
operation : str
487+
Operation to load the h5 data into
488+
filename : str
489+
The h5 file to load the data from.
490+
491+
Examples
492+
--------
493+
>>> LoadData('Main.Study', 'output.anydata.h5')
494+
classoperation Main.Study.Output "Load data" --file="output.anydata.h5"
495+
"""
496+
497+
def __init__(self, operation, filename):
498+
self.filename = filename
499+
self.opeation = operation
500+
501+
def get_macro(self, index, **kwarg):
502+
macro_str = 'classoperation {}.Output "Load data" --file="{}"'
503+
return macro_str.format(self.opeation, self.filename)
504+
505+
478506
class LoadValues(MacroCommand):
479507
"""Create a Load Values classoperation macro command.
480508

tests/test_macros.py

+6
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ def test_savedata():
105105
== 'classoperation Main.MyStudy.Output "Save data" --type="Deep" --file="output.anydata.h5"'
106106
)
107107

108+
def test_loaddata():
109+
c = mc.LoadData("Main.MyStudy", "output.anydata.h5")
110+
assert (
111+
c.get_macro(0)
112+
== 'classoperation Main.MyStudy.Output "Load data" --file="output.anydata.h5"'
113+
)
108114

109115
def test_loadvalues():
110116
c = mc.LoadValues("c:/design.anyset")

0 commit comments

Comments
 (0)