als package

Submodules

als.code_utilities module

Provides a set of utilities aimed at app developpers

exception als.code_utilities.AlsException(message, details)[source]

Bases: Exception

Base class for all custom errors

class als.code_utilities.SignalingQueue(maxsize=0)[source]

Bases: queue.Queue, PyQt5.QtCore.QObject

Queue subclass that emits a Qt signal when items are added or removed from the queue.

Signal is :

  • size_changed_signal

and carries the new queue size

get(block=True, timeout=None)[source]

Remove and return an item from the queue.

If optional args ‘block’ is true and ‘timeout’ is None (the default), block if necessary until an item is available. If ‘timeout’ is a non-negative number, it blocks at most ‘timeout’ seconds and raises the Empty exception if no item was available within that time. Otherwise (‘block’ is false), return an item if one is immediately available, else raise the Empty exception (‘timeout’ is ignored in that case).

get_nowait()[source]

Remove and return an item from the queue without blocking.

Only get an item if one is immediately available. Otherwise raise the Empty exception.

put(item, block=True, timeout=None)[source]

Put an item into the queue.

If optional args ‘block’ is true and ‘timeout’ is None (the default), block if necessary until a free slot is available. If ‘timeout’ is a non-negative number, it blocks at most ‘timeout’ seconds and raises the Full exception if no free slot was available within that time. Otherwise (‘block’ is false), put an item on the queue if a free slot is immediately available, else raise the Full exception (‘timeout’ is ignored in that case).

put_nowait(item)[source]

Put an item into the queue without blocking.

Only enqueue the item if a free slot is immediately available. Otherwise raise the Full exception.

size_changed_signal

Qt signal stating that a new item has just been pushed to the queue.

Param

the new size of the queue

Type

int

class als.code_utilities.Timer[source]

Bases: object

A context manager, timing any portion of code it encloses.

Basic usage :

with Timer() as t:

    # your code here
    # it can be many lines
    pass

_LOGGER.info(f"code ran in {t.elapsed_in_milli} ms.")

The context manager exposes 2 attributes :

  • elapsed_in_milli (float) = elapsed time

  • elapsed_in_milli_as_str (str) = string representation of elapsed time with only 3 decimal positions

als.code_utilities.log(func)[source]

Decorates a function to add logging.

A log entry (DEBUG level) is printed with decorated function’s qualified name and all its params.

If the decorated function returns anything, a log entry (DEBUG level) is printed with decorated function’s qualified name and return value(s).

Logs are issued using is the logger named after the decorated function’s enclosing module.

Parameters

func – The function to decorate

Returns

The decorated function

als.config module

Provides application defaults and high level access to user settings

exception als.config.CouldNotSaveConfig(message, details)[source]

Bases: als.code_utilities.AlsException

Raised when config could not be saved

class als.config.SignalLogHandler[source]

Bases: logging.Handler, PyQt5.QtCore.QObject

Logging handler responsible of sending log messages as a QT signal.

Any object can register, as soon as it has a on_log_message(str) function

add_receiver(receiver)[source]

Connects this handler’s message signal to a receiver

Parameters

receiver (any. It must have a on_log_message(str) function.) – the receiver

emit(record)[source]

Do whatever it takes to actually log the specified logging record.

This version is intended to be implemented by subclasses and so raises a NotImplementedError.

message_signal
als.config.get_full_screen_active()[source]

Get full screen indicator

Returns

True if app should be launched in fullscreen mode, False otherwise

Return type

bool

als.config.get_image_save_format()[source]

Retrieves the configured image save format.

Returns

format code. Can be any value from :

  • IMAGE_SAVE_TIFF

  • IMAGE_SAVE_PNG

  • IMAGE_SAVE_JPEG

Return type

str

als.config.get_scan_folder_path()[source]

Retrieves scan folder path.

Returns

the scan folder path

Return type

str

als.config.get_window_geometry()[source]

Retrieves main window geometry.

Returns

a tuple of 4 integers describing :

  • x coordinate of top left corner

  • y coordinate of top left corner

  • width of the window

  • height of the window

als.config.get_work_folder_path()[source]

Retrieves work folder path.

Returns

the work folder path

Return type

str

als.config.get_www_server_port_number()[source]

Retrieves the configured web server port number.

Returns

The configured port number, or its default value if config entry is not parsable as an int.

als.config.get_www_server_refresh_period()[source]

Retrieves the configured web server page refresh period.

