Deformation rate to strain rate conversion #39
-
|
Hi Is there a way to convert deformation-rate data to strain-rate data using XDAS existing tools ? The use of Thanks :) |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
|
Hi @ianis-g There is this documentation page about strain-rate to any quantity conversion. But if I understand well you want to do the opposite. In that case Do you encounter some problems while doing so ? You can further explain your use case if you want further help. |
Beta Was this translation helpful? Give feedback.
-
|
Oh I see, You could almost do what you describe with Numpy with Xdas BUT if you try it you will have some trouble with the space coordinates as Bellow a function that does what you want for any dimension you want : import xdas
def differentiate(da, span=1, method="forward", dim="last"):
d = xdas.get_sampling_interval(da, dim)
before = da.isel({dim:slice(None, -span)})
after = da.isel({dim:slice(span, None)})
data = (after.values - before.values) / (span * d)
match method:
case "forward":
out = before.copy(data=data)
case "backward":
out = after.copy(data=data)
case "central":
out = before.copy(data=data)
out[dim] = before[dim] + (span * d / 2)
case _:
raise ValueError(f"unknown method '{method}'")
return outNotes:
Tell me if it works as expected, I will add this to Xdas whenever I have some time. |
Beta Was this translation helpful? Give feedback.
-
|
Oh BTW a more modern approach could be to do Actually the N span differentiation can be seen as the convolution of a diff kernel [1, -1] (or the opposite and you must normalize) and a smoothing kernel [1, ..., 1] (with len the span of interrest and you must normalize again, i.e. rolling mean). This latter is the worst decimation kernel ever. You can replace it with a hann window or something better. |
Beta Was this translation helpful? Give feedback.
Oh I see,
You could almost do what you describe with Numpy with Xdas BUT if you try it you will have some trouble with the space coordinates as
da[:, gauge_samples:]anddata[:, :-gauge_samples]will not have the same space coordinate anymore. For now Xdas raises an Error when you try to do arithmetic with data arrays with different coordinates because it is not clear how to handle coordinates in that case.Bellow a function that does what you want for any dimension you want :