polo.utils package

Submodules

polo.utils.dialog_utils module

polo.utils.dialog_utils.make_message_box(message, parent=None, icon=1, buttons=1024, connected_function=None)[source]

General helper function to create popup message box dialogs to convey situational information to the user.

Parameters
  • message (str) – The message to display to the user.

  • parent (QDialog, optional) – Parent dialog, defaults to None

  • icon (int, optional) – QMessageBox icon to display along with the message, defaults to QtWidgets.QMessageBox.Information

  • buttons (set, optional) – Buttons to include in the message box, defaults to QtWidgets.QMessageBox.Ok

  • connected_function (func, optional) – Function to connect to buttonClicked event, defaults to None

Returns

The message box.

Return type

QMessageBox

polo.utils.exceptions module

exception polo.utils.exceptions.EmptyDirectoryError[source]

Bases: Exception

Raised when attempting to load images from an empty directory

exception polo.utils.exceptions.EmptyRunNameError[source]

Bases: Exception

Raised when reading in an HWI directory but it does not contain number of images corresponding to number of wells.

exception polo.utils.exceptions.ForbiddenImageTypeError[source]

Bases: Exception

Raised when user attempts to load in an image that is not in the allowed image types.

exception polo.utils.exceptions.IncompletePlateError[source]

Bases: Exception

Raised when reading in an HWI directory but it does not contain number of images corresponding to number of wells.

exception polo.utils.exceptions.InvalidCocktailFile[source]

Bases: Exception

Raised when user attempts to load in a file containing well cocktail information that does not confrom to existing formating standards.

exception polo.utils.exceptions.NotASolutionError[source]

Bases: Exception

Raised when user attempts to load in an image that is not in the allowed image types.

exception polo.utils.exceptions.NotHWIDirectoryError[source]

Bases: Exception

Raised when user attempts to read in a directory as HWI but it does not look like one.

TODO: Add utils function to determine when to raise this exception.

polo.utils.ftp_utils module

polo.utils.ftp_utils.catch_ftp_errors(func)[source]

General decorator function for catching any errors thrown by other ftp_utils functions.

polo.utils.ftp_utils.logon(*args, **kwargs)[source]

polo.utils.io_utils module

class polo.utils.io_utils.BarTender(cocktail_dir, cocktail_meta)[source]

Bases: object

Class for organizing and accessing Menu data.

Parameters
  • cocktail_dir (str or Path) – Directory containing cocktail menu csv filepaths

  • cocktail_meta (Path or str) – Path to cocktail metadata file which describes the contents of each cocktail menu csv file

Cocktail metadata file should be a csv file with the following headers ordered from top to bottom. Each header name is followed by a description.

File Name: Name of cocktail menu file
Dates Used: Range of dates the cocktail menu was used (m/d/y-m/d/y)
Plate Number
Screen Type: 'm' for membrane screens, 's' for soluble screens
add_menus_from_metadata()[source]

Adds Menu objects to the polo.utils.io_utils.BarTender.menus attribute by reading the cocktail csv files included in the COCKTAIL_DATA_PATH directory.

static date_range_parser(date_range_string)[source]

Utility function for converting the date ranges in the cocktail metadata csv file to datetime objects using the datetime_converter() method.

Date ranges should have the format

'start date - end date'

If the date range is for the most recent cocktail menu then there
will not be an end date and the format will be

'start date - '
Parameters

date_range_string (str) – string to pull dates out of

Returns

tuple of datetime objects, start date and end date

Return type

tuple

static datetime_converter(date_string)[source]

General utility function for converting strings to datetime objects. Attempts to convert the string by trying a couple of datetime formats that are common in cocktail menu files and other locations in the HWI file universe Polo runs across.

Parameters

date_string (str) – string to convert to datetime

Returns

datetime object

Return type

datetime

get_menu_by_basename(basename)[source]

Uses the basename of a Menu file path to return a Menu object. Useful for retrieving menus based on the text of comboBoxes since when menus are displayed to the user only the basename is used.

Parameters

