Page MenuHomec4science

RandomGenerator.py
No OneTemporary

File Metadata

Created
Sun, Oct 13, 17:16

RandomGenerator.py

###########################################################################
# #
# Copyright 2017 Andrea Cimatoribus #
# EPFL ENAC IIE ECOL #
# GR A1 435 (Batiment GR) #
# Station 2 #
# CH-1015 Lausanne #
# Andrea.Cimatoribus@epfl.ch #
# #
# Alexandre Serex #
# alexandre.serex@epfl.ch #
# #
# This file is part of ctracker #
# #
# ctracker is free software: you can redistribute it and/or modify it #
# under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# ctracker is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty #
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. #
# See the GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with ctracker. If not, see <http://www.gnu.org/licenses/>. #
# #
###########################################################################
import numpy as np
import random
from core.parameter import Parameter
class RandomGenerator(Parameter):
def __init__(self, name):
super(RandomGenerator, self).__init__(name)
random.seed()
self.outputs = ['default']
def array_from_shape(self, shape):
return np.random.rand(*shape)
def real_value(self):
return random.random()
def to_out_worker(self, time, tijk_shape, xyz_shape, ids_shape, out_shape):
ids = np.array(list(range(1, ids_shape[0] + 1)))
ids.shape = ids_shape
out = np.zeros(out_shape)
tijk = self.array_from_shape(tijk_shape)
xyz = self.array_from_shape(xyz_shape)
self.output('default',
(time,
tijk.copy(),
xyz.copy(),
ids.copy(),
out.copy(),
False)
)

Event Timeline