SleePyPhases 0.2.1__tar.gz → 0.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.
Files changed (62) hide show
  1. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/PKG-INFO +1 -1
  2. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/SleePyPhases/MultiScorer.py +8 -0
  3. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/SleePyPhases/phases/Eval.py +4 -10
  4. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/SleePyPhases/phases/EvalReport.py +2 -3
  5. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/SleePyPhases/phases/ExtractFeatures.py +4 -7
  6. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/SleePyPhases/phases/Setup.py +0 -19
  7. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/SleePyPhases.egg-info/PKG-INFO +1 -1
  8. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/SleePyPhases.egg-info/SOURCES.txt +0 -3
  9. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/setup.py +1 -1
  10. sleepyphases-0.2.1/SleePyPhases/recordloaders/MedicalDB.py +0 -124
  11. sleepyphases-0.2.1/SleePyPhases/recordloaders/RecordLoaderTSM.py +0 -34
  12. sleepyphases-0.2.1/tests/unit/__init__.py +0 -0
  13. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/LICENSE +0 -0
  14. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/README.md +0 -0
  15. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/SleePyPhases/DataManipulation.py +0 -0
  16. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/SleePyPhases/EventScorer.py +0 -0
  17. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/SleePyPhases/FeatureExtraction copy.py +0 -0
  18. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/SleePyPhases/FeatureExtraction.py +0 -0
  19. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/SleePyPhases/PSGEventManager.py +0 -0
  20. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/SleePyPhases/Plot.py +0 -0
  21. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/SleePyPhases/Plugin.py +0 -0
  22. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/SleePyPhases/PreManipulation.py +0 -0
  23. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/SleePyPhases/RecordFeatureExtraction.py +0 -0
  24. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/SleePyPhases/Reporter.py +0 -0
  25. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/SleePyPhases/SignalPreprocessing.py +0 -0
  26. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/SleePyPhases/SleepMetaData.py +0 -0
  27. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/SleePyPhases/__init__.py +0 -0
  28. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/SleePyPhases/phases/BuildDataset.py +0 -0
  29. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/SleePyPhases/phases/DataAnalysis.py +0 -0
  30. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/SleePyPhases/phases/DataReport.py +0 -0
  31. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/SleePyPhases/phases/EvalPlotExamples.py +0 -0
  32. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/SleePyPhases/phases/ExportMetadataToMeticalDB.py +0 -0
  33. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/SleePyPhases/phases/Extract.py +0 -0
  34. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/SleePyPhases/phases/ExtractEvents.py +0 -0
  35. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/SleePyPhases/phases/ExtractRecordFeatures.py +0 -0
  36. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/SleePyPhases/phases/GatherMetadata.py +0 -0
  37. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/SleePyPhases/phases/TestRun.py +0 -0
  38. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/SleePyPhases/phases/ThresholdOptimisation.py +0 -0
  39. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/SleePyPhases/phases/Training.py +0 -0
  40. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/SleePyPhases/phases/Validation.py +0 -0
  41. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/SleePyPhases/phases/VisualizeConfig.py +0 -0
  42. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/SleePyPhases/phases/__init__.py +0 -0
  43. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/SleePyPhases.egg-info/dependency_links.txt +0 -0
  44. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/SleePyPhases.egg-info/requires.txt +0 -0
  45. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/SleePyPhases.egg-info/top_level.txt +0 -0
  46. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/pyproject.toml +0 -0
  47. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/setup.cfg +0 -0
  48. {sleepyphases-0.2.1/SleePyPhases/recordloaders → sleepyphases-0.3.0/tests}/__init__.py +0 -0
  49. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/tests/conftest.py +0 -0
  50. {sleepyphases-0.2.1/tests → sleepyphases-0.3.0/tests/unit}/__init__.py +0 -0
  51. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/tests/unit/test_BuildDataset.py +0 -0
  52. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/tests/unit/test_BuildDatasetFolded.py +0 -0
  53. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/tests/unit/test_BuildDatasetSegments.py +0 -0
  54. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/tests/unit/test_DataManipulation.py +0 -0
  55. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/tests/unit/test_Eval.py +0 -0
  56. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/tests/unit/test_EventScorer.py +0 -0
  57. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/tests/unit/test_Extract.py +0 -0
  58. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/tests/unit/test_PreManipulation.py +0 -0
  59. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/tests/unit/test_RecordFeatureExtraction.py +0 -0
  60. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/tests/unit/test_RecordProcessor.py +0 -0
  61. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/tests/unit/test_Setup.py +0 -0
  62. {sleepyphases-0.2.1 → sleepyphases-0.3.0}/tests/unit/test_SignalPreprocessing.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: SleePyPhases