basename (str) – Basename of a Menu file path

Returns

Menu instance who’s basename matches the basename argument, returns None is no menu is found

Return type

Menu or None

get_menu_by_date(date, type_='s')[source]

Get a Menu instance who’s usage dates include the date passed through the date argument and matches the screen type passed through the type_ argument.

Screen types can either be ‘s’ for ‘soluble’ screens or ‘m’ for membrane screens.

Parameters
  • date (datetime) – Date to search menus with

  • type (str) – Type of screen to return (soluble or membrane)

Returns

menu matching the given date and type

Return type

Menu

get_menu_by_path(path)[source]

Returns a Menu instance by its file path, which is used as the key for accessing the menus attribute normally.

Parameters

path (str) – file path of a menu csv file

Returns

Menu instance that is mapped to given path

Return type

Menu

get_menus_by_type(type_='s')[source]

Returns all Menu instances of a given screen type.

‘s’ for soluble screens and ‘m’ for membrane screens. No other characters should be passed to type_.

Parameters

type (str (max length 1)) – Key for type of screen to return

Returns

list of menus of that screen type

Return type

list

class polo.utils.io_utils.CocktailMenuReader(menu_file_path, delim=',')[source]

Bases: object

CocktailMenuReader instances should be used to read a csv file containing a collection of cocktail screens. The csv file should contain cocktail related formulations and assign each cocktail to a specific well in the screening plate.

cocktail_menu = 'path/to/my/csv'
my_reader = CocktailMenuReader(cocktail_menu)
csv_cocktails = my_reader.read_menu_file()
# csv_cocktails now holds list of Cocktail objects read from
# cocktail_menu
Parameters
  • menu_file (str or Path) – Path to cocktail menu file to read. Should be csv formated

  • delim (str, optional) – Seperator for menu_file; really should not need to be changed, defaults to ‘,’

cocktail_map = {0: 'well_assignment', 1: 'number', 2: 'commercial_code', 8: 'pH'}
formula_pos = 4
read_menu_file()[source]

Read the contents of cocktail menu csv file. The Menu file path is read from the Menu.menu_file_path attribute. The first two lines of all the cocktail menu files included in Polo are header lines and so the reader will skip the first two lines before actually reading in any data. Each row is converted to a Cocktail object and then added to a dictionary based on the Cocktail instance’s well assignment.

Returns

Dictionary of Cocktail instances. Key value is the Cocktail’s well assignment in the screening plate (base 1).

Return type

dict

classmethod set_cocktail_map(map)[source]

Classmethod to edit the cocktail_map. The cocktail_map describes where the Cocktail level information is stored in a given cocktail row in the csv file. It is a dictionary that maps specific indices in a row to Cocktail attributes.

The default cocktail_map dictionary is below.

>>> cocktail_map = {
0: 'well_assignment',
1: 'number',
8: 'pH',
2: 'commercial_code'
}

This tells instances of CocktailMenuReader to look at index 0 of a row for the well_assignment attribute of the Cocktail class, index 1 for the number attribute of the Cocktail class, etc.

Parameters

map (dict) – Dictionary mapping csv row indices to Cocktail object attributes

classmethod set_formula_pos(pos)[source]

Classmethod to change the CocktailMenuReader.formula_pos attribute. The formula_pos describes the location (base 0) of the chemical formula in a row of a cocktail menu file csv. For some reason, HWI cocktail menu files will only have one chemical formula per row (cocktail) no matter the number of reagents that composite that cocktail. This is why its location is represented using an int instead of a dict.

Generally, CocktailMenuReader.formula_pos should not be changed without a very good reason as the position of the chemical formula is consistent across all HWI cocktail menu files.

Parameters

pos (int) – Index where chemical formula can be found

class polo.utils.io_utils.HtmlWriter(run, **kwargs)[source]

Bases: polo.utils.io_utils.RunSerializer

static make_template(template_path)[source]

Given a path to an html file to serve as a jinja2 template, read the file and create a new template object.

Parameters

template_path – Path to the jinja2 template file.

