geocif 0.1.32__tar.gz → 0.1.33__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 (52) hide show
  1. {geocif-0.1.32/geocif.egg-info → geocif-0.1.33}/PKG-INFO +1 -1
  2. {geocif-0.1.32 → geocif-0.1.33}/geocif/geocif.py +40 -0
  3. {geocif-0.1.32 → geocif-0.1.33}/geocif/ml/spatial_autocorrelation.py +6 -7
  4. {geocif-0.1.32 → geocif-0.1.33}/geocif/ml/trainers.py +34 -0
  5. {geocif-0.1.32 → geocif-0.1.33/geocif.egg-info}/PKG-INFO +1 -1
  6. {geocif-0.1.32 → geocif-0.1.33}/setup.py +1 -1
  7. {geocif-0.1.32 → geocif-0.1.33}/LICENSE +0 -0
  8. {geocif-0.1.32 → geocif-0.1.33}/MANIFEST.in +0 -0
  9. {geocif-0.1.32 → geocif-0.1.33}/README.md +0 -0
  10. {geocif-0.1.32 → geocif-0.1.33}/geocif/__init__.py +0 -0
  11. {geocif-0.1.32 → geocif-0.1.33}/geocif/agmet/__init__.py +0 -0
  12. {geocif-0.1.32 → geocif-0.1.33}/geocif/agmet/geoagmet.py +0 -0
  13. {geocif-0.1.32 → geocif-0.1.33}/geocif/agmet/plot.py +0 -0
  14. {geocif-0.1.32 → geocif-0.1.33}/geocif/agmet/utils.py +0 -0
  15. {geocif-0.1.32 → geocif-0.1.33}/geocif/analysis.py +0 -0
  16. {geocif-0.1.32 → geocif-0.1.33}/geocif/backup/__init__.py +0 -0
  17. {geocif-0.1.32 → geocif-0.1.33}/geocif/backup/constants.py +0 -0
  18. {geocif-0.1.32 → geocif-0.1.33}/geocif/backup/features.py +0 -0
  19. {geocif-0.1.32 → geocif-0.1.33}/geocif/backup/geo.py +0 -0
  20. {geocif-0.1.32 → geocif-0.1.33}/geocif/backup/geocif.py +0 -0
  21. {geocif-0.1.32 → geocif-0.1.33}/geocif/backup/metadata.py +0 -0
  22. {geocif-0.1.32 → geocif-0.1.33}/geocif/backup/models.py +0 -0
  23. {geocif-0.1.32 → geocif-0.1.33}/geocif/cei/__init__.py +0 -0
  24. {geocif-0.1.32 → geocif-0.1.33}/geocif/cei/definitions.py +0 -0
  25. {geocif-0.1.32 → geocif-0.1.33}/geocif/cei/indices.py +0 -0
  26. {geocif-0.1.32 → geocif-0.1.33}/geocif/indices_runner.py +0 -0
  27. {geocif-0.1.32 → geocif-0.1.33}/geocif/logger.py +0 -0
  28. {geocif-0.1.32 → geocif-0.1.33}/geocif/ml/__init__.py +0 -0
  29. {geocif-0.1.32 → geocif-0.1.33}/geocif/ml/correlations.py +0 -0
  30. {geocif-0.1.32 → geocif-0.1.33}/geocif/ml/embedding.py +0 -0
  31. {geocif-0.1.32 → geocif-0.1.33}/geocif/ml/feature_engineering.py +0 -0
  32. {geocif-0.1.32 → geocif-0.1.33}/geocif/ml/feature_selection.py +0 -0
  33. {geocif-0.1.32 → geocif-0.1.33}/geocif/ml/outliers.py +0 -0
  34. {geocif-0.1.32 → geocif-0.1.33}/geocif/ml/outlook.py +0 -0
  35. {geocif-0.1.32 → geocif-0.1.33}/geocif/ml/output.py +0 -0
  36. {geocif-0.1.32 → geocif-0.1.33}/geocif/ml/stages.py +0 -0
  37. {geocif-0.1.32 → geocif-0.1.33}/geocif/ml/stats.py +0 -0
  38. {geocif-0.1.32 → geocif-0.1.33}/geocif/ml/trend.py +0 -0
  39. {geocif-0.1.32 → geocif-0.1.33}/geocif/ml/xai.py +0 -0
  40. {geocif-0.1.32 → geocif-0.1.33}/geocif/playground/__init__.py +0 -0
  41. {geocif-0.1.32 → geocif-0.1.33}/geocif/playground/automl.py +0 -0
  42. {geocif-0.1.32 → geocif-0.1.33}/geocif/playground/misc.py +0 -0
  43. {geocif-0.1.32 → geocif-0.1.33}/geocif/utils.py +0 -0
  44. {geocif-0.1.32 → geocif-0.1.33}/geocif/viz/__init__.py +0 -0
  45. {geocif-0.1.32 → geocif-0.1.33}/geocif/viz/plot.py +0 -0
  46. {geocif-0.1.32 → geocif-0.1.33}/geocif.egg-info/SOURCES.txt +0 -0
  47. {geocif-0.1.32 → geocif-0.1.33}/geocif.egg-info/dependency_links.txt +0 -0
  48. {geocif-0.1.32 → geocif-0.1.33}/geocif.egg-info/not-zip-safe +0 -0
  49. {geocif-0.1.32 → geocif-0.1.33}/geocif.egg-info/top_level.txt +0 -0
  50. {geocif-0.1.32 → geocif-0.1.33}/requirements.txt +0 -0
  51. {geocif-0.1.32 → geocif-0.1.33}/setup.cfg +0 -0
  52. {geocif-0.1.32 → geocif-0.1.33}/tests/test_geocif.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: geocif
