Skip to content

Commit

Permalink
skeleton of module structure
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Oct 11, 2017
1 parent c050867 commit 4b489ad
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 0 deletions.
37 changes: 37 additions & 0 deletions qpformat/core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from . import file_formats


def load_data(path, fmt=None, h5out=None)
"""Load experimental data

Parameters
----------
path: str
Path to experimental data file or folder
fmt: str
The file format to use (see `file_formats.formats`).
If set to `None`, the file format will be guessed.
h5out: str
Path to an hdf5 output file where all data
will be written. If set to `None`, nothing
is written to disk.
meta_data: dict
Meta data (see `qpimage.meta.VALID_META_KEYS`)

Returns
-------
dataobj: `file_formats.Group` or `file_formats.Single`
A qpformat data object with unified access to the
experimental data.
"""
if fmt is None:
fmt = file_formats.guess_format(path)

dataobj = file_formats.formats_dict[fmt](path)

if h5out is not None:
# TODO:
# - store data in h5file using qimage
pass

return dataobj
27 changes: 27 additions & 0 deletions qpformat/file_formats/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from .group_folder import GroupFolder
from .group_hdf5_qpimage import GroupHdf5Qimage
from .group_zip_tif_phasics import GroupZipTifPhasics
from .single_hdf5_qimage import SingleHdf5Qimage
from .single_tif_phasics import SingleTifPhasics


def guess_format(path):
"""Determine the file format of a folder or a file"""
for fmt in formats:
if fmt.verify(path):
return path


# the order is important for
formats = [GroupFolder,
GroupZipTifPhasics,
GroupHdf5Qimage,
SingleHdf5Qimage,
SingleTifPhasics,
]


# convenience dictionary
formats_dict = {}
for _fmt in formats:
formats_dict[_fmt.name] = _fmt
12 changes: 12 additions & 0 deletions qpformat/file_formats/group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import abc

class Group(object):
__meta__ = abs.ABCMeta

@abc.abstractmethod
def verify(path):
"""Verify that `path` has this file format
Returns `True` if the file format matches.
"""

Empty file.
Empty file.
Empty file.
12 changes: 12 additions & 0 deletions qpformat/file_formats/single.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import abc

class Single(object):
__meta__ = abs.ABCMeta

@abc.abstractmethod
def verify(path):
"""Verify that `path` has this file format
Returns `True` if the file format matches.
"""

Empty file.
Empty file.

0 comments on commit 4b489ad

Please sign in to comment.