forked from Plastic-Scanner/PSplot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper_functions.py
More file actions
29 lines (20 loc) · 878 Bytes
/
Copy pathhelper_functions.py
File metadata and controls
29 lines (20 loc) · 878 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import numpy as np
from numpy.typing import ArrayLike
from typing import List, Union
def normalize(
input_data: List[float],
calibration_data: Union[List[float], ArrayLike],
) -> List[float]:
"""normalizes by dividing by `calibration_data` and also applies SNV_transform"""
input_data = np.asarray(input_data)
calibration_data = np.asarray(calibration_data)
# scale by calibration measurement
data_rescaled = input_data / calibration_data
data_snv = SNV_transform(data_rescaled)
return list(data_snv)
def SNV_transform(data: Union[ArrayLike, List[float]]) -> List[float]:
# the following is an SNV transform
# Subtract the mean and divide by the standarddiviation
return list((np.asarray(data) - np.mean(data)) / np.std(data))
def list_to_string(data: List[float]) -> str:
return " ".join([f"{i:.7f}" for i in data])