Functions
arg2np(arg, ext=4, pad=0, val=0, fill=False, bounds=None, dtype=np.int32)
Convert an argument into a NumPy array, assuming that we want the values to apply to some 2D property, such as image or kernel size, field of view, etc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
None | int | float | tuple | ndarray
|
The argument. |
required |
ext
|
int
|
Extent of the returned array. |
4
|
pad
|
int
|
Pad the array to the |
0
|
val
|
int
|
Value to use to pad the array. |
0
|
fill
|
bool
|
If |
False
|
bounds
|
tuple[int | float, ...] | None
|
Upper and lower bounds to apply to the argument. |
None
|
dtype
|
dtype
|
The dtype to use when converting to NumPy. |
int32
|
Raises:
| Type | Description |
|---|---|
AttributeError
|
Raised if the parameter is a tuple with 3 or more than 4 elements. |
AttributeError
|
Raised if the parameter is a NumPy array with 3 or more than 4 elements. |
Returns:
| Type | Description |
|---|---|
ndarray
|
The argument as a NumPy array. |
cartesian_prod(arr1, arr2)
Compute the Cartesian product of two 1D arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr1
|
ndarray
|
The first array. |
required |
arr2
|
ndarray
|
The second array. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The resulting Cartesian product. |
crop_to_fov(coordinates, size)
Crop some substrate coordinates to the dimensions of the visual field (the field of view, or FoV).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coordinates
|
ndarray
|
Substrate coordinates (rows, cols). |
required |
size
|
ndarray
|
The size of the FoV. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The FOV mask and the index array for the subset of |
...
|
unique coordinates cropped to the visual field. |
is_notebook()
Determine if the caller is running in a Jupyter notebook.
Credit: https://stackoverflow.com/a/39662359/4639195.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool | None
|
True if running in a notebook. |
make_substrate(height, width, step=1)
Create a Cartesian coordinate mesh with all possible combinations of widths and heights (= columns and rows). These are the coordinates of all the pixels in the raw input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
height
|
int
|
Substrate height. |
required |
width
|
int
|
Substrate width. |
required |
step
|
int
|
Grid step (defines the coarseness of the mesh). |
1
|
Returns:
| Type | Description |
|---|---|
ndarray
|
A substrate with the specified coarseness. |
mkdir(path)
Create a directory if it doesn't exist and return the resolved and expanded path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
A directory as a path or a string. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
The resolved and expanded path. |
timestamp(ms=False, split=False)
Create a datestamp and a timestamp as formatted strings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ms
|
bool
|
Use millisecond precision. |
False
|
split
|
bool
|
Split the string into date and time components. |
False
|
Returns:
| Type | Description |
|---|---|
str | tuple[str, str]
|
The formatted date and time. |
to_rgba(colour)
Convert a colour specified as HEX into RGBA (a 4-tuple).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
colour
|
str | Iterable
|
The colour specified as a HEX string or an iterable. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The RGBA values of the colour. |