shapepipe.utilities.cfis

shapepipe.utilities.cfis

CFIS TOOLS.

CFIS module.

Authors

Martin Kilbinger

class param(**kwds)[source]

Bases: object

Param Class.

General class to store (default) variables.

print(**kwds)[source]

Print.

var_list(**kwds)[source]

Get Variable List.

exception CfisError[source]

Bases: Exception

Cfis Error.

Generic error that is raised by this script.

class image(name, ra, dec, exp_time=- 1, valid='Unknown')[source]

Bases: object

Image Class.

Class to store and create image information.

Parameters
  • name (str) – file name

  • ra (Angle) – right ascension

  • dec (Angle) – declination

  • exp_time (int, optional, default=-1) – exposure time

  • valid (str, optional, default='Unknown') – validation flag

cut(no_cuts=False)[source]

Cut.

Return True (False) if image does (not) need to be cut from selection.

Parameters

no_cuts (bool, optiona, default=False) – do not cut if True

Returns

True (False) if image is (not) cut

Return type

bool

get_ID()[source]

Get ID.

Return image ID.

Returns

image iD

Return type

str

Raises

ValueError – if name does not match to ID pattern

print(file=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, base_name=False, name_only=True, ID_only=False)[source]

Print.

Print image information as ascii Table column.

Parameters
  • file (file, optional, default=sys.stdout) – output file handle

  • base_name (bool, optional, default=False) – if True (False), print image base name (full path)

  • name_only (bool, optional, default=False) – if True, do not print metainfo

  • ID_only (bool, optional, default=False) – if True, only print file ID instead of entire name

Raises

ValueError – if name does not match to ID pattern

print_header(file=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)[source]

Print Header.

Print header for ascii Table output

Parameters

file (file, optional, default=sys.stdout) – output file handle

log_command(argv, name=None, close_no_return=True)[source]

Log Command.

Write command with arguments to a file or stdout. Choose name = ‘sys.stdout’ or ‘sys.stderr’ for output on sceen.

Parameters
  • argv (numpy.ndarray of str) – Command line arguments

  • name (str) – Output file name (default: ‘log_<command>’)

  • close_no_return (bool) – If True (default), close log file. If False, keep log file open and return file handler

Returns

log file handler (if close_no_return is False)

Return type

filehandler

my_string_split(string, num=- 1, verbose=False, stop=False, sep=None)[source]

My String Split.

Split a string into a list of strings. Choose as separator the first in the list [space, underscore] that occurs in the string. (Thus, if both occur, use space.)

Parameters
  • string (str) – Input string

  • num (int) – Required length of output list of strings, -1 if no requirement.

  • verbose (bool) – Verbose output

  • stop (bool) – Stop programs with error if True, return None and continues otherwise

  • sep (bool) – Separator, try ‘ ‘, ‘_’, and ‘.’ if None (default)

Raises
  • CfisError – If number of elements in string and num are different, for stop=True

  • ValueError – If no separator found in string

Returns

List of string on success, and None if failed

Return type

list

get_file_pattern(pattern, band, image_type, want_re=True, ext=True)[source]

Get File Pattern.

Return file pattern of CFIS image file.

Parameters
  • pattern (str) – input pattern, can be ‘’

  • band (str) – band, one of ‘r’, ‘u’

  • image_type (str) – image type, one of ‘exposure’, ‘exposure_flag’, ‘exposure_flag.fz’, ‘exposure_weight’, ‘exposure_weight.fz’, ‘tile’, ‘cat’, ‘weight’, ‘weight.fz’

  • want_re (bool, optional, default=True) – return regular expression if True

  • ext (bool, optional, default=True) – if True add file extention to pattern

Returns

output pattern

Return type

str

get_tile_number_from_coord(ra, dec, return_type=<class 'str'>)[source]

Get Tile Number From Coord.

Return CFIS stacked image tile number covering input coordinates. This is the inverse to get_tile_coord_from_nixy.

