Skip to content

Commit

Permalink
allow error for each component of data vector to be specified (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpreistad authored Jan 18, 2024
1 parent 9192773 commit ece8796
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
13 changes: 10 additions & 3 deletions lompe/model/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,12 @@ def __init__(self, values, coordinates = None, LOS = None, components = 'all', d
magnetometer data and iweight=1.0 for ionospheric convection measurements. Keep in
mind that this weight is directly applied to the a priori inverse data covariance matrix,
so the data error is effectively increased by a factor of 1/sqrt(iweight).
error: array of same length as values, or float, optional
error: either float, or 1D array of same length as values, or 2D array
(shape 2,N or 3,N), optional
Measurement error. Used to calculate the data covariance matrix. Use SI units.
If 2D array, it means that the error of each component (east, north, up) is
specified separately. If 1D array, the same value is used for each component.
If float, the same value is used for all observations and components.
"""

Expand Down Expand Up @@ -214,8 +218,11 @@ def subset(self, indices):
"""

self.values = np.array(self.values , ndmin = 2)[:, indices].squeeze()
self.error = self.error[indices]

if np.array(self.error, ndmin=2).shape[0] >= 2: # errors for each component
self.error = self.error[:,indices]
else:
self.error = self.error[indices]

for key in self.coords.keys():
self.coords[key] = self.coords[key][indices]

Expand Down
7 changes: 5 additions & 2 deletions lompe/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,11 @@ def run_inversion(self, l1 = 0, l2 = 0,
spatial_weight = np.ones(ds.values.size)

dimensions = np.array(ds.values, ndmin = 2).shape[0]
error = np.tile(ds.error, dimensions)

if np.array(ds.error, ndmin=2).shape[0]==1:
error = np.tile(ds.error, dimensions)
else: #error is different for different components
error = ds.error.flatten()

w_i = spatial_weight * 1/(error**2) * iweights[ii]
if iweights[ii] != 1:
print('{}: Measurement uncertainty effectively changed from {} to {}'.format(dtype, np.median(error), np.median(error)/np.sqrt(iweights[ii])))
Expand Down

0 comments on commit ece8796

Please sign in to comment.