write_complete_run(output_path, encode_images=True)[source]

Create an HTML report from a Run or HWIRun instance.

Parameters
  • output_path (str or Path) – Path to write html file to.

  • encode_images (bool, optional) – Write images as base64 directly to the html file, defaults to True. Greatly increases the file size but means that report will still contain images even if the originals are deleted or removed.

Returns

Path to html report if write succeeds, Exception otherwise.

Return type

str or Exception

write_grid_screen(output_path, plate_list, well_number, x_reagent, y_reagent, well_volume, run_name=None)[source]

Write the contents of optimization grid screen to an html file.

Parameters
  • output_path (str) – Path to html file

  • plate_list (list) – list containing grid screen data

  • well_number (int or str) – well number of hit screen is created from

  • x_reagent (Reagent) – reagent varied in x direction

  • y_reagent (Reagent) – Reagent varied in y direction

  • well_volume (int or str) – Volume of well used in screen

  • run_name (str, optional) – name of run, defaults to None

class polo.utils.io_utils.JsonWriter(run, output_path)[source]

Bases: polo.utils.io_utils.RunSerializer

Small class that can be used to serialize a run to a json formated file.

Parameters
  • run (Run or HWIRun) – Run to write as a json file

  • output_path (str or Path) – Path to write json file to

static json_encoder(obj)[source]

General purpose json encoder for encoding python objects. Very similar to the encoder function json_encoder() except does not include class and module information in the returned dictionary. If the object cannot be converted to a dictionary it is returned as a string.

Parameters

obj (obj) – Object to convert to dictionary

Returns

dict or str

Return type

dict or str

write_json()[source]

Write the Run instance referenced by the run attribute to a json file at the location specified by the output_path attribute. If the file is written successfully returns True otherwise returns an Exception.

Returns

True or Exception

Return type

bool, Exception

class polo.utils.io_utils.Menu(path, start_date, end_date, type_, cocktails={})[source]

Bases: object

property cocktails
class polo.utils.io_utils.MsoReader(mso_path)[source]

Bases: object

The MsoReader class is used to parse the content of mso formated files and apply the image classifications stored in these files to runs in Polo.

classify_images_from_mso_file(images)[source]

Applies the image classifications stored in an mso file to a collection of Image objects. Allows for some degree of compatability with MarcoscopeJ and for users who have stored their image classifications in the mso format. Additionally, human classification backups are saved as mso files when Polo is closed as they take up much less space than xtal files.

Parameters

images (list) – List of images to apply classifications to

Returns

List of images with mso classifications applied, or Exception if this fails

Return type

list or Exception

static read_mso_classification(mso_classification)[source]

Helper method to read and convert image classifications in a mso file to MARCO image classifications. The exact conversion scheme is layed out in the REV_MSO_DICT constant. Additionally, MarcoscopeJ will allow images to have multiple classifications by assigning multiple image codes seperated by “-“. If this is the case Polo takes the classification corresponding to the mso code with the highest value.

Parameters

mso_classification (str) – Mso image classification code

Returns

MARCO classification if code can be decoded, None otherwise

Return type

str or None

class polo.utils.io_utils.MsoWriter(run, output_path)[source]

Bases: polo.utils.io_utils.RunSerializer

property first_line

Create the first line of the mso file.

Returns

List to write as the first line of the mso file.

Return type

list

get_cocktail_csv_data()[source]

Reads and returns the cocktail csv data assigned to the cocktail_menu attribute of the MsoWriter’s run attribute.

Returns

List of lists containing cocktail csv data.

Return type

list

mso_version = 'msoversion2'
static row_formater(cocktail_row)[source]

Format a cocktail row as read from a cocktail csv file to an mso file row. Main change is appending empty strings to the cocktail row so list ends up always having a length of 17. This is important because the image classification code always occurs at the 18th item in an mso file row.

Parameters

cocktail_row (list) – Cocktail row as read from cocktail csv file.

Returns

Cocktail row reformated for mso writing.

Return type

list

write_mso_file(use_marco_classifications=False)[source]