Returns

The web server page refresh period, or its default value if config entry is not parsable as an int.

als.config.is_debug_log_on()[source]

Checks if loglevel is DEBUG

Returns

True if loglevel is DEBUG, False otherwise

als.config.register_log_receiver(receiver)[source]

Registers any object as a log message receiver.

Parameters

receiver (any. It must have a on_log_message(str) function.) – the receiver

als.config.save()[source]

Saves settings to disk.

Raises

os_error – Saving could not be done

als.config.set_debug_log(debug_active)[source]

Sets logldevel to debug if debug_active is True, otherwise set loglevel to info

Parameters

debug_active (bool) – set loglevel to debug

als.config.set_full_screen_active(full: bool)[source]

Set full screen indicator

Parameters

full (bool) – should app be launched in fullscreen mode ?

als.config.set_image_save_format(save_format)[source]

Sets image save format.

Parameters

save_format (str) –

format code. Can be any value from :

  • IMAGE_SAVE_TIFF

  • IMAGE_SAVE_PNG

  • IMAGE_SAVE_JPEG

als.config.set_scan_folder_path(path)[source]

Sets the scan folder path.

Parameters

path (str) – the scan folder path

als.config.set_window_geometry(geometry_tuple)[source]

Sets main window geometry.

Parameters

geometry_tuple (tuple) –

The geometry_tuple tuple must contain 4 integers describing :

  • x coordinate of top left corner

  • y coordinate of top left corner

  • width of the window

  • height of the window

als.config.set_work_folder_path(path)[source]

Sets the work folder path.

Parameters

path (str) – the work folder path

als.config.set_www_server_port_number(port_number)[source]

Sets server port number.

Parameters

port_number (int) – the port number

als.config.set_www_server_refresh_period(period)[source]

Sets web server page refresh period.

Parameters

period (int) – the period

als.config.setup()[source]

Sets config and log systems up.

als.crunching module

A set of shared utilities for number crunching

als.crunching.compute_histograms_for_display(image, bin_count)[source]

Compute histograms

als.legacy_code_stash module

Provides image preprocessing features

als.legacy_code_stash.get_limit_and_utype(image)[source]

Test Image types (uint8 or uint16)

Parameters

image – image, numpy array

Returns

limit and type of image

als.legacy_code_stash.post_process_image(stack_image, mode='rgb', scnr_on=False, wavelets_on=False, wavelets_type='deep sky', wavelets_use_luminance=False, param=[])[source]

Fonction for create print image and post process this image

Parameters
  • stack_image – np.array(uintX), Image, 3xMxN or MxN

  • log_ui – QT log for print text in QT GUI

  • mode – image mode (“rgb” or “gray”)

  • scnr_on – bool, activate scnr correction

  • wavelets_on – bool, activate wavelet filtering

  • param – post process param

Returns

no return

als.legacy_code_stash.scnr(rgb_image, im_limit, rgb_type='RGB', scnr_type='ne_m', amount=0.5)[source]

Function for reduce green noise on image SCNR Average Neutral Protection

Parameters
  • rgb_image – Numpy array (float32), size 3xMxN

  • im_type – string, uint16 or uint8

  • im_limit – int, value limit, 255 or 65535

  • rgb_type – RGB or BGR

  • scnr_type – string, correction type : ne_m, ne_max, ma_ad or ma_max

  • amount – float, 0 to 1, param for ma_ad and ma_max

Returns

image corrected (np.array(float32))

als.legacy_code_stash.wavelets(image, wavelets_type, wavelets_use_luminance, parameters)[source]

Module allowing to play with coefficients of a redudant frame from the wavelet family. A ratio is applied to each level :param image: input image :param wavelets_type: either ‘deep sky’ or ‘planetary’ gives the family of wavelets to be used for processing :param parameters: ratio to be applied for each level of the wavelet decomposition :return: denoised/enhanced image

als.logic module

Module holding all application logic

class als.logic.Controller[source]

Bases: object

The application controller, in charge of implementing application logic

add_model_observer(observer)[source]

Adds an observer to our observers list.

Parameters

observer (any) – the new observer

apply_processing()[source]

Apply processing on last stacking result

get_align_before_stack() → bool[source]

Gets “align before stack” switch

Returns

Do we align before stacking ?

Return type

bool

get_autostretch_parameters() → List[als.model.params.ProcessingParameter][source]

Retrieves autostretch parameters

Returns

autostretch parameters

