Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • 2ff2b0a
  • /
  • test_hdf5.py
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge
swh:1:cnt:621fca216427f08faf9a7f7633782ab6d2e20a92
directory badge
swh:1:dir:2ff2b0acd6f24be1e58bca0542dd6f15c68cd88e

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
test_hdf5.py
# Copyright (c) 2024 Radio Astronomy Software Group
# Licensed under the 2-clause BSD License
"""Tests for hdf5 utility functions."""

import numpy as np
import pytest

import pyuvdata.utils.io.hdf5 as hdf5_utils
from pyuvdata import utils
from pyuvdata.datasets import fetch_data


@pytest.mark.filterwarnings("ignore:The uvw_array does not match the expected values")
def test_read_slicing():
    """Test HDF5 slicing helper functions"""
    # check trivial slice representations
    slices, _ = utils.tools._convert_to_slices([])
    assert slices == [slice(0, 0, None)]
    slices, _ = utils.tools._convert_to_slices(10)
    assert slices == [slice(10, 11, 1)]

    # dataset shape checking
    # check various kinds of indexing give the right answer
    indices = [slice(0, 10), 0, [0, 1, 2], [0]]
    dset = np.empty((100, 1, 1024, 2), dtype=np.float64)
    shape, _ = hdf5_utils._get_dset_shape(dset, indices)
    assert tuple(shape) == (10, 1, 3, 1)

    # dataset indexing
    # check various kinds of indexing give the right answer
    slices = [utils.tools._convert_to_slices(ind)[0] for ind in indices]
    slices[1] = 0
    data = hdf5_utils._index_dset(dset, slices)
    assert data.shape == tuple(shape)

    # Handling bool arrays
    bool_arr = np.zeros((10000,), dtype=bool)
    index_arr = np.arange(1, 10000, 2)
    bool_arr[index_arr] = True
    assert utils.tools._convert_to_slices(bool_arr) == utils.tools._convert_to_slices(
        index_arr
    )
    assert utils.tools._convert_to_slices(bool_arr, return_index_on_fail=True) == (
        utils.tools._convert_to_slices(index_arr, return_index_on_fail=True)
    )

    # Index return on fail with two slices
    index_arr[0] = 0
    bool_arr[0:2] = [True, False]

    for item in [index_arr, bool_arr]:
        result, check = utils.tools._convert_to_slices(
            item, max_nslice=1, return_index_on_fail=True
        )
        assert not check
        assert len(result) == 1
        assert result[0] is item

    # Check a more complicated pattern w/ just the max_slice_frac defined
    index_arr = np.arange(0, 100) ** 2
    bool_arr[:] = False
    bool_arr[index_arr] = True

    for item in [index_arr, bool_arr]:
        result, check = utils.tools._convert_to_slices(item, return_index_on_fail=True)
        assert not check
        assert len(result) == 1
        assert result[0] is item


def test_telescope_attr():
    """Test Telescope attribute handling"""
    meta = hdf5_utils.HDF5Meta(fetch_data("hera_h3c_uvh5"))

    assert meta.telescope.location == meta.telescope_location_obj

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API