Writes an mso formated file for use with MarcoScopeJ based on the images and classifications of the Run instance referenced by the MsoWriter’s run attribute.

Parameters

use_marco_classifications (bool, optional) – Include the MARCO classification in the mso file instead of human classifications, defaults to False

Returns

True if file is written successfully, False otherwise.

Return type

bool

class polo.utils.io_utils.PptxWriter(output_path)[source]

Bases: object

Use for creating pptx presentation slides from Run or HWIRun instances.

Parameters
  • output_path (str or Path) – Path to write pptx file to.

  • included_attributes (dict, optional) – [description], defaults to {}

  • image_types (set or list, optional) – Images included in the presentation must have a classification in this set, defaults to None

  • human (bool, optional) – Use human classification as the image classification, defaults to False

  • marco (bool, optional) – Use the MARCO classification as the image classification, defaults to False

  • favorite (bool, optional) – Only include images marked as favorite, defaults to False

_add_image_to_slide(image, slide, left, top, height)[source]

Private method for adding images to a slide. If the Image does not have a file written on the local machine as can be the case with saved runs who’s image data only exists in their xtal files this method will write a temporary image file to the Polo TEMP_DIR which then should be deleted after the presentaton file is written.

Parameters
  • image (Image) – Image to add to the slide

  • slide (slide) – Slide to add the image to

  • left (float) – Left cordinate location of the image in inches

  • top (float) – Top cordinate location of the image in inches

  • height (float) – Height of the image in inches

Returns

[]

Return type

[type]

_add_images_and_metadata_to_slideshow(images, metadata, all_specs, all_dates)[source]
_add_multi_image_slide(slide, images, labeler)[source]

Private method for adding a slide that will have multiple images.

Parameters
  • slide (slide) – Slide to add the images to

  • images (list) – Images to add to the slide

  • labeler (func) – Function to use to label the individual images

Returns

slide with images added

Return type

slide

_add_multi_spectrum_slide(images, well_number)[source]

Create a slide to show a all spectrums a well has been imaged in.

Parameters
  • images (list) – Images to include on the slide

  • well_number (int) – Well number to use in the slide title

Returns

New slide

Return type

slide

_add_new_slide(template=5)[source]

Add a new slide to the presentation referenced by the _presentation attribute.

Parameters

template (int, optional) – Slide template integer identifier, defaults to 5. See the python-pptx package for more details on template integers

Returns

Presentation with the new slide added

Return type

Presentation

_add_single_image_slide(image, title, metadata=None, img_scaler=0.65)[source]

General helper method for adding a slide with a single image to a presentation.

Parameters
  • image (Image) – Image to add to the slide

  • title (str) – Title to use for the slide

  • metadata (str, optional) – Additional information to write to the slide, defaults to None

  • img_scaler (float, optional) – Scaler to apply to size of the image, defaults to 0.65 ,should be between 0 and 1. 1 is full sized image.

Returns

The new slide with Image added

Return type

slide

_add_text_to_slide(slide, text, left, top, width, height, rotation=0, font_size=14)[source]

Helper method to add text to a slide

Parameters
  • slide (slide) – Slide to add text to

  • text (str) – Text to add to the slide

  • left (float) – Left cordinate location of the text in inches

  • top (float) – Top cordinate location of the text in inches

  • width (float) – Width of the text in inches

  • height (float) – Height of the text in inches

  • rotation (int, optional) – Rotation to apply to the text in degrees, defaults to 0

  • font_size (int, optional) – Font size of text, defaults to 14

Returns

Slide with text added

Return type

slide

_add_timeline_slide(images, well_number)[source]

Create a timeline (time resolved) slide that show the progression of a sample in a particular well.

Parameters
  • images (list) – List of images to include in the slide

  • well_number (int) – Well number to use in the title of the slide

Returns

New slide

Return type

slide

_delete_presentation()[source]
_delete_temp_images()[source]

Delete an temporary images used to create the pptx presentation.

Returns

True, if images are removed successfully, Exception otherwise.

Return type

bool or Exception

