Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changes/153.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The UVH5 writer now also writes timestamps to the file under the ``times`` key.
5 changes: 5 additions & 0 deletions src/pyvisgen/io/datawriters.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,8 @@ class UVH5Writer(DataWriter):
│ └── n
├── frequency_bands
├── channel_widths
├── normalize
├── times
└── sky/
└── SI

Expand Down Expand Up @@ -528,6 +530,9 @@ def write(
f.create_dataset("channel_widths", data=self.__to_numpy(obs.bandwidths))
f.create_dataset("normalize", data=np.bool_(normalize))

times = self.__to_numpy(vis_data.date)
f.create_dataset("times", data=times)

if sky is not None:
sky_grp = f.create_group("sky")
sky_grp.create_dataset("SI", data=self.__to_numpy(sky))
Expand Down
1 change: 1 addition & 0 deletions tests/io/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ def uvh5_vis_data() -> SimpleNamespace:
v=torch.randn(n_baselines, dtype=torch.float64),
w=torch.randn(n_baselines, dtype=torch.float64),
st_id_pairs=torch.arange(n_baselines * 2).reshape(n_baselines, 2),
date=torch.randn(n_baselines, dtype=torch.float64),
)


Expand Down
9 changes: 9 additions & 0 deletions tests/io/test_datawriters.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,15 @@ def test_frequency_bands(self, output_dir, uvh5_vis_data, uvh5_obs) -> None:
with h5py.File(output_dir / "train_0.uvh5", "r") as f:
np.testing.assert_array_almost_equal(f["frequency_bands"][...], expected)

def test_times(self, output_dir, uvh5_vis_data, uvh5_obs) -> None:
with UVH5Writer(output_path=output_dir, dataset_type="train") as writer:
writer.write(uvh5_vis_data, uvh5_obs, index=0)

expected = uvh5_vis_data.date

with h5py.File(output_dir / "train_0.uvh5", "r") as f:
np.testing.assert_array_almost_equal(f["times"], expected)

def test_sky_written(self, output_dir, uvh5_vis_data, uvh5_obs, uvh5_sky) -> None:
with UVH5Writer(output_path=output_dir, dataset_type="train") as writer:
writer.write(uvh5_vis_data, uvh5_obs, index=0, sky=uvh5_sky)
Expand Down