workflow_step

petrophys.workflow.custom.workflow_step

Also available as petrophys.workflow.workflow_step

workflow_step(func=None, *, requires=(), produces=None, description=None)[source]

Turn a function into a reusable workflow step.

The function takes the well first and its parameters as keywords, and returns the curves it calculates as a {name: array} dict (one value per depth sample). The workflow adds those curves to the well with the units declared in produces and records the step in the trace. Calling the decorated function with parameters gives a configured Step for Workflow.add().

Parameters:
  • func (callable, optional) – The function, when the decorator is used without arguments.

  • requires (str or sequence of str, optional) – Curves the function reads; the workflow checks they exist before running.

  • produces (mapping or sequence of str, optional) – Curves the function returns, mapped to their units ({"VSH_LIN": "v/v"}); a list of names means unitless curves. Omit it for a function that returns a pandas.DataFrame (stored in run.artifacts) or nothing.

  • description (str, optional) – One-line summary; defaults to the first line of the docstring.

Returns:

A step factory. factory(**params) validates the parameter names and returns a Step; factory(..., name="x") names it.

Return type:

callable

Raises:

TypeError – If the function does not take the well first, takes *args, or has a parameter called name (reserved for the step name).

Notes

Saved workflows store a custom step by its import path ("module:function"). Define steps you want to share in an importable module; a step defined in a notebook can only be reloaded in that session.

Examples

>>> import numpy as np
>>> import petrophys as pp
>>> from petrophys.workflow import workflow_step
>>> @workflow_step(requires=["GR"], produces={"VSH_LIN": "v/v"})
... def linear_vsh(well, gr_clean=20.0, gr_shale=120.0):
...     '''Linear shale volume from gamma ray.'''
...     gr = well.get("GR").data
...     return {"VSH_LIN": np.clip((gr - gr_clean) / (gr_shale - gr_clean), 0, 1)}
>>> step = linear_vsh(gr_clean=25)
>>> step
linear_vsh(gr_clean=25)
>>> step.requires, step.produces
(('GR',), {'VSH_LIN': 'v/v'})