import dascore as dc
= dc.get_example_patch()
patch
# Define a custom function that squares the data
def square_data(patch):
return patch.new(data=patch.data ** 2)
# Use pipe to apply the function
= patch.pipe(square_data)
squared
# Can also chain with other methods
= patch.pipe(square_data).mean(dim="time") result
pipe
Pipe the patch to a function.
This is primarily useful for maintaining a chain of patch calls for a function.
Parameters
Parameter | Description |
---|---|
func |
The function to pipe the patch. It must take a patch instance as the first argument followed by any number of positional or keyword arguments, then return a patch. |
*args | Positional arguments that get passed to func. |
**kwargs | Keyword arguments passed to func. |