3
- Version: 0.2.1
3
+ Version: 0.3.0
4
4
  Summary: A framwork for creating deep learning pipelines for sleep data
5
5
  Home-page: https://gitlab.com/sleep-is-all-you-need/sleepyphases
6
6
  Author: Franz Ehrlich
@@ -42,19 +42,27 @@ class MultiScorer(Scorer):
42
42
  if isinstance(predictions, list) or isinstance(predictions, tuple):
43
43
  p = predictions[i]
44
44
  elif predictions.shape[-1] == len(self.multiClassNums):
45
+ if len(predictions.shape) == 3:
46
+ predictions = predictions.reshape(-1, predictions.shape[-1])
45
47
  p = predictions[:, i]
46
48
  else:
47
49
  start = sum(self.multiClassNums[:i])
48
50
  end = start + self.multiClassNums[i]
51
+ if len(predictions.shape) == 3:
52
+ predictions = predictions.reshape(-1, predictions.shape[-1])
49
53
  p = predictions[:, start:end]
50
54
 
51
55
  if isinstance(truth, list) or isinstance(truth, tuple):
52
56
  t = truth[i]
53
57
  elif truth.shape[-1] == len(self.multiClassNums):
58
+ if len(truth.shape) == 3:
59
+ truth = truth.reshape(-1, truth.shape[-1])
54
60
  t = truth[:, i]
55
61
  else:
56
62
  start = sum(self.multiClassNums[:i])
57
63
  end = start + self.multiClassNums[i]
64
+ if len(truth.shape) == 3:
65
+ truth = truth.reshape(-1, truth.shape[-1])
58
66
  t = truth[:, start:end]
59
67
 
60
68
 
@@ -81,7 +81,7 @@ class Eval(Phase):
81
81
 
82
82
  # setup data and scorer
83
83
 
84
- classNums = self.getConfig("model.multiclassificationSize", [2])
84
+ classNums = self.getConfig("numClasses", [2])
85
85
  labelNames = self.getConfig("classification.labelNames")
86
86
  ignoreIndex = self.getConfig("classification.ignoreIndex", -1)
87
87
  metrics = self.getConfig("trainingParameter.validationMetrics")
@@ -99,16 +99,10 @@ class Eval(Phase):
99
99
 
100
100
  for data in tqdm(testData):
101
101
  x, truth = data
102
- # make sure to have a batchsize if batchSize == 1
103
- x = x.reshape(batchSize, x.shape[0], x.shape[1])
104
- truth = truth.reshape(batchSize, truth.shape[0], truth.shape[1])
105
102
 
106
- prediction = model.predict(x, get_likelihood=True, returnNumpy=False)
103
+ prediction = model.predict(x, returnNumpy=False)
107
104
  prediction, truth = da((prediction, truth))
108
105
 
109
- # prediction = prediction.reshape(-1, prediction.shape[2])
110
- # truth = truth.reshape(-1, truth.shape[2])
111
-
112
106
  scorer.score(truth, prediction, trace=True)
113
107
 
114
108
  result = scorer.scoreAllRecords()
@@ -152,7 +146,7 @@ class Eval(Phase):
152
146
  self.project.config.update(self.getConfig("eventEval", {}))
153
147
 
154
148
  evalMetrics = self.getConfig("eval.metrics")
155
- classNums = self.getConfig("model.multiclassificationSize", [2])
149
+ classNums = self.getConfig("numClasses", [2])
156
150
  labelNames = self.getConfig("classification.labelNames")
