punchbowl.data.punch_io#

Attributes#

Classes#

DefaultFormatter

A formatter that doesn't fail if a keyword is missing. Used for quicklook.

Functions#

write_file_hash(→ None)

Create a SHA-256 hash for a file.

get_base_file_name(→ str)

Determine the base file name without file type extension.

_header_to_xml(→ lxml.etree.Element)

Convert image header metadata into an XML Tree that can be inserted into a JPEG2000 file header.

_generate_jp2_xmlbox(→ glymur.jp2box.XMLBox)

Generate the JPEG2000 XML box to be inserted into the JPEG2000 file.

write_ndcube_to_quicklook(→ None)

Write an NDCube to a Quicklook format as a jpeg.

write_quicklook_to_mp4(→ None)

Write a list of input quicklook jpeg2000 files to an output mp4 animation.

write_ndcube_to_fits(→ None)

Write an NDCube as a FITS file.

_pack_uncertainty(→ numpy.ndarray)

Compress the uncertainty for writing to file.

_unpack_uncertainty(→ numpy.ndarray)

Uncompress the uncertainty when reading from a file.

_update_statistics(...)

Update image statistics in metadata before writing to file.

load_ndcube_from_fits(→ ndcube.NDCube)

Load an NDCube from a FITS file.

Module Contents#

punchbowl.data.punch_io._ROOT = b'.'#
punchbowl.data.punch_io.CALIBRATION_ANNOTATION = '{OBSRVTRY} - {TYPECODE}{OBSCODE} - {DATE-OBS} - exptime: {EXPTIME} s - polarizer: {POLAR} deg'#
punchbowl.data.punch_io.write_file_hash(path: str) None[source]#

Create a SHA-256 hash for a file.

punchbowl.data.punch_io.get_base_file_name(cube: ndcube.NDCube) str[source]#

Determine the base file name without file type extension.

class punchbowl.data.punch_io.DefaultFormatter[source]#

Bases: string.Formatter

A formatter that doesn’t fail if a keyword is missing. Used for quicklook.

get_field(field_name: str, args: Any, kwargs: Any) str[source]#

Provide a special getter that returns the name if it fails.

punchbowl.data.punch_io._header_to_xml(header: astropy.io.fits.Header) lxml.etree.Element[source]#

Convert image header metadata into an XML Tree that can be inserted into a JPEG2000 file header.

(Helper function adapted from SunPy)

punchbowl.data.punch_io._generate_jp2_xmlbox(header: astropy.io.fits.Header) glymur.jp2box.XMLBox[source]#

Generate the JPEG2000 XML box to be inserted into the JPEG2000 file.

(Helper function adapted from SunPy)

punchbowl.data.punch_io.write_ndcube_to_quicklook(cube: ndcube.NDCube, filename: str, layer: int | None = None, vmin: float = 1e-15, vmax: float = 8e-12, include_meta: bool = True, annotation: str | None = None, color: bool = False) None[source]#

Write an NDCube to a Quicklook format as a jpeg.

Parameters:
  • cube (NDCube) – data cube to visualize

  • filename (str) – path to save output, must end in .jp2, .j2k, .jpeg, .jpg

  • layer (int | None) – if the cube is 3D, then selects cube.data[layer] for visualization

  • vmin (float) – the lower limit value to visualize

  • vmax (float) – the upper limit value to visualize

  • include_meta (bool) – whether to include metadata in the JPEG2000 file

  • annotation (str | None) – a formatted string to add to the bottom of the image as a label can access metadata by key, e.g. “typecode={TYPECODE}” would write the data’s typecode into the image

  • color (bool) – flag to generate RGB quicklook files, grayscale by default

Return type:

None

punchbowl.data.punch_io.write_quicklook_to_mp4(files: list[str], filename: str, framerate: int = 5, resolution: int = 1024, codec: str = 'libx264', ffmpeg_cmd: str = 'ffmpeg') None[source]#

Write a list of input quicklook jpeg2000 files to an output mp4 animation.

Parameters:
  • files (list[str]) – List of input files to animate

  • filename (str) – Output filename

  • framerate (int, optional) – Frame rate (default 5)

  • resolution (int, optional) – Output resolution (default 1024)

  • codec (str, optional) – Codec to use for encoding. For GPU acceleration. “h264_videotoolbox” can be used on ARM Macs, “h264_nvenc” can be used on Intel machines.

  • ffmpeg_cmd (str) – path to the ffmpeg executable

punchbowl.data.punch_io.write_ndcube_to_fits(cube: ndcube.NDCube, filename: str, overwrite: bool = False, write_hash: bool = True, skip_stats: bool = False, skip_wcs_conversion: bool = False, uncertainty_quantize_level: float = 16) None[source]#

Write an NDCube as a FITS file.

punchbowl.data.punch_io._pack_uncertainty(cube: ndcube.NDCube) numpy.ndarray[source]#

Compress the uncertainty for writing to file.

punchbowl.data.punch_io._unpack_uncertainty(uncertainty_array: numpy.ndarray, data_array: numpy.ndarray) numpy.ndarray[source]#

Uncompress the uncertainty when reading from a file.

punchbowl.data.punch_io._update_statistics(cube: ndcube.NDCube) punchbowl.data.meta.NormalizedMetadata[source]#

Update image statistics in metadata before writing to file.

punchbowl.data.punch_io.load_ndcube_from_fits(path: str | pathlib.Path, key: str = ' ', include_provenance: bool = True, include_uncertainty: bool = True) ndcube.NDCube[source]#

Load an NDCube from a FITS file.