Skip to content

Commit

Permalink
Add reading from numpy
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed May 31, 2024
1 parent d16f8ab commit d0e5b9a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
27 changes: 27 additions & 0 deletions examples/advanced/ex09_convert_numpy_openpmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,33 @@
descriptor_calculation_kwargs={"working_directory": "./"},
)

data_converter.convert_snapshots(
descriptor_save_path="./",
target_save_path="./",
additional_info_save_path="./",
naming_scheme="Be_snapshot*.npy",
descriptor_calculation_kwargs={"working_directory": "./"},
)

data_converter = mala.DataConverter(parameters)

for snapshot in range(2):
data_converter.add_snapshot(
descriptor_input_path="Be_snapshot{}.in.npy".format(snapshot),
target_input_path="Be_snapshot{}.out.npy".format(snapshot),
additional_info_input_type=None,
additional_info_input_path=None,
target_units=None,
)

data_converter.convert_snapshots(
descriptor_save_path="./",
target_save_path="./",
additional_info_save_path="./",
naming_scheme="Be_snapshot*.bp4",
descriptor_calculation_kwargs={"working_directory": "./"},
)

data_converter.convert_snapshots(
descriptor_save_path="./",
target_save_path="./",
Expand Down
21 changes: 17 additions & 4 deletions mala/datahandling/data_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,13 +546,14 @@ def __convert_single_snapshot(
snapshot["input"], **descriptor_calculation_kwargs
)
)
print(tmp_input)
print(tmp_input.shape)
print(local_size)

elif description["input"] == "openpmd":
tmp_input = self.descriptor_calculator.read_from_openpmd_file(
snapshot["input"]
snapshot["input"], units=original_units["input"]
)
elif description["input"] == "numpy":
tmp_input = self.descriptor_calculator.read_from_numpy_file(
snapshot["input"], units=original_units["input"]
)

elif description["input"] is None:
Expand Down Expand Up @@ -629,6 +630,12 @@ def __convert_single_snapshot(
tmp_output = self.target_calculator.read_from_openpmd_file(
snapshot["output"], units=original_units["output"]
)
elif description["output"] == "numpy":
tmp_output = (
self.target_calculator.read_dimensions_from_numpy_file(
snapshot["output"], units=original_units["output"]
)
)

elif description["output"] is None:
# In this case, only the input is processed.
Expand Down Expand Up @@ -674,6 +681,12 @@ def __convert_single_snapshot(
tmp_output = self.target_calculator.read_from_openpmd_file(
snapshot["output"], units=original_units["output"]
)
elif description["output"] == "numpy":
tmp_output = (
self.target_calculator.read_dimensions_from_numpy_file(
snapshot["output"], units=original_units["output"]
)
)

elif description["output"] is None:
# In this case, only the input is processed.
Expand Down

0 comments on commit d0e5b9a

Please sign in to comment.