Sarikaa-Sridhar commited on
Commit
2247fc5
·
verified ·
1 Parent(s): c32f8d3

Upload 5 files

Browse files
Files changed (5) hide show
  1. config.json +283 -0
  2. model.safetensors +3 -0
  3. pipeline_yield.py +329 -0
  4. sample_input_weekly.json +399 -0
  5. sample_test.py +59 -0
config.json ADDED
@@ -0,0 +1,283 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "K": 52,
3
+ "S": 66,
4
+ "W": 6,
5
+ "architectures": [
6
+ "YieldForRegression"
7
+ ],
8
+ "crop_emb_dim": 8,
9
+ "d_model": 64,
10
+ "dim_ff": 128,
11
+ "dropout": 0.4,
12
+ "dtype": "float32",
13
+ "eval_cutoffs": [
14
+ 20,
15
+ 24,
16
+ 28,
17
+ 32,
18
+ 36,
19
+ 40,
20
+ 44,
21
+ 48,
22
+ 52
23
+ ],
24
+ "model_type": "yield-weather-soil",
25
+ "nhead": 4,
26
+ "num_layers": 4,
27
+ "pool": "last",
28
+ "s_mean": [
29
+ 138.40794372558594,
30
+ 152.29786682128906,
31
+ 154.56175231933594,
32
+ 160.80038452148438,
33
+ 164.22401428222656,
34
+ 165.8285675048828,
35
+ 232.1925506591797,
36
+ 211.66586303710938,
37
+ 208.61048889160156,
38
+ 210.4038543701172,
39
+ 196.25576782226562,
40
+ 169.04379272460938,
41
+ 16.51355743408203,
42
+ 16.052227020263672,
43
+ 16.29838752746582,
44
+ 18.991479873657227,
45
+ 26.101285934448242,
46
+ 35.37116241455078,
47
+ 293.3885192871094,
48
+ 296.4434814453125,
49
+ 315.0303039550781,
50
+ 331.96435546875,
51
+ 329.5356750488281,
52
+ 309.2357177734375,
53
+ 3859.735107421875,
54
+ 2151.462158203125,
55
+ 1574.3883056640625,
56
+ 1057.6832275390625,
57
+ 792.9168090820312,
58
+ 640.056884765625,
59
+ 401.9707946777344,
60
+ 282.0995178222656,
61
+ 218.99769592285156,
62
+ 119.24910736083984,
63
+ 71.83614349365234,
64
+ 44.02671432495117,
65
+ 61.37840270996094,
66
+ 61.37840270996094,
67
+ 61.37840270996094,
68
+ 61.37840270996094,
69
+ 61.37840270996094,
70
+ 61.37840270996094,
71
+ 64.16217041015625,
72
+ 64.32339477539062,
73
+ 64.31382751464844,
74
+ 65.56702423095703,
75
+ 68.18431854248047,
76
+ 71.56515502929688,
77
+ 197.78048706054688,
78
+ 196.43638610839844,
79
+ 191.7803955078125,
80
+ 190.5934295654297,
81
+ 205.2471466064453,
82
+ 238.66366577148438,
83
+ 508.832275390625,
84
+ 507.11798095703125,
85
+ 493.1898193359375,
86
+ 477.44244384765625,
87
+ 465.2177429199219,
88
+ 452.10076904296875,
89
+ 347.4835510253906,
90
+ 207.85842895507812,
91
+ 140.189453125,
92
+ 88.9273681640625,
93
+ 50.258174896240234,
94
+ 35.850830078125
95
+ ],
96
+ "s_std": [
97
+ 5.658433437347412,
98
+ 4.963406562805176,
99
+ 4.842231273651123,
100
+ 6.4795145988464355,
101
+ 7.407203674316406,
102
+ 8.543693542480469,
103
+ 32.758174896240234,
104
+ 43.4786262512207,
105
+ 41.363216400146484,
106
+ 36.315101623535156,
107
+ 37.40601348876953,
108
+ 44.32140350341797,
109
+ 14.699563980102539,
110
+ 14.964685440063477,
111
+ 15.500894546508789,
112
+ 18.559709548950195,
113
+ 22.95189666748047,
114
+ 28.39887046813965,
115
+ 55.16016387939453,
116
+ 54.736392974853516,
117
+ 54.40840148925781,
118
+ 57.90495681762695,
119
+ 59.78011703491211,
120
+ 68.35675048828125,
121
+ 1374.9456787109375,
122
+ 633.04736328125,
123
+ 509.03704833984375,
124
+ 386.8252258300781,
125
+ 327.8870849609375,
126
+ 311.1480407714844,
127
+ 57.87489318847656,
128
+ 59.43294906616211,
129
+ 50.55767059326172,
130
+ 27.027706146240234,
131
+ 13.878527641296387,
132
+ 10.90867805480957,
133
+ 14.719537734985352,
134
+ 14.719537734985352,
135
+ 14.719537734985352,
136
+ 14.719537734985352,
137
+ 14.719537734985352,
138
+ 14.719537734985352,
139
+ 3.2984049320220947,
140
+ 3.6471333503723145,
141
+ 4.528029441833496,
142
+ 6.537323951721191,
143
+ 7.542074203491211,
144
+ 6.777342796325684,
145
+ 131.77452087402344,
146
+ 133.4365692138672,
147
+ 134.30154418945312,
148
+ 137.3269500732422,
149
+ 143.42730712890625,
150
+ 147.23556518554688,
151
+ 106.86735534667969,
152
+ 106.61359405517578,
153
+ 99.10890197753906,
154
+ 93.6629638671875,
155
+ 95.26378631591797,
156
+ 95.61508178710938,
157
+ 88.6065444946289,
158
+ 62.81496047973633,
159
+ 45.79389190673828,
160
+ 31.114017486572266,
161
+ 18.991355895996094,
162
+ 19.752763748168945
163
+ ],
164
+ "soil_vars": [
165
+ "bdod_mean_0-5cm",
166
+ "bdod_mean_5-15cm",
167
+ "bdod_mean_15-30cm",
168
+ "bdod_mean_30-60cm",
169
+ "bdod_mean_60-100cm",
170
+ "bdod_mean_100-200cm",
171
+ "cec_mean_0-5cm",
172
+ "cec_mean_5-15cm",
173
+ "cec_mean_15-30cm",
174
+ "cec_mean_30-60cm",
175
+ "cec_mean_60-100cm",
176
+ "cec_mean_100-200cm",
177
+ "cfvo_mean_0-5cm",
178
+ "cfvo_mean_5-15cm",
179
+ "cfvo_mean_15-30cm",
180
+ "cfvo_mean_30-60cm",
181
+ "cfvo_mean_60-100cm",
182
+ "cfvo_mean_100-200cm",
183
+ "clay_mean_0-5cm",
184
+ "clay_mean_5-15cm",
185
+ "clay_mean_15-30cm",
186
+ "clay_mean_30-60cm",
187
+ "clay_mean_60-100cm",
188
+ "clay_mean_100-200cm",
189
+ "nitrogen_mean_0-5cm",
190
+ "nitrogen_mean_5-15cm",
191
+ "nitrogen_mean_15-30cm",
192
+ "nitrogen_mean_30-60cm",
193
+ "nitrogen_mean_60-100cm",
194
+ "nitrogen_mean_100-200cm",
195
+ "ocd_mean_0-5cm",
196
+ "ocd_mean_5-15cm",
197
+ "ocd_mean_15-30cm",
198
+ "ocd_mean_30-60cm",
199
+ "ocd_mean_60-100cm",
200
+ "ocd_mean_100-200cm",
201
+ "ocs_mean_0-5cm",
202
+ "ocs_mean_5-15cm",
203
+ "ocs_mean_15-30cm",
204
+ "ocs_mean_30-60cm",
205
+ "ocs_mean_60-100cm",
206
+ "ocs_mean_100-200cm",
207
+ "phh2o_mean_0-5cm",
208
+ "phh2o_mean_5-15cm",
209
+ "phh2o_mean_15-30cm",
210
+ "phh2o_mean_30-60cm",
211
+ "phh2o_mean_60-100cm",
212
+ "phh2o_mean_100-200cm",
213
+ "sand_mean_0-5cm",
214
+ "sand_mean_5-15cm",
215
+ "sand_mean_15-30cm",
216
+ "sand_mean_30-60cm",
217
+ "sand_mean_60-100cm",
218
+ "sand_mean_100-200cm",
219
+ "silt_mean_0-5cm",
220
+ "silt_mean_5-15cm",
221
+ "silt_mean_15-30cm",
222
+ "silt_mean_30-60cm",
223
+ "silt_mean_60-100cm",
224
+ "silt_mean_100-200cm",
225
+ "soc_mean_0-5cm",
226
+ "soc_mean_5-15cm",
227
+ "soc_mean_15-30cm",
228
+ "soc_mean_30-60cm",
229
+ "soc_mean_60-100cm",
230
+ "soc_mean_100-200cm"
231
+ ],
232
+ "train_cutoffs": [
233
+ 20,
234
+ 24,
235
+ 28,
236
+ 32,
237
+ 36,
238
+ 40,
239
+ 44,
240
+ 48,
241
+ 52
242
+ ],
243
+ "transformers_version": "5.13.0",
244
+ "use_crop": true,
245
+ "w_mean": [
246
+ 2.6932172775268555,
247
+ 319.30352783203125,
248
+ 5.36029577255249,
249
+ 15.82466983795166,
250
+ 3.981907606124878,
251
+ 1018.5076904296875
252
+ ],
253
+ "w_std": [
254
+ 3.367875814437866,
255
+ 91.14374542236328,
256
+ 13.447235107421875,
257
+ 11.749135971069336,
258
+ 11.175808906555176,
259
+ 684.6181030273438
260
+ ],
261
+ "weather_vars": [
262
+ "prcp",
263
+ "srad",
264
+ "swe",
265
+ "tmax",
266
+ "tmin",
267
+ "vp"
268
+ ],
269
+ "y_mean": 166.3075714111328,
270
+ "y_std": 30.291048049926758,
271
+ "auto_map": {
272
+ "AutoConfig": "configuration_yield.YieldConfig",
273
+ "AutoModel": "modeling_yield.YieldForRegression"
274
+ },
275
+ "custom_pipelines": {
276
+ "yield-estimation": {
277
+ "impl": "pipeline_yield.YieldEstimationPipeline",
278
+ "pt": [
279
+ "AutoModel"
280
+ ]
281
+ }
282
+ }
283
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4e4b7d06037041ac9e734375b88d384eaee73ee22c87ce016606facf29e85425
3
+ size 733108
pipeline_yield.py ADDED
@@ -0,0 +1,329 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import torch
3
+ from transformers import Pipeline
4
+
5
+
6
+ class YieldEstimationPipeline(Pipeline):
7
+ """
8
+ Hugging Face pipeline for county-level corn yield estimation.
9
+
10
+ Inputs:
11
+ - 52 weekly observations for each configured weather variable
12
+ - static soil properties
13
+ - crop = "corn"
14
+ - optional cutoff
15
+
16
+ Weather values are already weekly in the public Corn Belt dataset.
17
+ No daily-to-weekly aggregation or interpolation is performed.
18
+ """
19
+
20
+ def _sanitize_parameters(self, cutoff=None, **kwargs):
21
+ preprocess_kwargs = {}
22
+
23
+ if cutoff is not None:
24
+ preprocess_kwargs["cutoff"] = cutoff
25
+
26
+ return preprocess_kwargs, {}, {}
27
+
28
+ def preprocess(self, inputs, cutoff=None):
29
+ cfg = self.model.config
30
+
31
+ if not isinstance(inputs, dict):
32
+ raise ValueError("Input must be a dictionary.")
33
+
34
+ if "weather" not in inputs:
35
+ raise ValueError(
36
+ "Input must contain a 'weather' dictionary."
37
+ )
38
+
39
+ if "soil" not in inputs:
40
+ raise ValueError(
41
+ "Input must contain a 'soil' dictionary."
42
+ )
43
+
44
+ # ----------------------------------------------------
45
+ # Crop
46
+ # ----------------------------------------------------
47
+
48
+ crop = str(
49
+ inputs.get("crop", "corn")
50
+ ).strip().lower()
51
+
52
+ if crop != "corn":
53
+ raise ValueError(
54
+ "This model was trained only for corn. "
55
+ f"Received crop='{crop}'."
56
+ )
57
+
58
+ crop_id = 0
59
+
60
+ # ----------------------------------------------------
61
+ # Weather
62
+ # ----------------------------------------------------
63
+
64
+ weather_dict = inputs["weather"]
65
+
66
+ weather_cols = []
67
+
68
+ for v in cfg.weather_vars:
69
+
70
+ if v not in weather_dict:
71
+ raise ValueError(
72
+ f"Missing weather variable: '{v}'"
73
+ )
74
+
75
+ arr = np.asarray(
76
+ weather_dict[v],
77
+ dtype=np.float32,
78
+ )
79
+
80
+ if arr.ndim != 1:
81
+ raise ValueError(
82
+ f"Weather variable '{v}' must be a "
83
+ f"1D weekly sequence. Got shape {arr.shape}."
84
+ )
85
+
86
+ if len(arr) != int(cfg.K):
87
+ raise ValueError(
88
+ f"Weather variable '{v}' must contain "
89
+ f"{cfg.K} weekly values. Got {len(arr)}."
90
+ )
91
+
92
+ weather_cols.append(arr)
93
+
94
+ # [K, W] = [52, 6]
95
+ weather = np.stack(
96
+ weather_cols,
97
+ axis=1,
98
+ ).astype(np.float32)
99
+
100
+ if weather.shape != (
101
+ int(cfg.K),
102
+ int(cfg.W),
103
+ ):
104
+ raise ValueError(
105
+ f"Weather shape mismatch. "
106
+ f"Expected ({cfg.K}, {cfg.W}), "
107
+ f"got {weather.shape}."
108
+ )
109
+
110
+ # ----------------------------------------------------
111
+ # Cutoff
112
+ # ----------------------------------------------------
113
+
114
+ requested_cutoff = inputs.get(
115
+ "cutoff",
116
+ cutoff,
117
+ )
118
+
119
+ if requested_cutoff is None:
120
+ requested_cutoff = max(
121
+ cfg.eval_cutoffs
122
+ if cfg.eval_cutoffs
123
+ else [cfg.K]
124
+ )
125
+
126
+ requested_cutoff = int(
127
+ requested_cutoff
128
+ )
129
+
130
+ allowed_cutoffs = (
131
+ [int(x) for x in cfg.eval_cutoffs]
132
+ if cfg.eval_cutoffs
133
+ else [int(cfg.K)]
134
+ )
135
+
136
+ if requested_cutoff not in allowed_cutoffs:
137
+ raise ValueError(
138
+ f"Unsupported cutoff={requested_cutoff}. "
139
+ f"This released model was evaluated at "
140
+ f"{allowed_cutoffs}."
141
+ )
142
+
143
+ t_eff = requested_cutoff
144
+
145
+ # ----------------------------------------------------
146
+ # Soil
147
+ # ----------------------------------------------------
148
+
149
+ soil_dict = inputs["soil"]
150
+
151
+ soil = []
152
+
153
+ for v in cfg.soil_vars:
154
+
155
+ if v not in soil_dict:
156
+ raise ValueError(
157
+ f"Missing soil variable: '{v}'"
158
+ )
159
+
160
+ soil.append(
161
+ float(soil_dict[v])
162
+ )
163
+
164
+ soil = np.asarray(
165
+ soil,
166
+ dtype=np.float32,
167
+ )
168
+
169
+ if len(soil) != int(cfg.S):
170
+ raise ValueError(
171
+ f"Soil feature mismatch. "
172
+ f"Expected {cfg.S}, got {len(soil)}."
173
+ )
174
+
175
+ # ----------------------------------------------------
176
+ # Training normalization
177
+ # ----------------------------------------------------
178
+
179
+ w_mean = np.asarray(
180
+ cfg.w_mean,
181
+ dtype=np.float32,
182
+ )
183
+
184
+ w_std = np.asarray(
185
+ cfg.w_std,
186
+ dtype=np.float32,
187
+ )
188
+
189
+ s_mean = np.asarray(
190
+ cfg.s_mean,
191
+ dtype=np.float32,
192
+ )
193
+
194
+ s_std = np.asarray(
195
+ cfg.s_std,
196
+ dtype=np.float32,
197
+ )
198
+
199
+ if len(w_mean) != int(cfg.W):
200
+ raise ValueError(
201
+ f"w_mean has {len(w_mean)} values, "
202
+ f"but model W={cfg.W}."
203
+ )
204
+
205
+ if len(w_std) != int(cfg.W):
206
+ raise ValueError(
207
+ f"w_std has {len(w_std)} values, "
208
+ f"but model W={cfg.W}."
209
+ )
210
+
211
+ if len(s_mean) != int(cfg.S):
212
+ raise ValueError(
213
+ f"s_mean has {len(s_mean)} values, "
214
+ f"but model S={cfg.S}."
215
+ )
216
+
217
+ if len(s_std) != int(cfg.S):
218
+ raise ValueError(
219
+ f"s_std has {len(s_std)} values, "
220
+ f"but model S={cfg.S}."
221
+ )
222
+
223
+ # Impute NaNs with training means.
224
+ weather = np.where(
225
+ np.isnan(weather),
226
+ w_mean[None, :],
227
+ weather,
228
+ )
229
+
230
+ soil = np.where(
231
+ np.isnan(soil),
232
+ s_mean,
233
+ soil,
234
+ )
235
+
236
+ # Normalize with TRAINING statistics.
237
+ weather = (
238
+ weather - w_mean[None, :]
239
+ ) / w_std[None, :]
240
+
241
+ soil = (
242
+ soil - s_mean
243
+ ) / s_std
244
+
245
+ # Use only data through requested calendar-week cutoff.
246
+ weather = weather[:t_eff]
247
+
248
+ return {
249
+ "weather": torch.from_numpy(
250
+ weather
251
+ ).unsqueeze(0),
252
+
253
+ "soil": torch.from_numpy(
254
+ soil
255
+ ).unsqueeze(0),
256
+
257
+ "crop_id": torch.tensor(
258
+ [crop_id],
259
+ dtype=torch.long,
260
+ ),
261
+
262
+ "horizon_idx": t_eff,
263
+
264
+ "cutoff": requested_cutoff,
265
+
266
+ "crop": crop,
267
+
268
+ "weather_format": "weekly",
269
+
270
+ "weather_shape": list(
271
+ weather.shape
272
+ ),
273
+ }
274
+
275
+ def _forward(self, model_inputs):
276
+ cutoff = model_inputs.pop(
277
+ "cutoff"
278
+ )
279
+
280
+ crop = model_inputs.pop(
281
+ "crop"
282
+ )
283
+
284
+ weather_format = model_inputs.pop(
285
+ "weather_format"
286
+ )
287
+
288
+ weather_shape = model_inputs.pop(
289
+ "weather_shape"
290
+ )
291
+
292
+ outputs = self.model(
293
+ weather=model_inputs["weather"],
294
+ soil=model_inputs["soil"],
295
+ crop_id=model_inputs["crop_id"],
296
+ horizon_idx=model_inputs["horizon_idx"],
297
+ causal=True,
298
+ return_sequence=False,
299
+ )
300
+
301
+ return {
302
+ "outputs": outputs,
303
+ "cutoff": cutoff,
304
+ "crop": crop,
305
+ "weather_format": weather_format,
306
+ "weather_shape": weather_shape,
307
+ }
308
+
309
+ def postprocess(self, model_outputs):
310
+ pred = float(
311
+ model_outputs[
312
+ "outputs"
313
+ ].predictions.detach().cpu().item()
314
+ )
315
+
316
+ return {
317
+ "predicted_yield": pred,
318
+ "yield_units": "bu/acre",
319
+ "cutoff": int(
320
+ model_outputs["cutoff"]
321
+ ),
322
+ "crop": model_outputs["crop"],
323
+ "weather_format": model_outputs[
324
+ "weather_format"
325
+ ],
326
+ "weather_shape": model_outputs[
327
+ "weather_shape"
328
+ ],
329
+ }
sample_input_weekly.json ADDED
@@ -0,0 +1,399 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "crop": "corn",
3
+ "weather_format": "weekly",
4
+ "cutoff": 52,
5
+ "weather": {
6
+ "prcp": [
7
+ 0.0,
8
+ 0.701298713684082,
9
+ 0.4545454680919647,
10
+ 2.155844211578369,
11
+ 0.9350649118423462,
12
+ 0.11688311398029327,
13
+ 0.0,
14
+ 3.753246784210205,
15
+ 0.15584415197372437,
16
+ 2.2337663173675537,
17
+ 0.0,
18
+ 0.4285714328289032,
19
+ 2.402597427368164,
20
+ 2.3896102905273438,
21
+ 5.753246784210205,
22
+ 0.9220778942108154,
23
+ 0.0,
24
+ 1.1298701763153076,
25
+ 1.2077921628952026,
26
+ 1.2207791805267334,
27
+ 2.441558361053467,
28
+ 5.402597427368164,
29
+ 2.909090995788574,
30
+ 3.6883115768432617,
31
+ 5.1688313484191895,
32
+ 5.233766078948975,
33
+ 7.389610290527344,
34
+ 4.883116722106934,
35
+ 1.5194804668426514,
36
+ 0.8311688303947449,
37
+ 4.051948070526123,
38
+ 0.03896103799343109,
39
+ 0.0,
40
+ 5.350649356842041,
41
+ 2.0389609336853027,
42
+ 4.103896141052246,
43
+ 0.012987012974917889,
44
+ 15.49350643157959,
45
+ 1.1168831586837769,
46
+ 3.142857074737549,
47
+ 6.155844211578369,
48
+ 0.3246753215789795,
49
+ 1.6753246784210205,
50
+ 0.5714285969734192,
51
+ 2.8831169605255127,
52
+ 0.10389610379934311,
53
+ 0.9610389471054077,
54
+ 1.1168831586837769,
55
+ 0.0,
56
+ 0.0,
57
+ 0.051948051899671555,
58
+ 4.181818008422852
59
+ ],
60
+ "srad": [
61
+ 187.0129852294922,
62
+ 181.23635864257812,
63
+ 184.8935089111328,
64
+ 179.7818145751953,
65
+ 255.91688537597656,
66
+ 267.4701232910156,
67
+ 323.158447265625,
68
+ 282.09869384765625,
69
+ 347.76104736328125,
70
+ 274.28570556640625,
71
+ 384.70648193359375,
72
+ 332.7168884277344,
73
+ 384.0831298828125,
74
+ 455.7298583984375,
75
+ 359.5636291503906,
76
+ 525.6727294921875,
77
+ 584.2701416015625,
78
+ 522.7221069335938,
79
+ 385.9532470703125,
80
+ 420.5298767089844,
81
+ 386.36883544921875,
82
+ 335.12725830078125,
83
+ 327.6467590332031,
84
+ 329.35064697265625,
85
+ 319.7090759277344,
86
+ 341.6103820800781,
87
+ 374.150634765625,
88
+ 387.20001220703125,
89
+ 379.0545349121094,
90
+ 412.1766357421875,
91
+ 353.08050537109375,
92
+ 397.0493469238281,
93
+ 376.4363708496094,
94
+ 312.2701416015625,
95
+ 312.4363708496094,
96
+ 313.7662353515625,
97
+ 341.07012939453125,
98
+ 249.10130310058594,
99
+ 292.32208251953125,
100
+ 190.7532501220703,
101
+ 189.13246154785156,
102
+ 301.589599609375,
103
+ 214.69090270996094,
104
+ 198.7324676513672,
105
+ 148.0311737060547,
106
+ 213.77662658691406,
107
+ 168.64414978027344,
108
+ 116.23896026611328,
109
+ 148.4051971435547,
110
+ 169.22596740722656,
111
+ 130.86753845214844,
112
+ 157.7818145751953
113
+ ],
114
+ "swe": [
115
+ 18.909090042114258,
116
+ 18.753246307373047,
117
+ 23.220779418945312,
118
+ 32.93506622314453,
119
+ 37.24675369262695,
120
+ 41.45454406738281,
121
+ 41.45454406738281,
122
+ 51.22077941894531,
123
+ 67.84415435791016,
124
+ 62.181819915771484,
125
+ 61.610389709472656,
126
+ 59.844154357910156,
127
+ 54.80519485473633,
128
+ 71.94805145263672,
129
+ 78.9610366821289,
130
+ 100.98701477050781,
131
+ 84.467529296875,
132
+ 50.54545593261719,
133
+ 7.636363506317139,
134
+ 0.0,
135
+ 0.0,
136
+ 0.0,
137
+ 0.0,
138
+ 0.0,
139
+ 0.0,
140
+ 0.0,
141
+ 0.0,
142
+ 0.0,
143
+ 0.0,
144
+ 0.0,
145
+ 0.0,
146
+ 0.0,
147
+ 0.0,
148
+ 0.0,
149
+ 0.0,
150
+ 0.0,
151
+ 0.0,
152
+ 0.0,
153
+ 0.0,
154
+ 0.0,
155
+ 0.0,
156
+ 0.0,
157
+ 0.0,
158
+ 0.0,
159
+ 0.0,
160
+ 0.0,
161
+ 0.0,
162
+ 1.402597427368164,
163
+ 0.0,
164
+ 0.0,
165
+ 0.0,
166
+ 9.454545021057129
167
+ ],
168
+ "tmax": [
169
+ -13.350648880004883,
170
+ -3.694805145263672,
171
+ -2.4740259647369385,
172
+ -0.1428571492433548,
173
+ -7.298701286315918,
174
+ -10.746753692626953,
175
+ -1.3701298236846924,
176
+ -2.844155788421631,
177
+ 5.285714149475098,
178
+ 0.7272727489471436,
179
+ 4.675324440002441,
180
+ 3.948051929473877,
181
+ 4.324675559997559,
182
+ -0.4285714328289032,
183
+ 3.9285714626312256,
184
+ 8.292207717895508,
185
+ 16.785715103149414,
186
+ 23.915584564208984,
187
+ 19.662338256835938,
188
+ 25.34415626525879,
189
+ 28.39610481262207,
190
+ 28.39610481262207,
191
+ 24.863636016845703,
192
+ 27.415584564208984,
193
+ 25.766233444213867,
194
+ 28.10389518737793,
195
+ 28.441558837890625,
196
+ 30.61688232421875,
197
+ 26.87013053894043,
198
+ 26.402597427368164,
199
+ 26.571428298950195,
200
+ 29.324674606323242,
201
+ 29.714284896850586,
202
+ 25.02597427368164,
203
+ 25.441558837890625,
204
+ 23.467533111572266,
205
+ 28.746753692626953,
206
+ 20.162338256835938,
207
+ 15.733766555786133,
208
+ 12.071428298950195,
209
+ 8.357142448425293,
210
+ 12.409090995788574,
211
+ 11.629870414733887,
212
+ 9.253246307373047,
213
+ -0.012987012974917889,
214
+ -0.6623376607894897,
215
+ 0.9155844449996948,
216
+ -2.0,
217
+ -3.344155788421631,
218
+ 0.5064935088157654,
219
+ 1.7402597665786743,
220
+ -2.0568182468414307
221
+ ],
222
+ "tmin": [
223
+ -23.694805145263672,
224
+ -14.48051929473877,
225
+ -12.051947593688965,
226
+ -7.941558361053467,
227
+ -19.376623153686523,
228
+ -21.123376846313477,
229
+ -14.344156265258789,
230
+ -14.02597427368164,
231
+ -7.7207794189453125,
232
+ -7.7272725105285645,
233
+ -6.344155788421631,
234
+ -4.116883277893066,
235
+ -5.246753215789795,
236
+ -11.681818008422852,
237
+ -3.909090995788574,
238
+ -3.649350643157959,
239
+ 1.4220778942108154,
240
+ 8.98051929473877,
241
+ 8.870129585266113,
242
+ 10.454545021057129,
243
+ 15.129870414733887,
244
+ 16.363636016845703,
245
+ 14.461038589477539,
246
+ 17.175325393676758,
247
+ 16.701297760009766,
248
+ 18.720779418945312,
249
+ 17.922077178955078,
250
+ 19.519479751586914,
251
+ 16.305194854736328,
252
+ 14.642857551574707,
253
+ 15.694805145263672,
254
+ 17.422077178955078,
255
+ 18.220779418945312,
256
+ 15.175324440002441,
257
+ 15.558441162109375,
258
+ 13.49350643157959,
259
+ 17.201297760009766,
260
+ 11.655843734741211,
261
+ 5.7727274894714355,
262
+ 4.551948070526123,
263
+ 2.2272727489471436,
264
+ -0.16233766078948975,
265
+ 1.7727272510528564,
266
+ 1.0324674844741821,
267
+ -5.954545497894287,
268
+ -10.149351119995117,
269
+ -6.623376846313477,
270
+ -7.201298713684082,
271
+ -10.422078132629395,
272
+ -8.344156265258789,
273
+ -4.707792282104492,
274
+ -9.943181991577148
275
+ ],
276
+ "vp": [
277
+ 100.2597427368164,
278
+ 259.22076416015625,
279
+ 287.2727355957031,
280
+ 344.41558837890625,
281
+ 137.14285278320312,
282
+ 115.84415435791016,
283
+ 211.42857360839844,
284
+ 215.06494140625,
285
+ 359.48052978515625,
286
+ 358.4415588378906,
287
+ 377.6623229980469,
288
+ 454.5454406738281,
289
+ 409.8701171875,
290
+ 249.87013244628906,
291
+ 451.4285583496094,
292
+ 438.4415588378906,
293
+ 540.7792358398438,
294
+ 887.792236328125,
295
+ 1041.0389404296875,
296
+ 1108.052001953125,
297
+ 1534.54541015625,
298
+ 1750.6492919921875,
299
+ 1589.6103515625,
300
+ 1931.4285888671875,
301
+ 1902.337646484375,
302
+ 2178.181884765625,
303
+ 2062.857177734375,
304
+ 2275.32470703125,
305
+ 1851.947998046875,
306
+ 1670.1298828125,
307
+ 1802.077880859375,
308
+ 1990.1298828125,
309
+ 2097.662353515625,
310
+ 1738.1817626953125,
311
+ 1810.9090576171875,
312
+ 1587.012939453125,
313
+ 2006.7532958984375,
314
+ 1414.0260009765625,
315
+ 942.337646484375,
316
+ 852.467529296875,
317
+ 731.9480590820312,
318
+ 614.5454711914062,
319
+ 715.8441772460938,
320
+ 658.7012939453125,
321
+ 416.1038818359375,
322
+ 297.1428527832031,
323
+ 392.7272644042969,
324
+ 367.7922058105469,
325
+ 289.35064697265625,
326
+ 336.6233825683594,
327
+ 435.3246765136719,
328
+ 295.4545593261719
329
+ ]
330
+ },
331
+ "soil": {
332
+ "bdod_mean_0-5cm": 127.71450805664062,
333
+ "bdod_mean_5-15cm": 148.86965942382812,
334
+ "bdod_mean_15-30cm": 150.70364379882812,
335
+ "bdod_mean_30-60cm": 158.2148895263672,
336
+ "bdod_mean_60-100cm": 162.8789825439453,
337
+ "bdod_mean_100-200cm": 165.12025451660156,
338
+ "cec_mean_0-5cm": 252.34054565429688,
339
+ "cec_mean_5-15cm": 174.4131317138672,
340
+ "cec_mean_15-30cm": 142.52432250976562,
341
+ "cec_mean_30-60cm": 129.1745147705078,
342
+ "cec_mean_60-100cm": 119.97528839111328,
343
+ "cec_mean_100-200cm": 103.29729461669922,
344
+ "cfvo_mean_0-5cm": 21.431659698486328,
345
+ "cfvo_mean_5-15cm": 22.905019760131836,
346
+ "cfvo_mean_15-30cm": 21.820077896118164,
347
+ "cfvo_mean_30-60cm": 24.725868225097656,
348
+ "cfvo_mean_60-100cm": 34.54826354980469,
349
+ "cfvo_mean_100-200cm": 45.90888214111328,
350
+ "clay_mean_0-5cm": 150.02239990234375,
351
+ "clay_mean_5-15cm": 149.1436309814453,
352
+ "clay_mean_15-30cm": 150.81776428222656,
353
+ "clay_mean_30-60cm": 150.43707275390625,
354
+ "clay_mean_60-100cm": 134.29266357421875,
355
+ "clay_mean_100-200cm": 125.47721862792969,
356
+ "nitrogen_mean_0-5cm": 4723.78857421875,
357
+ "nitrogen_mean_5-15cm": 2148.763671875,
358
+ "nitrogen_mean_15-30cm": 1729.8802490234375,
359
+ "nitrogen_mean_30-60cm": 776.644775390625,
360
+ "nitrogen_mean_60-100cm": 547.14208984375,
361
+ "nitrogen_mean_100-200cm": 534.0015258789062,
362
+ "ocd_mean_0-5cm": 435.4494323730469,
363
+ "ocd_mean_5-15cm": 255.3752899169922,
364
+ "ocd_mean_15-30cm": 181.84786987304688,
365
+ "ocd_mean_30-60cm": 93.57837677001953,
366
+ "ocd_mean_60-100cm": 60.80463409423828,
367
+ "ocd_mean_100-200cm": 44.90888214111328,
368
+ "ocs_mean_0-5cm": 57.79845428466797,
369
+ "ocs_mean_5-15cm": 57.79845428466797,
370
+ "ocs_mean_15-30cm": 57.79845428466797,
371
+ "ocs_mean_30-60cm": 57.79845428466797,
372
+ "ocs_mean_60-100cm": 57.79845428466797,
373
+ "ocs_mean_100-200cm": 57.79845428466797,
374
+ "phh2o_mean_0-5cm": 61.812355041503906,
375
+ "phh2o_mean_5-15cm": 61.73050308227539,
376
+ "phh2o_mean_15-30cm": 61.63166046142578,
377
+ "phh2o_mean_30-60cm": 62.09111785888672,
378
+ "phh2o_mean_60-100cm": 64.0540542602539,
379
+ "phh2o_mean_100-200cm": 69.0687255859375,
380
+ "sand_mean_0-5cm": 625.2216186523438,
381
+ "sand_mean_5-15cm": 626.4702758789062,
382
+ "sand_mean_15-30cm": 631.22314453125,
383
+ "sand_mean_30-60cm": 649.113525390625,
384
+ "sand_mean_60-100cm": 697.4996337890625,
385
+ "sand_mean_100-200cm": 712.781494140625,
386
+ "silt_mean_0-5cm": 224.77297973632812,
387
+ "silt_mean_5-15cm": 224.3876495361328,
388
+ "silt_mean_15-30cm": 217.95135498046875,
389
+ "silt_mean_30-60cm": 200.43319702148438,
390
+ "silt_mean_60-100cm": 168.21775817871094,
391
+ "silt_mean_100-200cm": 161.7498016357422,
392
+ "soc_mean_0-5cm": 446.14508056640625,
393
+ "soc_mean_5-15cm": 223.34988403320312,
394
+ "soc_mean_15-30cm": 144.84561157226562,
395
+ "soc_mean_30-60cm": 107.50271606445312,
396
+ "soc_mean_60-100cm": 53.54926300048828,
397
+ "soc_mean_100-200cm": 47.3972053527832
398
+ }
399
+ }
sample_test.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+
3
+ from transformers import pipeline
4
+
5
+
6
+ MODEL_DIR = "."
7
+
8
+
9
+ with open(
10
+ "sample_input_weekly.json",
11
+ "r",
12
+ ) as f:
13
+ sample = json.load(f)
14
+
15
+
16
+ pipe = pipeline(
17
+ "yield-estimation",
18
+ model=MODEL_DIR,
19
+ trust_remote_code=True,
20
+ )
21
+
22
+
23
+ print("Testing released cutoffs...\n")
24
+
25
+ for cutoff in [
26
+ 20,
27
+ 24,
28
+ 28,
29
+ 32,
30
+ 36,
31
+ 40,
32
+ 44,
33
+ 48,
34
+ 52,
35
+ ]:
36
+ x = dict(sample)
37
+ x["cutoff"] = cutoff
38
+
39
+ output = pipe(x)
40
+
41
+ print(
42
+ f"Cutoff {cutoff}: "
43
+ f"{output['predicted_yield']:.2f} "
44
+ f"{output['yield_units']}"
45
+ )
46
+
47
+
48
+ print("\nFull output at cutoff 52:")
49
+
50
+ sample["cutoff"] = 52
51
+
52
+ output = pipe(sample)
53
+
54
+ print(
55
+ json.dumps(
56
+ output,
57
+ indent=2,
58
+ )
59
+ )