3
- Version: 0.1.32
3
+ Version: 0.1.33
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
@@ -222,6 +222,10 @@ class Geocif:
222
222
  self.logger.info(f"Selected features: {self.selected_features}")
223
223
 
224
224
  """ Update model to include conformal estimates """
225
+ if "lat" not in self.selected_features:
226
+ self.selected_features.append("lat")
227
+ if "lon" not in self.selected_features:
228
+ self.selected_features.append("lon")
225
229
  X_train = df_region[self.selected_features + self.cat_features]
226
230
  dir_output = (
227
231
  self.dir_analysis
@@ -275,6 +279,12 @@ class Geocif:
275
279
  verbose=False,
276
280
  # callbacks=[TQDMCallback(self.best_hyperparams["iterations"])],
277
281
  )
282
+ elif self.model_name == "geospaNN":
283
+ self.model.fit(
284
+ X_train,
285
+ y_train,
286
+ # callbacks=[TQDMCallback(self.best_hyperparams["iterations"])],
287
+ )
278
288
  elif self.model_name == "merf":
279
289
  Z_train = np.ones((len(X_train), 1))
280
290
  clusters_train = df_region["Region"]
@@ -341,6 +351,25 @@ class Geocif:
341
351
  X_test, Z_test, clusters_test.astype("object")
342
352
  )
343
353
  best_hyperparameters = self.model.fe_model.get_params().copy()
354
+ elif self.model_name == "geospaNN":
355
+ import torch
356
+ import geospaNN
357
+
358
+ # Remove any categorical features
359
+ X_test = X_test.drop(columns=self.cat_features)
360
+ X = torch.from_numpy(X_test.to_numpy()).float()
361
+ coord = torch.from_numpy(self.df_test[['lon', 'lat']].to_numpy()).float()
362
+
363
+ p = X.shape[1]
364
+ n = X.shape[0]
365
+ nn = 5
366
+
367
+ data = geospaNN.make_graph(X, Y, coord, nn)
368
+
369
+ # remove categorical features from df_train
370
+ data_train = df_region[self.selected_features + self.cat_features + [self.target]]
371
+ w_train = data_train.y - self.estimate(data_train.x)
372
+
344
373
  else:
345
374
  y_pred = self.model.predict(X_test)
346
375
  best_hyperparameters = self.model.get_params().copy()
@@ -527,6 +556,10 @@ class Geocif:
527
556
  if self.use_outlook_as_feature:
528
557
  self.feature_names.append("FCST")
529
558
 
559
+ # Add lat and lon to feature names
560
+ self.feature_names.append("lat")
561
+ self.feature_names.append("lon")
562
+
530
563
  self.selected_features = []
531
564
 
532
565
  def loop_ml(self, stages, dict_selected_features, dict_best_cei):
@@ -782,6 +815,13 @@ class Geocif:
782
815
  how="outer",
783
816
  )
784
817
 
818
+ # Add a lat and lon column to self.dg_country
819
+ self.dg_country["lat"] = self.dg_country.centroid.y
820
+ self.dg_country["lon"] = self.dg_country.centroid.x
821
+
822
+ # Add lat and lon columns to df by merging on Country Region column
823
+ df = df.merge(self.dg_country[["Country Region", "lat", "lon"]].drop_duplicates(), on="Country Region", how="left")
824
+
785
825
  dict_kwargs = {}
