ptypy.io package

Submodules

ptypy.io.edfIO module

IO module for handling the file format EDF used by the ESRF beamline id19 Provides read, write and readHeader functions.

translated to python: April 2010, Dieter Hahn

Among other, contains the functions

readData writeData WHICH IS NOT YET IMPLEMENTED

ptypy.io.edfIO.edfread(filename, doglob=None, roi=None)
d,meta = edfread(filename)

reads array in edf file filename and returns it as a numpy array, along with metadata (from header). d and meta are lists if filename is a list of file names.

… = edfread(filename, doglob=True)

reads all matching files if filename contains unix-style wildcards, and returns lists.

… = edfread(filename, doglob=False)

ignores wildcards

… = edfread(filename, doglob=None) [default]

behaves like doglob=True, except that it returns a list only if filename contains wildcards, while doglob=True always returns a list, even if there is only one match.

… = edfread(filename, roi=(RowFrom, RowTo, ColumnFrom, ColumnTo))

returns a region of interest (applied on all files if gobbing or if filename is a list)

ptypy.io.h5rw module

Wrapper to store nearly anything in an hdf5 file.

This file is part of the PTYPY package.

copyright

Copyright 2014 by the PTYPY team, see AUTHORS.

license

see LICENSE for details.

ptypy.io.h5rw.h5append(filename, {'var1'=..., 'var2'=..., ...})
ptypy.io.h5rw.h5append(filename, var1=..., var2=..., ...) None
ptypy.io.h5rw.h5append(filename, dict, var1=..., var2=...) None

Appends variables var1, var2, … to file filename. The key-value arguments have precedence on the provided dictionary.

supported variable types are: * scalars * numpy arrays * strings * lists * dictionaries

(Setting the option UNSUPPORTED equal to ‘ignore’ eliminates unsupported types. Default is ‘fail’, which raises an error.)

The file mode can be chosen according to the h5py documentation. It defaults to overwriting an existing file.

ptypy.io.h5rw.h5info(filename)

Prints out a tree structure of given h5 file.

ptypy.io.h5rw.h5read(filename)
ptypy.io.h5rw.h5read(filename, s1, s2, ...) None
ptypy.io.h5rw.h5read(filename, (s1, s2, ...)) None

Read variables from a hdf5 file created with h5write and returns them as a dictionary.

If specified, only variable named s1, s2, … are loaded.

Variable names support slicing and group access. For instance, provided that the file contains the appropriate objects, the following syntax is valid:

a = h5read(‘file.h5’, ‘myarray[2:4]’) a = h5read(‘file.h5’, ‘adict.thekeyIwant’)

Another way of slicing, is with the slice keyword argument, which will take the provided slice object and apply it on the last variable name:

a = h5read(‘file.h5’, ‘array1’, ‘array2’, slice=slice(1,2)) # Will read array2[1:2]

h5read(filename_with_wildcard, … , doglob=True) Reads sequentially all globbed filenames.

ptypy.io.h5rw.h5write(filename, {'var1'=..., 'var2'=..., ...})
ptypy.io.h5rw.h5write(filename, var1=..., var2=..., ...) None
ptypy.io.h5rw.h5write(filename, dict, var1=..., var2=...) None

Writes variables var1, var2, … to file filename. The key-value arguments have precedence on the provided dictionary.

supported variable types are: * scalars * numpy arrays * strings * lists * dictionaries

(Setting the option UNSUPPORTED equal to ‘ignore’ eliminates unsupported types. Default is ‘fail’, which raises an error.)

The file mode can be chosen according to the h5py documentation. It defaults to overwriting an existing file.

ptypy.io.imageIO module

Wrapper over Python Imaging Library to read images (+ metadata) and write images.

ptypy.io.imageIO.imread(filename, doglob=None, roi=None)
d,meta = imread(filename)

reads array in image file and returns it as a numpy array, along with metadata (from header). d and meta are lists if filename is a list of file names.

… = imread(filename, doglob=True)

reads all matching files if filename contains unix-style wildcards, and returns lists.

… = imread(filename, doglob=False)

ignores wildcards

… = imread(filename, doglob=None) [default]

behaves like doglob=True, except that it returns a list only if filename contains wildcards, while doglob=True always returns a list, even if there is only one match.

… = imread(filename, roi=(RowFrom, RowTo, ColumnFrom, ColumnTo))

returns a region of interest (applied on all files if gobbing or if filename is a list)

ptypy.io.image_read module

ptypy.io.image_read.image_read(filename, *args, **kwargs)

Try to load image data from any file.

Parameters

filename (str) – Name of the file. If filename contains a wildcard, load all files that match the pattern.

Return type

(image, metadict) or (list of images, list of metadicts)

ptypy.io.interaction module

Interaction module

Provides the server and a basic client to interact with it.

This file is part of the PTYPY package.

copyright

Copyright 2014 by the PTYPY team, see AUTHORS.

license

see LICENSE for details.

class ptypy.io.interaction.Client(pars=None, **kwargs)

Bases: object

Basic but complete client to interact with the server.

DEFAULT = {'address': 'tcp://127.0.0.1', 'connection_timeout': 3600000.0, 'pinginterval': 1, 'poll_timeout': 100.0, 'port': 5560}
activate()

Create the thread.

avail()

Queries the server for the name of objects available. ! Synchronous call !

do(execstr, timeout=0, tag=None)

