geocif 0.1.39__tar.gz → 0.1.41__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 (55) hide show
  1. {geocif-0.1.39/geocif.egg-info → geocif-0.1.41}/PKG-INFO +1 -1
  2. {geocif-0.1.39 → geocif-0.1.41}/geocif/experiments.py +24 -8
  3. {geocif-0.1.39 → geocif-0.1.41}/geocif/geocif.py +15 -5
  4. {geocif-0.1.39 → geocif-0.1.41}/geocif/indices_runner_v2.py +1 -1
  5. {geocif-0.1.39 → geocif-0.1.41}/geocif/ml/feature_engineering.py +1 -1
  6. {geocif-0.1.39 → geocif-0.1.41}/geocif/ml/output.py +2 -0
  7. {geocif-0.1.39 → geocif-0.1.41}/geocif/ml/xai.py +2 -1
  8. {geocif-0.1.39 → geocif-0.1.41}/geocif/utils.py +1 -1
  9. {geocif-0.1.39 → geocif-0.1.41/geocif.egg-info}/PKG-INFO +1 -1
  10. {geocif-0.1.39 → geocif-0.1.41}/setup.py +1 -1
  11. {geocif-0.1.39 → geocif-0.1.41}/LICENSE +0 -0
  12. {geocif-0.1.39 → geocif-0.1.41}/MANIFEST.in +0 -0
  13. {geocif-0.1.39 → geocif-0.1.41}/README.md +0 -0
  14. {geocif-0.1.39 → geocif-0.1.41}/geocif/__init__.py +0 -0
  15. {geocif-0.1.39 → geocif-0.1.41}/geocif/agmet/__init__.py +0 -0
  16. {geocif-0.1.39 → geocif-0.1.41}/geocif/agmet/geoagmet.py +0 -0
  17. {geocif-0.1.39 → geocif-0.1.41}/geocif/agmet/plot.py +0 -0
  18. {geocif-0.1.39 → geocif-0.1.41}/geocif/agmet/utils.py +0 -0
  19. {geocif-0.1.39 → geocif-0.1.41}/geocif/analysis.py +0 -0
  20. {geocif-0.1.39 → geocif-0.1.41}/geocif/backup/__init__.py +0 -0
  21. {geocif-0.1.39 → geocif-0.1.41}/geocif/backup/constants.py +0 -0
  22. {geocif-0.1.39 → geocif-0.1.41}/geocif/backup/features.py +0 -0
  23. {geocif-0.1.39 → geocif-0.1.41}/geocif/backup/geo.py +0 -0
  24. {geocif-0.1.39 → geocif-0.1.41}/geocif/backup/geocif.py +0 -0
  25. {geocif-0.1.39 → geocif-0.1.41}/geocif/backup/metadata.py +0 -0
  26. {geocif-0.1.39 → geocif-0.1.41}/geocif/backup/models.py +0 -0
  27. {geocif-0.1.39 → geocif-0.1.41}/geocif/cei/__init__.py +0 -0
  28. {geocif-0.1.39 → geocif-0.1.41}/geocif/cei/definitions.py +0 -0
  29. {geocif-0.1.39 → geocif-0.1.41}/geocif/cei/indices.py +0 -0
  30. {geocif-0.1.39 → geocif-0.1.41}/geocif/indices_runner.py +0 -0
  31. {geocif-0.1.39 → geocif-0.1.41}/geocif/logger.py +0 -0
  32. {geocif-0.1.39 → geocif-0.1.41}/geocif/ml/__init__.py +0 -0
  33. {geocif-0.1.39 → geocif-0.1.41}/geocif/ml/correlations.py +0 -0
  34. {geocif-0.1.39 → geocif-0.1.41}/geocif/ml/correlations_backup.py +0 -0
  35. {geocif-0.1.39 → geocif-0.1.41}/geocif/ml/embedding.py +0 -0
  36. {geocif-0.1.39 → geocif-0.1.41}/geocif/ml/feature_selection.py +0 -0
  37. {geocif-0.1.39 → geocif-0.1.41}/geocif/ml/outliers.py +0 -0
  38. {geocif-0.1.39 → geocif-0.1.41}/geocif/ml/outlook.py +0 -0
  39. {geocif-0.1.39 → geocif-0.1.41}/geocif/ml/spatial_autocorrelation.py +0 -0
  40. {geocif-0.1.39 → geocif-0.1.41}/geocif/ml/stages.py +0 -0
  41. {geocif-0.1.39 → geocif-0.1.41}/geocif/ml/stats.py +0 -0
  42. {geocif-0.1.39 → geocif-0.1.41}/geocif/ml/trainers.py +0 -0
  43. {geocif-0.1.39 → geocif-0.1.41}/geocif/ml/trend.py +0 -0
  44. {geocif-0.1.39 → geocif-0.1.41}/geocif/playground/__init__.py +0 -0
  45. {geocif-0.1.39 → geocif-0.1.41}/geocif/playground/automl.py +0 -0
  46. {geocif-0.1.39 → geocif-0.1.41}/geocif/playground/misc.py +0 -0
  47. {geocif-0.1.39 → geocif-0.1.41}/geocif/viz/__init__.py +0 -0
  48. {geocif-0.1.39 → geocif-0.1.41}/geocif/viz/plot.py +0 -0
  49. {geocif-0.1.39 → geocif-0.1.41}/geocif.egg-info/SOURCES.txt +0 -0
  50. {geocif-0.1.39 → geocif-0.1.41}/geocif.egg-info/dependency_links.txt +0 -0
  51. {geocif-0.1.39 → geocif-0.1.41}/geocif.egg-info/not-zip-safe +0 -0
  52. {geocif-0.1.39 → geocif-0.1.41}/geocif.egg-info/top_level.txt +0 -0
  53. {geocif-0.1.39 → geocif-0.1.41}/requirements.txt +0 -0
  54. {geocif-0.1.39 → geocif-0.1.41}/setup.cfg +0 -0
  55. {geocif-0.1.39 → geocif-0.1.41}/tests/test_geocif.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: geocif