_metadata_from_images(images, cocktail_data)[source]
_select_images(run)[source]

Selects images to add to the presentation.

add_cocktail_slide(well, cocktail)[source]

Add slide with details on Cocktail information.

Parameters
  • well (int) – Well number to use in slide title

  • cocktail (Cocktail) – Cocktail to write as a slide

add_table_to_slide(slide, data, left, top)[source]

General helper method for adding a table to a slide.

Parameters
  • slide (slide) – Slide to add the table to

  • data (list) – List of lists that has the data to write to the table

  • left (float) – Left offset in inches to place to table

  • top (float) – Top cordinate for placing the table

Returns

Slide with table added

Return type

slide

make_presentation(run, images, title, subtitle=None, cocktail_data=True, all_specs=False, all_dates=False)[source]

Create a pptx presentation file from a screening run instance. This should be the only public method in the class. All other methods are internal to actually creating the presentation file.

Parameters
  • run (Run) – Run to create the presentation from

  • title (str) – Title for the presentation

  • subtitle (str, optional) – Subtitle for the presentation, defaults to None

  • cocktail_data (bool, optional) – If True include cocktail data on slide, defaults to True

  • all_specs (bool, optional) – If True include all spectrum image slide, defaults to False

  • all_dates (bool, optional) – If True include all dates slide, defaults to False

Returns

True if presentation was created successfully, Exception otherwise

Return type

bool or Exception

slide_title_formater = 'Well Number {}'
sort_runs_by_spectrum(runs)[source]

Divids runs into two lists, one containing visible spectrum runs and another containing all non-visible runs.

Parameters

runs (list) – List or runs

Returns

tuple, first item is visible runs second is non-visible runs

Return type

tuple

class polo.utils.io_utils.RunCsvWriter(run, output_path=None, **kwargs)[source]

Bases: polo.utils.io_utils.RunSerializer

property fieldnames

Get the current fieldnames based on the data stored in the run attribute. Currently is somewhat expensive to call since it requires parsing all records in run in order to determine all the fieldnames that should be included in order to definitely avoid keyerrors later down the line.

Returns

List of fieldnames (headers) for the csv data

Return type

list

get_csv_data()[source]

Convert the run attribute to csv style data. Returns a tuple of headers and a list of dictionaries with each dictionary representing one row of csv data.

Returns

Tuple, list of headers and list of dicts

Return type

tuple

classmethod image_to_row(image)[source]

Given an Image object, convert it into a list that could be easily written to a csv file.

Parameters

image (Image) – Image object to convert to list

Returns

List

Return type

list

property output_path

Get the hidden attribute _output_path.

Returns

Output path

Return type

str

write_csv()[source]

Write the Run object referenced by the run attribute as a csv file to the location specified by the output_path attribute.

Returns

True, if csv file content was written successfully, return error thrown otherwise.

Return type

Bool or Exception

class polo.utils.io_utils.RunDeserializer(xtal_path)[source]

Bases: object

static clean_base64_string(string, out_fmt=<class 'bytes'>)[source]

Image instances may contain byte strings that store their actual crystallization image encoded as base64. Previously, these byte strings were written directly into the json file as strings causing the b’ byte string identifier to be written along with the actual base64 data. This method removes those artifacts if they are present and returns a clean byte string with only the actual base64 data.

Parameters

string (str) – a string to interrogate

Returns

byte string with non-data artifacts removed

Return type

bytes

static dict_to_obj(d)[source]

Opposite of the obj_to_dict method in XtalWriter class, this method takes a dictionary instance that has been previously serialized and attempts to convert it back into an object instance. Used as the object_hook argument when calling json.loads to read xtal files.

Parameters

d (dict) – dictionary to convert back to object

Returns

an object

Return type

object

xtal_header_reader(xtal_file_io)[source]

Reads the header section of an open xtal file. Should always be called before reading the json content of an xtal file. Note than xtal files must always have a line of equal signs before the json content even if there is no header content otherwise this method will read one line into the json content causing the json reader to throw an error.

Parameters

