sarapy 1.2.6__tar.gz → 1.3.1__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 (32) hide show
  1. {sarapy-1.2.6/sarapy.egg-info → sarapy-1.3.1}/PKG-INFO +9 -1
  2. {sarapy-1.2.6 → sarapy-1.3.1}/README.md +8 -0
  3. {sarapy-1.2.6 → sarapy-1.3.1}/pyproject.toml +1 -1
  4. {sarapy-1.2.6 → sarapy-1.3.1}/sarapy/dataProcessing/OpsProcessor.py +26 -6
  5. sarapy-1.3.1/sarapy/mlProcessors/FertilizerFMCreator.py +54 -0
  6. sarapy-1.3.1/sarapy/mlProcessors/FertilizerTransformer.py +81 -0
  7. {sarapy-1.2.6 → sarapy-1.3.1}/sarapy/mlProcessors/PlantinClassifier.py +3 -3
  8. {sarapy-1.2.6 → sarapy-1.3.1}/sarapy/preprocessing/TransformToOutputData.py +4 -2
  9. {sarapy-1.2.6 → sarapy-1.3.1}/sarapy/version.py +1 -1
  10. {sarapy-1.2.6 → sarapy-1.3.1/sarapy.egg-info}/PKG-INFO +9 -1
  11. {sarapy-1.2.6 → sarapy-1.3.1}/sarapy.egg-info/SOURCES.txt +2 -0
  12. {sarapy-1.2.6 → sarapy-1.3.1}/LICENCE +0 -0
  13. {sarapy-1.2.6 → sarapy-1.3.1}/sarapy/__init__.py +0 -0
  14. {sarapy-1.2.6 → sarapy-1.3.1}/sarapy/dataProcessing/GeoProcessor.py +0 -0
  15. {sarapy-1.2.6 → sarapy-1.3.1}/sarapy/dataProcessing/TLMSensorDataProcessor.py +0 -0
  16. {sarapy-1.2.6 → sarapy-1.3.1}/sarapy/dataProcessing/TimeSeriesProcessor.py +0 -0
  17. {sarapy-1.2.6 → sarapy-1.3.1}/sarapy/dataProcessing/__init__.py +0 -0
  18. {sarapy-1.2.6 → sarapy-1.3.1}/sarapy/mlProcessors/PlantinFMCreator.py +0 -0
  19. {sarapy-1.2.6 → sarapy-1.3.1}/sarapy/mlProcessors/__init__.py +0 -0
  20. {sarapy-1.2.6 → sarapy-1.3.1}/sarapy/preprocessing/DistancesImputer.py +0 -0
  21. {sarapy-1.2.6 → sarapy-1.3.1}/sarapy/preprocessing/FertilizerImputer.py +0 -0
  22. {sarapy-1.2.6 → sarapy-1.3.1}/sarapy/preprocessing/TransformInputData.py +0 -0
  23. {sarapy-1.2.6 → sarapy-1.3.1}/sarapy/preprocessing/__init__.py +0 -0
  24. {sarapy-1.2.6 → sarapy-1.3.1}/sarapy/utils/__init__.py +0 -0
  25. {sarapy-1.2.6 → sarapy-1.3.1}/sarapy/utils/amg_decoder.py +0 -0
  26. {sarapy-1.2.6 → sarapy-1.3.1}/sarapy/utils/amg_ppk.py +0 -0
  27. {sarapy-1.2.6 → sarapy-1.3.1}/sarapy/utils/getRawOperations.py +0 -0
  28. {sarapy-1.2.6 → sarapy-1.3.1}/sarapy.egg-info/dependency_links.txt +0 -0
  29. {sarapy-1.2.6 → sarapy-1.3.1}/sarapy.egg-info/requires.txt +0 -0
  30. {sarapy-1.2.6 → sarapy-1.3.1}/sarapy.egg-info/top_level.txt +0 -0
  31. {sarapy-1.2.6 → sarapy-1.3.1}/setup.cfg +0 -0
  32. {sarapy-1.2.6 → sarapy-1.3.1}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sarapy
3
- Version: 1.2.6
3
+ Version: 1.3.1
4
4
  Home-page: https://github.com/lucasbaldezzari/sarapy
5
5
  Author: Lucas Baldezzari
6
6
  Author-email: Lucas Baldezzari <lmbaldezzari@gmail.com>
@@ -19,6 +19,14 @@ Requires-Dist: geopy
19
19
 
20
20
  Library for processing SARAPICO project metadata of _AMG SA_.
21
21
 