3
- Version: 0.1.39
3
+ Version: 0.1.41
4
4
  Summary: Models to visualize and forecast crop conditions and yields
5
5
  Home-page: https://ritviksahajpal.github.io/yield_forecasting/
6
6
  Author: Ritvik Sahajpal
@@ -15,6 +15,10 @@ warnings.simplefilter(action="ignore", category=FutureWarning)
15
15
 
16
16
 
17
17
  def main(inputs, logger, parser, section, item, type, values):
18
+ # Set experiment_name
19
+ experiment_name = f"{section}_{item}"
20
+ parser.set("DEFAULT", "experiment_name", experiment_name)
21
+
18
22
  if type == "str":
19
23
  original_value = parser.get(section, item)
20
24
  elif type == "bool":
@@ -49,13 +53,25 @@ def run(path_config_files=[Path("../config/geocif.txt")]):
49
53
  logger.info("\tStarting GEOCIF Experiments")
50
54
  logger.info("=============================")
51
55
 
52
- # Experiment 1: include_lat_lon
56
+ # Experiment: Models
57
+ logger.info("Experiment 0: Models")
58
+ parser = main(
59
+ inputs,
60
+ logger,
61
+ parser,
62
+ "DEFAULT",
63
+ "model",
64
+ "str",
65
+ ["catboost", "merf", "linear"],
66
+ )
67
+
68
+ # Experiment: include_lat_lon
53
69
  logger.info("Experiment 1: include_lat_lon")
54
70
  parser = main(
55
71
  inputs, logger, parser, "ML", "include_lat_lon", "bool", [True, False]
56
72
  )
57
73
 
58
- # Experiment 2: feature_selection
74
+ # Experiment: feature_selection
59
75
  logger.info("Experiment 2: feature_selection")
60
76
  parser = main(
61
77
  inputs,
@@ -67,13 +83,13 @@ def run(path_config_files=[Path("../config/geocif.txt")]):
67
83
  ["SelectKBest", "BorutaPy", "Leshy", "RFECV", "RFE"],
68
84
  )
69
85
 
70
- # Experiment 3: lag_years
86
+ # Experiment: lag_years
71
87
  logger.info("Experiment 3: lag_years")
72
88
  parser = main(
73
89
  inputs, logger, parser, "ML", "lag_years", "int", [1, 2, 3, 4, 5]
74
90
  )
