PyOPIA 2.4.5__tar.gz → 2.4.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pyopia-2.4.5 → pyopia-2.4.7}/PKG-INFO +5 -1
- {pyopia-2.4.5 → pyopia-2.4.7}/README.md +4 -0
- pyopia-2.4.7/pyopia/__init__.py +1 -0
- {pyopia-2.4.5 → pyopia-2.4.7}/pyopia/instrument/silcam.py +81 -9
- {pyopia-2.4.5 → pyopia-2.4.7}/pyopia/io.py +33 -6
- pyopia-2.4.5/pyopia/__init__.py +0 -1
- {pyopia-2.4.5 → pyopia-2.4.7}/LICENSE +0 -0
- {pyopia-2.4.5 → pyopia-2.4.7}/pyopia/background.py +0 -0
- {pyopia-2.4.5 → pyopia-2.4.7}/pyopia/classify.py +0 -0
- {pyopia-2.4.5 → pyopia-2.4.7}/pyopia/cli.py +0 -0
- {pyopia-2.4.5 → pyopia-2.4.7}/pyopia/exampledata.py +0 -0
- {pyopia-2.4.5 → pyopia-2.4.7}/pyopia/instrument/__init__.py +0 -0
- {pyopia-2.4.5 → pyopia-2.4.7}/pyopia/instrument/common.py +0 -0
- {pyopia-2.4.5 → pyopia-2.4.7}/pyopia/instrument/holo.py +0 -0
- {pyopia-2.4.5 → pyopia-2.4.7}/pyopia/instrument/uvp.py +0 -0
- {pyopia-2.4.5 → pyopia-2.4.7}/pyopia/pipeline.py +0 -0
- {pyopia-2.4.5 → pyopia-2.4.7}/pyopia/plotting.py +0 -0
- {pyopia-2.4.5 → pyopia-2.4.7}/pyopia/process.py +0 -0
- {pyopia-2.4.5 → pyopia-2.4.7}/pyopia/simulator/__init__.py +0 -0
- {pyopia-2.4.5 → pyopia-2.4.7}/pyopia/simulator/silcam.py +0 -0
- {pyopia-2.4.5 → pyopia-2.4.7}/pyopia/statistics.py +0 -0
- {pyopia-2.4.5 → pyopia-2.4.7}/pyopia/tests/__init__.py +0 -0
- {pyopia-2.4.5 → pyopia-2.4.7}/pyopia/tests/test_classify.py +0 -0
- {pyopia-2.4.5 → pyopia-2.4.7}/pyopia/tests/test_notebooks.py +0 -0
- {pyopia-2.4.5 → pyopia-2.4.7}/pyopia/tests/test_pipeline.py +0 -0
- {pyopia-2.4.5 → pyopia-2.4.7}/pyproject.toml +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: PyOPIA
|
|
3
|
-
Version: 2.4.
|
|
3
|
+
Version: 2.4.7
|
|
4
4
|
Summary: A Python Ocean Particle Image Analysis toolbox.
|
|
5
5
|
Home-page: https://github.com/sintef/pyopia
|
|
6
6
|
Keywords: Ocean,Particles,Imaging,Measurement,Size distribution
|
|
@@ -91,6 +91,10 @@ We welcome additions and improvements to the code! We request that you follow a
|
|
|
91
91
|
4. All pull requests must be reviewed by a person. The benefits from code review are plenty, but we like to emphasise that code reviews help spreading the awarenes of code changes. Please note that code reviews should be a pleasant experience, so be plesant, polite and remember that there is a human being with good intentions on the other side of the screen.
|
|
92
92
|
5. All contributions are linted with flake8. We recommend that you run flake8 on your code while developing to fix any issues as you go. We recommend using autopep8 to autoformat your Python code (but please check the code behaviour is not affected by autoformatting before pushing). This makes flake8 happy, and makes it easier for us all to maintain a consistent and readable code base.
|
|
93
93
|
|
|
94
|
+
## Docstrings
|
|
95
|
+
|
|
96
|
+
Use the NumPy style in docstrings. See style guide [here](https://numpydoc.readthedocs.io/en/latest/format.html#documenting-classes)
|
|
97
|
+
|
|
94
98
|
# Installing
|
|
95
99
|
|
|
96
100
|
## For users
|
|
@@ -41,6 +41,10 @@ We welcome additions and improvements to the code! We request that you follow a
|
|
|
41
41
|
4. All pull requests must be reviewed by a person. The benefits from code review are plenty, but we like to emphasise that code reviews help spreading the awarenes of code changes. Please note that code reviews should be a pleasant experience, so be plesant, polite and remember that there is a human being with good intentions on the other side of the screen.
|
|
42
42
|
5. All contributions are linted with flake8. We recommend that you run flake8 on your code while developing to fix any issues as you go. We recommend using autopep8 to autoformat your Python code (but please check the code behaviour is not affected by autoformatting before pushing). This makes flake8 happy, and makes it easier for us all to maintain a consistent and readable code base.
|
|
43
43
|
|
|
44
|
+
## Docstrings
|
|
45
|
+
|
|
46
|
+
Use the NumPy style in docstrings. See style guide [here](https://numpydoc.readthedocs.io/en/latest/format.html#documenting-classes)
|
|
47
|
+
|
|
44
48
|
# Installing
|
|
45
49
|
|
|
46
50
|
## For users
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = '2.4.7'
|
|
@@ -6,6 +6,7 @@ import os
|
|
|
6
6
|
import numpy as np
|
|
7
7
|
import pandas as pd
|
|
8
8
|
from skimage.exposure import rescale_intensity
|
|
9
|
+
import skimage.io
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
def timestamp_from_filename(filename):
|
|
@@ -25,8 +26,35 @@ def timestamp_from_filename(filename):
|
|
|
25
26
|
return timestamp
|
|
26
27
|
|
|
27
28
|
|
|
28
|
-
def
|
|
29
|
-
'''load a .
|
|
29
|
+
def load_mono8(filename):
|
|
30
|
+
'''load a mono8 .msilc file from disc
|
|
31
|
+
|
|
32
|
+
Assumes 8-bit mono image in range 0-255
|
|
33
|
+
|
|
34
|
+
Parameters
|
|
35
|
+
----------
|
|
36
|
+
filename : string
|
|
37
|
+
filename to load
|
|
38
|
+
|
|
39
|
+
Returns
|
|
40
|
+
-------
|
|
41
|
+
array
|
|
42
|
+
raw image float between 0-1
|
|
43
|
+
'''
|
|
44
|
+
im_mono = np.load(filename, allow_pickle=False).astype(np.float64) / 255
|
|
45
|
+
image_shape = np.shape(im_mono)
|
|
46
|
+
if len(image_shape) > 2:
|
|
47
|
+
if image_shape[2] == 1:
|
|
48
|
+
img = im_mono[:, :, 0]
|
|
49
|
+
else:
|
|
50
|
+
raise RuntimeError('Invalid image dimension')
|
|
51
|
+
return img
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def load_rgb8(filename):
|
|
55
|
+
'''load an RGB .silc file from disc
|
|
56
|
+
|
|
57
|
+
Assumes 8-bit RGB image in range 0-255
|
|
30
58
|
|
|
31
59
|
Parameters
|
|
32
60
|
----------
|
|
@@ -42,15 +70,47 @@ def load_image(filename):
|
|
|
42
70
|
return img
|
|
43
71
|
|
|
44
72
|
|
|
73
|
+
def load_image(filename):
|
|
74
|
+
'''.. deprecated:: 2.4.6
|
|
75
|
+
:func:`pyopia.instrument.silcam.load_image` will be removed in version 3.0.0, it is replaced by
|
|
76
|
+
:func:`pyopia.instrument.silcam.load_rgb8` because this is more explicit to that image type.
|
|
77
|
+
|
|
78
|
+
Load an RGB .silc file from disc
|
|
79
|
+
|
|
80
|
+
Parameters
|
|
81
|
+
----------
|
|
82
|
+
filename : string
|
|
83
|
+
filename to load
|
|
84
|
+
|
|
85
|
+
Returns
|
|
86
|
+
-------
|
|
87
|
+
array
|
|
88
|
+
raw image float between 0-1
|
|
89
|
+
'''
|
|
90
|
+
|
|
91
|
+
return load_rgb8(filename)
|
|
92
|
+
|
|
93
|
+
|
|
45
94
|
class SilCamLoad():
|
|
46
95
|
'''PyOpia pipline-compatible class for loading a single silcam image
|
|
47
|
-
using :func:`pyopia.instrument.silcam.load_image`
|
|
48
96
|
and extracting the timestamp using
|
|
49
97
|
:func:`pyopia.instrument.silcam.timestamp_from_filename`
|
|
50
98
|
|
|
51
99
|
Required keys in :class:`pyopia.pipeline.Data`:
|
|
52
100
|
- :attr:`pyopia.pipeline.Data.filename`
|
|
53
101
|
|
|
102
|
+
Parameters
|
|
103
|
+
----------
|
|
104
|
+
image_format : str, optional
|
|
105
|
+
Image file format. Can be either 'infer', 'rgb8' or 'mono8', by default 'infer'.
|
|
106
|
+
|
|
107
|
+
Note
|
|
108
|
+
----
|
|
109
|
+
'infer' uses the file extension to determine the image format using the following convention:
|
|
110
|
+
- '.silc' for RGB8
|
|
111
|
+
- '.msilc' for MONO8
|
|
112
|
+
- '.bmp' for using skimage.io.imread
|
|
113
|
+
|
|
54
114
|
Returns
|
|
55
115
|
-------
|
|
56
116
|
data : :class:`pyopia.pipeline.Data`
|
|
@@ -61,16 +121,28 @@ class SilCamLoad():
|
|
|
61
121
|
:attr:`pyopia.pipeline.Data.img`
|
|
62
122
|
'''
|
|
63
123
|
|
|
64
|
-
def __init__(self):
|
|
65
|
-
|
|
124
|
+
def __init__(self, image_format='infer'):
|
|
125
|
+
self.image_format = image_format
|
|
126
|
+
self.extension_load = {'.silc': load_rgb8,
|
|
127
|
+
'.msilc': load_mono8,
|
|
128
|
+
'.bmp': skimage.io.imread}
|
|
129
|
+
self.format_load = {'RGB8': load_rgb8,
|
|
130
|
+
'MONO8': load_mono8}
|
|
66
131
|
|
|
67
132
|
def __call__(self, data):
|
|
68
|
-
timestamp = timestamp_from_filename(data['filename'])
|
|
69
|
-
|
|
70
|
-
data['timestamp'] = timestamp
|
|
71
|
-
data['imraw'] = img
|
|
133
|
+
data['timestamp'] = timestamp_from_filename(data['filename'])
|
|
134
|
+
data['imraw'] = self.load_image(data['filename'])
|
|
72
135
|
return data
|
|
73
136
|
|
|
137
|
+
def load_image(self, filename):
|
|
138
|
+
if self.image_format == 'infer':
|
|
139
|
+
file_extension = os.path.splitext(os.path.basename(filename))[-1]
|
|
140
|
+
load_function = self.extension_load[file_extension]
|
|
141
|
+
else:
|
|
142
|
+
load_function = self.format_load[self.image_format]
|
|
143
|
+
img = load_function(filename)
|
|
144
|
+
return img
|
|
145
|
+
|
|
74
146
|
|
|
75
147
|
class ImagePrep():
|
|
76
148
|
'''PyOpia pipline-compatible class for preparing silcam images for further analysis
|
|
@@ -85,14 +85,39 @@ def write_stats(stats,
|
|
|
85
85
|
elif not append:
|
|
86
86
|
datafilename += ('-Image-D' +
|
|
87
87
|
str(xstats['timestamp'][0].values).replace('-', '').replace(':', '').replace('.', '-'))
|
|
88
|
-
encoding =
|
|
88
|
+
encoding = setup_xstats_encoding(xstats)
|
|
89
89
|
xstats.to_netcdf(datafilename + '-STATS.nc', encoding=encoding, engine=NETCDF_ENGINE, format='NETCDF4')
|
|
90
90
|
|
|
91
|
-
# If we have image statistics, add
|
|
91
|
+
# If we have image statistics (summary data for each raw image), add the image_stats a group
|
|
92
92
|
if image_stats is not None:
|
|
93
93
|
image_stats.to_xarray().to_netcdf(datafilename + '-STATS.nc', group='image_stats', mode='a', engine=NETCDF_ENGINE)
|
|
94
94
|
|
|
95
95
|
|
|
96
|
+
def setup_xstats_encoding(xstats, string_vars=['export name', 'holo_filename']):
|
|
97
|
+
'''Setup encoding for writing to NetCDF, where string variables are explicitly defined as string types
|
|
98
|
+
|
|
99
|
+
Notes
|
|
100
|
+
-----
|
|
101
|
+
Setting up encoding like this for xstats is needed because default behaviour is to set everything as float if there is no
|
|
102
|
+
value, so in a situation where the first image contains no particles we must ensure that string variables are set as string
|
|
103
|
+
types.
|
|
104
|
+
|
|
105
|
+
Parameters
|
|
106
|
+
----------
|
|
107
|
+
xstats : xarray.Dataset
|
|
108
|
+
Xarray version of stats dataframe, including metadata
|
|
109
|
+
string_vars : list, optional
|
|
110
|
+
list of string columns in xstats, by default ['export name', 'holo_filename']
|
|
111
|
+
|
|
112
|
+
Returns
|
|
113
|
+
-------
|
|
114
|
+
encoding : dict
|
|
115
|
+
'encoding' input argument to be given to xstats.to_netcdf()
|
|
116
|
+
'''
|
|
117
|
+
encoding = {k: {'dtype': 'str'} for k in string_vars if k in xstats.data_vars}
|
|
118
|
+
return encoding
|
|
119
|
+
|
|
120
|
+
|
|
96
121
|
def make_xstats(stats, toml_steps):
|
|
97
122
|
'''Converts a stats dataframe into xarray DataSet, with metadata
|
|
98
123
|
|
|
@@ -225,10 +250,12 @@ def merge_and_save_mfdataset(path_to_data, prefix='*'):
|
|
|
225
250
|
output_name = os.path.join(path_to_data, prefix_out)
|
|
226
251
|
|
|
227
252
|
logging.info(f'writing {output_name}')
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
253
|
+
# save the particle statistics (xstats) to NetCDF
|
|
254
|
+
encoding = setup_xstats_encoding(xstats)
|
|
255
|
+
xstats.to_netcdf(output_name + '-STATS.nc', encoding=encoding, engine=NETCDF_ENGINE, format='NETCDF4')
|
|
256
|
+
# if summary data for each raw image are available (image_stats), save this into the image_stats group
|
|
257
|
+
if image_stats is not None:
|
|
258
|
+
image_stats.to_netcdf(output_name + '-STATS.nc', group='image_stats', mode='a', engine=NETCDF_ENGINE)
|
|
232
259
|
logging.info(f'writing {output_name} done.')
|
|
233
260
|
|
|
234
261
|
|
pyopia-2.4.5/pyopia/__init__.py
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = '2.4.5'
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|