DiaModality 0.1.4__tar.gz → 0.1.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.
- {diamodality-0.1.4/src/DiaModality.egg-info → diamodality-0.1.7}/PKG-INFO +161 -155
- {diamodality-0.1.4 → diamodality-0.1.7}/README.md +12 -6
- {diamodality-0.1.4 → diamodality-0.1.7}/pyproject.toml +34 -34
- {diamodality-0.1.4 → diamodality-0.1.7}/setup.cfg +4 -4
- {diamodality-0.1.4 → diamodality-0.1.7}/src/DiaModality/CsvParser.py +77 -77
- {diamodality-0.1.4 → diamodality-0.1.7}/src/DiaModality/ModalityPlot.py +344 -344
- {diamodality-0.1.4 → diamodality-0.1.7}/src/DiaModality/__init__.py +2 -2
- {diamodality-0.1.4 → diamodality-0.1.7}/src/DiaModality/__main__.py +4 -4
- diamodality-0.1.7/src/DiaModality/_version.py +1 -0
- {diamodality-0.1.4 → diamodality-0.1.7/src/DiaModality.egg-info}/PKG-INFO +161 -155
- diamodality-0.1.4/src/DiaModality/_version.py +0 -1
- {diamodality-0.1.4 → diamodality-0.1.7}/LICENSE +0 -0
- {diamodality-0.1.4 → diamodality-0.1.7}/MANIFEST.in +0 -0
- {diamodality-0.1.4 → diamodality-0.1.7}/src/DiaModality.egg-info/SOURCES.txt +0 -0
- {diamodality-0.1.4 → diamodality-0.1.7}/src/DiaModality.egg-info/dependency_links.txt +0 -0
- {diamodality-0.1.4 → diamodality-0.1.7}/src/DiaModality.egg-info/requires.txt +0 -0
- {diamodality-0.1.4 → diamodality-0.1.7}/src/DiaModality.egg-info/top_level.txt +0 -0
|
@@ -1,155 +1,161 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: DiaModality
|
|
3
|
-
Version: 0.1.
|
|
4
|
-
Summary: Tool to plot modality vector diagrams
|
|
5
|
-
Author-email: konung-yaropolk <yaropolk1995@gmail.com>
|
|
6
|
-
License: MIT License
|
|
7
|
-
|
|
8
|
-
Copyright (c) 2024 konung-yaropolk
|
|
9
|
-
|
|
10
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
-
in the Software without restriction, including without limitation the rights
|
|
13
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
-
furnished to do so, subject to the following conditions:
|
|
16
|
-
|
|
17
|
-
The above copyright notice and this permission notice shall be included in all
|
|
18
|
-
copies or substantial portions of the Software.
|
|
19
|
-
|
|
20
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
-
SOFTWARE.
|
|
27
|
-
Project-URL: Homepage, https://github.com/konung-yaropolk/DiaModality
|
|
28
|
-
Project-URL: Issues, https://github.com/konung-yaropolk/DiaModality/issues
|
|
29
|
-
Keywords: Visualization,Plotting,Matplotlib
|
|
30
|
-
Classifier: Programming Language :: Python :: 3
|
|
31
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
32
|
-
Classifier: Operating System :: OS Independent
|
|
33
|
-
Classifier: Development Status :: 4 - Beta
|
|
34
|
-
Classifier: Intended Audience :: Science/Research
|
|
35
|
-
Classifier: Natural Language :: English
|
|
36
|
-
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
37
|
-
Requires-Python: >=3.10
|
|
38
|
-
Description-Content-Type: text/markdown
|
|
39
|
-
License-File: LICENSE
|
|
40
|
-
Requires-Dist: numpy
|
|
41
|
-
Requires-Dist: matplotlib
|
|
42
|
-
|
|
43
|
-
# DiaModality - The Modality Diagram
|
|
44
|
-
|
|
45
|
-
Simple tool to plot vector modality diagram
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
'
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: DiaModality
|
|
3
|
+
Version: 0.1.7
|
|
4
|
+
Summary: Tool to plot modality vector diagrams
|
|
5
|
+
Author-email: konung-yaropolk <yaropolk1995@gmail.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2024 konung-yaropolk
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
Project-URL: Homepage, https://github.com/konung-yaropolk/DiaModality
|
|
28
|
+
Project-URL: Issues, https://github.com/konung-yaropolk/DiaModality/issues
|
|
29
|
+
Keywords: Visualization,Plotting,Matplotlib
|
|
30
|
+
Classifier: Programming Language :: Python :: 3
|
|
31
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
32
|
+
Classifier: Operating System :: OS Independent
|
|
33
|
+
Classifier: Development Status :: 4 - Beta
|
|
34
|
+
Classifier: Intended Audience :: Science/Research
|
|
35
|
+
Classifier: Natural Language :: English
|
|
36
|
+
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
37
|
+
Requires-Python: >=3.10
|
|
38
|
+
Description-Content-Type: text/markdown
|
|
39
|
+
License-File: LICENSE
|
|
40
|
+
Requires-Dist: numpy
|
|
41
|
+
Requires-Dist: matplotlib
|
|
42
|
+
|
|
43
|
+
# DiaModality - The Modality Diagram
|
|
44
|
+
|
|
45
|
+
Simple tool to plot vector modality diagram
|
|
46
|
+
|
|
47
|
+
[](https://pypi.org/project/diamodality)
|
|
48
|
+
[](https://pypi.org/project/diamodality)
|
|
49
|
+
[](https://pypi.org/project/diamodality)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
### To install package run the command:
|
|
53
|
+
```bash
|
|
54
|
+
pip install diamodality
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
### Example of use:
|
|
59
|
+
See the /demo directory on Git repo or
|
|
60
|
+
create and run the following two files:
|
|
61
|
+
*(file names don't matter)*
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
``generate_sample_data.py``:
|
|
65
|
+
```python
|
|
66
|
+
import csv
|
|
67
|
+
import random
|
|
68
|
+
import os
|
|
69
|
+
|
|
70
|
+
num_rows = 1500
|
|
71
|
+
output_file = 'modality_data.csv'
|
|
72
|
+
|
|
73
|
+
# locate working directory
|
|
74
|
+
script_dir = os.path.dirname(os.path.realpath(__file__))
|
|
75
|
+
file_path = os.path.join(script_dir, output_file)
|
|
76
|
+
|
|
77
|
+
# Open a new CSV file to write the data
|
|
78
|
+
with open(file_path, mode='w', newline='') as file:
|
|
79
|
+
writer = csv.writer(file)
|
|
80
|
+
|
|
81
|
+
# Generate the data
|
|
82
|
+
signal_treshold = 1.5
|
|
83
|
+
for _ in range(num_rows):
|
|
84
|
+
|
|
85
|
+
# generate data columns:
|
|
86
|
+
col1 = random.uniform(0, 2.7)
|
|
87
|
+
col2 = random.uniform(0, 3.3)
|
|
88
|
+
col3 = random.uniform(0, 7.3)
|
|
89
|
+
|
|
90
|
+
# generate binarization columns:
|
|
91
|
+
col4 = 1 if col1 > signal_treshold else ''
|
|
92
|
+
col5 = 1 if col2 > signal_treshold else ''
|
|
93
|
+
col6 = 1 if col3 > signal_treshold else ''
|
|
94
|
+
|
|
95
|
+
writer.writerow([col1, col2, col3, col4, col5, col6])
|
|
96
|
+
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
``plot_sample_data.py``:
|
|
102
|
+
```python
|
|
103
|
+
import DiaModality.CsvParser as csv
|
|
104
|
+
import DiaModality.ModalityPlot as plt
|
|
105
|
+
import os
|
|
106
|
+
|
|
107
|
+
# input files:
|
|
108
|
+
files = ['modality_data.csv']
|
|
109
|
+
|
|
110
|
+
# Get full path
|
|
111
|
+
script_dir = os.path.dirname(os.path.realpath(__file__))
|
|
112
|
+
|
|
113
|
+
for file in files:
|
|
114
|
+
|
|
115
|
+
# Get full path of input files
|
|
116
|
+
file_path = os.path.join(script_dir, file)
|
|
117
|
+
|
|
118
|
+
# Parse data from csv file
|
|
119
|
+
new_csv = csv.LoadCsv(file_path)
|
|
120
|
+
data, binarization = new_csv.ParseCsv(3, 3)
|
|
121
|
+
|
|
122
|
+
# Make figure:
|
|
123
|
+
plot = plt.ModalityPlot(
|
|
124
|
+
data,
|
|
125
|
+
binarization,
|
|
126
|
+
modalities=['Set 1', 'Set 2', 'Set 3'],
|
|
127
|
+
angles=[210, 90, 330],
|
|
128
|
+
labels=False,
|
|
129
|
+
scalecircle=0.5, # Scale circle radius
|
|
130
|
+
scalecircle_linestyle=':',
|
|
131
|
+
scalecircle_linewidth=0.75,
|
|
132
|
+
marker='', # vector endpoints marker
|
|
133
|
+
linestyle='-',
|
|
134
|
+
linewidth=0.5,
|
|
135
|
+
alpha=0.5,
|
|
136
|
+
same_scale=False, # Draw all the subplots in the same scale
|
|
137
|
+
full_center=True, # Draw all vectors in the central subplot,
|
|
138
|
+
# else draw trimodal vectors only
|
|
139
|
+
whole_sum=True, # Calculate all three modality vectors despite binarization
|
|
140
|
+
figsize=(10, 10),
|
|
141
|
+
title='Modality Diagram Example',
|
|
142
|
+
colors=(
|
|
143
|
+
'tab:green', # Set 1 color
|
|
144
|
+
'navy', # Set 2 color
|
|
145
|
+
'tab:red', # Set 3 color
|
|
146
|
+
'#1E88E5', # Sets 1 & 2 intersection color
|
|
147
|
+
'#FF9933', # Sets 1 & 3 intersection color
|
|
148
|
+
'#9900FF', # Sets 2 & 3 intersection color
|
|
149
|
+
'black', # All sets intersection color
|
|
150
|
+
),
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
plot.save(file_path, type='png', transparent=False)
|
|
154
|
+
plot.show()
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Source page:
|
|
158
|
+
https://github.com/konung-yaropolk/DiaModality
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+

|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
# DiaModality - The Modality Diagram
|
|
2
2
|
|
|
3
|
-
Simple tool to plot vector modality diagram
|
|
3
|
+
Simple tool to plot vector modality diagram
|
|
4
|
+
|
|
5
|
+
[](https://pypi.org/project/diamodality)
|
|
6
|
+
[](https://pypi.org/project/diamodality)
|
|
7
|
+
[](https://pypi.org/project/diamodality)
|
|
8
|
+
|
|
4
9
|
|
|
5
10
|
### To install package run the command:
|
|
6
11
|
```bash
|
|
@@ -8,9 +13,10 @@ pip install diamodality
|
|
|
8
13
|
```
|
|
9
14
|
|
|
10
15
|
|
|
11
|
-
###
|
|
16
|
+
### Example of use:
|
|
12
17
|
See the /demo directory on Git repo or
|
|
13
|
-
create and run the following two files:
|
|
18
|
+
create and run the following two files:
|
|
19
|
+
*(file names don't matter)*
|
|
14
20
|
|
|
15
21
|
---
|
|
16
22
|
``generate_sample_data.py``:
|
|
@@ -75,8 +81,7 @@ for file in files:
|
|
|
75
81
|
plot = plt.ModalityPlot(
|
|
76
82
|
data,
|
|
77
83
|
binarization,
|
|
78
|
-
modalities=[
|
|
79
|
-
'Set 1', 'Set 2', 'Set 3'],
|
|
84
|
+
modalities=['Set 1', 'Set 2', 'Set 3'],
|
|
80
85
|
angles=[210, 90, 330],
|
|
81
86
|
labels=False,
|
|
82
87
|
scalecircle=0.5, # Scale circle radius
|
|
@@ -87,7 +92,8 @@ for file in files:
|
|
|
87
92
|
linewidth=0.5,
|
|
88
93
|
alpha=0.5,
|
|
89
94
|
same_scale=False, # Draw all the subplots in the same scale
|
|
90
|
-
full_center=True, # Draw all vectors in the central subplot,
|
|
95
|
+
full_center=True, # Draw all vectors in the central subplot,
|
|
96
|
+
# else draw trimodal vectors only
|
|
91
97
|
whole_sum=True, # Calculate all three modality vectors despite binarization
|
|
92
98
|
figsize=(10, 10),
|
|
93
99
|
title='Modality Diagram Example',
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
[build-system]
|
|
2
|
-
requires = ["setuptools>=61.0"]
|
|
3
|
-
build-backend = "setuptools.build_meta"
|
|
4
|
-
|
|
5
|
-
[project]
|
|
6
|
-
name = "DiaModality"
|
|
7
|
-
dynamic = ["version"]
|
|
8
|
-
license = {file = "LICENSE"}
|
|
9
|
-
authors = [
|
|
10
|
-
{ name="konung-yaropolk", email="yaropolk1995@gmail.com" },
|
|
11
|
-
]
|
|
12
|
-
description = "Tool to plot modality vector diagrams"
|
|
13
|
-
keywords = ["Visualization", "Plotting", "Matplotlib"]
|
|
14
|
-
readme = "README.md"
|
|
15
|
-
requires-python = ">=3.10"
|
|
16
|
-
classifiers = [
|
|
17
|
-
"Programming Language :: Python :: 3",
|
|
18
|
-
"License :: OSI Approved :: MIT License",
|
|
19
|
-
"Operating System :: OS Independent",
|
|
20
|
-
"Development Status :: 4 - Beta",
|
|
21
|
-
"Intended Audience :: Science/Research",
|
|
22
|
-
"Natural Language :: English",
|
|
23
|
-
"Topic :: Scientific/Engineering :: Visualization",
|
|
24
|
-
]
|
|
25
|
-
dependencies = [
|
|
26
|
-
"numpy",
|
|
27
|
-
"matplotlib",
|
|
28
|
-
]
|
|
29
|
-
|
|
30
|
-
[project.urls]
|
|
31
|
-
Homepage = "https://github.com/konung-yaropolk/DiaModality"
|
|
32
|
-
Issues = "https://github.com/konung-yaropolk/DiaModality/issues"
|
|
33
|
-
|
|
34
|
-
[tool.setuptools.dynamic]
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "DiaModality"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
license = {file = "LICENSE"}
|
|
9
|
+
authors = [
|
|
10
|
+
{ name="konung-yaropolk", email="yaropolk1995@gmail.com" },
|
|
11
|
+
]
|
|
12
|
+
description = "Tool to plot modality vector diagrams"
|
|
13
|
+
keywords = ["Visualization", "Plotting", "Matplotlib"]
|
|
14
|
+
readme = "README.md"
|
|
15
|
+
requires-python = ">=3.10"
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"License :: OSI Approved :: MIT License",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
"Development Status :: 4 - Beta",
|
|
21
|
+
"Intended Audience :: Science/Research",
|
|
22
|
+
"Natural Language :: English",
|
|
23
|
+
"Topic :: Scientific/Engineering :: Visualization",
|
|
24
|
+
]
|
|
25
|
+
dependencies = [
|
|
26
|
+
"numpy",
|
|
27
|
+
"matplotlib",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[project.urls]
|
|
31
|
+
Homepage = "https://github.com/konung-yaropolk/DiaModality"
|
|
32
|
+
Issues = "https://github.com/konung-yaropolk/DiaModality/issues"
|
|
33
|
+
|
|
34
|
+
[tool.setuptools.dynamic]
|
|
35
35
|
version = {attr = "DiaModality.__version__"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[egg_info]
|
|
2
|
-
tag_build =
|
|
3
|
-
tag_date = 0
|
|
4
|
-
|
|
1
|
+
[egg_info]
|
|
2
|
+
tag_build =
|
|
3
|
+
tag_date = 0
|
|
4
|
+
|
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
|
-
import csv
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
class LoadCsv:
|
|
6
|
-
'''
|
|
7
|
-
The input CSV file must be comma delimited and contains only numeric
|
|
8
|
-
data or empty cells. Each empty cell concideres as None.
|
|
9
|
-
'''
|
|
10
|
-
|
|
11
|
-
def __init__(self, file_path: str) -> None:
|
|
12
|
-
self.file_path = file_path
|
|
13
|
-
|
|
14
|
-
def ParseCsv(self, *args) -> list:
|
|
15
|
-
'''
|
|
16
|
-
The input is a list of integers.
|
|
17
|
-
Output is list of matrices.
|
|
18
|
-
Each int represent each output matrix and defines
|
|
19
|
-
how many columns to include into matrix.
|
|
20
|
-
Eg: input: (3, 2)
|
|
21
|
-
output: list of two matrices, first one with 1-3 cols
|
|
22
|
-
and second one with 4-5 cols from the original csv.
|
|
23
|
-
'''
|
|
24
|
-
|
|
25
|
-
with open(self.file_path, 'r') as file:
|
|
26
|
-
reader = csv.reader(file)
|
|
27
|
-
table = tuple(reader)
|
|
28
|
-
output = []
|
|
29
|
-
|
|
30
|
-
for i, arg in enumerate(args):
|
|
31
|
-
|
|
32
|
-
output.append([])
|
|
33
|
-
start = sum(args) - sum(args[i:])
|
|
34
|
-
stop = start + arg
|
|
35
|
-
|
|
36
|
-
for row in table:
|
|
37
|
-
output[i].append(
|
|
38
|
-
tuple(
|
|
39
|
-
float(cell) if cell
|
|
40
|
-
else None
|
|
41
|
-
for cell in row[start:stop]
|
|
42
|
-
)
|
|
43
|
-
)
|
|
44
|
-
|
|
45
|
-
return output
|
|
46
|
-
|
|
47
|
-
def ParseCsv_old(self) -> list:
|
|
48
|
-
'''
|
|
49
|
-
Ugly legacy method specific for modality plot only
|
|
50
|
-
to be removed if new one works well
|
|
51
|
-
'''
|
|
52
|
-
with open(self.file_path, 'r') as file:
|
|
53
|
-
reader = csv.reader(file)
|
|
54
|
-
data, binarization = [], []
|
|
55
|
-
for row in reader:
|
|
56
|
-
data.append(
|
|
57
|
-
tuple(
|
|
58
|
-
float(cell)
|
|
59
|
-
if cell
|
|
60
|
-
else 0
|
|
61
|
-
for cell in row[:3]
|
|
62
|
-
)
|
|
63
|
-
)
|
|
64
|
-
binarization.append(
|
|
65
|
-
tuple(
|
|
66
|
-
True
|
|
67
|
-
if cell
|
|
68
|
-
else False
|
|
69
|
-
for cell in row[3:6]
|
|
70
|
-
)
|
|
71
|
-
)
|
|
72
|
-
|
|
73
|
-
return data, binarization
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if __name__ == '__main__':
|
|
77
|
-
print('\nThis script can be used as an imported module only\n')
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
import csv
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class LoadCsv:
|
|
6
|
+
'''
|
|
7
|
+
The input CSV file must be comma delimited and contains only numeric
|
|
8
|
+
data or empty cells. Each empty cell concideres as None.
|
|
9
|
+
'''
|
|
10
|
+
|
|
11
|
+
def __init__(self, file_path: str) -> None:
|
|
12
|
+
self.file_path = file_path
|
|
13
|
+
|
|
14
|
+
def ParseCsv(self, *args) -> list:
|
|
15
|
+
'''
|
|
16
|
+
The input is a list of integers.
|
|
17
|
+
Output is list of matrices.
|
|
18
|
+
Each int represent each output matrix and defines
|
|
19
|
+
how many columns to include into matrix.
|
|
20
|
+
Eg: input: (3, 2)
|
|
21
|
+
output: list of two matrices, first one with 1-3 cols
|
|
22
|
+
and second one with 4-5 cols from the original csv.
|
|
23
|
+
'''
|
|
24
|
+
|
|
25
|
+
with open(self.file_path, 'r') as file:
|
|
26
|
+
reader = csv.reader(file)
|
|
27
|
+
table = tuple(reader)
|
|
28
|
+
output = []
|
|
29
|
+
|
|
30
|
+
for i, arg in enumerate(args):
|
|
31
|
+
|
|
32
|
+
output.append([])
|
|
33
|
+
start = sum(args) - sum(args[i:])
|
|
34
|
+
stop = start + arg
|
|
35
|
+
|
|
36
|
+
for row in table:
|
|
37
|
+
output[i].append(
|
|
38
|
+
tuple(
|
|
39
|
+
float(cell) if cell
|
|
40
|
+
else None
|
|
41
|
+
for cell in row[start:stop]
|
|
42
|
+
)
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
return output
|
|
46
|
+
|
|
47
|
+
def ParseCsv_old(self) -> list:
|
|
48
|
+
'''
|
|
49
|
+
Ugly legacy method specific for modality plot only
|
|
50
|
+
to be removed if new one works well
|
|
51
|
+
'''
|
|
52
|
+
with open(self.file_path, 'r') as file:
|
|
53
|
+
reader = csv.reader(file)
|
|
54
|
+
data, binarization = [], []
|
|
55
|
+
for row in reader:
|
|
56
|
+
data.append(
|
|
57
|
+
tuple(
|
|
58
|
+
float(cell)
|
|
59
|
+
if cell
|
|
60
|
+
else 0
|
|
61
|
+
for cell in row[:3]
|
|
62
|
+
)
|
|
63
|
+
)
|
|
64
|
+
binarization.append(
|
|
65
|
+
tuple(
|
|
66
|
+
True
|
|
67
|
+
if cell
|
|
68
|
+
else False
|
|
69
|
+
for cell in row[3:6]
|
|
70
|
+
)
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
return data, binarization
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
if __name__ == '__main__':
|
|
77
|
+
print('\nThis script can be used as an imported module only\n')
|