API Reference

This is the public interface to the biorad1sc_reader functionality.

biorad1sc_reader.Reader

class biorad1sc_reader.Reader(in_file=None)

Object to manage reading a Bio-Rad 1sc file and extracting data from it, including image.

Assumes the 1sc file does not change while this instance has it open.

Instantiation:
Args:
in_file (str or file-like obj): filepath (str) or file-like
object, 1sc file to read with this instance
Raises:
BioRadInvalidFileError if file is not a valid Bio-Rad 1sc file
get_img_data(invert=False)

Return image_x_size, image_y_size, and list containing image data. Also ability to invert brightness.

Parameters:invert (bool, optional) – True to invert the brightness scale of output image data compared to 1sc image data (black <-> white)
Returns:(xsize, ysize, image_data) where xsize and ysize are integers specifying the size of the image.

image_data is a list of uint16 numbers comprising the image data starting from upper-left and progressing to lower-right.

Return type:tuple
get_img_summary()

NOTE: Safer to use get_metadata() or get_metadata_compact()

Read from Data Block 7, containing strings describing image.

Returns:dict containing data from strings in Data Block 7:
{
    'Scanner Name':'ChemiDoc XRS'
    'Number of Pixels':'(<x pix size> x <y pix size>)'
    'Image Area':'(<x float size> mm x <y float size> mm)'
    'Scan Memory Size': '<size in bytes>'
    'Old file name': '<orig file name>'
    'New file name': '<new file name>'
    'path':'CHEMIDOC\Chemi'
    'New Image Acquired':'New Image Acquired'
    'Save As...':'Save As...'
    'Quantity One':'Quantity One <version> build <build number>'
}
Return type:dict
get_metadata()

Fetch All Metadata in File, return hierarchical dict/list

Returns:collections where each item in list collections is a dict:
collection_dict = {
    'data':<list items>
    'label':'<str name of collection>'
}

where items is a list of dicts, each with the structure:

item_dict = {
    'data':<list regions>
    'id':<uint32 Field ID>
    'label':'<str name of item>'
    'type':'<int Field Type>'
}

where regions is a list of dicts, each with the structure:

region_dict = {
    'data': <dict data_of_region>
    'dtype': <str written type of data>
    'dtype_num': <int data type code of data>
    'key_iter': <??>
    'label': <str name of region>
    'num_words': <int number of words in data>
    'region_idx': <int 1sc-given index>
    'word_size': <int number of bytes per word of data>
}

where data_of_region has the structure:

data_of_region = {
    'raw': <bytes raw bytes, unconverted data>
    'proc': <various unpacked/decoded data from bytes>
    'interp': <various 'interpreted' data>
}
data_of_region[‘interp’] can also be another item_dict, if this
region contained a reference to another field, creating a hierarchical structure.

e.g. collections[0]['data'][0]['data'][0]['label'] = 'array'

Return type:list
Raises:BioRadParsingError – if there was an error in parsing the file
get_metadata_compact()

Fetch All Metadata in File, return compact version of hierarchical dict/list

Convert dict(list()) of Collections, Items to dict(). Leave Regions as list, because they are not guaranteed to have unique labels.

Remove everything except ‘label’ and most-interpreted form of ‘data’ available.

Returns:collections:
collections = {
    '<collection name1>':<dict collection_dict1>
    '<collection name2>':<dict collection_dict2>
    ...
}

where each collection_dict is:

collection_dict = {
    '<name of item1>':<list regions1>
    '<name of item2>':<list regions2>
    ...
}

where regions is a list of dicts, each with the structure:

region_dict = {
    'data': <various most interpreted version possible of data>
    'label': <str name of region>
}
region_dict[‘data’] can also be another regions list, if this
region contained a reference to another field, creating a hierarchical structure.

e.g. collections['Overlay Header']['OverlaySaveArray'][0]['label] = 'array'

Return type:dict
open_file(in_filename)

Open file and read into memory.

Raises Errors if File is not valid 1sc file.

Parameters:in_filename (str) – filepath to 1sc file to read with object instance
Raises:BioRadInvalidFileError if file is not a valid Bio-Rad 1sc file
read_stream(in_fh)

Read file-like object into memory.

Raises Errors if File is not valid 1sc file. Give it object returned by: open(<filename>, ‘rb’)

Parameters:in_fh (byte stream) – filehandle to 1sc filedata to read with object instance. e.g. result from open(<filename>, ‘rb’)
Raises:BioRadInvalidFileError if file is not a valid Bio-Rad 1sc file
refresh()

Reset and refresh all internal state using same input 1sc file.

reset()

Reset all internal state. (Must load file afterwards.)

save_img_as_tiff(tiff_filename, invert=False)

Save image data as TIFF image

Also ability to invert brightness

Parameters:
  • tiff_filename (str) – filepath for output TIFF file
  • invert (bool, optional) – True to invert the brightness scale of output TIFF image compared to 1sc image data (black <-> white)
save_img_as_tiff_sc(tiff_filename, imgsc=1.0, invert=False)

Save image data as TIFF image, with brightness dynamic range expanded

Also ability to invert brightness

Parameters:
  • tiff_filename (str) – filepath for output TIFF file
  • imgsc (float, optional) –

    Expand brightness scale. Value of 1.0 means that dynamic range of output TIFF will be maximum, with brightest pixel having value 65535 and darkest pixel having value 0.

    imgsc > 1.0 will cause the brightness dynamic range to be expanded less than imgsc=1.0, and imgsc < 1.0 will cause the dynamic range to be expanded more than the imgsc=1.0 case.

    For non-inverted images, the pixel with the minimum brightness will always be 0. For inverted images, the pixel with the maximum brightness will always be 65535.

  • invert (bool, optional) – True to invert the brightness scale of output TIFF image compared to 1sc image data (black <-> white)