sarapy 3.0.0__tar.gz → 3.1.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.
- {sarapy-3.0.0/sarapy.egg-info → sarapy-3.1.0}/PKG-INFO +31 -12
- {sarapy-3.0.0 → sarapy-3.1.0}/README.md +6 -0
- sarapy-3.1.0/pyproject.toml +47 -0
- {sarapy-3.0.0 → sarapy-3.1.0}/sarapy/dataProcessing/OpsProcessor.py +4 -3
- sarapy-3.1.0/sarapy/mlProcessors/FertilizerTransformer.py +198 -0
- {sarapy-3.0.0 → sarapy-3.1.0}/sarapy/version.py +1 -1
- {sarapy-3.0.0 → sarapy-3.1.0/sarapy.egg-info}/PKG-INFO +31 -12
- {sarapy-3.0.0 → sarapy-3.1.0}/sarapy.egg-info/SOURCES.txt +4 -1
- sarapy-3.1.0/sarapy.egg-info/requires.txt +15 -0
- sarapy-3.1.0/sarapy.egg-info/top_level.txt +5 -0
- sarapy-3.1.0/setup.py +40 -0
- sarapy-3.1.0/test/checking_regresor.py +162 -0
- sarapy-3.1.0/test/probabilidades_test.py +77 -0
- sarapy-3.1.0/test/test_import.py +5 -0
- sarapy-3.0.0/pyproject.toml +0 -21
- sarapy-3.0.0/sarapy/mlProcessors/FertilizerTransformer.py +0 -70
- sarapy-3.0.0/sarapy.egg-info/requires.txt +0 -6
- sarapy-3.0.0/sarapy.egg-info/top_level.txt +0 -1
- sarapy-3.0.0/setup.py +0 -35
- {sarapy-3.0.0 → sarapy-3.1.0}/LICENCE +0 -0
- {sarapy-3.0.0 → sarapy-3.1.0}/sarapy/__init__.py +0 -0
- {sarapy-3.0.0 → sarapy-3.1.0}/sarapy/analysis/FeaturesResume.py +0 -0
- {sarapy-3.0.0 → sarapy-3.1.0}/sarapy/analysis/__init__.py +0 -0
- {sarapy-3.0.0 → sarapy-3.1.0}/sarapy/dataProcessing/GeoProcessor.py +0 -0
- {sarapy-3.0.0 → sarapy-3.1.0}/sarapy/dataProcessing/TLMSensorDataProcessor.py +0 -0
- {sarapy-3.0.0 → sarapy-3.1.0}/sarapy/dataProcessing/TimeSeriesProcessor.py +0 -0
- {sarapy-3.0.0 → sarapy-3.1.0}/sarapy/dataProcessing/__init__.py +0 -0
- {sarapy-3.0.0 → sarapy-3.1.0}/sarapy/mlProcessors/FertilizerFMCreator.py +0 -0
- {sarapy-3.0.0 → sarapy-3.1.0}/sarapy/mlProcessors/PlantinClassifier.py +0 -0
- {sarapy-3.0.0 → sarapy-3.1.0}/sarapy/mlProcessors/PlantinFMCreator.py +0 -0
- {sarapy-3.0.0 → sarapy-3.1.0}/sarapy/mlProcessors/__init__.py +0 -0
- {sarapy-3.0.0 → sarapy-3.1.0}/sarapy/preprocessing/DistancesImputer.py +0 -0
- {sarapy-3.0.0 → sarapy-3.1.0}/sarapy/preprocessing/FertilizerImputer.py +0 -0
- {sarapy-3.0.0 → sarapy-3.1.0}/sarapy/preprocessing/TransformInputData.py +0 -0
- {sarapy-3.0.0 → sarapy-3.1.0}/sarapy/preprocessing/TransformToOutputData.py +0 -0
- {sarapy-3.0.0 → sarapy-3.1.0}/sarapy/preprocessing/__init__.py +0 -0
- {sarapy-3.0.0 → sarapy-3.1.0}/sarapy/stats/__init__.py +0 -0
- {sarapy-3.0.0 → sarapy-3.1.0}/sarapy/stats/stats.py +0 -0
- {sarapy-3.0.0 → sarapy-3.1.0}/sarapy/utils/__init__.py +0 -0
- {sarapy-3.0.0 → sarapy-3.1.0}/sarapy/utils/plotting.py +0 -0
- {sarapy-3.0.0 → sarapy-3.1.0}/sarapy/utils/utils.py +0 -0
- {sarapy-3.0.0 → sarapy-3.1.0}/sarapy.egg-info/dependency_links.txt +0 -0
- {sarapy-3.0.0 → sarapy-3.1.0}/setup.cfg +0 -0
|
@@ -1,24 +1,43 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: sarapy
|
|
3
|
-
Version: 3.
|
|
4
|
-
|
|
5
|
-
Author: Lucas Baldezzari
|
|
3
|
+
Version: 3.1.0
|
|
4
|
+
Summary: Library for Sarapico Metadata processing
|
|
6
5
|
Author-email: Lucas Baldezzari <lmbaldezzari@gmail.com>
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
License: MIT
|
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Operating System :: Microsoft :: Windows :: Windows 10
|
|
10
|
+
Classifier: Operating System :: Microsoft :: Windows :: Windows 11
|
|
11
|
+
Classifier: Operating System :: Unix
|
|
12
|
+
Requires-Python: >=3.9
|
|
9
13
|
Description-Content-Type: text/markdown
|
|
10
14
|
License-File: LICENCE
|
|
11
|
-
Requires-Dist: numpy
|
|
12
|
-
Requires-Dist:
|
|
13
|
-
Requires-Dist:
|
|
14
|
-
Requires-Dist:
|
|
15
|
-
Requires-Dist:
|
|
16
|
-
Requires-Dist:
|
|
15
|
+
Requires-Dist: numpy>=1.23
|
|
16
|
+
Requires-Dist: pandas>=1.5
|
|
17
|
+
Requires-Dist: scipy>=1.9
|
|
18
|
+
Requires-Dist: scikit-learn>=1.2
|
|
19
|
+
Requires-Dist: matplotlib>=3.6
|
|
20
|
+
Requires-Dist: seaborn>=0.12
|
|
21
|
+
Requires-Dist: requests>=2.28
|
|
22
|
+
Requires-Dist: python-dotenv>=1.0
|
|
23
|
+
Requires-Dist: geopy>=2.3
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: pytest; extra == "dev"
|
|
26
|
+
Requires-Dist: black; extra == "dev"
|
|
27
|
+
Requires-Dist: ruff; extra == "dev"
|
|
28
|
+
Requires-Dist: mypy; extra == "dev"
|
|
29
|
+
Dynamic: license-file
|
|
17
30
|
|
|
18
31
|
# SARAPY
|
|
19
32
|
|
|
20
33
|
Library for processing SARAPICO project metadata of _AMG SA_.
|
|
21
34
|
|
|
35
|
+
#### Version 3.1.0
|
|
36
|
+
|
|
37
|
+
- Se actualiza regresor para estimar fertilizante.
|
|
38
|
+
- Actualización de archivos para instalar la libería.
|
|
39
|
+
|
|
40
|
+
|
|
22
41
|
#### Version 3.0.0
|
|
23
42
|
- Se mejora la forma de obtener valores de media movil para todas las variables en las que se usa.
|
|
24
43
|
- Se corrigen bugs debido a nodos con pocas operaciones.
|
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
Library for processing SARAPICO project metadata of _AMG SA_.
|
|
4
4
|
|
|
5
|
+
#### Version 3.1.0
|
|
6
|
+
|
|
7
|
+
- Se actualiza regresor para estimar fertilizante.
|
|
8
|
+
- Actualización de archivos para instalar la libería.
|
|
9
|
+
|
|
10
|
+
|
|
5
11
|
#### Version 3.0.0
|
|
6
12
|
- Se mejora la forma de obtener valores de media movil para todas las variables en las que se usa.
|
|
7
13
|
- Se corrigen bugs debido a nodos con pocas operaciones.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=64", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "sarapy"
|
|
7
|
+
version = "3.1.0"
|
|
8
|
+
description = "Library for Sarapico Metadata processing"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "Lucas Baldezzari", email = "lmbaldezzari@gmail.com" }
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
license = { text = "MIT" }
|
|
17
|
+
|
|
18
|
+
classifiers = [
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Operating System :: Microsoft :: Windows :: Windows 10",
|
|
22
|
+
"Operating System :: Microsoft :: Windows :: Windows 11",
|
|
23
|
+
"Operating System :: Unix",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
dependencies = [
|
|
27
|
+
"numpy>=1.23",
|
|
28
|
+
"pandas>=1.5",
|
|
29
|
+
"scipy>=1.9",
|
|
30
|
+
"scikit-learn>=1.2",
|
|
31
|
+
"matplotlib>=3.6",
|
|
32
|
+
"seaborn>=0.12",
|
|
33
|
+
"requests>=2.28",
|
|
34
|
+
"python-dotenv>=1.0",
|
|
35
|
+
"geopy>=2.3",
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
[project.optional-dependencies]
|
|
39
|
+
dev = [
|
|
40
|
+
"pytest",
|
|
41
|
+
"black",
|
|
42
|
+
"ruff",
|
|
43
|
+
"mypy",
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
[tool.setuptools]
|
|
47
|
+
packages = { find = {} }
|
|
@@ -32,8 +32,8 @@ class OpsProcessor():
|
|
|
32
32
|
self.classifications_probas = None
|
|
33
33
|
plclass_map = {"classifier_file"}
|
|
34
34
|
self._operationsDict = {} ##diccionario de operarios con sus operaciones
|
|
35
|
-
self._platin_classifiedOperations = np.array([]) ##array con las operaciones clasificadas para plantin
|
|
36
|
-
self._fertilizer_classifiedOperations = np.array([]) ##array con las operaciones clasificadas para plantin
|
|
35
|
+
# self._platin_classifiedOperations = np.array([]) ##array con las operaciones clasificadas para plantin
|
|
36
|
+
# self._fertilizer_classifiedOperations = np.array([]) ##array con las operaciones clasificadas para plantin
|
|
37
37
|
self._last_row_db = 0 ##indicador de la última fila de los datos extraidos de la base de datos histórica
|
|
38
38
|
|
|
39
39
|
kwargs_plclass = {}
|
|
@@ -343,7 +343,8 @@ if __name__ == "__main__":
|
|
|
343
343
|
samples = json.load(file)
|
|
344
344
|
|
|
345
345
|
op = OpsProcessor(classifier_file='modelos\\pipeline_rf.pkl',
|
|
346
|
-
regresor_file='modelos\\regresor.pkl', poly_features_file='modelos\\poly_features.pkl',
|
|
346
|
+
# regresor_file='modelos\\regresor.pkl', poly_features_file='modelos\\poly_features.pkl',
|
|
347
|
+
regresor_file='modelos\\regfresor_v2.pkl', poly_features_file='modelos\\poly_features_v2.pkl',
|
|
347
348
|
**kwargs_fmcreator)
|
|
348
349
|
|
|
349
350
|
ops_clasificadas = op.processOperations(samples, **kwargs_classifier)
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import pickle
|
|
2
|
+
import logging
|
|
3
|
+
from sarapy.dataProcessing import TLMSensorDataProcessor
|
|
4
|
+
|
|
5
|
+
class FertilizerTransformer:
|
|
6
|
+
"""
|
|
7
|
+
Clase para tomar los valores de distorsión de fertilizante y transformarlos a gramos
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
def __init__(self, regresor_file, poly_features_file):
|
|
11
|
+
"""Constructor de la clase FertilizerImputer.
|
|
12
|
+
|
|
13
|
+
Args:
|
|
14
|
+
- regresor: Regresor que transforma los valores de distorsión a gramos.
|
|
15
|
+
- poly_features: Grado del polinomio a utilizar en la transformación de los datos.
|
|
16
|
+
"""
|
|
17
|
+
self.logger = logging.getLogger("FertilizerTransformer")
|
|
18
|
+
##cargo el regresor con pickle. Usamos try para capturar el error FileNotFoundError
|
|
19
|
+
try:
|
|
20
|
+
with open(regresor_file, 'rb') as file:
|
|
21
|
+
self._regresor = pickle.load(file)
|
|
22
|
+
self.logger.info("Regresor cargado con éxito.")
|
|
23
|
+
except FileNotFoundError:
|
|
24
|
+
self.logger.error("El archivo no se encuentra en el directorio actual.")
|
|
25
|
+
|
|
26
|
+
##cargo las características polinómicas con pickle. Usamos try para capturar el error FileNotFoundError
|
|
27
|
+
try:
|
|
28
|
+
with open(poly_features_file, 'rb') as file:
|
|
29
|
+
self._poly_features = pickle.load(file)
|
|
30
|
+
self.logger.info("Características polinómicas cargadas con éxito.")
|
|
31
|
+
except FileNotFoundError:
|
|
32
|
+
self.logger.error("El archivo no se encuentra en el directorio actual.")
|
|
33
|
+
|
|
34
|
+
self.fertilizer_grams = None ##cuando no se ha transformado ningún dato, se inicializa en None
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def transform(self, data):
|
|
38
|
+
"""Transforma los datos de distorsión de fertilizante a gramos.
|
|
39
|
+
|
|
40
|
+
Params:
|
|
41
|
+
- data: Es una lista de diccionarios (como un JSON) con los datos de telemetría.
|
|
42
|
+
|
|
43
|
+
Returns:
|
|
44
|
+
- 0: Array con los valores de distorsión de fertilizante transformados a gramos.
|
|
45
|
+
"""
|
|
46
|
+
tlmDataProcessor = TLMSensorDataProcessor.TLMSensorDataProcessor(data)
|
|
47
|
+
X = tlmDataProcessor["SC_FT",:]
|
|
48
|
+
X_poly = self._poly_features.fit_transform(X.reshape(-1, 1))
|
|
49
|
+
self.fertilizer_grams = self._regresor.predict(X_poly)
|
|
50
|
+
|
|
51
|
+
##para valores de distorsión de 13+-0.3 y 15+-0.3, pongo los valores en 8 y 9 gramos, respectivamente
|
|
52
|
+
##uso máscara booleana para encontrar los índices
|
|
53
|
+
mask_13 = (X >= 12.7) & (X <= 13.3)
|
|
54
|
+
mask_15 = (X >= 14.7) & (X <= 15.3)
|
|
55
|
+
self.fertilizer_grams[mask_13] = 8
|
|
56
|
+
self.fertilizer_grams[mask_15] = 9
|
|
57
|
+
|
|
58
|
+
##retorno con shape (n,)
|
|
59
|
+
return self.fertilizer_grams.reshape(-1,)
|
|
60
|
+
|
|
61
|
+
if __name__ == "__main__":
|
|
62
|
+
import pandas as pd
|
|
63
|
+
import numpy as np
|
|
64
|
+
import json
|
|
65
|
+
from sarapy.preprocessing import TransformInputData
|
|
66
|
+
import matplotlib.pyplot as plt
|
|
67
|
+
from collections import Counter
|
|
68
|
+
|
|
69
|
+
fecha = "2025-08-09"
|
|
70
|
+
nodo_interes = "UPM095N"
|
|
71
|
+
|
|
72
|
+
historical_data_path = f"examples//{fecha}//{nodo_interes}//historical-data.json"
|
|
73
|
+
with open(historical_data_path, 'r') as file:
|
|
74
|
+
historical_data = json.load(file)
|
|
75
|
+
|
|
76
|
+
##cargo en un diccionario sarapy\preprocessing\telemetriaDataPosition.json
|
|
77
|
+
data_positions = json.load(open("sarapy/preprocessing/telemetriaDataPosition.json", 'r'))
|
|
78
|
+
transform_input_data = TransformInputData()
|
|
79
|
+
transformed_data = transform_input_data.transform(historical_data)
|
|
80
|
+
|
|
81
|
+
fertransformer = FertilizerTransformer(regresor_file='modelos\\regresor_v2.pkl', poly_features_file='modelos\\poly_features_v2.pkl')
|
|
82
|
+
gramos = fertransformer.transform(transformed_data)
|
|
83
|
+
print(gramos[:10])
|
|
84
|
+
|
|
85
|
+
df = pd.DataFrame(transformed_data)
|
|
86
|
+
score_ft = df["SC_FT"].values
|
|
87
|
+
|
|
88
|
+
print(score_ft.mean(), gramos.mean())
|
|
89
|
+
print(score_ft.max(), gramos.max())
|
|
90
|
+
print(score_ft.min(), gramos.min())
|
|
91
|
+
|
|
92
|
+
puntos = list(zip(score_ft, gramos))
|
|
93
|
+
conteos = Counter(puntos)
|
|
94
|
+
xs, ys, sizes = zip(*[(x, y, c) for (x, y), c in conteos.items()])
|
|
95
|
+
|
|
96
|
+
np.array([s*10 for s in sizes]).shape
|
|
97
|
+
|
|
98
|
+
points = np.column_stack((score_ft, gramos))
|
|
99
|
+
unique_points, counts = np.unique(points, axis=0, return_counts=True)
|
|
100
|
+
|
|
101
|
+
sizes = np.log1p(counts) * 50
|
|
102
|
+
|
|
103
|
+
plt.figure(figsize=(10, 6))
|
|
104
|
+
handles, labels = plt.gca().get_legend_handles_labels()
|
|
105
|
+
order = [2, 0, 1]
|
|
106
|
+
plt.scatter(unique_points[:,0], unique_points[:,1], color="#5612af", label="Regresor 1 - Orden 12",zorder=1,
|
|
107
|
+
s=sizes)
|
|
108
|
+
plt.scatter(score_ft.mean(), gramos.mean(), color="#af121f", label="Punto promedio", marker='X',s=400)
|
|
109
|
+
plt.title(f'Predicciones Regresor 2 de orden 12 para NODO: {nodo_interes}')
|
|
110
|
+
plt.xlabel('Score de Fertilizante (SC_FT)')
|
|
111
|
+
plt.ylabel('Predicciones de Gramos de Fertilizante')
|
|
112
|
+
plt.grid(True)
|
|
113
|
+
plt.legend()
|
|
114
|
+
plt.savefig(f'predicciones_regresor2_orden12_{nodo_interes}.png')
|
|
115
|
+
plt.show()
|
|
116
|
+
|
|
117
|
+
nodos = ["UPM075N", "UPM076N", "UPM077N", "UPM078N", "UPM079N", "UPM080N", "UPM081N", "UPM082N", "UPM083N", "UPM084N",
|
|
118
|
+
"UPM085N", "UPM086N", "UPM087N", "UPM088N", "UPM089N", "UPM090N", "UPM091N", "UPM092N", "UPM093N", "UPM094N", "UPM095N",
|
|
119
|
+
"UPM096N", "UPM097N", "UPM098N", "UPM099N"]
|
|
120
|
+
|
|
121
|
+
##cargo datos históricos de ejemplo
|
|
122
|
+
|
|
123
|
+
scores_ft_maximos = {}
|
|
124
|
+
scores_ft_minimos = {}
|
|
125
|
+
gramos_maximos = {}
|
|
126
|
+
gramos_minimos = {}
|
|
127
|
+
for nodo in nodos:
|
|
128
|
+
historical_data_path = f"examples//{fecha}//{nodo}//historical-data.json"
|
|
129
|
+
try:
|
|
130
|
+
with open(historical_data_path, 'r') as file:
|
|
131
|
+
historical_data = json.load(file)
|
|
132
|
+
except FileNotFoundError:
|
|
133
|
+
print(f"El archivo {historical_data_path} no se encuentra en el directorio actual.")
|
|
134
|
+
continue
|
|
135
|
+
transform_input_data = TransformInputData()
|
|
136
|
+
transformed_data = transform_input_data.transform(historical_data)
|
|
137
|
+
fertransformer = FertilizerTransformer(regresor_file='modelos\\regresor_v2.pkl', poly_features_file='modelos\\poly_features_v2.pkl')
|
|
138
|
+
gramos = fertransformer.transform(transformed_data)
|
|
139
|
+
gramos_maximos[nodo] = gramos.max()
|
|
140
|
+
gramos_minimos[nodo] = gramos.min()
|
|
141
|
+
|
|
142
|
+
df = pd.DataFrame(transformed_data)
|
|
143
|
+
score_ft = df["SC_FT"].values
|
|
144
|
+
scores_ft_maximos[nodo] = score_ft.max()
|
|
145
|
+
scores_ft_minimos[nodo] = score_ft.min()
|
|
146
|
+
|
|
147
|
+
data = np.array([[gramos_maximos[nodo] for nodo in nodos],
|
|
148
|
+
[scores_ft_maximos[nodo] for nodo in nodos],
|
|
149
|
+
[gramos_minimos[nodo] for nodo in nodos],
|
|
150
|
+
[scores_ft_minimos[nodo] for nodo in nodos]])
|
|
151
|
+
|
|
152
|
+
data_df = pd.DataFrame(data=data.T, index=nodos, columns=['Gramos_Fertilizante', 'Score_Fertilizante', 'Gramos_Fertilizante_Min', 'Score_Fertilizante_Min'])
|
|
153
|
+
|
|
154
|
+
data_df['Gramos_Fertilizante'].plot.bar(figsize=(12, 6), color="#34a853", legend=False)
|
|
155
|
+
#add text labels on top of each bar with the height value
|
|
156
|
+
for i, v in enumerate(data_df['Gramos_Fertilizante']):
|
|
157
|
+
plt.text(i, v + 0.1, f"{v:.1f}", ha='center', va='bottom',color="#34a853")
|
|
158
|
+
plt.title('Máximos de gramos de fertilizante por nodo')
|
|
159
|
+
plt.xlabel('Nodos')
|
|
160
|
+
plt.ylabel('Gramos de Fertilizante')
|
|
161
|
+
plt.grid(axis='y')
|
|
162
|
+
plt.savefig('maximos_gramos_fertilizante_por_nodo.png')
|
|
163
|
+
plt.show()
|
|
164
|
+
|
|
165
|
+
data_df['Gramos_Fertilizante_Min'].plot.bar(figsize=(12, 6), color="#34a853", legend=False)
|
|
166
|
+
#add text labels on top of each bar with the height value
|
|
167
|
+
for i, v in enumerate(data_df['Gramos_Fertilizante_Min']):
|
|
168
|
+
plt.text(i, v + 0.1, f"{v:.1f}", ha='center', va='bottom',color="#34a853")
|
|
169
|
+
plt.title('Mínimos de gramos de fertilizante por nodo')
|
|
170
|
+
plt.xlabel('Nodos')
|
|
171
|
+
plt.ylabel('Gramos de Fertilizante')
|
|
172
|
+
plt.grid(axis='y')
|
|
173
|
+
plt.savefig('minimos_gramos_fertilizante_por_nodo.png')
|
|
174
|
+
plt.show()
|
|
175
|
+
|
|
176
|
+
data_df['Score_Fertilizante'].plot.bar(figsize=(12, 6), color="#3434a8", legend=False)
|
|
177
|
+
#add text labels on top of each bar with the height value
|
|
178
|
+
for i, v in enumerate(data_df['Score_Fertilizante']):
|
|
179
|
+
plt.text(i, v + 0.1, f"{v:.1f}", ha='center', va='bottom',color="#3434a8")
|
|
180
|
+
plt.title('Máximos de score de fertilizante por nodo')
|
|
181
|
+
plt.xlabel('Nodos')
|
|
182
|
+
plt.ylabel('Score de Fertilizante')
|
|
183
|
+
plt.grid(axis='y')
|
|
184
|
+
plt.savefig('maximos_score_fertilizante_por_nodo.png')
|
|
185
|
+
plt.show()
|
|
186
|
+
|
|
187
|
+
data_df['Score_Fertilizante_Min'].plot.bar(figsize=(12, 6), color="#3434a8", legend=False)
|
|
188
|
+
#add text labels on top of each bar with the height value
|
|
189
|
+
for i, v in enumerate(data_df['Score_Fertilizante_Min']):
|
|
190
|
+
plt.text(i, v + 0.1, f"{v:.1f}", ha='center', va='bottom',color="#3434a8")
|
|
191
|
+
plt.title('Mínimos de score de fertilizante por nodo')
|
|
192
|
+
plt.xlabel('Nodos')
|
|
193
|
+
plt.ylabel('Score de Fertilizante')
|
|
194
|
+
plt.grid(axis='y')
|
|
195
|
+
plt.savefig('minimos_score_fertilizante_por_nodo.png')
|
|
196
|
+
plt.show()
|
|
197
|
+
|
|
198
|
+
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
## Version of the package
|
|
2
|
-
__version__ = "3.
|
|
2
|
+
__version__ = "3.1.0"
|
|
@@ -1,24 +1,43 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: sarapy
|
|
3
|
-
Version: 3.
|
|
4
|
-
|
|
5
|
-
Author: Lucas Baldezzari
|
|
3
|
+
Version: 3.1.0
|
|
4
|
+
Summary: Library for Sarapico Metadata processing
|
|
6
5
|
Author-email: Lucas Baldezzari <lmbaldezzari@gmail.com>
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
License: MIT
|
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Operating System :: Microsoft :: Windows :: Windows 10
|
|
10
|
+
Classifier: Operating System :: Microsoft :: Windows :: Windows 11
|
|
11
|
+
Classifier: Operating System :: Unix
|
|
12
|
+
Requires-Python: >=3.9
|
|
9
13
|
Description-Content-Type: text/markdown
|
|
10
14
|
License-File: LICENCE
|
|
11
|
-
Requires-Dist: numpy
|
|
12
|
-
Requires-Dist:
|
|
13
|
-
Requires-Dist:
|
|
14
|
-
Requires-Dist:
|
|
15
|
-
Requires-Dist:
|
|
16
|
-
Requires-Dist:
|
|
15
|
+
Requires-Dist: numpy>=1.23
|
|
16
|
+
Requires-Dist: pandas>=1.5
|
|
17
|
+
Requires-Dist: scipy>=1.9
|
|
18
|
+
Requires-Dist: scikit-learn>=1.2
|
|
19
|
+
Requires-Dist: matplotlib>=3.6
|
|
20
|
+
Requires-Dist: seaborn>=0.12
|
|
21
|
+
Requires-Dist: requests>=2.28
|
|
22
|
+
Requires-Dist: python-dotenv>=1.0
|
|
23
|
+
Requires-Dist: geopy>=2.3
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: pytest; extra == "dev"
|
|
26
|
+
Requires-Dist: black; extra == "dev"
|
|
27
|
+
Requires-Dist: ruff; extra == "dev"
|
|
28
|
+
Requires-Dist: mypy; extra == "dev"
|
|
29
|
+
Dynamic: license-file
|
|
17
30
|
|
|
18
31
|
# SARAPY
|
|
19
32
|
|
|
20
33
|
Library for processing SARAPICO project metadata of _AMG SA_.
|
|
21
34
|
|
|
35
|
+
#### Version 3.1.0
|
|
36
|
+
|
|
37
|
+
- Se actualiza regresor para estimar fertilizante.
|
|
38
|
+
- Actualización de archivos para instalar la libería.
|
|
39
|
+
|
|
40
|
+
|
|
22
41
|
#### Version 3.0.0
|
|
23
42
|
- Se mejora la forma de obtener valores de media movil para todas las variables en las que se usa.
|
|
24
43
|
- Se corrigen bugs debido a nodos con pocas operaciones.
|
sarapy-3.1.0/setup.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#from setuptools import setup#, find_packages
|
|
2
|
+
|
|
3
|
+
from setuptools import setup
|
|
4
|
+
|
|
5
|
+
setup()
|
|
6
|
+
|
|
7
|
+
# import toml
|
|
8
|
+
|
|
9
|
+
# def getRequirements():
|
|
10
|
+
# with open('requirements.txt', 'r') as f:
|
|
11
|
+
# requirements = f.read().splitlines()
|
|
12
|
+
# return requirements
|
|
13
|
+
|
|
14
|
+
# def readme():
|
|
15
|
+
# with open('README.md') as f:
|
|
16
|
+
# return f.read()
|
|
17
|
+
|
|
18
|
+
# def version():
|
|
19
|
+
# with open('pyproject.toml') as f:
|
|
20
|
+
# return toml.load(f)['project']['version']
|
|
21
|
+
|
|
22
|
+
# setup(
|
|
23
|
+
# name='sarapy',
|
|
24
|
+
# version=version(),
|
|
25
|
+
# packages=find_packages(),
|
|
26
|
+
# install_requires=getRequirements(),
|
|
27
|
+
# author='Lucas Baldezzari',
|
|
28
|
+
# author_email='lmbaldezzari@gmail.com',
|
|
29
|
+
# description='Library for Sarapico Metadata processing',
|
|
30
|
+
# long_description=readme(),
|
|
31
|
+
# url='https://github.com/lucasbaldezzari/sarapy',
|
|
32
|
+
# license='MIT', ##revisar licencia
|
|
33
|
+
# classifiers=[
|
|
34
|
+
# 'License :: OSI Approved :: MIT License',
|
|
35
|
+
# 'Programming Language :: Python :: 3',
|
|
36
|
+
# 'Operating System :: Microsoft :: Windows :: Windows 10',
|
|
37
|
+
# 'Operating System :: Microsoft :: Windows :: Windows 11',
|
|
38
|
+
# 'Operating System :: Unix',
|
|
39
|
+
# ],
|
|
40
|
+
# )
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import pickle
|
|
2
|
+
import pandas as pd
|
|
3
|
+
import numpy as np
|
|
4
|
+
import matplotlib.pyplot as plt
|
|
5
|
+
from sklearn.preprocessing import PolynomialFeatures
|
|
6
|
+
from sklearn.linear_model import LinearRegression
|
|
7
|
+
from sklearn.preprocessing import StandardScaler
|
|
8
|
+
|
|
9
|
+
regresor = "modelos//regresor.pkl"
|
|
10
|
+
poly_features = "modelos//poly_features.pkl"
|
|
11
|
+
|
|
12
|
+
with open(regresor, "rb") as file:
|
|
13
|
+
loaded_regresor = pickle.load(file)
|
|
14
|
+
|
|
15
|
+
with open(poly_features, "rb") as file:
|
|
16
|
+
loaded_poly_features = pickle.load(file)
|
|
17
|
+
|
|
18
|
+
coeficientes = loaded_regresor.coef_.flatten()
|
|
19
|
+
intercept = loaded_regresor.intercept_
|
|
20
|
+
index = np.arange(len(coeficientes)) + 1
|
|
21
|
+
distorsiones = np.linspace(0, 15, 1000)
|
|
22
|
+
X_poly = loaded_poly_features.transform(distorsiones.reshape(-1, 1))
|
|
23
|
+
predicciones = loaded_regresor.predict(X_poly)
|
|
24
|
+
|
|
25
|
+
##genero un dataframe con los coeficientes
|
|
26
|
+
labels = [f"Exponente/Coeficiente {i}" for i in index]
|
|
27
|
+
tabla = pd.DataFrame(coeficientes, labels).rename(columns={0:"Valores"})
|
|
28
|
+
tabla.loc[len(tabla)+1] = intercept
|
|
29
|
+
tabla = tabla.rename(index={len(tabla):"intercepción"})
|
|
30
|
+
|
|
31
|
+
#grafico de líneas de los coeficientes vs su índice
|
|
32
|
+
plt.figure(figsize=(10, 6))
|
|
33
|
+
plt.plot(index, coeficientes, marker='o', linestyle='-', color='b')
|
|
34
|
+
plt.title('Coeficientes del Regresor Polinómico')
|
|
35
|
+
plt.xlabel('Índice del Coeficiente')
|
|
36
|
+
plt.ylabel('Valor del Coeficiente')
|
|
37
|
+
plt.grid(True)
|
|
38
|
+
plt.axhline(0, color='black', linewidth=0.8, linestyle='--')
|
|
39
|
+
plt.show()
|
|
40
|
+
|
|
41
|
+
# gráfico de dispersión de distorsión vs predicciones
|
|
42
|
+
plt.figure(figsize=(10, 6))
|
|
43
|
+
plt.scatter(distorsiones, predicciones, color='r', alpha=0.6)
|
|
44
|
+
plt.title('Score de Fertilizante vs Predicciones en Gramos')
|
|
45
|
+
plt.xlabel('Score de Fertilizante (SC_FT)')
|
|
46
|
+
plt.ylabel('Predicciones de Gramos de Fertilizante')
|
|
47
|
+
plt.grid(True)
|
|
48
|
+
plt.show()
|
|
49
|
+
|
|
50
|
+
inf, sup = 7, 13
|
|
51
|
+
distorsiones[int(inf/0.1):int(sup/0.1+1)].mean()
|
|
52
|
+
predicciones[int(inf/0.1):int(sup/0.1+1)].mean()
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
# Definición de tramos: (x1, x2, y1, y2)
|
|
56
|
+
segmentos1 = [(0, 4, 0, 0.821),
|
|
57
|
+
(4, 7, 0.821, 5),
|
|
58
|
+
(7, 9.5, 5, 5.41),
|
|
59
|
+
(9.5, 13, 5.41, 8),
|
|
60
|
+
(13, 15, 8, 9)]
|
|
61
|
+
segmentos2 = [(0, 4, 0, 0.821),
|
|
62
|
+
(4, 7, 0.821, 5),
|
|
63
|
+
# (7, 9.5, 5, 5.41),
|
|
64
|
+
(7, 13, 5, 8),
|
|
65
|
+
(13, 15, 8, 9)]
|
|
66
|
+
|
|
67
|
+
def get_line(x1, x2, y1, y2):
|
|
68
|
+
m = (y2 - y1) / (x2 - x1)
|
|
69
|
+
b = y1 - m * x1
|
|
70
|
+
return m, b
|
|
71
|
+
|
|
72
|
+
def piecewise_linear(x, segmentos, lines):
|
|
73
|
+
for (x1, x2, _, _), (m, b) in zip(segmentos, lines):
|
|
74
|
+
if x1 <= x <= x2:
|
|
75
|
+
return m * x + b
|
|
76
|
+
raise ValueError("x fuera de rango")
|
|
77
|
+
|
|
78
|
+
lines1 = [get_line(*seg) for seg in segmentos1]
|
|
79
|
+
lines2 = [get_line(*seg) for seg in segmentos2]
|
|
80
|
+
|
|
81
|
+
# Ejemplo
|
|
82
|
+
ys1 = np.array([piecewise_linear(x, segmentos1, lines1) for x in distorsiones])
|
|
83
|
+
ys2 = np.array([piecewise_linear(x, segmentos2, lines2) for x in distorsiones])
|
|
84
|
+
|
|
85
|
+
# gráfico de dispersión de distorsión vs predicciones
|
|
86
|
+
plt.figure(figsize=(10, 6))
|
|
87
|
+
handles, labels = plt.gca().get_legend_handles_labels()
|
|
88
|
+
order = [2, 0, 1]
|
|
89
|
+
plt.scatter(distorsiones, predicciones, color='r', alpha=0.5, label="Predicciones actuales",zorder=2)
|
|
90
|
+
plt.scatter(distorsiones, ys1, color='g', alpha=0.5, label="Propuesta 1",zorder=1)
|
|
91
|
+
plt.scatter(distorsiones, ys2, color='b', alpha=0.5, label="Propuesta 2",zorder=0)
|
|
92
|
+
plt.title('Score de Fertilizante vs Predicciones en Gramos')
|
|
93
|
+
plt.xlabel('Score de Fertilizante (SC_FT)')
|
|
94
|
+
plt.ylabel('Predicciones de Gramos de Fertilizante')
|
|
95
|
+
plt.grid(True)
|
|
96
|
+
plt.legend()
|
|
97
|
+
plt.show()
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
### ************* Obteniendo nuevos regresores a partir de ys1 y ys2 ************* ###
|
|
101
|
+
X = distorsiones.reshape(-1, 1)
|
|
102
|
+
|
|
103
|
+
poly = PolynomialFeatures(
|
|
104
|
+
degree=12,
|
|
105
|
+
include_bias=True # incluye el término β0
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
X_poly = poly.fit_transform(X)
|
|
109
|
+
|
|
110
|
+
modelo1 = LinearRegression(fit_intercept=False)
|
|
111
|
+
modelo1.fit(X_poly, ys1)
|
|
112
|
+
modelo2 = LinearRegression(fit_intercept=False)
|
|
113
|
+
modelo2.fit(X_poly, ys2)
|
|
114
|
+
|
|
115
|
+
ys1_pred = modelo1.predict(X_poly)
|
|
116
|
+
ys2_pred = modelo2.predict(X_poly)
|
|
117
|
+
|
|
118
|
+
# gráfico de dispersión de distorsión vs predicciones
|
|
119
|
+
plt.figure(figsize=(10, 6))
|
|
120
|
+
handles, labels = plt.gca().get_legend_handles_labels()
|
|
121
|
+
order = [2, 0, 1]
|
|
122
|
+
plt.scatter(distorsiones, ys1, color='g', alpha=0.1, label="Función 1 Hardcodeada ",zorder=1)
|
|
123
|
+
plt.scatter(distorsiones, ys1_pred, color="#5612af", alpha=0.5, label="Regresor 1 - Orden 12",zorder=2)
|
|
124
|
+
plt.title('Comparación Función de Propuesta vs Regresor 1 de orden 12')
|
|
125
|
+
plt.xlabel('Score de Fertilizante (SC_FT)')
|
|
126
|
+
plt.ylabel('Predicciones de Gramos de Fertilizante')
|
|
127
|
+
plt.grid(True)
|
|
128
|
+
plt.legend()
|
|
129
|
+
plt.show()
|
|
130
|
+
|
|
131
|
+
# gráfico de dispersión de distorsión vs predicciones
|
|
132
|
+
plt.figure(figsize=(10, 6))
|
|
133
|
+
handles, labels = plt.gca().get_legend_handles_labels()
|
|
134
|
+
order = [2, 0, 1]
|
|
135
|
+
plt.scatter(distorsiones, ys2, color='b', alpha=0.1, label="Función 2 Hardcodeada ",zorder=1)
|
|
136
|
+
plt.scatter(distorsiones, ys2_pred, color="#12af12", alpha=0.5, label="Regresor 2 - Orden 12",zorder=2)
|
|
137
|
+
plt.title('Comparación Función de Propuesta vs Regresor 2 de orden 12')
|
|
138
|
+
plt.xlabel('Score de Fertilizante (SC_FT)')
|
|
139
|
+
plt.ylabel('Predicciones de Gramos de Fertilizante')
|
|
140
|
+
plt.grid(True)
|
|
141
|
+
plt.legend()
|
|
142
|
+
plt.show()
|
|
143
|
+
|
|
144
|
+
# gráfico de dispersión de distorsión vs predicciones
|
|
145
|
+
plt.figure(figsize=(10, 6))
|
|
146
|
+
handles, labels = plt.gca().get_legend_handles_labels()
|
|
147
|
+
order = [2, 0, 1]
|
|
148
|
+
plt.scatter(distorsiones, ys1_pred, color="#5612af", alpha=0.1, label="Regresor 1 - Orden 12",zorder=1)
|
|
149
|
+
plt.scatter(distorsiones, ys2_pred, color="#12af12", alpha=0.5, label="Regresor 2 - Orden 12",zorder=2)
|
|
150
|
+
plt.title('Regresor 1 vs Regresor 2 de orden 12')
|
|
151
|
+
plt.xlabel('Score de Fertilizante (SC_FT)')
|
|
152
|
+
plt.ylabel('Predicciones de Gramos de Fertilizante')
|
|
153
|
+
plt.grid(True)
|
|
154
|
+
plt.legend()
|
|
155
|
+
plt.show()
|
|
156
|
+
|
|
157
|
+
## Guardo el modelo 2 y las características polinómicas
|
|
158
|
+
with open("modelos//regfresor_v2.pkl", "wb") as file:
|
|
159
|
+
pickle.dump(modelo2, file)
|
|
160
|
+
|
|
161
|
+
with open("modelos//poly_features_v2.pkl", "wb") as file:
|
|
162
|
+
pickle.dump(poly, file)
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
from sarapy.utils.plotting import plotTemporalData
|
|
2
|
+
import pandas as pd
|
|
3
|
+
import numpy as np
|
|
4
|
+
import os
|
|
5
|
+
import sarapy.utils.getRawOperations as getRawOperations
|
|
6
|
+
from sarapy.dataProcessing import OpsProcessor
|
|
7
|
+
from sarapy.preprocessing import TransformInputData
|
|
8
|
+
from sarapy.dataProcessing import TLMSensorDataProcessor
|
|
9
|
+
import sarapy.stats.stats as stats
|
|
10
|
+
|
|
11
|
+
tlmsde = TLMSensorDataProcessor.TLMSensorDataProcessor()
|
|
12
|
+
|
|
13
|
+
nodo = "UPM017N"
|
|
14
|
+
|
|
15
|
+
data_path = os.path.join(os.getcwd(), f"examples\\2025-04-10\\{nodo}\\data.json")
|
|
16
|
+
historical_data_path = os.path.join(os.getcwd(), f"examples\\2025-04-10\\{nodo}\\historical-data.json")
|
|
17
|
+
|
|
18
|
+
raw_data = pd.read_json(data_path, orient="records").to_dict(orient="records")
|
|
19
|
+
raw_data2 = pd.read_json(historical_data_path, orient="records").to_dict(orient="records")
|
|
20
|
+
|
|
21
|
+
transform_input_data = TransformInputData.TransformInputData()
|
|
22
|
+
|
|
23
|
+
raw_ops = getRawOperations.getRawOperations(raw_data, raw_data2)
|
|
24
|
+
datum = transform_input_data.fit_transform(raw_ops)[:,2]
|
|
25
|
+
telemetria = tlmsde.fit_transform(datum)
|
|
26
|
+
mode = telemetria[:,tlmsde.dataPositions["MODEFlag"]]
|
|
27
|
+
dstpt = telemetria[:,tlmsde.dataPositions["DSTRPT"]]
|
|
28
|
+
|
|
29
|
+
op = OpsProcessor.OpsProcessor(classifier_file='modelos\\pipeline_rf.pkl', imputeDistances = False,
|
|
30
|
+
regresor_file='modelos\\regresor.pkl', poly_features_file='modelos\\poly_features.pkl')
|
|
31
|
+
op.operationsDict
|
|
32
|
+
data_processed = op.processOperations(raw_ops)
|
|
33
|
+
|
|
34
|
+
#paso la lista de operaciones a un dataframe
|
|
35
|
+
df = pd.DataFrame(data_processed)
|
|
36
|
+
df["mode"] = mode
|
|
37
|
+
df["dstpt"] = dstpt
|
|
38
|
+
df["nodo"] = nodo
|
|
39
|
+
ma = stats.getMA(df["dstpt"].values, window_size=104, mode='same')
|
|
40
|
+
df["dstpt_ma"] = ma
|
|
41
|
+
##me quedo con los datos donde mode==0
|
|
42
|
+
df = df[df["mode"] == 0]
|
|
43
|
+
|
|
44
|
+
#calculo el resumen del sensor
|
|
45
|
+
resumen = stats.resumen_sensor(df, values_col="dstpt_ma", pctbajo_value=1, pctalto_value=14)
|
|
46
|
+
print(resumen)
|
|
47
|
+
#calculo la probabilidad de saturación
|
|
48
|
+
prob_saturacion = stats.calcular_prob_saturacion(ma[2000:], saturation_mode="alto", umbrales=(1, 14),
|
|
49
|
+
alpha=0.2, beta=0.2)
|
|
50
|
+
print(f"Probabilidad de saturación: {prob_saturacion}")
|
|
51
|
+
|
|
52
|
+
# Definimos grilla de alpha y beta
|
|
53
|
+
alpha_vals = np.linspace(0, 1, 20)
|
|
54
|
+
beta_vals = np.linspace(0, 1, 20)
|
|
55
|
+
|
|
56
|
+
# Creamos matriz de resultados
|
|
57
|
+
Psat_matrix = np.zeros((len(alpha_vals), len(beta_vals)))
|
|
58
|
+
|
|
59
|
+
for i, alpha in enumerate(alpha_vals):
|
|
60
|
+
for j, beta in enumerate(beta_vals):
|
|
61
|
+
Psat = prob_saturacion = stats.calcular_prob_saturacion(ma, saturation_mode="alto", umbrales=(1, 14),
|
|
62
|
+
alpha=alpha, beta=beta)
|
|
63
|
+
Psat_matrix[i, j] = Psat
|
|
64
|
+
|
|
65
|
+
import matplotlib.pyplot as plt
|
|
66
|
+
import seaborn as sns
|
|
67
|
+
|
|
68
|
+
plt.figure(figsize=(10, 8))
|
|
69
|
+
sns.heatmap(Psat_matrix, xticklabels=np.round(beta_vals, 2), yticklabels=np.round(alpha_vals, 2), cmap="coolwarm")
|
|
70
|
+
plt.title("Evolución de Psat en función de α (vertical) y β (horizontal)")
|
|
71
|
+
plt.xlabel("β (peso de kurtosis)")
|
|
72
|
+
plt.ylabel("α (peso de skewness)")
|
|
73
|
+
plt.show()
|
|
74
|
+
|
|
75
|
+
colors = ["#0b3256","#fa0000"]
|
|
76
|
+
plotTemporalData(df, nodos = [nodo], columnas = ["dstpt_ma"], title = "DSTPT",sameFig = False, show = True,
|
|
77
|
+
save = False, filename = "dstpt_plot.png", figsize=(15, 10), colors=colors)
|
sarapy-3.0.0/pyproject.toml
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
[project]
|
|
2
|
-
name = "sarapy"
|
|
3
|
-
|
|
4
|
-
version = "3.0.0"
|
|
5
|
-
authors = [
|
|
6
|
-
{name = "Lucas Baldezzari", email = "lmbaldezzari@gmail.com"},]
|
|
7
|
-
maintainers = [
|
|
8
|
-
{name = "Lucas Baldezzari", email = "lmbaldezzari@gmail.com"}
|
|
9
|
-
]
|
|
10
|
-
|
|
11
|
-
dependencies = [
|
|
12
|
-
"numpy",
|
|
13
|
-
"matplotlib",
|
|
14
|
-
"pandas",
|
|
15
|
-
"scipy",
|
|
16
|
-
"scikit-learn",
|
|
17
|
-
"geopy",
|
|
18
|
-
]
|
|
19
|
-
|
|
20
|
-
readme = "README.md"
|
|
21
|
-
license = {text = "For private use only. Owner AMG Servicios profesionales (Mercedes, Uruguay)"}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import pickle
|
|
2
|
-
import logging
|
|
3
|
-
from sarapy.dataProcessing import TLMSensorDataProcessor
|
|
4
|
-
|
|
5
|
-
class FertilizerTransformer:
|
|
6
|
-
"""
|
|
7
|
-
Clase para tomar los valores de distorsión de fertilizante y transformarlos a gramos
|
|
8
|
-
"""
|
|
9
|
-
|
|
10
|
-
def __init__(self, regresor_file, poly_features_file):
|
|
11
|
-
"""Constructor de la clase FertilizerImputer.
|
|
12
|
-
|
|
13
|
-
Args:
|
|
14
|
-
- regresor: Regresor que transforma los valores de distorsión a gramos.
|
|
15
|
-
- poly_features: Grado del polinomio a utilizar en la transformación de los datos.
|
|
16
|
-
"""
|
|
17
|
-
self.logger = logging.getLogger("FertilizerTransformer")
|
|
18
|
-
##cargo el regresor con pickle. Usamos try para capturar el error FileNotFoundError
|
|
19
|
-
try:
|
|
20
|
-
with open(regresor_file, 'rb') as file:
|
|
21
|
-
self._regresor = pickle.load(file)
|
|
22
|
-
self.logger.info("Regresor cargado con éxito.")
|
|
23
|
-
except FileNotFoundError:
|
|
24
|
-
self.logger.error("El archivo no se encuentra en el directorio actual.")
|
|
25
|
-
|
|
26
|
-
##cargo las características polinómicas con pickle. Usamos try para capturar el error FileNotFoundError
|
|
27
|
-
try:
|
|
28
|
-
with open(poly_features_file, 'rb') as file:
|
|
29
|
-
self._poly_features = pickle.load(file)
|
|
30
|
-
self.logger.info("Características polinómicas cargadas con éxito.")
|
|
31
|
-
except FileNotFoundError:
|
|
32
|
-
self.logger.error("El archivo no se encuentra en el directorio actual.")
|
|
33
|
-
|
|
34
|
-
self.fertilizer_grams = None ##cuando no se ha transformado ningún dato, se inicializa en None
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
def transform(self, data):
|
|
38
|
-
"""Transforma los datos de distorsión de fertilizante a gramos.
|
|
39
|
-
|
|
40
|
-
Params:
|
|
41
|
-
- data: Es una lista de diccionarios (como un JSON) con los datos de telemetría.
|
|
42
|
-
|
|
43
|
-
Returns:
|
|
44
|
-
- 0: Array con los valores de distorsión de fertilizante transformados a gramos.
|
|
45
|
-
"""
|
|
46
|
-
tlmDataProcessor = TLMSensorDataProcessor.TLMSensorDataProcessor(data)
|
|
47
|
-
X = tlmDataProcessor["SC_FT",:]
|
|
48
|
-
X_poly = self._poly_features.fit_transform(X.reshape(-1, 1))
|
|
49
|
-
self.fertilizer_grams = self._regresor.predict(X_poly)
|
|
50
|
-
|
|
51
|
-
##retorno con shape (n,)
|
|
52
|
-
return self.fertilizer_grams.reshape(-1,)
|
|
53
|
-
|
|
54
|
-
if __name__ == "__main__":
|
|
55
|
-
import pandas as pd
|
|
56
|
-
import json
|
|
57
|
-
from sarapy.preprocessing import TransformInputData
|
|
58
|
-
|
|
59
|
-
historical_data_path = "examples/2025-06-21/UPM000N/historical-data.json"
|
|
60
|
-
with open(historical_data_path, 'r') as file:
|
|
61
|
-
historical_data = json.load(file)
|
|
62
|
-
|
|
63
|
-
##cargo en un diccionario sarapy\preprocessing\telemetriaDataPosition.json
|
|
64
|
-
data_positions = json.load(open("sarapy/preprocessing/telemetriaDataPosition.json", 'r'))
|
|
65
|
-
transform_input_data = TransformInputData.TransformInputData()
|
|
66
|
-
transformed_data = transform_input_data.transform(historical_data)
|
|
67
|
-
|
|
68
|
-
fertransformer = FertilizerTransformer(regresor_file='modelos\\regresor.pkl', poly_features_file='modelos\\poly_features.pkl')
|
|
69
|
-
gramos = fertransformer.transform(transformed_data)
|
|
70
|
-
print(gramos[:10])
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
sarapy
|
sarapy-3.0.0/setup.py
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
from setuptools import setup, find_packages
|
|
2
|
-
import toml
|
|
3
|
-
|
|
4
|
-
def getRequirements():
|
|
5
|
-
with open('requirements.txt', 'r') as f:
|
|
6
|
-
requirements = f.read().splitlines()
|
|
7
|
-
return requirements
|
|
8
|
-
|
|
9
|
-
def readme():
|
|
10
|
-
with open('README.md') as f:
|
|
11
|
-
return f.read()
|
|
12
|
-
|
|
13
|
-
def version():
|
|
14
|
-
with open('pyproject.toml') as f:
|
|
15
|
-
return toml.load(f)['project']['version']
|
|
16
|
-
|
|
17
|
-
setup(
|
|
18
|
-
name='sarapy',
|
|
19
|
-
version=version(),
|
|
20
|
-
packages=find_packages(),
|
|
21
|
-
install_requires=getRequirements(),
|
|
22
|
-
author='Lucas Baldezzari',
|
|
23
|
-
author_email='lmbaldezzari@gmail.com',
|
|
24
|
-
description='Library for Sarapico Metadata processing',
|
|
25
|
-
long_description=readme(),
|
|
26
|
-
url='https://github.com/lucasbaldezzari/sarapy',
|
|
27
|
-
license='MIT', ##revisar licencia
|
|
28
|
-
classifiers=[
|
|
29
|
-
'License :: OSI Approved :: MIT License',
|
|
30
|
-
'Programming Language :: Python :: 3',
|
|
31
|
-
'Operating System :: Microsoft :: Windows :: Windows 10',
|
|
32
|
-
'Operating System :: Microsoft :: Windows :: Windows 11',
|
|
33
|
-
'Operating System :: Unix',
|
|
34
|
-
],
|
|
35
|
-
)
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|