157
151
  predictionNames = self.getConfig("classification.predictionSignals")
158
152
  predictionFrequencies = self.getConfig("classification.predictionFrequencies")
@@ -193,7 +187,7 @@ class Eval(Phase):
193
187
  x = x.reshape([1] + list(x.shape))
194
188
  truth = truth.reshape([1] + list(truth.shape))
195
189
 
196
- prediction = model.predict(x, get_likelihood=True, returnNumpy=False)
190
+ prediction = model.predict(x, returnNumpy=False)
197
191
  prediction, truth = da((prediction, truth))
198
192
 
199
193
  # for labelIndex, labelName in enumerate(recordResults.keys()):
@@ -10,7 +10,6 @@ from pyPhasesRecordloader import RecordSignal, Signal
10
10
 
11
11
  from SleePyPhases import Plot
12
12
  from SleePyPhases.DataManipulation import DataManipulation
13
- from SleePyPhases.Reporter import Reporter
14
13
 
15
14
 
16
15
  class EvalReport(Phase):
@@ -244,8 +243,8 @@ class EvalReport(Phase):
244
243
  def copyRawData(self):
245
244
  modelConfigString = self.project.getDataFromName("modelState").getTagString()
246
245
  trainingLogPath = f"logs/{modelConfigString}/"
247
- shutil.copyfile(trainingLogPath + "log.csv", Reporter.basePath + "training.log")
248
- shutil.copyfile(trainingLogPath + "project.config", Reporter.basePath + "project.json")
246
+ shutil.copyfile(trainingLogPath + "log.csv", self.evalPath + "training.log")
247
+ shutil.copyfile(trainingLogPath + "project.config", self.evalPath + "project.json")
249
248
 
250
249
  def trainingPlot(self, logFile):
251
250
  import matplotlib.pyplot as plt
@@ -209,18 +209,15 @@ class ExtractFeatures(Phase):
209
209
  self.features = None
210
210
  metadata = self.project.getData("metadata", pd.DataFrame)
211
211
  recordIds = metadata["recordId"]
212
+ forceCalculation = self.getConfig("featureExtraction.features", True)
212
213
 
213
214
  reqFeatures = {f["name"]: True for f in self.getConfig("featureExtraction.features", [])}
214
215
 
215
- # groupedRecords = {"pid_202436073": "acq_237478592"}
216
216
  for recordId in tqdm(recordIds.iloc):
217
- # tryToGenerate has no meaning, it is just known to be not in the metadata, so the record will always be recalculated
218
- # self.getData("features", pd.DataFrame, recordId=recordId, tryToGenerate=True, **reqFeatures)
217
+ if forceCalculation:
218
+ # the parameter forced has no meaning, it is just known to be not in the metadata, so the record will always be recalculated
219
+ reqFeatures["forced"] = True # should never be found
219
220
  rows = self.getData("features", pd.DataFrame, recordId=recordId, **reqFeatures)
220
221
  if len(rows) == 0:
221
222
  self.logError(f"no features for {recordId}")
222
223
 
223
-
224
- # get a single feature:
225
- # feat = {"swa": True}
226
- # x = self.getData("features", pd.DataFrame, recordId="shhs1-200002", channel="EEG", **feat)
@@ -4,7 +4,6 @@ from pyPhases import Phase
4
4
  from pyPhasesML import DataversionManager, Scorer
5
5
  from pyPhasesRecordloader import RecordLoader
6
6
 
7
- from SleePyPhases.recordloaders.MedicalDB import MedicalDB
8
7
 
9
8
 
10
9
  class Setup(Phase):
@@ -17,21 +16,6 @@ class Setup(Phase):
17
16
 
18
17
  defaultValidationbatchManipulation = self.getConfig("segmentManipulationEval", self.getConfig("segmentManipulation"))
19
18
  self.setConfig("segmentManipulationEval", defaultValidationbatchManipulation)
