ctdclient.model.near_real_time_publication module

ctdclient.model.near_real_time_publication.instantiate_near_real_time_target(*args, frequency_of_action='23:59:00', **kwargs)[source]

Differentiate the two NRT modes and instantiates respecive classes.

Parameters:
  • *args – Are given to NRT classes

  • frequency_of_action (str) – The information to distinguish the two NRT modes

  • **kwargs – Are given to NRT classes

Return type:

NearRealTimeTarget

class ctdclient.model.near_real_time_publication.NRTList(*args, **kwargs)[source]

Bases: UserList

A collection of NearRealTimeTargets.

update_nrt_data(clear_data=True)[source]

Fills collection with NRT instances.

Parameters:

clear_data (bool) – Whether to reset previous data when updating

create_nrt_instance(path)[source]

Get new instance of NearRealTimeTarget.

Parameters:

path (Path) – File path to toml config file

Return type:

NearRealTimeTarget instance.

get_template(template_path=PosixPath('/home/runner/work/CTD-Client/CTD-Client/src/ctdclient/resources/templates/nrt_template.toml'))[source]

Create template NearRealTimeTarget instance.

Parameters:

template_path (Path) – File path to template file config

Return type:

NearRealTimeTarget instance.

toggle_activity(nrt)[source]

Toggle whether a particluar NearRealTimeTarget is active or not.

Parameters:

nrt (NearRealTimeTarget) – The target instance to toggle

kill_processes()[source]

Kills a running NearRealTimeTarget action.

delete_nrt(nrt)[source]

Removes a NearRealTimeTarget from the collection.

Parameters:

nrt (NearRealTimeTarget) – The instance to remove

class ctdclient.model.near_real_time_publication.NearRealTimeTarget(recipient_address, target_file_suffix, target_file_directory='', geo_filter='', email_info={}, file_path='', active=False, **kwargs)[source]

Bases: object

Stores information for near-real-time distribution of latest CTD data files. Can work in two modes: email or rsync/copy. Will distinguish between these by checking ‘recipient_adress’ for an ‘@’.

Parameters:
  • recipient_address (str) – Target of the action, email address or file path

  • target_file_suffix (str) – File suffix to select target files with

  • target_file_directory (Path | str) – The directory to look for target files

  • geo_filter (str) – A geographic location to filter target files with

  • email_info (dict) – Collection of email information

  • file_path (Path | str) – File path to config file

  • active (bool) – Whether the NRT job is active

abstractmethod toggle_activity()[source]

Toggles the NRT activity.

abstractmethod run()[source]

Will move the recent files to the target location.

create_email_message(target_files, to_address='', from_address='', subject='', body='')[source]

Creates an email with target files attached.

Parameters:
  • target_files (list[Path]) – Target files to attach

  • to_address (str) – Email address to send to

  • from_address (str) – Email address to send from

  • subject (str) – Email subject line

  • body (str) – Email text

Return type:

Assembled email message.

create_email_draft(msg, file_path='')[source]

Creates an email .eml draft file, that can be opened by common email programs.

Parameters:
  • msg (EmailMessage) – Assembled email message ready for sending

  • file_path (Path | str) – File path to save .eml draft file to

Return type:

Path

open_draft_msg(file_path)[source]

Open an .eml file using the default email program.

Parameters:

file_path (Path | str) – File path to .eml file

run_email_logic(files_to_attach, run_manually=False)[source]

Master method to coordinate email assembly and sending.

Parameters:
  • files_to_attach (list) – List of target files to attach to email

  • run_manually (bool) – Whether to automatically send email or open draft message for editing

send_email(msg)[source]

Sends the email message using the given smtp server configuration.

Parameters:

msg (EmailMessage) – Assembled email message to send

copy_files(target_file)[source]

Copies target files to given location.

Parameters:

target_file (Path) – The target file to copy

get_target_files(target_file=PosixPath('.'))[source]

Creates a list of paths to files that are meant to be published.

Parameters:

target_file (Path) – File path to target file

Return type:

list[Path]

deg_min_to_deg_decimal(value)[source]

Converts coordinates from deg minutes to decimal degrees.

Parameters:

value (str) – Coordinate information

Return type:

float

geographic_filter(coordinate_pair)[source]

Checks, whether we are inside of a certain polygon.

The polygon will usually be the EEZ of a certain country. Does support all data formats that geopandas can handle.

Parameters:

coordinate_pair (tuple) – Coordinates of the target file

Return type:

bool

point_in_polygon(point, polygon)[source]

Check if a point is inside a polygon using the Ray Casting Algorithm.

Parameters:
  • point – Tuple (x, y) representing the point to check.

  • polygon – List of tuples [(x1, y1), (x2, y2), …] representing the polygon vertices.

Return type:

True if the point is inside the polygon, False otherwise.

time_filter(file)[source]

Ensure, that file has been modified in the last 24 hours.

Parameters:

file (Path) – Target file to check

Return type:

bool

class ctdclient.model.near_real_time_publication.DailyPublication(*args, time_to_run_at='23:59:30', single_run=False, **kwargs)[source]

Bases: NearRealTimeTarget

Automatic publication once a day.

Parameters:
  • time_to_run_at (str) – The time point to publish

  • single_run (bool) – Whether to run once or infinitely

action()[source]

Multiprocessing target method that run publication logic.

start()[source]

Activates multiprocessing process to repeatedly publish.

stop()[source]

Stops multiprocessing process.

toggle_activity()[source]

Sets activity on or off.

ctdclient.model.near_real_time_publication.timer(time_to_run_at, function, single_run)[source]

Timer to next publication moment.

Parameters:
  • time_to_run_at (datetime) – Next target time

  • function (Callable) – Action to perform on publication time

  • single_run (bool) – Whether to run only once

class ctdclient.model.near_real_time_publication.EachProcessingPublication(*args, **kwargs)[source]

Bases: NearRealTimeTarget

Automatic publication every processing.

toggle_activity()[source]

Sets activity on or off.

run(target=PosixPath('.'))[source]

The action to perform after processing.

Parameters:

target (Path) – The file path to retrieve target files from

stop()[source]

Stops automatic publication.