def test_flatnonzero():
    for shape, chunks in [(0, ()), ((0, 0), (0, 0)), ((15, 16), (4, 5))]:
        x = np.random.randint(10, size=shape)
        d = da.from_array(x, chunks=chunks)

        x_fnz = np.flatnonzero(x)
        d_fnz = da.flatnonzero(d)

        assert_eq(d_fnz, x_fnz)
Ejemplo n.º 2
0
def test_flatnonzero():
    for shape, chunks in [(0, ()), ((0, 0), (0, 0)), ((15, 16), (4, 5))]:
        x = np.random.randint(10, size=shape)
        d = da.from_array(x, chunks=chunks)

        x_fnz = np.flatnonzero(x)
        d_fnz = da.flatnonzero(d)

        assert_eq(d_fnz, x_fnz)
Ejemplo n.º 3
0
def test_cue_times(dummy_data):
    """Test the utility for finding all timestamps of a given cue."""
    with latrd_data(sorted(dummy_data.iterdir())) as data:
        # The cue_id '3' appears four times in the test data,
        # with one duplicate timestamp.
        message = 3
        index = da.flatnonzero(data[cue_id_key] == message).compute()
        assert np.all(data[cue_time_key][index] == (8, 8, 7, 9))
        # Check that cue_times finds and de-duplicates these timestamps.
        assert np.all(cue_times(data, message).compute() == (7, 8, 9))

        # Check that searching for a cue message that does not appear in the data
        # results in an empty array being returned.
        times_of_absent_cue = cue_times(data, random_range)
        times_of_absent_cue.compute_chunk_sizes()
        assert not times_of_absent_cue.size
Ejemplo n.º 4
0
def cue_times(data: Dict[str, da.Array], message: int) -> da.Array:
    """
    Find the timestamps of all instances of a cue message in a Tristan data set.

    The found timestamps are de-duplicated.

    Args:
        data:     A LATRD data dictionary (a dictionary with data set names as keys
                  and Dask arrays as values).  Must contain one entry for cue id
                  messages and one for cue timestamps.  The two arrays are assumed
                  to have the same length.
        message:  The message code, as defined in the Tristan standard.

    Returns:
        The timestamps, measured in clock cycles from the global synchronisation
        signal, de-duplicated.
    """
    index = da.flatnonzero(data[cue_id_key] == message)
    return da.unique(data[cue_time_key][index])
Ejemplo n.º 5
0
 def interp_after_median3(x, b):
     return np.interp(
         da.arange(len(bP), chunks=cfg_out['chunksize']),
         da.flatnonzero(bP), median3(x[b]), da.NaN, da.NaN)