xtal_file_io (TextIoWrapper) – xtal file currently being read

Returns

xtal header contents

Return type

list

xtal_to_run(**kwargs)[source]

Attempt to convert the file specified by the path stored in the xtal_path attribute to a Run object.

Returns

Run object encoded by an xtal file

Return type

Run

class polo.utils.io_utils.RunImporter(target_path)[source]

Bases: object

_target_is_valid()[source]

Private method to check if a the file or directory referenced by target_path is valid for import.

Returns

True if could be imported, False otherwise

Return type

bool

allowed_filetypes = {'.rar', '.xtal'}
static crack_open_a_rar_one(rar_path)[source]

Unrar a directory of images

Parameters

rar_path (str or Path) – Path to rar archive file

Returns

Unrar result

Return type

str, exception or int

create_import_thread()[source]

Creates a polo.threads.thread.QuickThread with function based on the type of file that is to be imported.

Returns

QuickThread

Return type

QuickThread

static make_xtal_file_dialog(parent=None)[source]

Create a file dialog specifically for browsing for xtal files.

Parameters

parent (QDialog, optional) – Parent for the file dialog, defaults to None

Returns

QFileDialog

Return type

QFileDialog

class polo.utils.io_utils.RunLinker[source]

Bases: object

Class to hold methods relating to linking runs either by date or by spectrum.

Link a collection of HWIRun instances together by spectrum. All non-visible HWIRun instances are linked together in a monodirectional circular linked list. Each visible HWIRun instance will then point to the same non-visible run through their alt_spectrum attribute as a way to access the non-visible linked list.

Parameters

runs (list) – List of runs to link together

Returns

List of runs linked by spectrum

Return type

list

Create a text representation of the linked list structure between runs for debugging.

Parameters

run (Run) – Run to build representation from

Returns

Text representation of the linked list

Return type

str

Wrapper method to do all the linking required for a collection of runs. First calls unlink_runs_completely() to separate any existing links so things do not get tangled. Then calls link_runs_by_date() and link_runs_by_spectrum().

Parameters

runs (list) – List of runs to link

Returns

List of runs with links made

Return type

list

Cuts all links between the HWIRun instances passed through the runs argument and the Image instances in those runs.

Parameters

runs (list) – List of runs

Returns

List of runs without any links

Return type

list

class polo.utils.io_utils.RunSerializer(run=None)[source]

Bases: object

classmethod make_thread(job_function, **kwargs)[source]

Creates a new QuickThread object. The job function is the function the thread will execute and and arguments that the job function requires should be passed has keyword arguments. These are stored as a dictionary in the new thread object until the thread is activated and they are passed as arguments.

static path_suffix_checker(path, desired_suffix)[source]

Check is a file path has a desired suffix, if not then replace the current suffix with the desired suffix. Useful for checking filenames that are taken from user input.

Parameters

desired_suffix – File extension for given file path.

static path_validator(path, parent=False)[source]

Tests to ensure a path exists. Passing parent = True will check for the existence of the parent directory of the path.

class polo.utils.io_utils.SceneExporter(graphics_scene=None, file_path=None)[source]

Bases: object

write()[source]
static write_image(scene, file_path)[source]

Write the contents of a QGraphicsScene to a png file.

Parameters
  • scene (QGraphicsScene) – QGraphicsScene to convert to image file.

  • file_path (str) – Path to save image to.

Returns

File path to saved image if successful, Exception otherwise.

Return type

str or Exception

class polo.utils.io_utils.XmlReader(xml_path=None)[source]

Bases: object

static get_data_from_xml_element(xml_element)[source]

Return the data stored in an xml_element. Helper method for reading xml files.

Parameters

xml_element ([type]) – xml element to read data from

Returns

Dictionary of data stored in xml element

Return type

dict

class polo.utils.io_utils.XtalToImages(run, output_dir)[source]

Bases: object

One of the features of Polo is the ability to save images, classifications and cocktail data all as one (xtal) file. This also means that users may be loading in their run data from xtal files but want some way to recover the images that are encoded (as base64) within the delicious onion like layers of the JSON formated xtal file. This class acomplishes this goal by intializing with a run that has base64 encoded image data and writes that data as jpegs to a user specified directory.

