Class for managing operation history
Attributes:
Initialize operation memory structure:
>>> from simo.simulation.caller.operationmemory import OperationMemory
>>> m = OperationMemory()
Check that operation memory is large enough for given objects, resize memory if necessary:
>>> import numpy as np
>>> from datetime import date as dt
>>> obj_row = (0,2,3)
>>> m._size_check(obj_row, 1)
>>> m._dates.shape
(1, 3, 4, 2)
>>> m._times.shape
(1, 3, 4, 2)
>>> m._size_check(obj_row, 4)
>>> m._dates.shape
(1, 3, 4, 5)
>>> m._times.shape
(1, 3, 4, 5)
Update operation memory by adding operation defined by operation indice (opind) for the objects defined by target index (tind):
>>> tind = np.array([[0,0,1,0,0],[0,0,2,0,0],[0,1,1,0,0],[0,2,3,0,0]], dtype=int)
>>> m.update(tind, 0, 1, dt(2005, 1, 1))
>>> m._dates.shape
(1, 3, 4, 5)
>>> m._times.shape
(1, 3, 4, 5)
>>> m._dates[0,0,:,0]
array([...1...1...1..., ...2005...1...1...,
...2005...1...1..., ...1...1...1...], dtype=object)
>>> m._times[0,0,:,0]
array([0, 1, 1, 0])
>>> tind = np.array([[0,0,2,0,0],[0,0,5,0,0],[0,4,7,0,0]], dtype=int)
>>> m.update(tind, 0, 1, dt(2015, 1, 1))
>>> m._dates.shape
(1, 5, 8, 5)
>>> m._times.shape
(1, 5, 8, 5)
>>> m._dates[0,0,:,0]
array([...1...1...1..., ...2005...1...1..., ...2015...1...1...,
...1...1...1..., ...1...1...1..., ...2015...1...1...,
...1...1...1..., ...1...1...1...],
dtype=object)
>>> m._times[0,0,:,0]
array([0, 1, 2, 0, 0, 1, 0, 0])
>>> m._level_map[1]
set([0])
Reset operation memory. Sets all operation memory values to zero.
Get number of timesteps since operation was done last time relative to given date:
>>> tind = np.array([[0,0,1,0,0]], dtype=int)
>>> m.since(tind, 0, dt(2005,1,1), 'year')[0]
0
>>> m.since(tind, 0, dt(2005,12,31), 'year')[0]
0
>>> m.since(tind, 0, dt(2006,1,1), 'year')[0]
1
>>> m.since(tind, 0, dt(2006,12,31), 'year')[0]
1
>>> m.since(tind, 0, dt(2005,1,1), 'month')[0]
0
>>> m.since(tind, 0, dt(2005,1,31), 'month')[0]
0
>>> m.since(tind, 0, dt(2005,2,1), 'month')[0]
1
>>> m.since(tind, 0, dt(2005,7,1), 'month')[0]
6
>>> m.since(tind, 0, dt(2005,12,31), 'month')[0]
11
>>> m.since(tind, 0, dt(2006,1,1), 'month')[0]
12
>>> m.since(tind, 0, dt(2006,12,31), 'month')[0]
23
>>> m._dates[0,0,1,0] = dt(2000, 3, 31)
>>> m.since(tind, 0, dt(2000,4,1), 'year')[0]
0
>>> m.since(tind, 0, dt(2001,4,1), 'year')[0]
1
>>> m.since(tind, 0, dt(2000,4,1), 'month')[0]
1
>>> m.since(tind, 0, dt(2000,12,31), 'month')[0]
9
>>> m.since(tind, 0, dt(2001,1,1), 'month')[0]
10
>>> m.since(tind, 0, dt(2001,3,31), 'month')[0]
12
>>> m.since(tind, 0, dt(2001,4,1), 'month')[0]
13
>>> m.since(tind, 0, dt(2001,6,30), 'month')[0]
15
>>> m.since(tind, 0, dt(2000,4,1), 'day')[0]
0
>>> m.since(tind, 0, dt(2000,12,31), 'day')[0]
273
>>> m.since(tind, 0, dt(2001,1,1), 'day')[0]
274
>>> m.since(tind, 0, dt(2001,3,31), 'day')[0]
365
>>> m.since(tind, 0, dt(2001,4,1), 'day')[0]
365
>>> m.since(tind, 0, dt(2001,6,30), 'day')[0]
455
Get number of times a given operation has been done:
>>> tind = np.array([[0,0,1,0,0],[0,0,2,0,0],[0,0,3,0,0],[0,0,5,0,0]], dtype=int)
>>> m.times(tind, 0)
array([1, 2, 0, 1])
>>> m.times(tind, 1)
array([0, 0, 0, 0])
Update operation memory after adding a new branch to simulation data matrix
>>> par_obj = (0,0,1)
>>> new_obj = (0,1,1)
>>> m.add_branch(par_obj, new_obj, 1)
>>> m._dates[0,(0,1),1]
array([[...2...3...31..., ...1...1...1..., ...1...1...1...,
...1...1...1..., ...1...1...1...],
[...2...3...31..., ...1...1...1..., ...1...1...1...,
...1...1...1..., ...1...1...1...]], dtype=object)
>>> m._times[0,(0,1),1]
array([[1, 0, 0, 0, 0],
[1, 0, 0, 0, 0]])
Delete objects from operation memory (reset given objects)
>>> m.del_objects(0, 0, [0,1,2], 1)
>>> m._dates[0,0,(0,1,2),0]
array([...1...1...1..., ...1...1...1..., ...1...1...1...], dtype=object)
>>> m._times[0,0,(0,1,2),0]
array([0, 0, 0])