示例#1
0
def translate_types(translation_table):
        """Translate types for rwa files.
        """
        # reduce the table
        _table = dict(translation_table)
        _any_update = True
        while _any_update:
                _any_update = False
                for _former_type, _current_type in list(_table.items()):
                        try:
                                _more_current_type = _table[_current_type]
                        except KeyError:
                                pass
                        else:
                                _table[_former_type] = _more_current_type
                                _any_update = True

        # load and register
        for _former_type, _current_type in _table.items():
                _module_name = _current_type.split('.')
                _type_name = _module_name.pop()
                _module_name = '.'.join(_module_name)
                _module = importlib.import_module(_module_name)
                _type = getattr(_module, _type_name)
                try:
                        _storable = rwa.hdf5.hdf5_service.byStorableType(_current_type)
                except:
                        _storable = rwa.default_storable(_type, storable_type=_current_type)
                        _storable_handler = _storable.handlers[0]
                else:
                        _storable_handler = copy.copy(_storable.asVersion())
                _storable_handler._poke = None # peek only
                _storable = rwa.Storable(_type, key=_former_type, handlers=_storable_handler)
                rwa.hdf5_storable(_storable, agnostic=True)
示例#2
0
        space_columns = self.scaler.columns
        n_centroids = int(1. / self.avg_probability)
        centroids = pd.DataFrame(np.random.rand(n_centroids, len(space_columns)), columns=space_columns)
        centroids *= self.upper_bound - self.lower_bound
        centroids += self.lower_bound
        # make the Voronoi tessellation
        Voronoi.tessellate(self, centroids)
        #
        if not allow_empty_cells:
            cells = CellStats(points, self)
            #cells.cell_index = cells.cell_index(centroids, **kwargs)
            ok = 0 < cells.location_count
            self.cell_centers = None
            Voronoi.tessellate(self, centroids[ok])


__all__ = ['setup', 'RandomMesh']

import sys
if sys.version_info[0] < 3:

    import rwa
    import tramway.core.hdf5 as rules
    random_mesh_exposes = rules.voronoi_exposes + list(RandomMesh.__slots__)
    rwa.hdf5_storable(
        rwa.default_storable(RandomMesh, exposes=random_mesh_exposes),
        agnostic=True)

    __all__.append('random_mesh_exposes')

示例#3
0
        t0, t1 = ts.min(), ts.max()
        if self.start_time is not None:
            t0 = self.start_time
        duration, shift = self.duration, self.shift
        if isinstance(duration, int):
            dt = np.median(np.diff(np.unique(ts)))
            duration *= dt
            shift *= dt
            dt /= 10.
        else:
            dt = 1e-7  # precision down to a microsecond (quantum < microsecond)
        nsegments = np.round((t1 - t0 - duration) / shift) + 1.
        t1 = t0 + (nsegments - 1.) * shift + duration
        t0s = np.arange(t0, t1 - duration + dt, shift)
        t1s = t0s + duration
        self.time_lattice = np.stack((t0s, t1s), axis=-1)
        return TimeLattice.cell_index(self, points, *args, **kwargs)


import sys
if sys.version_info[0] < 3:

    import rwa
    sliding_window_exposes = hdf5.time_lattice_exposes + list(
        SlidingWindow.__slots__)  #['duration', 'shift']
    rwa.hdf5_storable(rwa.default_storable(SlidingWindow,
                                           exposes=sliding_window_exposes),
                      agnostic=True)

    __all__.append('sliding_window_exposes')
示例#4
0
            dict(
                args=("-c", "--location-count"),
                kwargs=dict(
                    type=int,
                    default=80,
                    help="average number of locations per cell",
                ),
                translate=True,
            ),
        ),
    )),
}

__all__ = ["setup", "HexagonalMesh"]

import sys

if sys.version_info[0] < 3:

    import rwa
    import tramway.core.hdf5 as rules

    hexagonal_mesh_exposes = rules.voronoi_exposes + list(
        HexagonalMesh.__slots__)
    rwa.hdf5_storable(
        rwa.default_storable(HexagonalMesh, exposes=hexagonal_mesh_exposes),
        agnostic=True,
    )

    __all__.append("hexagonal_mesh_exposes")
示例#5
0
        (
            "avg_location_count",
            dict(
                args=("-c", "--location-count"),
                kwargs=dict(
                    type=int,
                    default=80,
                    help="average number of locations per cell",
                ),
                translate=True,
            ),
        ),
    )),
}

__all__ = ["setup", "KohonenMesh"]

import sys

if sys.version_info[0] < 3:

    import rwa
    import tramway.core.hdf5 as rules

    kohonen_mesh_exposes = rules.voronoi_exposes + list(KohonenMesh.__slots__)
    rwa.hdf5_storable(rwa.default_storable(KohonenMesh,
                                           exposes=kohonen_mesh_exposes),
                      agnostic=True)

    __all__.append("kohonen_mesh_exposes")