get_levels_parameters() → List[als.model.params.ProcessingParameter][source]

Retrieves Levels processor parameters

Returns

Levels processor parameters

get_rgb_parameters() → List[als.model.params.ProcessingParameter][source]

Retrieves rgb parameters

Returns

rgb parameters

get_save_every_image() → bool[source]

Retrieves the flag that tells if we need to save every process result image

Returns

the flag that tells if we need to save every process result image

Return type

bool

get_stacking_mode()[source]

Gets current stacking mode

Returns

the stacking mode

Return type

str

static get_timestamp()[source]

Return a timestamp build from current date and time

Returns

the timestamp

Return type

str

on_new_image_read(image: als.model.base.Image)[source]

A new image as been read by input scanner

Parameters

image (Image) – the new image

on_new_post_processor_result(image: als.model.base.Image)[source]

A new image processing result is here

Parameters

image (Image) – the new processing result

on_new_pre_processed_image(image: als.model.base.Image)[source]

A new image as been pre-processed

Parameters

image (Image) – the image

on_new_stack_result(image: als.model.base.Image)[source]

A new image has been stacked

Parameters

image (Image) – the result of the stack

on_post_processor_busy()[source]

post-processor just started working on new image

on_post_processor_queue_size_changed(new_size)[source]

Qt slot executed when an item has just been pushed to the process queue

Parameters

new_size (int) – new queue size

on_post_processor_waiting()[source]

post-processor just finished working on new image

on_pre_process_queue_size_changed(new_size)[source]

Qt slot executed when an item has just been pushed to the pre-processor queue

Parameters

new_size (int) – new queue size

on_pre_processor_busy()[source]

pre-processor just started working on new image

on_pre_processor_waiting()[source]

pre-processor just finished working on new image

on_saver_busy()[source]

saver just started working on new image

on_saver_queue_size_changed(new_size)[source]

Qt slot executed when an item has just been pushed to the save queue

Parameters

new_size (int) – new queue size

on_saver_waiting()[source]

saver just finished working on new image

on_stack_size_changed(size)[source]

Stack size just changed

Parameters

size (int) – the stack size

on_stacker_busy()[source]

stacker just started working on new image

on_stacker_queue_size_changed(new_size)[source]

Qt slot executed when an item has just been pushed to the stacker queue

Parameters

new_size (int) – new queue size

on_stacker_waiting()[source]

stacker just finished working on new image

pause_session()[source]

Pauses session : just stop input scanner

static purge_queue(queue: als.code_utilities.SignalingQueue)[source]

Purge a queue

Parameters

queue (SignalingQueue) – the queue to purge

remove_model_observer(observer)[source]

Removes observer from our observers list.

Parameters

observer (any) – the observer to remove

save_image(image: als.model.base.Image, file_extension: str, dest_folder_path: str, filename_base: str, add_timestamp: bool = False)[source]

Save an image to disk.

Parameters
  • image (Image) – the image to save

  • file_extension (str) – The image save file format extension

  • dest_folder_path (str) – The path of the folder image will be saved to

  • filename_base (str) – The name of the file to save to (without extension)

  • add_timestamp (bool) – Do we add a timestamp to image name

save_post_process_result()[source]

Saves stacking result image to disk

set_align_before_stack(align: bool)[source]

Sets “align before stack” switch

Parameters

align (bool) – Do we align before stacking ?

set_save_every_image(save_every_image: bool)[source]

Sets the flag that tells if we need to save every process result image

Parameters

save_every_image (bool) – flag that tells if we need to save every process result image

set_stacking_mode(mode)[source]

Sets current stacking mode

Parameters

mode (str) – stacking mode

shutdown()[source]

Proper shutdown of all app components

start_session()[source]

Starts session

start_www()[source]

Starts web server

stop_session()[source]

Stops session : stop input scanner and purge input queue

stop_www()[source]

Stops web server

exception als.logic.CriticalFolderMissing(message, details)[source]

Bases: als.logic.SessionError

Raised when a critical folder is missing

exception als.logic.SessionError(message, details)[source]

Bases: als.code_utilities.AlsException

Class for all errors related to session management

exception als.logic.WebServerStartFailure(message, details)[source]

Bases: als.code_utilities.AlsException

Raised when web server fails

als.main module

Main module, basically in charge of application init / start

als.main.main()[source]

Application launcher

als.processing module

Provides all means of image processing

class als.processing.AutoStretch[source]