Parameters
  • ra (Angle) – right ascension

  • dec (Angle) – declination

  • type (return) – return type, int or str

Raises

CfisError – for invalid return type

Returns

tile number for x and tile number for y

Return type

tuple

get_tile_coord_from_nixy(nix, niy)[source]

Get Tile Coord From Nixy.

Return coordinates corresponding to tile with number (nix,niy). This is the inverse to get_tile_number_from_coord.

Parameters
  • nix (str or int) – tile number for x, can be list

  • niy (str or int) – tile number for y, can be list

Returns

right ascension and declination

Return type

tuple

get_tile_name(nix, niy, band, image_type='tile', input_format='full')[source]

Get Tile Name.

Return tile name for given tile numbers.

Parameters
  • nix (str) – tile number for x

  • niy (str) – tile number for y

  • band (str) – band, one in ‘r’ or ‘u’

  • image_type (str optional, default='tile') – image type

  • input_format (str optional, default='full') – ‘full’ (name) or ‘ID_only’ input format for image names

Raises

CfisError – for invalid type

Returns

tile name

Return type

str

get_tile_number(tile_name)[source]

Get Tile Number.

Return tile number of given image tile name.

Parameters

tile_name (str) – tile name

Raises

CfisError – if tile name does not match expected pipeline numbering scheme

Returns

tile number for x and tile number for y

Return type

tuple

get_tile_number_list(tile_name_list)[source]

Get Tile Number List.

Return tile numbers of given image tiles.

Parameters

tile_name_list (list of str) – tile names

Returns

tile numbers for x and tile numbers for y

Return type

tuple

get_log_file(path, verbose=False)[source]

Get Log File.

Return log file content.

Parameters
  • path (str) – log file path

  • verbose (bool, optional, default=False) – verbose output if True

Raises

CfisError – if input path does not exist

Returns

log file lines

Return type

list of str

check_ra(ra)[source]

Check RA.

Range check of right ascension.

Parameters

ra (Angle) – right ascension

Raises

CfisError – for invalid ra range on input

Returns

result of check (True if pass, False if fail)

Return type

bool

check_dec(dec)[source]

Check Dec.

Range check of declination.

Parameters

dec (Angle) – declination

Raises

CfisError – for invalid dec range on input

Returns

result of check (True if pass, False if fail)

Return type

bool

get_Angle(str_coord)[source]

Get Angle.

Return Angles ra, dec from coordinate string

Parameters

str_coord (string) – string of input coordinates

Returns

right ascension and declination

Return type

tuple

get_Angle_arr(str_coord, num=- 1, wrap=True, verbose=False)[source]

Get Angle Arr.

Return array of Angles from coordinate string

Parameters
  • str_coord (str) – string of input coordinates

  • num (int, optional, default=-1) – expected number of coordinates (even number)

  • wrap (bool, optional, default=True) – if True, wrap ra to [0; 360)

  • verbose (bool, optional, default=False) – verbose output

Returns

array of sky coordinates (pairs ra, dec)

Return type

numpy.ndarray of SkyCoord

read_list(fname, col=None)[source]

Read List.

Read list from ascii file.

Parameters
  • fname (str) – ascii file name

  • col (str, optional, default=None) – column name

Returns

list of file names

Return type

list of str

create_image_list(fname, ra, dec, exp_time=[], valid=[])[source]

Create Image List.

Return list of image information.

Parameters
  • fname (list of str) – file names

  • ra (list of str) – right ascension

  • dec (list of str) – declination

  • exp_time (list of int, optional, default=[]) – exposure time

  • valid (list of str, optional, default=[]) – QSO exposure validation flag

Returns

list of image information

Return type

list of images

get_image_list(inp, band, image_type, col=None, input_format='full', verbose=False)[source]

Get Image List.

Return list of images.