75
91
 
76
- # Experiment 4: lag_yield_as_feature
92
+ # Experiment: lag_yield_as_feature
77
93
  logger.info("Experiment 4: lag_yield_as_feature")
78
94
  parser = main(
79
95
  inputs,
@@ -85,13 +101,13 @@ def run(path_config_files=[Path("../config/geocif.txt")]):
85
101
  [True, False],
86
102
  )
87
103
 
88
- # Experiment 5: median_years
104
+ # Experiment: median_years
89
105
  logger.info("Experiment 5: median_years")
90
106
  parser = main(
91
107
  inputs, logger, parser, "ML", "median_years", "int", [2, 3, 4, 5]
92
108
  )
93
109
 
94
- # Experiment 6: median_yield_as_feature
110
+ # Experiment: median_yield_as_feature
95
111
  logger.info("Experiment 6: median_yield_as_feature")
96
112
  parser = main(
97
113
  inputs,
@@ -103,7 +119,7 @@ def run(path_config_files=[Path("../config/geocif.txt")]):
103
119
  [True, False],
104
120
  )
105
121
 
106
- # Experiment 7: analogous_year_yield_as_feature
122
+ # Experiment: analogous_year_yield_as_feature
107
123
  logger.info("Experiment 7: analogous_year_yield_as_feature")
108
124
  parser = main(
109
125
  inputs,
@@ -115,7 +131,7 @@ def run(path_config_files=[Path("../config/geocif.txt")]):
115
131
  [True, False],
116
132
  )
117
133
 
118
- # Experiment 8: optimize
134
+ # Experiment: optimize
119
135
  logger.info("Experiment 8: optimize")
