Module azcam.functions.utils

azcam.utils contains general purpose support commands used throughout azcam.

Functions

def add_searchfolder(search_folder: str = '', include_subfolders: bool = True) ‑> None

Appends search_folder (and by default all its subfolders) to the current python search path. Default is current folder and its subfolders. Subfolders beginning with "_" are not included.

Args

search_folder
Name of folder to add to sys.path
include_subfolders
True to include all subfolders in sys.path
def beep(frequency=2000, duration=500) ‑> None

Play a sound. Install beep on Linux systems.

def check_keyboard(wait: bool = False) ‑> str

Checks keyboard for a key press. For Windows OS only.

Args

wait
True to wait until a key is pressed

Returns

key which was pressed or empty string.

def curdir(folder: str = '') ‑> str

Gets and sets the working folder. If folder is not specified then just return the current working folder.

Args

folder
name of folder set.

Returns

the current folder (after changing).

def execute_command(tool: Callable, args: list, kwargs: dict = {}) ‑> str

Executes a tool command which has been parsed into tool method and arguments and returns its reply string.

Args

tool
tool object (not name)
args
list of arguments
kwargs
dictionary of keyword:value pairs for arguments

Returns

reply
reply from command executed. Always starts with OK or ERROR.
def file_browser(Path: str = '', SelectString: str = '*.*', Label: str = '') ‑> list

Filebrowser GUI to select files. This is the tcl/tk version.

Args

Path
Starting path for selection.
SelectString
Selection string like [('all files',('.'))] for filtering file names or folder to select folders.
Label
Dialog box label.

Returns

list of selected files/folders or None

def find_file(filename, include_curdir=False) ‑> str

Find the absolute filename for a file in the current search path. Set include_curdir True to add curdir() to search path.

Args

filename
Name of file.
include_curdir
True to include current folder in sys.path.

Returns

Cleaned path name

Raises

FileNotFoundError if file not found.

def find_file_in_sequence(file_root: str, file_number: int = 1) ‑> tuple

Returns the Nth file in an image sequence where N is file_number (-1 for first file).

Args

file_root
image file root name.
file_number
image file number in sequence.

Returns

tuple (filename,sequencenumber).

def fix_path(path: str = '', no_drive_letter: bool = True) ‑> str

Makes a nice absolute path, leaving only forward slashes.

Args

path
name of path to cleanup.

bool no_drive_letter: Removes leading drive letter.

Returns

cleaned path name.

def get_datatype(value) ‑> list

Determine the data type for an object and set the type if possible. A string such as "1.23" will result in a type "float" and "2" will result in type "int".

Args

value
object to be typed

Returns

list [type, value] of data type as a code and object with that type

def get_image_roi() ‑> list

Get the data and noise regions of interest in image image coordinates. Check for ROI's in the following order: - azcam.db.imageroi if defined - display.roi if defined

Returns

list of ROIs

def get_tools(tool_names: list) ‑> list

Return a list of tool objects from a list of their names.

Args

tool_names
list of the tool names to get

Returns

list of tool objects

def make_file_folder(subfolder: str, increment: bool = True, use_number: bool = False) ‑> tuple

Creates a new subfolder in the current FileFolder.

Args

subfolder
subfolder name to create
increment
  • if True, subfolder name may be incremented to create a unique name (e.g. ptc1, ptc2, ptc3…)
use_number
  • if True, starts with '1' after Subfolder name (e.g. report1 not report)

Returns

tuple (currentfolder,newfolder)

def make_image_filename(imagefile: str) ‑> str

Returns the absolute file imagefile, with forward slashes. Appends ".fits" if no extension is included.

Args

imagefile
image filename to be expanded

Returns

expanded image filename.

def parse(string: str, set_type=0) ‑> List[str]

Parse a string into tokens using the standard azcam rules. If setType is true, try and set data data type for each token.

Args

string
String to be parsed into tokens
set_type
True to try and set the type of each token ("1" to 1)

Returns

list of parsed tokens

def parse_command_string(command: str, case_insensitive: int = 0)

Parse a command string into tool and arguments. If command does not start with a dotted object.method token, then assume it is the method of the default_tool.

Returns (objid, args, kwargs) objid is a bound method of a class args is a list of strings kwargs is a dict of strings

def prompt(prompt_message: str = 'Enter a string', default: str = '') ‑> str

Prints a message and waits for user input.

Args

prompt_message
string to be printed
default
string to be returned if no value is entered

Returns

string entered or default value

def restore_imagepars(imagepars: dict, folder: str = '') ‑> None

Restore image parameters from dictionary.

Args

imagepars
dictionary set with save_imagepars().
folder
folder to set as current
def save_imagepars(imagepars={}) ‑> None

Save current image parameters. imagepars is a dictionary.

Args

imagepars
dict of azcam.db.imageparnames names to save
def set_image_roi(roi: list = []) ‑> None

Set the global image region of interest "db.imageroi". If roi is not specified, use display ROI.

Args

roi
ROI list or []
def show_menu(configs: dict) ‑> str

Interative: Show a menu and wait for selection. "blank" may be used to display an empty line. print() is allowed here as this is for interactive use only.

Args

configs
Dictionary of strings which are menu items

Returns

string associated with item selected or empty string.