예제 #1
0
    def build():
        ts_index = time_series_factory()

        ts_h5 = h5_file_for_index(ts_index)
        ts = TimeSeries()
        ts_h5.load_into(ts)
        ts_h5.close()

        data_shape = ts.data.shape

        result_shape = (data_shape[2], data_shape[2], data_shape[1],
                        data_shape[3])
        result = numpy.zeros(result_shape)

        for mode in range(data_shape[3]):
            for var in range(data_shape[1]):
                data = ts_h5.data[:, var, :, mode]
                data = data - data.mean(axis=0)[numpy.newaxis, 0]
                result[:, :, var, mode] = numpy.cov(data.T)

        covariance = Covariance(source=ts, array_data=result)

        op = operation_factory()

        covariance_db = CovarianceIndex()
        covariance_db.fk_from_operation = op.id
        covariance_db.fill_from_has_traits(covariance)

        covariance_h5_path = h5.path_for_stored_index(covariance_db)
        with TimeSeriesH5(covariance_h5_path) as f:
            f.store(ts)

        session.add(covariance_db)
        session.commit()
        return covariance_db
예제 #2
0
    def build():

        time_series_index = time_series_index_factory()
        time_series = h5.load_from_index(time_series_index)
        data = numpy.random.random((10, 10))
        covariance = graph.Covariance(source=time_series, array_data=data)

        op = operation_factory()

        covariance_index = CovarianceIndex()
        covariance_index.fk_from_operation = op.id
        covariance_index.fill_from_has_traits(covariance)

        covariance_h5_path = h5.path_for_stored_index(covariance_index)
        with CovarianceH5(covariance_h5_path) as f:
            f.store(covariance)

        covariance_index = dao.store_entity(covariance_index)
        return covariance_index