Bases: als.processing.ImageProcessor

Implements auto stretch feature

process_image(image: als.model.base.Image)[source]

Perform image processing specific to this class

Parameters

image (Image) – the image to process

Raises

ProcessingError - an error occurred while processing image

Returns

the processed image

Return type

Image

class als.processing.ColorBalance[source]

Bases: als.processing.ImageProcessor

Implements color balance processing

process_image(image: als.model.base.Image)[source]

Performs RGB balance

Parameters

image (Image) – the image to process

class als.processing.ConvertForOutput[source]

Bases: als.processing.ImageProcessor

Moves colors data to 3rd array axis for color images and reduce data range to unsigned 16 bits

process_image(image: als.model.base.Image)[source]

Perform image processing specific to this class

Parameters

image (Image) – the image to process

Raises

ProcessingError - an error occurred while processing image

Returns

the processed image

Return type

Image

class als.processing.Debayer[source]

Bases: als.processing.ImageProcessor

Provides image debayering.

process_image(image: als.model.base.Image)[source]

Perform image processing specific to this class

Parameters

image (Image) – the image to process

Raises

ProcessingError - an error occurred while processing image

Returns

the processed image

Return type

Image

class als.processing.ImageProcessor[source]

Bases: object

Base abstract class for all image processors, regardless of what pipeline they are used in

Subclasses must implement a single method : process_image(image: Image)

get_parameters() → List[als.model.params.ProcessingParameter][source]

Gets processes parameters

Returns

the parameters

Return type

List[ProcessingParameter]

abstract process_image(image: als.model.base.Image)[source]

Perform image processing specific to this class

Parameters

image (Image) – the image to process

Raises

ProcessingError - an error occurred while processing image

Returns

the processed image

Return type

Image

class als.processing.Levels[source]

Bases: als.processing.ImageProcessor

Implements levels processing

process_image(image: als.model.base.Image)[source]

Perform image processing specific to this class

Parameters

image (Image) – the image to process

Raises

ProcessingError - an error occurred while processing image

Returns

the processed image

Return type

Image

class als.processing.Pipeline(name: str, queue: als.code_utilities.SignalingQueue, final_processes: list)[source]

Bases: als.processing.QueueConsumer

QueueConsumer specialization allowing to apply a list of image processors to each image

add_process(process: als.processing.ImageProcessor)[source]

Add an image processor to the list of processes to run on images

Parameters

process (ImageProcessor) – the processor to add

exception als.processing.ProcessingError[source]

Bases: Exception

Must be raised in case of processing error.

class als.processing.QueueConsumer(name: str, queue: als.code_utilities.SignalingQueue)[source]

Bases: PyQt5.QtCore.QThread

Abstract class for all our queue consumers.

Responsible of grabbing images from a queue

actual processing payload is to be implemented in the following abstract method : _handle_image().

busy_signal

Qt signal to emit when an image has been retrieved and we are about to process it

new_result_signal

Qt signal to emit when a new image has been processed

run()[source]

Starts polling the queue and perform processing units to each image

If any processing error occurs, the current image is dropped

stop()[source]

Sets flag that will interrupt the main loop in run()

waiting_signal

Qt signal to emit when image processing is complete

class als.processing.Standardize[source]

Bases: als.processing.ImageProcessor

Make image data structure conform to all processing needs.

Here are the aspects we enforce :

  1. data array of color (debayered) images have color as the first axis. So a typical shape for a color image would be : (3, y, x).

  2. each array element is of type float32

process_image(image: als.model.base.Image)[source]

Perform image processing specific to this class

Parameters

image (Image) – the image to process

Raises

ProcessingError - an error occurred while processing image

Returns

the processed image

Return type

Image

als.stack module

Provides image stacking features

class als.stack.Stacker(stack_queue)[source]

Bases: als.processing.QueueConsumer

Responsible of image stacking : alignment and registration

property align_before_stack

Gets “align before stack” switch

Returns

Do we align before stacking ?

Return type

bool

reset()[source]

Reset stacker to its starting state : No reference, no result and counter = 0.

property size

Retrieves the number of stacked images since last reset

Returns

how many images did we stack

Return type

int

stack_size_changed_signal

Qt signal emitted when stack size changed

property stacking_mode

Gets current stacking mode

Returns

the stacking mode

Return type

str

exception als.stack.StackingError[source]

Bases: Exception

Base class for stacking errors

Module contents

The main ALS package