22
+ #### Version 1.3.1
23
+
24
+ - Se modifica PlantinClassifier para tomar el umbral máximo de dst_pt en 4 y no en 7.
25
+
26
+ #### Version 1.3.0
27
+
28
+ - Se agrega funcionalidad para estimar la cantidad de gramos de fertilizante en base al nivel de distorsión de fertilizante arrojado por la electrónica. Se implementa mlProcessor.FertlizerFMCreator y mlProcessor.FertilizerTransformer. Además se modifican las clases OpsProcessor y TransformToOutputData para poder usar estas nuevas clases.
29
+
22
30
  #### Version 1.2.6
23
31
 
24
32
  - Se agrega línea dentro de clase OpsProcessor.
@@ -2,6 +2,14 @@
2
2
 
3
3
  Library for processing SARAPICO project metadata of _AMG SA_.
4
4
 
5
+ #### Version 1.3.1
6
+
7
+ - Se modifica PlantinClassifier para tomar el umbral máximo de dst_pt en 4 y no en 7.
8
+
9
+ #### Version 1.3.0
10
+
11
+ - Se agrega funcionalidad para estimar la cantidad de gramos de fertilizante en base al nivel de distorsión de fertilizante arrojado por la electrónica. Se implementa mlProcessor.FertlizerFMCreator y mlProcessor.FertilizerTransformer. Además se modifican las clases OpsProcessor y TransformToOutputData para poder usar estas nuevas clases.
12
+
5
13
  #### Version 1.2.6
6
14
 
7
15
  - Se agrega línea dentro de clase OpsProcessor.
@@ -1,7 +1,7 @@
1
1
  [project]
2
2
  name = "sarapy"
3
3
 
4
- version = "1.2.6"
4
+ version = "1.3.1"
5
5
  authors = [
6
6
  {name = "Lucas Baldezzari", email = "lmbaldezzari@gmail.com"},]