120
136
  parser = main(
121
137
  inputs, logger, parser, "DEFAULT", "optimize", "bool", [True, False]
@@ -132,6 +132,9 @@ class Geocif:
132
132
  self.median_yield_as_feature = self.parser.getboolean(
133
133
  "ML", "median_yield_as_feature"
134
134
  )
135
+ self.median_area_as_feature = self.parser.getboolean(
136
+ "ML", "median_area_as_feature"
137
+ )
135
138
  self.number_lag_years = self.parser.getint("ML", "lag_years")
136
139
  self.cluster_strategy = self.parser.get("ML", "cluster_strategy")
137
140
  self.feature_selection = self.parser.get("ML", "feature_selection")
@@ -644,6 +647,7 @@ class Geocif:
644
647
  kwargs = {
645
648
  "cluster_strategy": self.cluster_strategy,
646
649
  "model": self.model,
650
+ "model_name": self.model_name,
647
651
  "forecast_season": self.forecast_season,
648
652
  "crop": self.crop,
649
653
  "country": self.country,
@@ -659,6 +663,7 @@ class Geocif:
659
663
  model = self.model.estimator_
660
664
  else:
661
665
  model = self.model
666
+
662
667
  output.store(self.db_path, experiment_id, df, model, self.model_name)
663
668
 
664
669
  def get_cei_column_names(self, df):
@@ -734,10 +739,15 @@ class Geocif:
734
739
  df = fe.compute_last_year_yield(df)
735
740
 
736
741
  if self.median_yield_as_feature:
737
- df = fe.compute_median_yield(
742
+ df = fe.compute_median_statistics(
738
743
  df, self.all_seasons_with_yield, self.number_median_years
739
744
  )
740
745
 
746
+ if self.median_area_as_feature:
747
+ df = fe.compute_median_statistics(
748
+ df, self.all_seasons_with_area, self.number_median_years, "Area (ha)"
749
+ )
750
+
741
751
  if self.lag_yield_as_feature:
742
752
  df = fe.compute_lag_yield(
743
753
  df, self.all_seasons_with_yield, self.number_lag_years
@@ -1105,6 +1115,10 @@ def loop_execute(inputs):
1105
1115
  with PyCallGraph(output=graphviz, config=config):
1106
1116
  country, crop, season, model, logger, parser = inputs
1107
1117
 
1118
+ logger.info("=====================================================")
1119
+ logger.info(f"\tStarting GEOCIF: {country} {crop} {season} {model}")
1120
+ logger.info("=====================================================")
1121
+
1108
1122
  obj = Geocif(logger=logger, parser=parser)
1109
1123
  obj.read_data(country, crop, season)
1110
1124
 
@@ -1176,10 +1190,6 @@ def main(logger, parser):
1176
1190
  Returns:
1177
1191
 
1178
1192
  """
1179
- logger.info("===========================")
1180
- logger.info("\tStarting GEOCIF")
1181
- logger.info("===========================")
1182
-
1183
1193
  inputs = gather_inputs(parser)
1184
1194
  execute_models(inputs, logger, parser)
1185
1195
 
@@ -157,7 +157,7 @@ class cei_runner(base.BaseGeo):
157
157
  "ndvi",
158
158
  False, # redo
159
159
  )
160
- for year in range(2024, ar.utcnow().year + 1)
160
+ for year in range(2001, ar.utcnow().year + 1)
161
161
  for status, path, filename, admin_zone, category in combinations
162
162
  ]
163
163
 
@@ -62,7 +62,7 @@ def compute_closest_years(all_years, harvest_year, number_lag_years):
62
62
  return closest_years.tolist()
63
63
 
64
64
 
65
- def compute_median_yield(
65
+ def compute_median_statistics(
66
66
  df, all_seasons_with_yield, number_median_years, target_col="Yield (tn per ha)"
67
67
  ):
68
68
  """
@@ -107,6 +107,7 @@ def store(db_path, experiment_id, df, model, model_name):
107
107
  try:
108
108
  utils.to_db(db_path, experiment_id, df)
109
109
  except Exception as e:
110
+ breakpoint()
110
111
  print(f"Error: {e}")
111
112
 
112
113
  index_columns = ["Country", "Region", "Crop", "Harvest Year", "Stages"]
@@ -127,6 +128,7 @@ def store(db_path, experiment_id, df, model, model_name):
127
128
  df_model.index.set_names(["Index"], inplace=True)
128
129
  utils.to_db(db_path, "models", df_model)
129
130
  except Exception as e:
131
+ breakpoint()
130
132
  print(f"Error: {e}")
131
133
 
132
134
  con.commit()
@@ -8,6 +8,7 @@ from tqdm import tqdm
8
8
  def explain(df_train, df_test, **kwargs):
9
9
  cluster_strategy = kwargs.get("cluster_strategy", "auto_detect")
10
10
  model = kwargs.get("model")
11
+ model_name = kwargs.get("model_name")
11
12
  forecast_season = kwargs.get("forecast_season")
12
13
  crop = kwargs.get("crop")
13
14
  country = kwargs.get("country")
@@ -48,7 +49,7 @@ def explain(df_train, df_test, **kwargs):
48
49
  plt.tight_layout()
49
50
 
50
51
  fname = f"beeswarm_{region_name}_{forecast_season}.png"
51
- out_dir = analysis_dir / country / crop / str(forecast_season)
52
+ out_dir = analysis_dir / country / crop / model_name / str(forecast_season)
52
53
  os.makedirs(out_dir, exist_ok=True)
53
54
  plt.savefig(out_dir / fname, dpi=250)
54
55
  plt.close()
@@ -332,7 +332,7 @@ def create_output_directory(method, admin_zone, country, crop, path_output):
332
332
 
333
333
  :return:
334
334
  """
335
- dir_output = path_output / "fao" / "indices" / method / admin_zone / country / crop
335
+ dir_output = path_output / "cei" / "indices" / method / admin_zone / country / crop
336
336
  os.makedirs(dir_output, exist_ok=True)
337
337
 
338
338
  return dir_output
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: geocif
3
- Version: 0.1.39
3
+ Version: 0.1.41
4
4
  Summary: Models to visualize and forecast crop conditions and yields
5
5
  Home-page: https://ritviksahajpal.github.io/yield_forecasting/
6
6
  Author: Ritvik Sahajpal
@@ -50,6 +50,6 @@ setup(
50
50
  test_suite="tests",
51
51
  tests_require=test_requirements,
52
52
  url="https://ritviksahajpal.github.io/yield_forecasting/",
53
- version="0.1.39",
53
+ version="0.1.41",
54
54
  zip_safe=False,
55
55
  )
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
File without changes
File without changes