Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds SimulationData.mnt_data_from_file() method to load individual MonitorData #1249

Merged
merged 1 commit into from
Nov 14, 2023

Conversation

tylerflex
Copy link
Collaborator

Syntax:

mnt_data = SimulationData.mnt_data_from_file(fname, mnt_name, **kwargs)

loads a monitor data from a subgroup in the SimulationData file.

  1. grabs the JSON_STRING to get the monitor type info.
  2. Looks up the proper MonitorDataType
  3. Iterates through the hdf5 file until a match is found on monitor name
  4. Uses MonitorData.from_file() with a constructed group path to do the loading.

Some error checking thrown in, only works with .hdf5 files at the moment.

Copy link
Contributor

@shashwat-sh shashwat-sh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Just one small clarification below.

@@ -369,6 +376,65 @@ def get_intensity(self, field_monitor_name: str) -> xr.DataArray:
field_monitor_name=field_monitor_name, field_name="E", val="abs^2"
)

@classmethod
def mnt_data_from_file(cls, fname: str, mnt_name: str, **parse_obj_kwargs) -> MonitorDataType:
"""Loads a monitor data from .hdf5, or .hdf5.gz file.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check below (line 404) does not seem to allow .hdf5.gz. Does pathlib.Path(fname) internally extract .gz files?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh right, no the pathlib.path just is to check the extension but I'll make the docstring clearer that it only works for hdf5.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess if we start gzipping simulation data files, we should still unzip them right after download.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea, it seems like a bit of a complication to do the unzipping in this function, would need to specify another path for the new file I think. might be possible to do it through a temporary file but perhaps it's too complicated for this application.

@momchil-flex momchil-flex merged commit 0a52c99 into pre/2.5 Nov 14, 2023
12 checks passed
@momchil-flex momchil-flex deleted the tyler/mnt_load branch November 14, 2023 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Convenience wrapper for loading data from hdf5 for specific monitors only
3 participants