7
7
  maintainers = [
@@ -4,6 +4,7 @@ import pandas as pd
4
4
  from sarapy.mlProcessors import PlantinFMCreator
5
5
  from sarapy.mlProcessors import PlantinClassifier
6
6
  from sarapy.preprocessing import TransformInputData, TransformToOutputData
7
+ from sarapy.mlProcessors import FertilizerFMCreator, FertilizerTransformer
7
8
 
8
9
  class OpsProcessor():
9
10
  """Clase para procesar las operaciones de los operarios. La información se toma de la base de datos
@@ -40,7 +41,17 @@ class OpsProcessor():
40
41
 
41
42
  self._plantin_classifier = PlantinClassifier.PlantinClassifier(**kwargs_plclass)
42
43
  self.plantinFMCreator = PlantinFMCreator.PlantinFMCreator(**fmcreator_kargs)
43
- # self._fertilizerFMCreator = FertilizerFMCreator() ## PARA IMPLEMENTAR
44
+
45
+ ##mapa de argumentos para FertilizerTransformer
46
+ ft_map = {"regresor_file", "poly_features_file"}
47
+ ft_kwargs = {}
48
+ ##recorro kwargs y usando ft_map creo un nuevo diccionario con los valores que se pasaron
49
+ for key, value in kwargs.items():
50
+ if key in ft_map:
51
+ ft_kwargs[key] = value
52
+
53
+ self._ftfmcreator = FertilizerFMCreator.FertilizerFMCreator()
54
+ self._fertilizer_transformer = FertilizerTransformer.FertilizerTransformer(**ft_kwargs)
44
55
 
45
56
  self._operationsDict = {} ##diccionario de operarios con sus operaciones
46
57
  self._platin_classifiedOperations = np.array([]) ##array con las operaciones clasificadas para plantin
@@ -77,7 +88,7 @@ class OpsProcessor():
77
88
 
78
89
  Returns:
79
90
  Lista de diccionarios con las clasificaciones. Cada diccionario tiene la forma
80
- {"id_db_h": 10, "id_db_dw": 10, "tag_seedling": 1, "tag_fertilizer": 1}
91
+ {"id_db_h": 10, "id_db_dw": 10, "tag_seedling": 1, "tag_fertilizer": gramos (float)}
81
92
  """
82
93
 
83
94
  ##chqueo que newSample no esté vacío
@@ -86,13 +97,16 @@ class OpsProcessor():
86
97
  #Si tenemos nuevas operaciones, actualizamos el diccionario de operaciones
87
98
  self.updateOperationsDict(newSample) #actualizamos diccionario interno de la clase
88
99
  pl_clas = self.classifyForPlantin(**kwargs) #clasificamos las operaciones para plantín
89
- ft_clas = newSample[:,7].astype(int) #clasificamos las operaciones para fertilizante
100
+
101
+ #estimamos los gramos de fertilizante
102
+ dst_ft = self._ftfmcreator.transform(newSample[:,2]).astype(int)
103
+ ft_grams = self._fertilizer_transformer.transform(dst_ft.reshape(-1,1))
90
104
  id_db_h_nums, id_db_dw_nums = self.getActualOperationsNumbers() #obtenemos los números de operaciones desde el diccionario de operaciones
91
105
  date_oprc = newSample[:,3]
92
106
  return self.transformToOutputData.fit_transform(np.column_stack((id_db_h_nums,
93
107
  id_db_dw_nums,
94
108
  pl_clas,
95
- ft_clas,
109
+ ft_grams,
96
110
  date_oprc)))
97
111
  else:
98
112
  self.resetAllNewSamplesValues()
@@ -324,7 +338,8 @@ if __name__ == "__main__":
324
338
 
325
339
  import time
326
340
  start_time = time.time()
327
- op = OpsProcessor.OpsProcessor(classifier_file='modelos\\pipeline_rf.pkl', imputeDistances = False)
341
+ op = OpsProcessor.OpsProcessor(classifier_file='modelos\\pipeline_rf.pkl', imputeDistances = False,
342
+ regresor_file='modelos\\regresor.pkl', poly_features_file='modelos\\poly_features.pkl')
328
343
  classifications = op.processOperations(raw_ops, update_samePlace=True, useRatioStats=True)
329
344
  end_time = time.time()
330
345
  execution_time = end_time - start_time
@@ -334,4 +349,9 @@ if __name__ == "__main__":
334
349
  df = pd.DataFrame(classifications)
335
350
  tag_seedling = df["tag_seedling"].values
336
351
  print(tag_seedling.mean())
337
- print(df["tag_seedling"].shape)
352
+ print(df["tag_seedling"].shape)
353
+
354
+ ##datos de fertilizante
355
+ tag_fertilizer = df["tag_fertilizer"].values
356
+ print(tag_fertilizer[1500:1560])
357
+ print(tag_fertilizer.mean())
@@ -0,0 +1,54 @@
1
+ import numpy as np
2
+ from sklearn.base import BaseEstimator, TransformerMixin
3
+ from sarapy.dataProcessing import TLMSensorDataProcessor
4
+
5
+
6
+ class FertilizerFMCreator():
7
+ """Clase para crear la matriz de características para el procesamiento del fertilizante"""
8
+
9
+ def __init__(self):
10
+ self._dataPositions = {"DST_FT": 0}
11
+ self.dst_ft = None ##cuando no se ha transformado ningún dato, se inicializa en None
12
+
13
+ def transform(self, X):
14
+ """
15
+ Transforma los datos de telemetría para retornar los datos de distorsión de fertilizante.
16
+
17
+ Params:
18
+ - X: Es un array con los datos de telemetría. La forma de X es (n,1)
19
+
20
+ Returns:
21
+ - dst_ft: Array con los valores de distorsión de fertilizante.
22
+ """
23
+ tlmDataExtractor = TLMSensorDataProcessor.TLMSensorDataProcessor()
24
+ tlmdeDP = tlmDataExtractor.dataPositions #posiciones de los datos transformados de tlmDataExtractor
25
+
26
+ tlmExtracted = tlmDataExtractor.fit_transform(X)
27
+
28
+ self.dst_ft = tlmExtracted[:,tlmdeDP["DSTRFT"]]
29
+
30
+ return self.dst_ft
31
+
32
+ if __name__ == "__main__":
33
+ import os
34
+ import pandas as pd
35
+ import numpy as np
36
+ from sarapy.preprocessing import TransformInputData
37
+ from sarapy.mlProcessors import PlantinFMCreator
38
+ import sarapy.utils.getRawOperations as getRawOperations
39
+ tindata = TransformInputData.TransformInputData()
40
+
41
+ ##cargo los archivos examples\2024-09-04\UPM001N\data.json y examples\2024-09-04\UPM001N\historical-data.json
42
+ data_path = os.path.join(os.getcwd(), "examples\\2024-09-04\\UPM001N\\data.json")
43
+ historical_data_path = os.path.join(os.getcwd(), "examples\\2024-09-04\\UPM001N\\historical-data.json")
44
+ raw_data = pd.read_json(data_path, orient="records").to_dict(orient="records")
45
+ raw_data2 = pd.read_json(historical_data_path, orient="records").to_dict(orient="records")
46
+
47
+ raw_ops = np.array(getRawOperations.getRawOperations(raw_data, raw_data2))
48
+ X = tindata.fit_transform(raw_ops) #transforma los datos de operaciones a un array de numpy
49
+
50
+ from sarapy.mlProcessors import FertilizerFMCreator
51
+
52
+ ftfmcreator = FertilizerFMCreator.FertilizerFMCreator()
53
+ dst_ft = ftfmcreator.transform(X[:,2])
54
+ print(dst_ft[:10]) #imprime los primeros 10 valores de DST_FT
@@ -0,0 +1,81 @@
1
+ import pickle
2
+
3
+ class FertilizerTransformer:
4
+ """
5
+ Clase para tomar los valores de distorsión de fertilizante y transformarlos a gramos
6
+ """
7
+
8
+ def __init__(self, regresor_file, poly_features_file):
9
+ """Constructor de la clase FertilizerImputer.
10
+
11
+ Args:
12
+ - regresor: Regresor que transforma los valores de distorsión a gramos.
13
+ - poly_features: Grado del polinomio a utilizar en la transformación de los datos.
14
+ """
15
+ ##cargo el regresor con pickle. Usamos try para capturar el error FileNotFoundError
16
+ try:
17
+ with open(regresor_file, 'rb') as file:
18
+ self._regresor = pickle.load(file)
19
+ print("Regresor cargado con éxito.")
20
+ except FileNotFoundError:
21
+ print("El archivo no se encuentra en el directorio actual.")
22
+
23
+ ##cargo las características polinómicas con pickle. Usamos try para capturar el error FileNotFoundError
24
+ try:
25
+ with open(poly_features_file, 'rb') as file:
26
+ self._poly_features = pickle.load(file)
27
+ print("Características polinómicas cargadas con éxito.")
28
+ except FileNotFoundError:
29
+ print("El archivo no se encuentra en el directorio actual.")
30
+
31
+ self.fertilizer_grams = None ##cuando no se ha transformado ningún dato, se inicializa en None
32
+
33
+
34
+ def transform(self, X):
35
+ """Transforma los datos de distorsión de fertilizante a gramos.
36
+
37
+ Params:
38
+ - X: Es un array con los datos de distorsión de fertilizante. La forma de X es (n,1)
39
+
40
+ Ejemplo: [12. 1. 12. 0. 0. 0. 0. 0. 0. 12.]
41
+
42
+ Returns:
43
+ - 0: Array con los valores de distorsión de fertilizante transformados a gramos.
44
+ """
45
+
46
+ X_poly = self._poly_features.fit_transform(X)
47
+ self.fertilizer_grams = self._regresor.predict(X_poly)
48
+
49
+ ##retorno con shape (n,)
50
+ return self.fertilizer_grams.reshape(-1,)
51
+
52
+ if __name__ == "__main__":
53
+ import os
54
+ import pandas as pd
55
+ import numpy as np
56
+ from sarapy.preprocessing import TransformInputData
57
+ from sarapy.mlProcessors import PlantinFMCreator
58
+ import sarapy.utils.getRawOperations as getRawOperations
59
+ tindata = TransformInputData.TransformInputData()
60
+
61
+ ##cargo los archivos examples\2024-09-04\UPM001N\data.json y examples\2024-09-04\UPM001N\historical-data.json
62
+ data_path = os.path.join(os.getcwd(), "examples\\2024-09-04\\UPM001N\\data.json")
63
+ historical_data_path = os.path.join(os.getcwd(), "examples\\2024-09-04\\UPM001N\\historical-data.json")
64
+ raw_data = pd.read_json(data_path, orient="records").to_dict(orient="records")
65
+ raw_data2 = pd.read_json(historical_data_path, orient="records").to_dict(orient="records")
66
+
67
+ raw_ops = np.array(getRawOperations.getRawOperations(raw_data, raw_data2))
68
+ X = tindata.fit_transform(raw_ops) #transforma los datos de operaciones a un array de numpy
69
+
70
+ from sarapy.mlProcessors import FertilizerFMCreator
71
+
72
+ ftfmcreator = FertilizerFMCreator.FertilizerFMCreator()
73
+ dst_ft = ftfmcreator.transform(X[:,2])
74
+ ##convierto a int dst_ft
75
+ dst_ft = dst_ft.astype(int)
76
+
77
+ from sarapy.mlProcessors import FertilizerTransformer
78
+
79
+ fertransformer = FertilizerTransformer.FertilizerTransformer(regresor_file='modelos\\regresor.pkl', poly_features_file='modelos\\poly_features.pkl')
80
+ gramos = fertransformer.transform(dst_ft.reshape(-1,1))
81
+ print(gramos[:10])
@@ -129,12 +129,12 @@ class PlantinClassifier(BaseEstimator, TransformerMixin):
129
129
  Función para actualizar las etiquetas de las operaciones que tengan distorsiones de plantín.
130
130
  """
131
131
  new_labels = labels.copy()
132
+
132
133
  ##filtro si dst_pt es menor a 7 y si inest_pt es 0
133
- new_labels[(dst_pt < 7) & (inest_pt == 0)] = 0
134
+ new_labels[(dst_pt < 4) & (inest_pt == 0)] = 0
134
135
 
135
- ##si inest_pt es y umbral_proba es menor a umbra_proba, entonces la operación es 0
136
+ ##si inest_pt 1 es y umbral_proba es menor a umbra_proba, entonces la operación es 0
136
137
  new_labels[(inest_pt == 1) & (self.probas[:,1] < umbral_proba)] = 0
137
- # new_labels[(inest_pt == 1) & (self.probas[:,1] >= umbral_proba)] = 1
138
138
 
139
139
  return new_labels
140
140
 
@@ -53,9 +53,11 @@ class TransformToOutputData(BaseEstimator, TransformerMixin):
53
53
  date_data = X[:,4].astype(int)
54
54
  date_oprc = np.array([datetime.datetime.fromtimestamp(date, datetime.timezone.utc) for date in date_data])
55
55
  self.temp_df.loc[:,"date_oprc"] = date_oprc.flatten()
56
- ##convierto las columnas "id_db_h", "id_db_dw", "tag_seedling", "tag_fertilizer" a int
57
- for col in ["id_db_h", "id_db_dw", "tag_seedling", "tag_fertilizer"]:
56
+ ##convierto las columnas "id_db_h", "id_db_dw", "tag_seedling" a int
57
+ for col in ["id_db_h", "id_db_dw", "tag_seedling"]:
58
58
  self.temp_df[col] = self.temp_df[col].astype(float).astype(int)
59
+ ##convierto la columna "tag_fertilizer" a float de y redondeo a 3 decimales
60
+ self.temp_df["tag_fertilizer"] = self.temp_df["tag_fertilizer"].astype(float).round(3)
59
61
 
60
62
  return self
61
63
 
@@ -1,2 +1,2 @@
1
1
  ## Version of the package
2
- __version__ = "1.2.6"
2
+ __version__ = "1.3.1"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sarapy
3
- Version: 1.2.6
3
+ Version: 1.3.1
4
4
  Home-page: https://github.com/lucasbaldezzari/sarapy
5
5
  Author: Lucas Baldezzari
6
6
  Author-email: Lucas Baldezzari <lmbaldezzari@gmail.com>
@@ -19,6 +19,14 @@ Requires-Dist: geopy
19
19
 
20
20
  Library for processing SARAPICO project metadata of _AMG SA_.
21
21
 
22
+ #### Version 1.3.1
23
+
24
+ - Se modifica PlantinClassifier para tomar el umbral máximo de dst_pt en 4 y no en 7.
25
+
26
+ #### Version 1.3.0
27
+
28
+ - Se agrega funcionalidad para estimar la cantidad de gramos de fertilizante en base al nivel de distorsión de fertilizante arrojado por la electrónica. Se implementa mlProcessor.FertlizerFMCreator y mlProcessor.FertilizerTransformer. Además se modifican las clases OpsProcessor y TransformToOutputData para poder usar estas nuevas clases.
29
+
22
30
  #### Version 1.2.6
23
31
 
24
32
  - Se agrega línea dentro de clase OpsProcessor.
@@ -14,6 +14,8 @@ sarapy/dataProcessing/OpsProcessor.py
14
14
  sarapy/dataProcessing/TLMSensorDataProcessor.py
15
15
  sarapy/dataProcessing/TimeSeriesProcessor.py
16
16
  sarapy/dataProcessing/__init__.py
17
+ sarapy/mlProcessors/FertilizerFMCreator.py
18
+ sarapy/mlProcessors/FertilizerTransformer.py
17
19
  sarapy/mlProcessors/PlantinClassifier.py
18
20
  sarapy/mlProcessors/PlantinFMCreator.py
19
21
  sarapy/mlProcessors/__init__.py
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes