Skip to content
Snippets Groups Projects
Commit 40a747ed authored by Stefano Serafin's avatar Stefano Serafin
Browse files

added ability to randomize true system states (besides observations and coordinates)

parent 9cf5a3ed
No related branches found
No related tags found
No related merge requests found
......@@ -39,7 +39,7 @@ def decode_observations(observation_files):
return observations,ocoords
def random_sort_observations(observations,ocoords):
def random_sort_observations(observations,ocoords,truths=None):
# Check that input arrays have consistent dimensions
assert (observations.shape == ocoords.shape),\
......@@ -50,14 +50,32 @@ def random_sort_observations(observations,ocoords):
shuffled_obs = np.zeros(observations.shape)+np.nan
shuffled_coords = np.zeros(observations.shape)+np.nan
# Randomize observation order, differently at each time
indices = np.arange(nobs)
for i in range(nassim):
np.random.shuffle(indices)
shuffled_obs[i,:] = observations[i,indices]
shuffled_coords[i,:] = ocoords[i,indices]
return shuffled_obs,shuffled_coords
# Randomize arrays, differently at each time
if truths is None:
indices = np.arange(nobs)
for i in range(nassim):
np.random.shuffle(indices)
shuffled_obs[i,:] = observations[i,indices]
shuffled_coords[i,:] = ocoords[i,indices]
return shuffled_obs,shuffled_coords
else:
# Check that truths array has consistent dimensions
assert (truths.shape == ocoords.shape),\
f'observation and coordinate arrays must have the same size'
# Preallocate truths array
shuffled_truths = np.zeros(ocoords.shape)+np.nan
# Randomize arrays, differently at each time
indices = np.arange(nobs)
for i in range(nassim):
np.random.shuffle(indices)
shuffled_obs[i,:] = observations[i,indices]
shuffled_coords[i,:] = ocoords[i,indices]
shuffled_truths[i,:] = truths[i,indices]
return shuffled_obs,shuffled_coords,shuffled_truths
if __name__ == '__main__':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment