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

DataArray accepts file path and handle #1385

Merged
merged 1 commit into from
Jan 18, 2024

Conversation

tylerflex
Copy link
Collaborator

@tylerflex tylerflex commented Jan 15, 2024

Formerly, the docstring made it look like to save a DataArray, one should pass a fname: str. However, the function internals accept an h5py file handle and this method is called as such, internally.

This PR makes DataArray.to_hdf5() work either when passed a file name or a file handle.

Copy link
Collaborator

@e-g-melo e-g-melo left a comment

Choose a reason for hiding this comment

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

Thanks @tylerflex!

Both options are working very well in the code below now.

Nx = 1
Ny = 10
Nz = 11
x = [0]
y = np.linspace(-Ly / 2, Ly / 2, Ny)
z = [0]
coords = dict(x=x, y=y, z=z)
xgrid, ygrid, zgrid = np.meshgrid(x, y, z, indexing="ij")

phase = td.SpatialDataArray(2 * np.pi * ygrid / Ly, coords=coords)

phase.to_hdf5("phase_file.hdf5", group_path="phase")

with h5.File("phase_handle.hdf5", "w") as f:
    phase.to_hdf5(f, group_path="phase")

Copy link
Collaborator

@momchil-flex momchil-flex left a comment

Choose a reason for hiding this comment

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

We could also put in 2.5 depending on how soon we want this officially out.

@tylerflex
Copy link
Collaborator Author

I dont think it's urgent. let's just do 2.6 for simplicity.

@tylerflex tylerflex merged commit aefed35 into pre/2.6 Jan 18, 2024
16 checks passed
@tylerflex tylerflex deleted the tyler/fix/data_array_to_hdf5 branch January 18, 2024 21:26
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.

None yet

3 participants