Example #1
0
class TestMapping(BaseTest):
    """
        Test if the registration of Group as a
        Mapping behaves as expected
    """
    def setUp(self):
        data = ('a', 'b')
        self.f = File('foo.hdf5', 'w')
        self.grp = self.f.create_group('bar')
        self.attr = self.f.attrs.create('x', data)

    def TearDown(self):
        if self.f:
            self.close()

    def test_keys(self):
        key_1 = self.f.keys()
        self.assertIsInstance(repr(key_1), str)
        key_2 = self.grp.keys()
        self.assertIsInstance(repr(key_2), str)

    def test_values(self):
        value_1 = self.f.values()
        self.assertIsInstance(repr(value_1), str)
        value_2 = self.grp.values()
        self.assertIsInstance(repr(value_2), str)

    def test_items(self):
        item_1 = self.f.items()
        self.assertIsInstance(repr(item_1), str)
        item_2 = self.grp.items()
        self.assertIsInstance(repr(item_1), str)
Example #2
0
def _scan_neurodata_types(grp: h5py.File) -> List[Tuple[Any, Any]]:
    out = []
    if "neurodata_type" in grp.attrs:
        out.append(
            (grp.attrs["neurodata_type"], grp.attrs.get("description", None)))
    for v in list(grp.values()):
        if isinstance(v, h5py._hl.group.Group):
            out += _scan_neurodata_types(v)
    return out
Example #3
0
def get_table_df(hdf5_file: File, table_name: str,
                 columns: List[str]) -> pd.DataFrame:
    columns_with_hour = columns[:] + ['hour']
    df = pd.DataFrame(columns=columns_with_hour, index=None)

    for hour in [x for x in hdf5_file.values()][0]:
        try:
            hour_int = int(hour.removeprefix('hour_'))
        except ValueError:
            logger.error('wrong hour format=%s != hour_{int}' % hour)
            continue

        hour_df = pd.DataFrame(columns=['node_from', 'node_to', 'flow'],
                               data=np.array(hdf5_file['results/' + hour +
                                                       '/' + table_name]))
        hour_df['hour'] = [hour_int for _ in range(len(hour_df))]
        df = df.append(hour_df, ignore_index=True)

    return df