Skip to content

Commit

Permalink
Add workaround for xr.apply_ufunc issue in 1D unwrapping routines
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Pechnikov committed Apr 28, 2024
1 parent 2aef4e6 commit 1c2d559
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pygmtsar/pygmtsar/Stack_unwrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,12 @@ def unwrap_pairs(data : np.ndarray,
assert weight.ndim == 1 or weight.ndim == 0
assert matrix.ndim == 2
assert data.shape[0] == matrix.shape[0]


# for now, xr.apply_ufunc always call specified function with float64 arguments
# this error should be resolved controlling the output datatype
#assert data.dtype == np.float32, f'ERROR: data argument should be float32 array but it is {data.dtype}'
#assert weight.dtype == np.float32, f'ERROR: weight argument should be float32 array but it is {weight.dtype}'

if np.all(np.isnan(data)) or (weight.size != 0 and np.all(np.isnan(weight))):
return np.full(data.size, np.nan, dtype=np.float32)

Expand All @@ -232,6 +237,7 @@ def unwrap_pairs(data : np.ndarray,
return np.full(data.size, np.nan, dtype=np.float32)

# the buffer variable will be modified
# buffer datatype is the same as input data datatype
buffer = data[~nanmask].copy()
if weight.size != 0:
weight = weight[~nanmask]
Expand Down Expand Up @@ -363,7 +369,8 @@ def unwrap_pairs(data : np.ndarray,

# return original values when unwrapping is not possible at all
if len(pairs_ok) == 0:
return buffer
# buffer datatype is the same as input data datatype
return buffer.astype(np.float32)
# return unwrapped values
# validity mask
mask = [idx in pairs_ok for idx in range(buffer.size)]
Expand Down

0 comments on commit 1c2d559

Please sign in to comment.