Data Transformation Examples

This page provides examples of data processing via the data transformation framework.

All examples are tested.


Curve Fitting

For fitting a curve to some data, the following operations can be combined:

select:
  data_to_fit: path/to/elephant_ts  # 1D data with `time` dimension

transform:
  # Define the model function as a lambda
  - lambda: "lambda x, a0, a1, a2, a3, a4, a5: a5*x**5 + a4*x**4 + a3*x**3 + a2*x**2 + a1*x**1 + a0"
    tag: elephant_f

  # Extract the independent variable (here: the `time` coordinates)
  - .coords: [!dag_tag data_to_fit, time]
    tag: times

  # Do the fit; result will be that of `scipy.optimize.curve_fit`
  - curve_fit:
      - !dag_tag elephant_f
      - !dag_tag times
      - !dag_tag data_to_fit
    tag: fit_results

Note

The polynomial above of course doesn’t quite achieve fitting an elephant to the data, as John von Neumann wanted to show. However, see this blog post on how this can actually be achieved.