Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Mar 24, 2022
1 parent 36cb7f2 commit 2953ca6
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 29 deletions.
26 changes: 13 additions & 13 deletions qpimage/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


class QPImage(object):
# required to create in-memory hdf5 files with unique fd
# required to create in-memory HDF5 files with unique fd
_instances = 0

def __init__(self, data=None, bg_data=None, which_data="phase",
Expand Down Expand Up @@ -70,7 +70,7 @@ def __init__(self, data=None, bg_data=None, which_data="phase",
Previous versions always performed phase unwrapping
and did so without offset correction
h5file: str, pathlib.Path, h5py.Group, h5py.File, or None
A path to an hdf5 data file where all data is cached. If
A path to an HDF5 data file where all data is cached. If
set to `None` (default), all data will be handled in
memory using the "core" driver of the :mod:`h5py`'s
:class:`h5py:File` class. If the file does not exist,
Expand Down Expand Up @@ -385,7 +385,7 @@ def field(self):

@property
def info(self):
"""list of tuples with QPImage meta data"""
"""list of tuples with QPImage metadata"""
info = []
# meta data
meta = self.meta
Expand Down Expand Up @@ -561,7 +561,7 @@ def compute_bg(self, which_data="phase",
def copy(self, h5file=None):
"""Create a copy of the current instance
This is done by recursively copying the underlying hdf5 data.
This is done by recursively copying the underlying HDF5 data.
Parameters
----------
Expand All @@ -583,13 +583,13 @@ def refocus(self, distance, kernel="helmholtz", padding=True,
kernel: str
Refocusing method, one of ["helmholtz","fresnel"]
padding: bool
Whether or not to perform padding during refocusing.
Whether to perform padding during refocusing.
You may disable padding if your input image does not
have any discontinuities at the border (i.e. you can
tile your input image and it would look good), otherwise
tile your input image, and it would look good), otherwise
you will experience ringing artifacts.
h5file: str, h5py.Group, h5py.File, or None
A path to an hdf5 data file where the QPImage is cached.
A path to an HDF5 data file where the QPImage is cached.
If set to `None` (default), all data will be handled in
memory using the "core" driver of the :mod:`h5py`'s
:class:`h5py:File` class. If the file does not exist,
Expand Down Expand Up @@ -704,18 +704,18 @@ def set_bg_data(self, bg_data, which_data=None, proc_phase=True):


def copyh5(inh5, outh5):
"""Recursively copy all hdf5 data from one group to another
"""Recursively copy all HDF5 data from one group to another
Data from links is copied.
Parameters
----------
inh5: str, h5py.File, or h5py.Group
The input hdf5 data. This can be either a file name or
an hdf5 object.
The input HDF5 data. This can be either a file name or
an HDF5 object.
outh5: str, h5py.File, h5py.Group, or None
The output hdf5 data. This can be either a file name or
an hdf5 object. If set to `None`, a new hdf5 object is
The output HDF5 data. This can be either a file name or
an HDF5 object. If set to `None`, a new HDF5 object is
created in memory.
Notes
Expand Down Expand Up @@ -765,7 +765,7 @@ def copyh5(inh5, outh5):


def divmod_neg(a, b):
"""Return divmod with closest result to zero"""
"""Return divmod with the closest result to zero"""
q, r = divmod(a, b)
# make sure r is close to zero
sr = np.sign(r)
Expand Down
14 changes: 8 additions & 6 deletions qpimage/image_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from . import bg_estimate

#: default hdf5 compression keyword arguments
#: default HDF5 compression keyword arguments
COMPRESSION = {"compression": "gzip",
"compression_opts": 9,
}
Expand Down Expand Up @@ -178,7 +178,7 @@ def estimate_bg(self, fit_offset="mean", fit_profile="tilt",
intersection of the two resulting mask images is used.
The arguments passed to this method are stored in the
hdf5 file `self.h5` and are used for optional integrity
HDF5 file `self.h5` and are used for optional integrity
checking using `qpimage.integrity_check.check`.
See Also
Expand Down Expand Up @@ -241,14 +241,14 @@ def get_bg(self, key=None, ret_attrs=False):
raise KeyError("No background data for {}!".format(key))
return ret

def set_bg(self, bg, key="data", attrs={}):
def set_bg(self, bg, key="data", attrs=None):
"""Set the background data
Parameters
----------
bg: numbers.Real, 2d ndarray, ImageData, or h5py.Dataset
The background data. If `bg` is an `h5py.Dataset` object,
it must exist in the same hdf5 file (a hard link is created).
it must exist in the same HDF5 file (a hard link is created).
If set to `None`, the data will be removed.
key: str
One of :const:`VALID_BG_KEYS`)
Expand All @@ -259,6 +259,8 @@ def set_bg(self, bg, key="data", attrs={}):
--------
del_bg: removing background data
"""
if attrs is None:
attrs = {}
if key not in VALID_BG_KEYS:
raise ValueError("Invalid bg key: {}".format(key))
# remove previous background key
Expand Down Expand Up @@ -324,7 +326,7 @@ def _bg_correct(self, raw, bg):


def write_image_dataset(group, key, data, h5dtype=None):
"""Write an image to an hdf5 group as a dataset
"""Write an image to an HDF5 group as a dataset
This convenience function sets all attributes such that the image
can be visualized with HDFView, sets the compression and fletcher32
Expand All @@ -338,7 +340,7 @@ def write_image_dataset(group, key, data, h5dtype=None):
Dataset identifier
data: np.ndarray of shape (M,N)
Image data to store
h5dtype: str
h5dtype: str or dtype
The datatype in which to store the image data. The default
is the datatype of `data`.
Expand Down
8 changes: 5 additions & 3 deletions qpimage/integrity_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ class IntegrityCheckError(BaseException):
pass


def check(qpi_or_h5file, checks=["attributes", "background"]):
def check(qpi_or_h5file, checks=None):
"""Checks various properties of a :class:`qpimage.core.QPImage` instance
Parameters
----------
qpi_or_h5file: qpimage.core.QPImage or str
A QPImage object or a path to an hdf5 file
A QPImage object or a path to an HDF5 file
checks: list of str
Which checks to perform ("attributes" and/or "background")
Expand All @@ -25,7 +25,9 @@ def check(qpi_or_h5file, checks=["attributes", "background"]):
IntegrityCheckError
if the checks fail
"""
if isinstance(checks, str):
if checks is None:
checks = ["attributes", "background"]
elif isinstance(checks, str):
checks = [checks]
for ch in checks:
if ch not in ["attributes", "background"]:
Expand Down
2 changes: 1 addition & 1 deletion qpimage/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@


class MetaDataMissingError(BaseException):
"""Raised when meta data is missing"""
"""Raised when metadata is missing"""
pass


Expand Down
12 changes: 6 additions & 6 deletions qpimage/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ def __init__(self, qpimage_list=[], meta_data={},
qpimage_list: list
A list of instances of :class:`qpimage.QPImage`.
meta_data: dict
Meta data associated with the input data
Metadata associated with the input data
(see :const:`qpimage.META_KEYS`). This overrides
the meta data of the QPImages in `qpimage_list` and, if
the metadata of the QPImages in `qpimage_list` and, if
`h5file` is given and `h5mode` is not "r", overrides
the meta data in `h5file`.
the metadata in `h5file`.
h5file: str, h5py.Group, h5py.File, or None
A path to an hdf5 data file where all data is cached. If
A path to an HDF5 data file where all data is cached. If
set to `None` (default), all data will be handled in
memory using the "core" driver of the :mod:`h5py`'s
:class:`h5py:File` class. If the file does not exist,
Expand Down Expand Up @@ -138,7 +138,7 @@ def add_qpimage(self, qpi, identifier=None, bg_from_idx=None):
Identifier key for `qpi`
bg_from_idx: int or None
Use the background data from the data stored in this index,
creating hard links within the hdf5 file.
creating hard links within the HDF5 file.
(Saves memory if e.g. all qpimages is corrected with the same data)
"""
if not isinstance(qpi, QPImage):
Expand Down Expand Up @@ -178,7 +178,7 @@ def get_qpimage(self, index):
Notes
-----
Instead of ``qps.get_qpimage(index)``, it is possible
to use the short-hand ``qps[index]``.
to use the shorthand ``qps[index]``.
"""
if isinstance(index, str):
# search for the identifier
Expand Down

0 comments on commit 2953ca6

Please sign in to comment.