Currently under construction as of 12-14-2020

_collect_writable_image_indicies()[source]
write_images()[source]
class polo.utils.io_utils.XtalWriter(run, main_window, **kwargs)[source]

Bases: polo.utils.io_utils.RunSerializer

static clean_run_for_save(run)[source]

Remove circular references from the run passed through the run argument to avoid issues when writing to json files.

Parameters

run (Run or HWIRun) – Run to clean (remove circular references)

Returns

Run, free from circular references

Return type

Run or HWIRun

file_ext = '.xtal'
finished_save()[source]
header_flag = '<>'
header_line = '{}{}:{}\n'
static json_encoder(obj)[source]

Use instead of the default json encoder when writing an xtal file. If the encoded object is from a module within Polo will include a module and class identifier so it can be more easily deserialized when loaded back into the program.

Param

obj: An object to serialize to json.

Returns

A dictionary or string version of the passed object

run_to_dict()[source]

Create a json string from the run stored in the run attribute.

Returns

Run instance serialized to json

Return type

str

write_xtal_file(output_path=None)[source]

Method to serialize run object to xtal file format.

Parameters

output_path (str) – Xtal file path

Returns

path to xtal file

Return type

str

write_xtal_file_on_thread(output_path)[source]

Wrapper method around write_xtal_file() that executes on a QuickThread instance to prevent freezing the GUI when saving large xtal files

Parameters

output_path (str) – Path to xtal file

property xtal_header

Creates the header for an xtal file when called. Header lines are indicated as such by the string in the header_line constant, which should be ‘<>’. The last line of the header will be a row of equal signs and then the actual json content begins on the next line.

polo.utils.io_utils.check_for_missing_images(dir_path, expected_image_count)[source]
polo.utils.io_utils.directory_validator(dir_path)[source]
polo.utils.io_utils.if_dir_not_exists_make(parent_dir, child_dir=None)[source]

If only parent_dir is given attempts to make that directory. If parent and child are given tries to make a directory child_dir within parent dir.

polo.utils.io_utils.list_dir_abs(parent_dir, allowed=False)[source]
polo.utils.io_utils.parse_HWI_filename_meta(HWI_image_file)[source]

HWI images have a standard file nameing schema that gives info about when they are taken and well number and that kind of thing. This function returns that data

polo.utils.io_utils.parse_hwi_dir_metadata(dir_name)[source]
polo.utils.io_utils.run_name_validator(new_run_name, current_run_names)[source]
polo.utils.io_utils.write_screen_html(plate_list, well_number, run_name, x_reagent, y_reagent, well_volume, output_path)[source]

polo.utils.math_utils module

polo.utils.math_utils.best_aspect_ratio(w, h, n)[source]
polo.utils.math_utils.factors(n)[source]
polo.utils.math_utils.get_cell_image_dims(w, h, n)[source]
polo.utils.math_utils.get_image_cell_size(cell_aspect, w, h)[source]

polo.utils.unrar_utils module

polo.utils.unrar_utils.test_for_working_unrar(unrar_exe='unrar')[source]

Tests if a working unrar installation exists on the machine.

Parameters

unrar_exe (Path or str, optional) – Path to unrar executable file, defaults to UNRAR_EXE

Returns

True if working installation exists, False otherwise

Return type

bool

polo.utils.unrar_utils.unrar_archive(rar_path, target_dir=None)[source]

De-compress a rar archive and return the path to the uncompressed archive if it exists. All unrar functions including this one are dependent of their being a working unrar installation. Unrar is included for both Windows and Mac operating systems but not for Linux.

Parameters
  • rar_path (Path or str) – Path to rar archive file

  • target_dir (Path or str, optional) – Location to place the unrared file, defaults to None

Returns

Path if unrar is successful, error code if unrar fails or Exception if

exception is raised in the unrar process. :rtype: Path, str or Exception

Module contents