mirar package

Subpackages

Submodules

mirar.io module

Python script containing all IO functions.

All opening/writing of fits files should run via this script.

exception mirar.io.MissingCoreFieldError[source]

Bases: KeyError

Base class for missing core field errors

mirar.io.check_file_is_complete(path: str) bool[source]

Function to check whether a fits file is as large as expected. Useful to verify with e.g rsync, where files can be partially transferred

Disclaimer: I (Robert) do not feel great about having written this code block. It seems to works though, let’s hope no one finds out! I will cover my tracks by hiding the astropy warning which inspired this block, informing the user that the file is not as long as expected

Parameters:

path – path of file to check

Returns:

boolean file complete

mirar.io.check_image_has_core_fields(img: Image)[source]

Function to ensure that an image has all the core fields

Parameters:

img – Image object to check

Returns:

None

mirar.io.combine_mef_extension_file_headers(primary_header: Header, extension_header: Header) Header[source]

Function to combine the primary header with an extension header in a MEF frame

Parameters:
  • primary_header – astropy Header object

  • extension_header – astropy Header object

Returns:

astropy Header object

mirar.io.create_fits(data: ndarray, header: Header | None) PrimaryHDU[source]

Return an astropy PrimaryHDU object created with <data> and <header>

Parameters:
  • data – numpy ndarray containing image data

  • header – astropy Header object

Returns:

astropy PrimaryHDU object containing the image data and header

mirar.io.open_fits(path: str | Path) tuple[ndarray, Header][source]

Function to open a fits file saved to <path>

Parameters:

path – path of fits file

Returns:

tuple containing image data and image header

mirar.io.open_mef_fits(path: str | Path) tuple[Header, list[ndarray], list[Header]][source]

Function to open a MEF fits file saved to <path>

Parameters:

path – path of fits file

Returns:

tuple containing image data and image header

mirar.io.open_mef_image(path: str | ~pathlib.Path, open_f: ~typing.Callable[[str | ~pathlib.Path], tuple[~astropy.io.fits.header.Header, list[~numpy.ndarray], list[~astropy.io.fits.header.Header]]] = <function open_mef_fits>, extension_key: str | None = None) list[Image][source]

Function to open a raw image as an Image object

Parameters:
  • path – path of raw image

  • open_f – function to open the raw image

  • extension_key – key to use to number the MEF frames

Returns:

Image object

mirar.io.open_raw_image(path: str | ~pathlib.Path, open_f: ~typing.Callable[[str | ~pathlib.Path], tuple[~numpy.ndarray, ~astropy.io.fits.header.Header]] = <function open_fits>) Image[source]

Function to open a raw image as an Image object

Parameters:
  • path – path of raw image

  • open_f – function to open the raw image

Returns:

Image object

mirar.io.save_fits(image: Image, path: str | Path)[source]

Save an Image to path

Parameters:
  • image – Image to save

  • path – path

Returns:

None

mirar.io.save_hdu_as_fits(hdu: PrimaryHDU, path: str | Path, overwrite: bool = True)[source]

Wrapper function to save an astropy hdu to file

Parameters:
  • hdu – hdu to save

  • path – path to save

  • overwrite – boolean whether to overwrite

Returns:

None

mirar.io.save_mef_to_path(data_list, header_list, primary_header, path)[source]

Function to save a MEF image with <data> and <header> to <path>.

mirar.io.save_to_path(data: ndarray, header: Header | None, path: str | Path, overwrite: bool = True)[source]

Function to save an image with <data> and <header> to <path>.

Parameters:
  • data – numpy ndarray containing image data

  • header – astropy Header object

  • path – output path to save to

  • overwrite – boolean variable opn whether to overwrite of an image exists at <path>. Defaults to True.

Returns:

None

mirar.io.tag_mef_extension_file_headers(primary_header: Header, extension_headers: list[Header], extension_key: str | None = None) list[Header][source]

Function to tag the extension headers in a MEF frame

Parameters:
  • primary_header – Primary header

  • extension_headers – Extension headers

  • extension_key – Key to use for tagging the extension headers

Returns:

List of tagged extension headers

mirar.paths module

Central module hosting all shared paths/directory conventions/keys/variables

mirar.paths.copy_temp_file(output_dir: Path, file_path: Path) Path[source]

Copies a file at file_path to a temporary path in output dir, then returns temp path

Parameters:
  • output_dir – output directory

  • file_path – file to cope

Returns:

path of temporary file

mirar.paths.get_astrometry_keys() list[source]

Function to get a list of common astrometric keywords that could be present in a fits header Returns:

mirar.paths.get_mask_path(img_path: str | Path) Path[source]

Returns a mask image path

Parameters:

img_path – parent image

Returns:

custom path for weight image

mirar.paths.get_output_dir(dir_root: str, sub_dir: str | int = '', output_dir: Path = PosixPath('/home/docs')) Path[source]

Generic function to get a full output directory combining dir_root, sub_dir and the parent output directory

Parameters:
  • dir_root – directory within subdir, e.g ‘raw’ or ‘processed’

  • sub_dir – subdirectory in parent directory, typically a night e.g 20221223

  • output_dir – parent output directory

Returns:

full output directory

mirar.paths.get_output_path(base_name: str, dir_root: str, sub_dir: str | int = '', output_dir: Path = PosixPath('/home/docs')) Path[source]

Generic function to get a full output path combining the file name, dir_root, sub_dir and the parent output directory

Parameters:
  • base_name – name of file

  • dir_root – directory within subdir, e.g ‘raw’ or ‘processed’

  • sub_dir – subdirectory in parent directory, typically a night e.g 20221223

  • output_dir – parent output directory

Returns:

full output directory

mirar.paths.get_temp_path(output_dir: Path, file_path: Path | str) Path[source]

Gets a temporary path, in output dir, with name of file_path

Parameters:
  • output_dir – Output directory

  • file_path – current path of file

Returns:

temporary path

mirar.paths.get_untemp_path(temp_path: Path | str) Path[source]

Converts a temporary path to a regular path.

Essentially undoes ..:func:mirar.path.get_temp_path

Parameters:

temp_path – temporary file path

Returns:

normal file path

mirar.paths.get_weight_path(img_path: str | Path) Path[source]

Returns a weight image path

Parameters:

img_path – parent image

Returns:

custom path for weight image

mirar.paths.raw_img_dir(sub_dir: str = '', raw_dir: Path = PosixPath('/home/docs'), img_sub_dir: str = 'raw') Path[source]

Get directory for raw images

Parameters:
  • sub_dir – sub-dir (night)

  • raw_dir – Root raw directory for data

  • img_sub_dir – Default ‘raw’

Returns:

Full path of raw images

mirar.testing module

Base class for unit testing, with common cleanup method

class mirar.testing.BaseTestCase(*arg, **kwargs)[source]

Bases: TestCase

Base TestCase object with additional cleanup