20
-
21
- # alice loader
22
- RecordLoader.registerRecordLoader("RecordLoaderTest", "SleePyPhases.recordloaders")
23
- RecordLoader.registerRecordLoader("RecordLoaderTSM", "SleePyPhases.recordloaders")
24
- tsmPath = self.getConfig("tsm-path", False)
25
- if tsmPath is not False:
26
- tsmPath = Path(tsmPath)
27
- self.project.setConfig("loader.tsm.filePath", tsmPath.as_posix())
28
- self.project.setConfig("loader.tsm.dataset.downloader.basePath", tsmPath.as_posix())
29
-
30
- tsmPath = self.getConfig("tsm-domino-path", False)
31
- if tsmPath is not False:
32
- tsmPath = Path(tsmPath)
33
- self.project.setConfig("loader.tsm-domino.filePath", tsmPath.as_posix())
34
- self.project.setConfig("loader.tsm-domino.dataset.downloader.basePath", tsmPath.as_posix())
35
19
 
36
20
  preprocessingConfig = self.getConfig("preprocessing")
37
21
  if "combineChannels" in preprocessingConfig:
@@ -62,9 +46,6 @@ class Setup(Phase):
62
46
  return kappa
63
47
  Scorer.registerMetric("reduceAndKappa", reduceKappa, combineReduceKappa)
64
48
 
65
- MedicalDB.config = self.getConfig("medicalDB", {})
66
-
67
-
68
49
  def getDataVersionManager(self):
69
50
  groupedRecords = self.project.getData("allDBRecordIds", list)
70
51
  seed = self.getConfig("dataversion.seed", None)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: SleePyPhases
3
- Version: 0.2.1
3
+ Version: 0.3.0
4
4
  Summary: A framwork for creating deep learning pipelines for sleep data
5
5
  Home-page: https://gitlab.com/sleep-is-all-you-need/sleepyphases
6
6
  Author: Franz Ehrlich
@@ -40,9 +40,6 @@ SleePyPhases/phases/Training.py
40
40
  SleePyPhases/phases/Validation.py
41
41
  SleePyPhases/phases/VisualizeConfig.py
42
42
  SleePyPhases/phases/__init__.py
43
- SleePyPhases/recordloaders/MedicalDB.py
44
- SleePyPhases/recordloaders/RecordLoaderTSM.py
45
- SleePyPhases/recordloaders/__init__.py
46
43
  tests/__init__.py
47
44
  tests/conftest.py
48
45
  tests/unit/__init__.py
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
5
5
 