786
826
  dict_kwargs["all_stages"] = self.all_stages
787
827
  dict_kwargs["target_col"] = self.target
@@ -77,7 +77,7 @@ def create_base_weights(merged_df):
77
77
  return w_base, dg
78
78
 
79
79
 
80
- def create_weights_for_year(dg_country, regions_with_data):
80
+ def create_weights_for_year(dg_country, regions_with_data, year):
81
81
  """
82
82
 
83
83
  Args:
@@ -97,10 +97,8 @@ def create_weights_for_year(dg_country, regions_with_data):
97
97
  ]
98
98
  if no_neighbors:
99
99
  dg = dg.drop(index=no_neighbors[0]).reset_index(drop=True)
100
- try:
101
- wt = weights.Queen.from_dataframe(dg[["Country Region", "geometry"]])
102
- except:
103
- breakpoint()
100
+ wt = weights.Queen.from_dataframe(dg[["Country Region", "geometry"]])
101
+
104
102
  return wt, dg
105
103
 
106
104
 
@@ -125,6 +123,8 @@ def compute_morans_i(merged_df):
125
123
  for year in tqdm(years, desc="Compute Moran's I"):
126
124
  year_data = merged_df[merged_df["Harvest Year"] == year]
127
125
  regions_with_data = year_data["Country Region"].unique()
126
+ if len(regions_with_data) < 3:
127
+ continue
128
128
  year_data = year_data[year_data["Country Region"].isin(regions_with_data)]
129
129
 
130
130
  y = year_data[
@@ -132,9 +132,8 @@ def compute_morans_i(merged_df):
132
132
  ].drop_duplicates()
133
133
  dg_country = year_data[["Country Region", "geometry"]].drop_duplicates()
134
134
 
135
- w, x = create_weights_for_year(dg_country, regions_with_data)
135
+ w, x = create_weights_for_year(dg_country, regions_with_data, year)
136
136
  y = y[y["Country Region"].isin(x["Country Region"])]
137
-
138
137
  if len(y) > 1:
139
138
  try:
140
139
  mi = esda.Moran(y["Yield (tn per ha)"].values, w, permutations=999)
@@ -289,6 +289,40 @@ def auto_train(
289
289
  model = LinearGAM(n_splines=25, spline_order=3).gridsearch(
290
290
  X_train.values, y_train.values, lam=np.logspace(-3, 3, 11)
291
291
  )
292
+ elif model_name == "geospaNN":
293
+ import torch
294
+ import geospaNN
295
+
296
+ # Remove any categorical features
297
+ X_train = X_train.drop(columns=cat_features)
298
+ X = torch.from_numpy(X_train.to_numpy()).float()
299
+ Y = torch.from_numpy(y_train.to_numpy().reshape(-1)).float()
300
+
301
+ coord = torch.from_numpy(df_train[['lon', 'lat']].to_numpy()).float()
302
+
303
+ p = X.shape[1]
304
+ n = X.shape[0]
305
+ nn = 5
306
+
307
+ data = geospaNN.make_graph(X, Y, coord, nn)
308
+
309
+ mlp = torch.nn.Sequential(
310
+ torch.nn.Linear(p, 50),
311
+ torch.nn.ReLU(),
312
+ torch.nn.Linear(50, 20),
313
+ torch.nn.ReLU(),
314
+ torch.nn.Linear(20, 10),
315
+ torch.nn.ReLU(),
316
+ torch.nn.Linear(10, 1),
317
+ )
318
+
319
+ # Split data
320
+ data_train, data_val, data_test = geospaNN.split_data(X, Y, coord, neighbor_size=nn, test_proportion=0.1)
321
+ theta0 = geospaNN.theta_update(torch.tensor([1, 1.5, 0.01]), mlp(data_train.x).squeeze() - data_train.y, data_train.pos, neighbor_size=5)
322
+ model = geospaNN.nngls(p=p, neighbor_size=nn, coord_dimensions=2, mlp=mlp, theta=torch.tensor(theta0))
323
+ nngls_model = geospaNN.nngls_train(model, lr=0.01, min_delta=0.001)
324
+ # Log training process
325
+ training_log = nngls_model.train(data_train, data_val, data_test, Update_init=10, Update_step=10)
292
326
  elif model_name == "xgboost":
293
327
  raise NotImplementedError
294
328
  else:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: geocif
3
- Version: 0.1.32
3
+ Version: 0.1.33
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.32",
53
+ version="0.1.33",
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
File without changes
File without changes