Workflow¶
petrophys.workflow.custom.Workflow
Also available as petrophys.workflow.Workflow
- class Workflow(name='Custom workflow', steps=(), *, description='')[source]¶
An ordered, reusable recipe of interpretation steps.
Add built-in steps from
petrophys.workflow.stepsand your ownworkflow_step()functions, check the recipe against a well, run it on one well or many, and save it as JSON to share. Steps run in the order they were added; each can use the curves of the well and of earlier steps.- Parameters:
- Raises:
WorkflowValidationError – If two steps share a name, or a step needs a curve that only a later step produces.
See also
petrophys.interpretThe prebuilt workflow that chooses methods automatically.
Examples
>>> import petrophys as pp >>> from petrophys.workflow import Workflow, steps >>> wf = Workflow("Brent Group quick look", [ ... steps.clay_volume(method="gr", gr_clean=20, gr_shale=110), ... steps.porosity(method="density", matrix_density=2.65), ... steps.formation_water(rw=0.07, rw_temp_f=230), ... steps.saturation(model="archie", a=1, m=2, n=2), ... steps.net_pay(vcl_cutoff=0.35, phie_cutoff=0.10, sw_cutoff=0.60), ... ]) >>> len(wf) 5 >>> run = wf.run(pp.read(pp.sample("30_6-5"))) >>> run.summary(top=2841, bottom=2958)["net_thickness"]["depth_unit"] 'm'
Attributes
The steps, in run order.
Methods
Append a step.
Check what each step needs against a well, before running anything.
Return an independent copy, optionally renamed.
Table of the steps: what each needs, produces and is configured with.
Rebuild a workflow from
to_dict()output.Insert a step before or after a named step.
Load a workflow saved with
save().Remove the step called
name.Replace the step called
namewith another step, in place.Run the workflow on one well.
Run the workflow on many wells, collecting failures per well.
Save the workflow as JSON.
Return the workflow as a JSON-serializable dictionary.
- add(step)[source]¶
Append a step.
- Parameters:
step (Step) – A configured step, e.g.
steps.porosity(method="density").- Returns:
This workflow, so calls can be chained.
- Return type:
- Raises:
TypeError – If
stepis not aStep(for example a factory that was not called).WorkflowValidationError – If the name is already used, or an earlier step needs a curve that only this step produces.
Examples
>>> import petrophys as pp >>> from petrophys.workflow import Workflow, steps >>> wf = Workflow("demo").add(steps.clay_volume()).add(steps.porosity()) >>> [step.name for step in wf] ['clay_volume', 'porosity']
- insert(step, *, before=None, after=None)[source]¶
Insert a step before or after a named step.
- Parameters:
- Returns:
This workflow.
- Return type:
- Raises:
KeyError – If the named step does not exist.
TypeError – If neither or both of
beforeandafterare given.WorkflowValidationError – If the result has duplicate names or out-of-order dependencies.
Examples
>>> import petrophys as pp >>> from petrophys.workflow import Workflow, steps >>> wf = Workflow("demo", [steps.clay_volume(), steps.porosity()]) >>> _ = wf.insert(steps.temperature(), before="clay_volume") >>> [step.name for step in wf] ['temperature', 'clay_volume', 'porosity']
- replace(name, step)[source]¶
Replace the step called
namewith another step, in place.- Parameters:
- Returns:
This workflow.
- Return type:
Examples
>>> import petrophys as pp >>> from petrophys.workflow import Workflow, steps >>> wf = Workflow("demo", [steps.clay_volume(method="gr")]) >>> wf.replace("clay_volume", steps.clay_volume(method="minimum"))["clay_volume"] steps.clay_volume(method='minimum')
- remove(name)[source]¶
Remove the step called
name.Examples
>>> import petrophys as pp >>> from petrophys.workflow import Workflow, steps >>> wf = Workflow("demo", [steps.clay_volume(), steps.porosity()]) >>> [step.name for step in wf.remove("porosity")] ['clay_volume']
- copy(name=None)[source]¶
Return an independent copy, optionally renamed.
Examples
>>> import petrophys as pp >>> from petrophys.workflow import Workflow, steps >>> base = Workflow("base", [steps.clay_volume()]) >>> variant = base.copy("variant").add(steps.porosity()) >>> len(base), len(variant) (1, 2)
- describe()[source]¶
Table of the steps: what each needs, produces and is configured with.
- Returns:
One row per step, numbered from 1, with columns
Step,Kind,Requires,ProducesandParameters(the parameters set explicitly;"defaults"when none were).- Return type:
Examples
>>> import petrophys as pp >>> from petrophys.workflow import Workflow, steps >>> wf = Workflow("demo", [steps.formation_water(rw=0.07, rw_temp_f=230)]) >>> wf.describe().loc[1, "Parameters"] 'rw=0.07, rw_temp_f=230'
- check(well)[source]¶
Check what each step needs against a well, before running anything.
Outputs of earlier steps count as available. A step that cannot run also blocks the steps that need its outputs; those rows say which step is the cause.
- Parameters:
well (Well or path) – The well to check (not modified).
- Returns:
One row per requirement with columns
Step,Requires,Met(bool),Source("well (RDEP)","step porosity"or"missing") andNote(why it is unmet and how to fix it). A step without requirements has one row,(nothing).- Return type:
Examples
>>> import petrophys as pp >>> from petrophys.workflow import Workflow, steps >>> wf = Workflow("demo", [steps.saturation(model="archie")]) >>> table = wf.check(pp.read(pp.sample("30_6-5"))) >>> table.loc[~table["Met"], "Requires"].tolist() ['PHIE', 'RW']
- run(well, *, strict=True, params=None, inplace=False)[source]¶
Run the workflow on one well.
- Parameters:
well (Well or path) – The well, or a well file to read with
petrophys.read().strict (bool, default True) – If True, raise
WorkflowValidationErrorbefore any calculation when a step lacks an input, andWorkflowStepErrorif a step fails. If False, skip steps that cannot run (recording the reason insteps_skipped) and record failed steps inerrors.params (dict, optional) – One-off parameter changes by step name, e.g.
{"saturation": {"n": 2.2}}. The workflow itself is unchanged.inplace (bool, default False) – If False, the well is copied and yours is left unchanged.
- Returns:
The interpreted well, the step trace, skipped steps, warnings and artifacts.
- Return type:
- Raises:
WorkflowValidationError – With
strict=True, listing every unmet requirement by step.WorkflowStepError – With
strict=True, if a step raises.KeyError – If
paramsnames a step that does not exist.
Examples
>>> import petrophys as pp >>> from petrophys.workflow import Workflow, steps >>> wf = Workflow("demo", [ ... steps.clay_volume(), ... steps.porosity(), ... steps.formation_water(rw=0.07, rw_temp_f=230), ... steps.saturation(model="archie"), ... ]) >>> well = pp.read(pp.sample("30_6-5")) >>> run = wf.run(well, params={"saturation": {"n": 2.2}}) >>> run.status, run.steps[-1].parameters["n"] ('complete', 2.2)
- run_many(wells, *, strict=True, formations=None, params=None, pattern='*.las')[source]¶
Run the workflow on many wells, collecting failures per well.
- Parameters:
wells (folder, path, Well, or iterable of Wells and paths) – A folder is expanded to the files matching
pattern. Files are read withpetrophys.read(); Well objects are copied.strict (bool, default True) – As in
run(), per well: a well that cannot run, or whose step fails, is recorded inerrorsand the batch continues.formations (path or DataFrame, optional) – Formation tops attached to every well (a multi-well table is matched by well name), for per-formation summaries.
params (dict, optional) – One-off parameter changes by step name, applied to every well.
pattern (str, default
"*.las") – File pattern used whenwellsis a folder.
- Returns:
resultsby well name,errorsby well name, andWorkflowBatchResult.summary_table().- Return type:
- Raises:
FileNotFoundError – If a folder has no matching files, or a path does not exist.
ValueError – If no wells are given.
Examples
>>> import petrophys as pp >>> from petrophys.workflow import Workflow, steps >>> wf = Workflow("vcl", [steps.clay_volume(method="gr")]) >>> batch = wf.run_many([pp.sample("HW-3"), pp.sample("HW-4")]) >>> list(batch.results), batch.errors (['HW-3', 'HW-4'], {})
- to_dict(*, include_version=True)[source]¶
Return the workflow as a JSON-serializable dictionary.
- Parameters:
include_version (bool, default True) – Include the petrophys version that wrote it.
- Returns:
schema,schema_version,name,descriptionandsteps(each{"name", "kind", "params"}).- Return type:
Examples
>>> import petrophys as pp >>> from petrophys.workflow import Workflow, steps >>> Workflow("demo", [steps.porosity(method="density")]).to_dict()["steps"] [{'name': 'porosity', 'kind': 'porosity', 'params': {'method': 'density'}}]
- classmethod from_dict(data)[source]¶
Rebuild a workflow from
to_dict()output.Every step is re-created through its factory, so parameters are validated again.
Warning
A custom step is stored as
"module:function"and rebuilt by importing that module, which runs its code. Only load workflows from sources you trust, as you would only run their Python files.- Parameters:
data (mapping) – A workflow dictionary.
- Return type:
- Raises:
ValueError – If the dictionary is not a workflow, was written by a newer format, or a step cannot be rebuilt (unknown kind, invalid parameters, or a custom step that cannot be imported).
Examples
>>> import petrophys as pp >>> from petrophys.workflow import Workflow, steps >>> wf = Workflow("demo", [steps.net_pay(sw_cutoff=0.5)]) >>> Workflow.from_dict(wf.to_dict()) == wf True
- save(path)[source]¶
Save the workflow as JSON.
- Parameters:
path (str or Path) – Output file; parent folders are created.
- Returns:
The written file.
- Return type:
Path
- Raises:
ValueError – If a custom step is defined inside a function and so could never be imported again.
- Warns:
UserWarning – If a custom step is defined in
__main__(a script or notebook): the file then loads only where that function exists.
Examples
>>> import tempfile, pathlib >>> import petrophys as pp >>> from petrophys.workflow import Workflow, steps >>> wf = Workflow("demo", [steps.clay_volume(method="gr")]) >>> with tempfile.TemporaryDirectory() as folder: ... path = wf.save(pathlib.Path(folder) / "demo.json") ... Workflow.load(path) == wf True
- classmethod load(path)[source]¶
Load a workflow saved with
save().Warning
Custom steps are rebuilt by importing their modules; only load workflow files you trust (see
from_dict()).- Parameters:
path (str or Path) – A workflow JSON file.
- Return type:
- Raises:
FileNotFoundError – If the file does not exist.
ValueError – If the file is not valid workflow JSON, or a step cannot be rebuilt; see
from_dict().