agrifoodpy.utils.scaling

Scaling utilities module

Functions

logistic_scale(y0, y1, y2, y3, c_init, c_end)

Create an xarray DataArray with a logistic growth interval

linear_scale(y0, y1, y2, y3, c_init, c_end)

Create an xarray DataArray with a linear growth interval.

piecewise_linear_scale(years, values)

Create an xarray DataArray with a piecewise linear scale.

piecewise_constant_scale(years, values)

Create an xarray DataArray with a piecewise constant scale.

step_scale(y0, y1, y2, c_init, c_end)

Create an xarray DataArray with a step function.

pulse_scale(y0, y1, y2, y3, c_init, c_pulse)

Create an xarray DataArray with a pulse function.

piecewise_smoothstep_scale(years, values[, smoother])

Create an xarray DataArray with a piecewise smoothstep scale.

smoothstep_scale(y0, y1, y2, y3, c_init, c_end[, smoother])

Create an xarray DataArray with a smoothstep function.

Module Contents

agrifoodpy.utils.scaling.logistic_scale(y0, y1, y2, y3, c_init, c_end)

Create an xarray DataArray with a logistic growth interval

The returned DataArray contains values that remain constant at c_init from year y0 to y1, then transition following a logistic curve from c_init to c_end between years y1 and y2, and finally remain constant at c_end from year y2 to y3.

Parameters:
  • y0 – (int) The initial year.

  • y1 – (int) The year when the values start to transition.

  • y2 – (int) The year when the transition completes.

  • y3 – (int) The final year.

  • c_init – (float) The initial constant value.

  • c_end – (float) The final constant value.

Returns: xarray DataArray

An xarray DataArray object with ‘Year’ as the coordinate and values set by a logistic growth between the user defined intervals.

agrifoodpy.utils.scaling.linear_scale(y0, y1, y2, y3, c_init, c_end)

Create an xarray DataArray with a linear growth interval.

The returned DataArray contains values that remain constant at c_init from year y0 to y1, then transition linearly from c_init to c_end between years y1 and y2, and finally remain constant at c_end from year y2 to y3.

Parameters:
  • y0 – (int) Starting year.

  • y1 – (int) Year where the linear variation starts.

  • y2 – (int) Year where the linear variation ends.

  • y3 – (int) Last year in the array.

  • c_init – (float) Value to use for initial constant scale segment.

  • c_end – (float)

Returns: xr.DataArray

An xarray DataArray object with ‘Year’ as the coordinate and values set by a linear growth between the user defined intervals.

agrifoodpy.utils.scaling.piecewise_linear_scale(years, values)

Create an xarray DataArray with a piecewise linear scale.

The returned DataArray contains values that transition linearly between specified years and values.

Parameters:
  • years – (list of int) A list of years where the values change.

  • values – (list of float) A list of values corresponding to each year in the ‘years’ list.

Returns: xr.DataArray

An xarray DataArray object with ‘Year’ as the coordinate and values set by a piecewise linear scale between the user defined intervals.

agrifoodpy.utils.scaling.piecewise_constant_scale(years, values)

Create an xarray DataArray with a piecewise constant scale.

The returned DataArray contains values that remain constant between specified years and values.

Parameters:
  • years – (list of int) A list of years where the values change.

  • values – (list of float) A list of values corresponding to each year in the ‘years’ list.

Returns: xr.DataArray

An xarray DataArray object with ‘Year’ as the coordinate and values set by a piecewise constant scale between the user defined intervals.

agrifoodpy.utils.scaling.step_scale(y0, y1, y2, c_init, c_end)

Create an xarray DataArray with a step function.

The returned DataArray contains values that remain constant at c_init from year y0 to y1, then transition immediately to c_end at year y1 and remain constant at c_end thereafter.

Parameters:
  • y0 – (int) Starting year.

  • y1 – (int) Year where the step change occurs.

  • y2 – (int) Last year in the array.

  • c_init – (float) Value to use for initial constant scale segment.

  • c_end – (float) Value to use for final constant scale segment.

Returns: xr.DataArray

An xarray DataArray object with ‘Year’ as the coordinate and values set by a step change between the user defined intervals.

agrifoodpy.utils.scaling.pulse_scale(y0, y1, y2, y3, c_init, c_pulse)

Create an xarray DataArray with a pulse function.

The returned DataArray contains values that remain constant at c_init from year y0 to y1, then transition immediately to c_pulse at year y1 and remain constant at c_pulse until year y2, after which it transitions back to c_init and remains constant at c_init until year y3.

Parameters:
  • y0 – (int) Starting year.

  • y1 – (int) Year where the pulse starts.

  • y2 – (int) Year where the pulse ends.

  • y3 – (int) Last year in the array.

  • c_init – (float) Value to use for initial and final constant scale segments.

  • c_pulse – (float) Value to use for the pulse segment.

Returns: xr.DataArray

An xarray DataArray object with ‘Year’ as the coordinate and values set by a pulse function between the user defined intervals.

agrifoodpy.utils.scaling.piecewise_smoothstep_scale(years, values, smoother=False)

Create an xarray DataArray with a piecewise smoothstep scale.

The returned DataArray contains values that transition smoothly between specified years and values using a smoothstep function.

Parameters:
  • years – (list of int) A list of years where the values change.

  • values – (list of float) A list of values corresponding to each year in the ‘years’ list.

  • smoother – (bool), optional If True, use a smoother 5th-degree polynomial smoothstep; otherwise use the standard smoothstep.

Returns: xr.DataArray

An xarray DataArray object with ‘Year’ as the coordinate and values set by a piecewise smoothstep scale between the user defined intervals.

agrifoodpy.utils.scaling.smoothstep_scale(y0, y1, y2, y3, c_init, c_end, smoother=False)

Create an xarray DataArray with a smoothstep function.

The returned DataArray contains values that remain constant at c_init from year y0 to y1, then transition smoothly to c_end between years y1 and y2, and finally remain constant at c_end from year y2 to y3.

Parameters:
  • y0 – (int) Starting year.

  • y1 – (int) Year where the smooth transition starts.

  • y2 – (int) Year where the smooth transition ends.

  • y3 – (int) Last year in the array.

  • c_init – (float) Value to use for initial constant scale segment.

  • c_end – (float) Value to use for final constant scale segment.

Returns: xr.DataArray

An xarray DataArray object with ‘Year’ as the coordinate and values set by a smoothstep function between the user defined intervals.