PyOPIA 2.2.0__tar.gz → 2.3.0__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyOPIA
3
- Version: 2.2.0
3
+ Version: 2.3.0
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
@@ -0,0 +1 @@
1
+ __version__ = '2.3.0'
@@ -15,6 +15,7 @@ import pandas as pd
15
15
  import pyopia.background
16
16
  import pyopia.instrument.silcam
17
17
  import pyopia.instrument.holo
18
+ import pyopia.instrument.uvp
18
19
  import pyopia.instrument.common
19
20
  import pyopia.io
20
21
  import pyopia.pipeline
@@ -80,7 +81,7 @@ def generate_config(instrument: str, raw_files: str, model_path: str, outfolder:
80
81
  Parameters
81
82
  ----------
82
83
  instrument : str
83
- either `silcam` or `holo`
84
+ either `silcam`, `holo` or `uvp`
84
85
  raw_files : str
85
86
  raw_files
86
87
  model_path : str
@@ -95,6 +96,8 @@ def generate_config(instrument: str, raw_files: str, model_path: str, outfolder:
95
96
  pipeline_config = pyopia.instrument.silcam.generate_config(raw_files, model_path, outfolder, output_prefix)
96
97
  case 'holo':
97
98
  pipeline_config = pyopia.instrument.holo.generate_config(raw_files, model_path, outfolder, output_prefix)
99
+ case 'uvp':
100
+ pipeline_config = pyopia.instrument.uvp.generate_config(raw_files, model_path, outfolder, output_prefix)
98
101
 
99
102
  config_filename = instrument + "-config.toml"
100
103
  with open(config_filename, "w") as toml_file:
@@ -34,9 +34,9 @@ def load_image(filename):
34
34
  Returns
35
35
  -------
36
36
  array
37
- raw image
37
+ raw image float between 0-1
38
38
  '''
39
- img = np.load(filename, allow_pickle=False).astype(np.float64)
39
+ img = np.load(filename, allow_pickle=False).astype(np.float64) / 255
40
40
  return img
41
41
 
42
42
 
@@ -68,7 +68,7 @@ class SilCamLoad():
68
68
 
69
69
  def __call__(self, data):
70
70
  timestamp = timestamp_from_filename(data['filename'])
71
- img = load_image(data['filename']).astype(np.float64)/255
71
+ img = load_image(data['filename'])
72
72
  data['timestamp'] = timestamp
73
73
  data['imraw'] = img
74
74
  return data
@@ -0,0 +1,127 @@
1
+ '''
2
+ Module containing UVP specific tools to enable compatability with the :mod:`pyopia.pipeline`
3
+ '''
4
+
5
+ import os
6
+ import numpy as np
7
+ import pandas as pd
8
+ import skimage.io
9
+
10
+
11
+ def timestamp_from_filename(filename):
12
+ '''get a pandas timestamp from a UVP vignette image filename
13
+
14
+ Args:
15
+ filename (string): UVP filename (.png)
16
+
17
+ Returns:
18
+ timestamp: timestamp from pandas.to_datetime()
19
+ '''
20
+
21
+ # get the timestamp of the image (in this case from the filename)
22
+ timestr = os.path.split(filename)[-1].strip('.png')
23
+ timestamp = pd.to_datetime(timestr)
24
+ return timestamp
25
+
26
+
27
+ def load_image(filename):
28
+ '''load a UVP .png file from disc
29
+
30
+ Parameters
31
+ ----------
32
+ filename : string
33
+ filename to load
34
+
35
+ Returns
36
+ -------
37
+ array
38
+ raw image float between 0-1, inverted so that particles are dark on a light background
39
+ '''
40
+ img_darkfield = skimage.io.imread(filename).astype(np.float64)
41
+ img_inverted = (255 - img_darkfield) / 255
42
+ return img_inverted
43
+
44
+
45
+ class UVPLoad():
46
+ '''PyOpia pipline-compatible class for loading a single UVP image
47
+ using :func:`pyopia.instrument.uvp.load_image`
48
+ and extracting the timestamp using
49
+ :func:`pyopia.instrument.uvp.timestamp_from_filename`
50
+
51
+ Pipeline input data:
52
+ ---------
53
+ :class:`pyopia.pipeline.Data`
54
+ containing the following keys:
55
+
56
+ :attr:`pyopia.pipeline.Data.filename`
57
+
58
+ Returns:
59
+ --------
60
+ :class:`pyopia.pipeline.Data`
61
+ containing the following new keys:
62
+
63
+ :attr:`pyopia.pipeline.Data.timestamp`
64
+
65
+ :attr:`pyopia.pipeline.Data.img`
66
+ '''
67
+
68
+ def __init__(self):
69
+ pass
70
+
71
+ def __call__(self, data):
72
+ timestamp = timestamp_from_filename(data['filename'])
73
+ img = load_image(data['filename'])
74
+ data['timestamp'] = timestamp
75
+ data['imraw'] = img
76
+ return data
77
+
78
+
79
+ def generate_config(raw_files: str, model_path: str, outfolder: str, output_prefix: str):
80
+ '''Generate example uvp config.toml as a dict
81
+
82
+ Parameters
83
+ ----------
84
+ raw_files : str
85
+ raw_files
86
+ model_path : str
87
+ model_path
88
+ outfolder : str
89
+ outfolder
90
+ output_prefix : str
91
+ output_prefix
92
+
93
+ Returns:
94
+ --------
95
+ dict
96
+ pipeline_config toml dict
97
+ '''
98
+ # define the configuration to use in the processing pipeline - given as a dictionary - with some values defined above
99
+ pipeline_config = {
100
+ 'general': {
101
+ 'raw_files': raw_files,
102
+ 'pixel_size': 80 # pixel size in um
103
+ },
104
+ 'steps': {
105
+ 'classifier': {
106
+ 'pipeline_class': 'pyopia.classify.Classify',
107
+ 'model_path': model_path
108
+ },
109
+ 'load': {
110
+ 'pipeline_class': 'pyopia.instrument.uvp.UVPLoad'
111
+ },
112
+ 'segmentation': {
113
+ 'pipeline_class': 'pyopia.process.Segment',
114
+ 'threshold': 0.95,
115
+ 'segment_source': 'imraw'
116
+ },
117
+ 'statextract': {
118
+ 'pipeline_class': 'pyopia.process.CalculateStats',
119
+ 'roi_source': 'imraw'
120
+ },
121
+ 'output': {
122
+ 'pipeline_class': 'pyopia.io.StatsH5',
123
+ 'output_datafile': os.path.join(outfolder, output_prefix)
124
+ }
125
+ }
126
+ }
127
+ return pipeline_config
@@ -1 +0,0 @@
1
- __version__ = '2.2.0'
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