HARPgroup / HSPsquared

Hydrologic Simulation Program Python (HSPsquared)
GNU Affero General Public License v3.0
1 stars 0 forks source link

Specl and Objects hdf5 data model #20

Open rburghol opened 2 years ago

rburghol commented 2 years ago

Overview

All data paths are to be added to hdf5 structure.

See also:

In Memory Runtime Variables

As it stands, it appears that the entirety of the hsp2 simulation state data is stored in the hdf5 table, meaning there are no persistent object of any sort, but rather, functions that operate on the data that is present in the hdf5, passed in to the given function in the form of the ui and ts variables. SPECL or other dynamic objects may need to be stored in the hdf5 table? Or do we deviate from the standard process?

numpy array slices

Note: np array slices are views (pass by references), but a simple extract of a value is NOT.

a = np.array([[1,2,3],[2,4,6]])
b = a[1,2] # extracts the 6
b
> 6
b = 77
b
> 77
a   # is unchanged
> array([[1, 2, 3],
>       [2, 4, 6]])

b = a[1:2,2:3] # extract a slice
b   # show the contents and it is an array, with 6 as value
> array([[6]])
# now, set the value of the extracted element
b[[0]] = 77
a    # now the final element of a has been set to 77
> array([[ 1,  2,  3],
>       [ 2,  4, 77]])

b = 99 # doing this OVERWRITES b, rather than setting the *view* element
a       # so final element of a is STILL 77
array([[ 1,  2,  3],
       [ 2,  4, 77]])
rburghol commented 1 year ago

Note. np array slices are views (pass by references), but a simple extract of a value is NOT.

a = np.array([[1,2,3],[2,4,6]])
b = a[1,2] # extracts the 6
b
> 6
b = 77
b
> 77
a   # is unchanged
> array([[1, 2, 3],
>       [2, 4, 6]])

b = a[1:2,2:3] # extract a slice
b   # show the contents and it is an array, with 6 as value
> array([[6]])
# now, set the value of the extracted element
b[[0]] = 77
a    # now the final element of a has been set to 77
> array([[ 1,  2,  3],
>       [ 2,  4, 77]])

b = 99 # doing this OVERWRITES b, rather than setting the *view* element
a       # so final element of a is STILL 77
array([[ 1,  2,  3],
       [ 2,  4, 77]])
rburghol commented 1 year ago

@jdkleiner -- just tagged you in this so we can review at least some of this in todays work session.

jdkleiner commented 1 year ago

@rburghol Below works as well, so it might not be just slicing that does it, setting b = a and then setting a value in the b array updates the a array

a = np.array([[1,2,3],[2,4,6]])
b = a
print(b)
[[1 2 3]
 [2 4 6]]

b[1,2] = 77
print(a)
[[ 1  2  3]
 [ 2  4 77]]