Modify and object using an exec string. This function returns the “ticket number” which identifies the object once it will have been transmitted. If timeout > 0 and the requested object has been transmitted within timeout seconds, return a tuple (ticket, data).

flush()

Delete all stored data (and accompanying status).

get(evalstr, timeout=0, tag=None)

Requests an object (or part of it) using an eval string. This function returns the “ticket number” which identifies the object once it will have been transmitted. If timeout > 0 and the requested object has been transmitted within timeout seconds, return a tuple (ticket, data).

get_now(evalstr)

Synchronous get. May be dangerous, but should be safe for small objects like parameters.

newdata(ticket)

Meant to be replaced, e.g. to send signals to a GUI.

poll(ticket=None, tag=None)

Returns true if the transaction for a given ticket is completed. If ticket and tag are None, returns true only if no transaction is pending

set(varname, varvalue, timeout=0, tag=None)

Sets an object named varname to the value varvalue.

stop()
stop_server()

Send a SHUTDOWN command - is this a good idea?

unexpected_ticket(ticket)

Used to deal with warnings sent by the server.

wait(ticket=None, tag=None, timeout=None)

Blocks and return True only when the transaction for a given ticket is completed. If ticket is None, returns only when no more transaction are pending. If timeout is a positive number, wait will return False after timeout seconds if the ticket(s) had not been processed yet.

class ptypy.io.interaction.Server(pars=None, **kwargs)

Bases: object

Main ZMQ server class.

Interaction server, meant to run asynchronously with process 0 to manage client requests.

Parameters

pars (dict or Param) – Parameter set for the server.

Keyword Arguments
  • address (str) – Primary address

  • port (int) – Primary port

  • connections (int) – number of ports to open on demand behind the primary port.

  • poll_timeout (float) – Network polling interval (in milliseconds!).

  • pinginterval (float) – Interval to check pings (in seconds).

  • pingtimeout (float) – Ping time out: client disconnected after this period (in seconds).

DEFAULT = {'active': True, 'address': 'tcp://127.0.0.1', 'connections': 10, 'pinginterval': 2, 'pingtimeout': 10, 'poll_timeout': 10.0, 'port': 5560}
activate()

This needs to be run for the thread to initialize. Returns port where the server listens or None if Server failed

make_ID_pool()
process_requests(tinterval=0.001)

Give permission to the serving thread to send objects and wait for it to complete (safer!)

register(obj, name)

Exposes the content of an object for transmission and interaction. For now this is equivalent to Interactor.object[name] = obj, but maybe use weakref in the future?

send_error(error_message)

Queue an ERROR message for all connected clients.

send_warning(warning_message)

Queue a warning message for all connected clients.

stop()

ptypy.io.json_rw module

Wrapper to store nearly anything in a file using JSON encoding.

This file is part of the PTYPY package.

copyright

Copyright 2014 by the PTYPY team, see AUTHORS.

license

see LICENSE for details.

ptypy.io.json_rw.jread(filename, *args, **kwargs)

h5read(filename) h5read(filename, s1, s2, …) h5read(filename, (s1,s2, …))

Read variables from a JSON file created with jwrite and returns them as a dictionary.

The following features are meant to have an interface identical to h5read. Note however that no time of memory is saved by “loading” only a subset of variables or slices.

If specified, only variable named s1, s2, … are loaded.

Variable names support slicing and group access. For instance, provided that the file contains the appropriate objects, the following syntax is valid:

a = jread(‘file.h5’, ‘myarray[2:4]’) a = jread(‘file.h5’, ‘adict.thekeyIwant’)

Another way of slicing is with the slice keyword argument which will take the provided slice object and apply it on the last variable name:

a = jread(‘file.json’, ‘array1’, ‘array2’, slice=slice(1,2)) # Will read array2[1:2]

jread(filename_with_wildcard, … , doglob=True) Reads sequentially all globbed filenames.

ptypy.io.json_rw.jwrite(filename, {'var1'=..., 'var2'=..., ...})
ptypy.io.json_rw.jwrite(filename, var1=..., var2=..., ...) None
ptypy.io.json_rw.jwrite(filename, dict, var1=..., var2=...) None

Writes variables var1, var2, … to file filename using JSON encoding. The key-value arguments have precedence on the provided dictionary.

All JSON supported types are supported, as well as numpy arrays, which are replaced by a base64 encoding.

ptypy.io.rawIO module

read .raw images from FLI camera Created in Nov 2013 TODO: add masking function to mask out hot/dead pixels of detector @author: Bjoern Enders

ptypy.io.rawIO.rawread(filename, doglob=None, roi=None)
d,meta = rawread(filename)

reads array in CDF file filename and returns it as a numpy array, along with metadata (from header). d and meta are lists if filename is a list of file names.

… = rawread(filename, doglob=True)

reads all matching files if filename contains unix-style wildcards, and returns lists.

… = rawread(filename, doglob=False)

ignores wildcards

… = rawread(filename, doglob=None) [default]

behaves like doglob=True, except that it returns a list only if filename contains wildcards, while doglob=True always returns a list, even if there is only one match.

… = rawread(filename, roi=(RowFrom, RowTo, ColumnFrom, ColumnTo))

returns a region of interest (applied on all files if gobbing or if filename is a list)

Module contents

Input/Output utilities.

This file is part of the PTYPY package.

copyright

Copyright 2014 by the PTYPY team, see AUTHORS.

license

see LICENSE for details.