Parameters
  • inp (str) – file name or direcory path

  • band (str) – optical band

  • image_type (str) – image type (‘tile’, ‘exposure’, ‘cat’, ‘weight’, ‘weight.fz’)

  • col (str, optionalm default=None) – column name for file list input file

  • input_format (str, optional, default='full') – ‘full’ (name) or ‘ID_only’ input format for image names

  • verbose (bool, optional, default=False) – verbose output if True

Returns

image list

Return type

list of class images

exclude(f, exclude_list)[source]

Exclude.

Return True if f is on exclude_list.

Parameters
  • f (str) – file name

  • exclude_list (list of str) – list of files

Returns

True (False) if f is in list

Return type

bool

find_image_at_coord(images, coord, band, image_type, no_cuts=False, input_format='full', verbose=False)[source]

Find Image At Coordinates.

Return image covering given coordinate.

Parameters
  • images (list of class image) – list of images

  • coord (str) – coordinate ra and dec with units

  • band (str) – optical band

  • image_type (str) – image type (‘tile’, ‘weight’, ‘weight.fz’, ‘exposure’, ‘exposure_weight’, ‘exposure_weight.fz’, ‘exposure_flag’, ‘exposure_flag.fz’, ‘cat’)

  • no_cuts (bool, optional, default=False) – no cuts (of short exposure, validation flag) if True

  • input_format (str, optional, default='full') – one of ‘full’, ‘ID_only’

  • verbose (bool, optional) – verbose output if True, default=False

Raises

CfisError – if image type is not ‘tile’; if more than one tile matches if input image coordinates are already set

Returns

Found image(s), None if none found.

Return type

list of images

find_images_in_area(images, angles, band, image_type, no_cuts=False, verbose=False)[source]

Fine Images In Area.

Return image list within coordinate area (rectangle)

Parameters
  • images (list of class image) – list of images

  • angles (array(2) of SkyCoord) – coordinates [(ra0, dec0), (ra1, dec1)]

  • band (string) – optical band

  • image_type (str) – image type (‘tile’, ‘exposure’, ‘cat’, ‘weight’, ‘weight.fz’)

  • no_cuts (bool, optional, default=False) – no cuts (of short exposure, validation flag) if True

  • verbose (bool, optional, default=False) – verbose output if True

Returns

found images

Return type

list of images

plot_init()[source]

Plot Init.

Initialize a plot

plot_area(images, angles, image_type, outbase, interactive, col=None, show_numbers=False, show_circle=True, show_area_border=False, ax=None, lw=None, save=True, dxy=0)[source]

Plot Area.

Plot images within area.

Parameters
  • images (numpy.ndarray of image) – images

  • angles (numpy.ndarray (SkyCoord, 2)) – Corner coordinates of area rectangle

  • image_type (str) – image type (‘tile’, ‘exposure’, ‘cat’, weight’)

  • outbase (str) – output file name base

  • interactive (bool) – show plot if True

  • col (str, optional, default=None) – color

  • show_numbers (bool, optional, default=False) – show tile numbers if True

  • show_circle (bool, optional, default=True) – plot circle center and circumference around area if True

  • show_area_border (bool, optional, default=False) – plot rectangle around area

  • ax (axes, optional, default None) – Init axes if None

  • lw (float, optional, default None) – line width

  • save (bool, optional, default=True) – save plot to pdf file if True

  • dxy (float, optional, default=0) – shift

square_from_centre(x, y, dx, dy, dxy=0)[source]

Square From Centre.

Return coordinate vectors of corners that define a closed square for plotting.

Parameters
  • x (float) – x-coordinate centre

  • y (float) – y-coordinate centre

  • dx (float) – size in x

  • dy (float) – size in y

  • dxy (float, optional, default=0) – constant offset

Returns

square coordinates in x and y

Return type

tuple

square_from_corners(ang0, ang1)[source]

Square From Corners.

Return coordinate vectors of corners that define a closed square for plotting.

Parameters
  • ang0 (Angle) – lower-left square coordinates

  • ang1 (Angle) – upper-right square coordinates

Returns

square coordinates in x and y, in unit ‘unitdef’

Return type

tuple