6
6
  setuptools.setup(
7
7
  name="SleePyPhases",
8
- version="v0.2.1"[1:],
8
+ version="v0.3.0"[1:],
9
9
  author="Franz Ehrlich",
10
10
  author_email="fehrlichd@gmail.com",
11
11
  description="A framwork for creating deep learning pipelines for sleep data",
@@ -1,124 +0,0 @@
1
- import sys
2
-
3
- from pyPhases.util.Logger import classLogger
4
- from pypika import Table, PostgreSQLQuery as Query
5
- from pypika.queries import QueryBuilder
6
-
7
-
8
- @classLogger
9
- class MedicalDB:
10
- connection = None
11
- client = None
12
- assocCursor = None
13
- _instance = None
14
-
15
- config = {
16
- "user": "root",
17
- "password": "example",
18
- "host": "localhost",
19
- "port": 5432,
20
- "database": "data",
21
- }
22
-
23
- @classmethod
24
- def get(cls) -> "MedicalDB":
25
- if cls._instance is None:
26
- cls._instance = cls.__new__(cls)
27
- cls._instance.connect()
28
- return cls._instance
29
-
30
- def connect(self):
31
-
32
- import psycopg2
33
-
34
- try:
35
- c = MedicalDB.config
36
- conn = psycopg2.connect(
37
- "host=%s port=%i dbname=%s user=%s password=%s"
38
- % (
39
- c["host"],
40
- c["port"],
41
- c["database"],
42
- c["user"],
43
- c["password"],
44
- )
45
- )
46
-
47
- except psycopg2.Error as e:
48
- self.logError(f"Error connecting to Postgres Platform: {e}")
49
- sys.exit(1)
50
- self.conn = conn
51
- self.cursor = conn.cursor()
52
-
53
- def execute(self, sql, **vars):
54
- if isinstance(sql, QueryBuilder):
55
- sql = sql.get_sql()
56
- return self.cursor.execute(sql, **vars)
57
-
58
- def executeAndFetch(self, sql, **vars):
59
- self.execute(sql, **vars)
60
- return self.cursor.fetchall()
61
-
62
- def commit(self):
63
- self.conn.commit()
64
-
65
- def executeAndFetchOne(self, sql, **vars):
66
- self.execute(sql, **vars)
67
- return self.cursor.fetchone()
68
-
69
- def close(self):
70
- if self.connection is not None:
71
- self.connection.close()
72
-
73
- def fillRecordId(self, id):
74
- return id
75
-
76
- def getRecordData(self, recordId):
77
- record = Table("record", schema=self.config["schema"])
78
- patient = Table("patient", schema=self.config["schema"])
79
- medCase = Table("medical_case", schema=self.config["schema"])
80
- q = (
81
- Query.from_(record)
82
- .select(patient.id_patient, record.id_medical_case, record.start, patient.date_of_birth, patient.gender)
83
- .join(medCase).on(record.id_medical_case == medCase.id_medical_case)
84
- .join(patient).on(patient.id_patient == medCase.id_patient)
85
- .where(record.id_record == recordId)
86
- )
87
- row = self.executeAndFetchOne(q)
88
-
89
- if row is None:
90
- return None
91
-
92
- row = list(row)
93
- age = None if row[2] or row[3] is None else row[2] - row[3]
94
- row[3] = age
95
-
96
- return row
97
-
98
- def getDiagnoses(self, recordId):
99
- diag = Table("diagnosis", schema=self.config["schema"])
100
- record = Table("record", schema=self.config["schema"])
101
- medCase = Table("medical_case", schema=self.config["schema"])
102
- q = Query.from_(diag)\
103
- .select("diagnosis_category_id", "diagnosis")\
104
- .join(medCase).on(diag.id_medical_case == medCase.id_medical_case)\
105
- .join(record).on(medCase.id_medical_case == record.id_medical_case)\
106
- .where(record.id_record == recordId)\
107
- .get_sql()
108
-
109
- diagnoses = self.executeAndFetch(q)
110
-
111
- diagnoseCats = {d[0]: d[1] for d in diagnoses}
112
- return diagnoseCats
113
-
114
- def getPSGType(self, recordId):
115
-
116
- record = Table("record", schema=self.config["schema"])
117
- q = (
118
- Query.from_(record)
119
- .select("psg_config")
120
- .where(record.id_record == recordId)
121
- )
122
- r = self.executeAndFetchOne(q)
123
-
124
- return r[0] if bool(r) else ""
@@ -1,34 +0,0 @@
1
- from SleePyPhases.recordloaders.MedicalDB import MedicalDB
2
- from SleepHarmonizer import RecordLoaderAlice
3
-
4
-
5
- class RecordLoaderTSM(RecordLoaderAlice):
6
- config = {}
7
-
8
- def getMetaData(self, recordName):
9
- metadata = super().getMetaData(recordName)
10
- del metadata["patientName"]
11
- del metadata["patientCode"]
12
- del metadata["patientAdd"]
13
- del metadata["technician"]
14
-
15
- db = MedicalDB.get()
16
- row = db.getRecordData(recordName)
17
- diagnoses = db.getDiagnoses(recordName)
18
- metadata["psg_type"] = db.getPSGType(recordName)
19
-
20
- if row is not None:
21
- patient_id, case_id, recordDate, patientAge, gender = row
22
-
23
- metadata["patient"] = patient_id
24
- metadata["case"] = case_id
25
- metadata["age"] = patientAge
26
- metadata["gender"] = gender
27
- metadata["startRecord"] = recordDate
28
-
29
- if diagnoses is not None:
30
- metadata.update(diagnoses)
31
-
32
- db.close()
33
-
34
- return metadata
File without changes
File without changes
File without changes
File without changes