[TOC]
This simple module is meant to simplify the loading and treatment of images at CERVO. The ultimate goal of this module is to allow users to rapidly extract useful and pertinent information about microscopy images taken in their lab, possibly at the CERVO research center.
The first API, for users, is said to be "image-oriented". This is likely going to be the most used API: I have an image, show me the filtered image, the z-stack or segment this collection of images. It must be expressed in a natural language for people who deal with images. An Image() keeps an internal reference (hidden) to a ImageFile.
Sometimes however, a user has a specific file and needs to comb through all the data it contains. For instance, a Carl-Zeiss File (.czi) contains several images and Leica file (.lif) can contain several stacks and time series. Hence, in this particular case, it become very much application-specific. An file-oriented API uses the file as the source and can return Images, zStacks, TimeSeries, etc… contained in the file. An ImageFile can be created independently, and methods exist to obtain ImageData, ImageStackData, etc...
Everything needs to be unit tested.
Import env first. A testcase file should look like this:
import env # important: definition of dcclabTestCase, sys.path modified for dcclab testing
from dcclab import *
import unittest
import numpy as np
class TestChannelFloat(env.dcclabTestCase):
def setUp(self) -> None:
array = np.ones((10, 10), dtype=np.float32) * 2.35
self.channelNotNormalized = Channel(array)
arrayNormed = np.ones_like(array) * 0.87
self.channelNormalized = Channel(arrayNormed)
def testIsNormalizedAfterInit(self):
self.assertTrue(np.max(self.channelNotNormalized.pixels) == 1)
...You should use the dcclabTestCase base class for your test cases, since that will give you access to 4 special directories:
| Class variable | Description |
|---|---|
| tmpDir | A temporary directory that gets deleted with its content when tests are done |
| dataDir | The directory (testData) where all data for testing (i.e. test files) should be stored |
| moduleDir | The directory where the module is |
| testsDir | The tests directory |
If generally useful functions are needed in the module, they should go there. You also get dataFile(filename) and tmpFile(filename) to quickly obtain a path into those directories. If generally useful functions are needed, they should go there.
You can run all tests with:
cd dcclab/tests/
python -m unittestYou can check the coverage of your code with
coverage run testFile.py
coverage htmlthen open htmlcov/index.html. We should always aim for nearly 100% coverage.
The coding style for the group is available online. However, we highlight important aspects here:
-
Plan for usage, not for coders.
-
The code should read as a text. Variable names and function names are important. A boolean variable can be called
isDone. A table representing an image can be calledimage. A function can have an action verb in its name. -
We do not need to use "array" in the name to describe an array, because it could be an array, a list, a set. We use th eplural form instead. For instance, in
Image, the channels are kept inImage().channels, which happens to be a list. InImageCollection, the images are inimages. -
We take a "camel-case" style, that is, the first letter is lowercase, and then each word is capitalized, as in
createRayPlot(). We never use underscores (_) which are reserved for internal, hidden, private, low-level variables. -
Properties must be declared with
@property. -
Functions shoudl have an action word (
applyFilter). If we "get" something, we use the name withoutget(i.e.imageData). When we set something that is not a property, we useset(i.e.setPermissionToReadOnly) -
Always expose as little as possible.
