punchbowl.util#

Attributes#

T

Classes#

DataLoader

Interface for passing callable objects instead of file paths to be loaded.

Functions#

validate_image_is_square(→ None)

Check that the input array is square.

output_image_task(→ None)

Prefect task to write an image to disk.

load_image_task(→ ndcube.NDCube)

Prefect task to load data for processing.

average_datetime(→ datetime.datetime)

Compute average datetime from a list of datetimes.

_zvalue_from_index(arr, ind)

Do math.

nan_percentile(→ numpy.ndarray)

Calculate the nan percentile faster of a 3D cube.

interpolate_data(→ numpy.ndarray)

Interpolates between two data objects.

find_first_existing_file(→ ndcube.NDCube | None)

Find the first cube that's not None in a list of NDCubes.

Module Contents#

punchbowl.util.validate_image_is_square(image: numpy.ndarray) None[source]#

Check that the input array is square.

punchbowl.util.output_image_task(data: ndcube.NDCube, output_filename: str) None[source]#

Prefect task to write an image to disk.

Parameters:
  • data (NDCube) – data that is to be written

  • output_filename (str) – where to write the file out

Return type:

None

punchbowl.util.load_image_task(input_filename: str, include_provenance: bool = True, include_uncertainty: bool = True) ndcube.NDCube[source]#

Prefect task to load data for processing.

Parameters:
  • input_filename (str) – path to file to load

  • include_provenance (bool) – whether to load the provenance layer

  • include_uncertainty (bool) – whether to load the uncertainty layer

Returns:

loaded version of the image

Return type:

NDCube

punchbowl.util.average_datetime(datetimes: list[datetime.datetime]) datetime.datetime[source]#

Compute average datetime from a list of datetimes.

punchbowl.util._zvalue_from_index(arr, ind)[source]#

Do math.

Private helper function to work around the limitation of np.choose() by employing np.take(). arr has to be a 3D array ind has to be a 2D array containing values for z-indicies to take from arr See: http://stackoverflow.com/a/32091712/4169585 This is faster and more memory efficient than using the ogrid based solution with fancy indexing.

punchbowl.util.nan_percentile(arr: numpy.ndarray, q: list[float] | float) numpy.ndarray[source]#

Calculate the nan percentile faster of a 3D cube.

punchbowl.util.interpolate_data(data_before: ndcube.NDCube, data_after: ndcube.NDCube, reference_time: datetime.datetime) numpy.ndarray[source]#

Interpolates between two data objects.

punchbowl.util.find_first_existing_file(inputs: list[ndcube.NDCube]) ndcube.NDCube | None[source]#

Find the first cube that’s not None in a list of NDCubes.

punchbowl.util.T#
class punchbowl.util.DataLoader[source]#

Bases: abc.ABC, Generic[T]

Interface for passing callable objects instead of file paths to be loaded.

abstractmethod load() T[source]#

Load the data.

abstractmethod src_repr() str[source]#

Return a string representation of the data source.