def extract_slice(cube, path, spacing=1.0, order=3, respect_nan=True,
                  wcs=None):

    if not respect_nan:
        cube = np.nan_to_num(cube)

    if path.width is None:
        x, y = path.sample_points(spacing=spacing, wcs=wcs)
        slice = extract_line_slice(cube, x, y, order=order)
    else:
        polygons = path.sample_polygons(spacing=spacing, wcs=wcs)
        slice = extract_poly_slice(cube, polygons)

    return slice
Given an array with shape (z, y, x), extract a (z, n) slice from a path
dataset/ETHPy150Open glue-viz/glue/glue/external/pvextractor/geometry/slices.py/extract_slice