Instructions: Your task is to decide which interventions need to be done at which agricultural plots (crops, type='ag_plot') and how to place them geometrically based on how the interventions increase ecological connectivity, while not decreasing NPV from a baseline value. The choice is between margin (convert only the margins) and habitat (convert a contiguous region) interventions. The margin interventions are chosen among the following directions on the boundary: north-east, north-west, south-east, south-west. The habitat conversions are chosen among the same directions in the internal area of polygons. The directions are computed by running a horizontal and a vertical line through the centre of each plot, and choosing them if they have interventions (as computed by IPOPT optimization) greater than a threshold. Existing habitat plots (type='hab_plots') remain unaffected. Integral index of connectivity (IIC) is used as the metric for ecological connectivity, which tries to increase the size of the connected components in the neighbourhood. It promotes fractions touching each other and extending the connectivity between existing habitats in the landscape, which includes the farm and its neighbours. There is a tradeoff between maximizing connectivity and maintaining NPV. The NPV is calculated based on how the interventions affect pollination and pest control services over distance and time, and how these affect yield. There is also the tradeoff between the cost of implementation and maintenance vs the benefit of increased yield. I will show you examples of initial input geojson and the output interventions and geometries suggested by IPOPT optimization for your neighbouring farms. In the input geojson, the id for each plot is in 'id', land use class in 'label', whether ag_plot ot hab_plot in 'type', yield in 'yield, the neighboring plot ids in 'nbs', and plot polygon in 'geometry'. In the output, 'plot_id' refers to the plot id, 'plot_type' refers to whether ag_plot ot hab_plot, 'label' refers to land use class, 'margin_directions' and 'habitat_directions' show the margin intervention and habitat conversion directions on the boundary and internally respectively.

Given these examples, provided input geojson of your farm, you need to predict the final intervention directions using heuristics created in python. Use names of margin_directions and habitat_directions for the predicted intervention geometries in the output, and don't alter these variable names. Look at properties that you think have a pattern (like yield, label, type, nbs, geometry), and the relative positioning of both the farm neighbours with respect to your farm and the plots with respect to each other within the farm in the context of ecological connectivity. Use all the given geometry information to infer these geographical relationships. Do not use plot_ids in the if statements as rules to assign directions. You can incorporate the parameters like crop prices and implementation and maintenance costs provided at the end in your heuristics. 

 Data:

Neighbour 1: input: {"type": "FeatureCollection", "features": [{"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[62.84, 92.76], [55.0, 91.11], [55.0, 95.0], [45.0, 100.0], [65.0, 100.0], [67.7, 99.1], [62.84, 92.76]]]}, "properties": {"label": "Broadleaf", "type": "hab_plots", "id": 1, "yield": 2.8913626521299998, "nbs": [6, 7]}}, {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[62.42, 75.14], [62.81, 73.35], [62.72, 73.21], [55.0, 70.77], [55.0, 80.29], [62.42, 75.14]]]}, "properties": {"label": "Exposed land/barren", "type": "hab_plots", "id": 2, "yield": 2.49122591337, "nbs": [3, 4, 5, 8]}}, {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[62.72, 73.21], [62.81, 73.35], [75.59, 70.59], [70.0, 65.0], [62.23, 67.59], [62.72, 73.21]]]}, "properties": {"label": "Exposed land/barren", "type": "hab_plots", "id": 3, "yield": 2.54648059192, "nbs": [2, 4, 8]}}, {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[62.72, 73.21], [62.23, 67.59], [55.0, 70.0], [55.0, 70.77], [62.72, 73.21]]]}, "properties": {"label": "Canola/rapeseed", "type": "ag_plot", "id": 4, "yield": 2.10801145417, "nbs": [2, 3]}}, {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[55.0, 80.29], [55.0, 89.32], [67.55, 82.1], [62.42, 75.14], [55.0, 80.29]]]}, "properties": {"label": "Soybeans", "type": "ag_plot", "id": 5, "yield": 2.6199581846199997, "nbs": [2, 6, 8]}}, {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[55.0, 89.32], [55.0, 91.11], [62.84, 92.76], [66.27, 92.21], [73.48, 82.23], [67.55, 82.1], [55.0, 89.32]]]}, "properties": {"label": "Canola/rapeseed", "type": "ag_plot", "id": 6, "yield": 2.6210248863000003, "nbs": [1, 5, 7, 8, 9]}}, {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[66.27, 92.21], [62.84, 92.76], [67.7, 99.1], [76.73, 96.09], [66.27, 92.21]]]}, "properties": {"label": "Grassland", "type": "hab_plots", "id": 7, "yield": 2.10801145417, "nbs": [1, 6, 9]}}, {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[62.81, 73.35], [62.42, 75.14], [67.55, 82.1], [73.48, 82.23], [84.9, 79.9], [75.59, 70.59], [62.81, 73.35]]]}, "properties": {"label": "Exposed land/barren", "type": "hab_plots", "id": 8, "yield": 2.59051019914, "nbs": [2, 3, 5, 6, 9]}}, {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[73.48, 82.23], [66.27, 92.21], [76.73, 96.09], [80.0, 95.0], [85.0, 80.0], [84.9, 79.9], [73.48, 82.23]]]}, "properties": {"label": "Grassland", "type": "hab_plots", "id": 9, "yield": 2.6210248863000003, "nbs": [6, 7, 8]}}]}

Output: [{"id": 4, "type": "ag_plot", "label": "Canola/rapeseed", "margin_directions": ["north-east", "south-east"], "habitat_directions": []}, {"id": 5, "type": "ag_plot", "label": "Soybeans", "margin_directions": ["north-west", "north-east", "south-west", "south-east"], "habitat_directions": []}, {"id": 6, "type": "ag_plot", "label": "Canola/rapeseed", "margin_directions": ["north-east", "south-east"], "habitat_directions": []}]

Neighbour 2: input: {"type": "FeatureCollection", "features": [{"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[3.79, 47.51], [6.95, 45.41], [13.87, 35.0], [0.0, 35.0], [0.0, 49.04], [3.79, 47.51]]]}, "properties": {"label": "Broadleaf", "type": "hab_plots", "id": 1, "yield": 0.5, "nbs": [2, 3, 9]}}, {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[14.83, 59.35], [14.25, 54.59], [12.47, 52.15], [3.79, 47.51], [0.0, 49.04], [0.0, 65.0], [8.15, 65.0], [14.83, 59.35]]]}, "properties": {"label": "Corn", "type": "ag_plot", "id": 2, "yield": 2.4580683244799997, "nbs": [1, 3, 4, 5, 7]}}, {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[12.47, 52.15], [21.41, 52.72], [21.98, 48.2], [6.95, 45.41], [3.79, 47.51], [12.47, 52.15]]]}, "properties": {"label": "Soybeans", "type": "ag_plot", "id": 3, "yield": 2.68434075533, "nbs": [1, 2, 5, 6, 9]}}, {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[14.83, 59.35], [22.06, 56.07], [21.42, 52.91], [14.25, 54.59], [14.83, 59.35]]]}, "properties": {"label": "Spring wheat", "type": "ag_plot", "id": 4, "yield": 0.5, "nbs": [2, 5, 6, 7]}}, {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[14.25, 54.59], [21.42, 52.91], [21.41, 52.72], [12.47, 52.15], [14.25, 54.59]]]}, "properties": {"label": "Barley", "type": "ag_plot", "id": 5, "yield": 2.59051019914, "nbs": [2, 3, 4, 6]}}, {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[26.0, 43.51], [21.98, 48.2], [21.41, 52.72], [21.42, 52.91], [22.06, 56.07], [31.1, 65.0], [40.0, 65.0], [30.0, 60.0], [30.0, 50.0], [34.71, 45.29], [26.0, 43.51]]]}, "properties": {"label": "Soybeans", "type": "ag_plot", "id": 6, "yield": 2.49122591337, "nbs": [3, 4, 5, 7, 8, 9]}}, {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[22.06, 56.07], [14.83, 59.35], [8.15, 65.0], [31.1, 65.0], [22.06, 56.07]]]}, "properties": {"label": "Broadleaf", "type": "hab_plots", "id": 7, "yield": 1.6948931827, "nbs": [2, 4, 6]}}, {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[26.0, 43.51], [34.71, 45.29], [40.0, 40.0], [45.0, 40.0], [45.0, 35.0], [21.59, 35.0], [26.0, 43.51]]]}, "properties": {"label": "Exposed land/barren", "type": "hab_plots", "id": 8, "yield": 2.2448700065200002, "nbs": [6, 9]}}, {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[21.98, 48.2], [26.0, 43.51], [21.59, 35.0], [13.87, 35.0], [6.95, 45.41], [21.98, 48.2]]]}, "properties": {"label": "Oats", "type": "ag_plot", "id": 9, "yield": 1.69809901566, "nbs": [1, 3, 6, 8]}}]}

Output: [{"id": 2, "type": "ag_plot", "label": "Corn", "margin_directions": ["north-east", "south-west", "south-east"], "habitat_directions": []}, {"id": 3, "type": "ag_plot", "label": "Soybeans", "margin_directions": ["north-west", "north-east", "south-west", "south-east"], "habitat_directions": []}, {"id": 4, "type": "ag_plot", "label": "Spring wheat", "margin_directions": ["north-west", "north-east", "south-west", "south-east"], "habitat_directions": ["north-west", "north-east", "south-west", "south-east"]}, {"id": 5, "type": "ag_plot", "label": "Barley", "margin_directions": ["north-west", "north-east", "south-west", "south-east"], "habitat_directions": ["north-west", "north-east", "south-west", "south-east"]}, {"id": 6, "type": "ag_plot", "label": "Soybeans", "margin_directions": ["north-west", "north-east", "south-east"], "habitat_directions": []}, {"id": 9, "type": "ag_plot", "label": "Oats", "margin_directions": ["north-west", "north-east"], "habitat_directions": []}]

Neighbour 3: input: {"type": "FeatureCollection", "features": [{"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[39.42, 58.32], [41.71, 54.82], [41.33, 46.06], [39.7, 40.3], [30.0, 50.0], [30.0, 60.0], [34.59, 62.29], [39.42, 58.32]]]}, "properties": {"label": "Spring wheat", "type": "ag_plot", "id": 1, "yield": 2.77115452086, "nbs": [2, 3, 5, 6]}}, {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[41.33, 46.06], [56.82, 49.5], [57.59, 49.41], [60.89, 42.87], [61.37, 41.37], [60.0, 40.0], [40.0, 40.0], [39.7, 40.3], [41.33, 46.06]]]}, "properties": {"label": "Spring wheat", "type": "ag_plot", "id": 2, "yield": 0.5, "nbs": [1, 6, 7, 8, 9]}}, {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[53.38, 67.5], [39.42, 58.32], [34.59, 62.29], [40.0, 65.0], [53.61, 69.54], [53.38, 67.5]]]}, "properties": {"label": "Oats", "type": "ag_plot", "id": 3, "yield": 2.54648059192, "nbs": [1, 4, 5]}}, {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[58.52, 57.11], [55.28, 60.1], [53.38, 67.5], [53.61, 69.54], [55.0, 70.0], [70.0, 65.0], [70.0, 61.05], [58.52, 57.11]]]}, "properties": {"label": "Exposed land/barren", "type": "hab_plots", "id": 4, "yield": 1.57057809328, "nbs": [3, 5, 7, 8]}}, {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[55.28, 60.1], [44.64, 55.11], [41.71, 54.82], [39.42, 58.32], [53.38, 67.5], [55.28, 60.1]]]}, "properties": {"label": "Canola/rapeseed", "type": "ag_plot", "id": 5, "yield": 2.8164643300799996, "nbs": [1, 3, 4, 6, 7]}}, {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[56.82, 49.5], [41.33, 46.06], [41.71, 54.82], [44.64, 55.11], [56.82, 49.5]]]}, "properties": {"label": "Spring wheat", "type": "ag_plot", "id": 6, "yield": 1.5964614396, "nbs": [1, 2, 5, 7]}}, {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[44.64, 55.11], [55.28, 60.1], [58.52, 57.11], [57.59, 49.41], [56.82, 49.5], [44.64, 55.11]]]}, "properties": {"label": "Soybeans", "type": "ag_plot", "id": 7, "yield": 0.5, "nbs": [2, 4, 5, 6, 8]}}, {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[58.52, 57.11], [70.0, 61.05], [70.0, 59.46], [60.89, 42.87], [57.59, 49.41], [58.52, 57.11]]]}, "properties": {"label": "Soybeans", "type": "ag_plot", "id": 8, "yield": 2.6210248863000003, "nbs": [2, 4, 7, 9]}}, {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[60.89, 42.87], [70.0, 59.46], [70.0, 50.0], [61.37, 41.37], [60.89, 42.87]]]}, "properties": {"label": "Spring wheat", "type": "ag_plot", "id": 9, "yield": 0.5, "nbs": [2, 8]}}]}

Output: [{"id": 1, "type": "ag_plot", "label": "Spring wheat", "margin_directions": ["north-west", "north-east", "south-west"], "habitat_directions": []}, {"id": 2, "type": "ag_plot", "label": "Spring wheat", "margin_directions": ["north-west", "north-east", "south-east"], "habitat_directions": ["north-west", "north-east"]}, {"id": 3, "type": "ag_plot", "label": "Oats", "margin_directions": ["north-west", "north-east"], "habitat_directions": ["north-west", "north-east", "south-west", "south-east"]}, {"id": 5, "type": "ag_plot", "label": "Canola/rapeseed", "margin_directions": ["north-west", "north-east", "south-west", "south-east"], "habitat_directions": []}, {"id": 6, "type": "ag_plot", "label": "Spring wheat", "margin_directions": ["north-west", "north-east", "south-west", "south-east"], "habitat_directions": ["north-west", "north-east", "south-west", "south-east"]}, {"id": 7, "type": "ag_plot", "label": "Soybeans", "margin_directions": ["north-west", "north-east", "south-west", "south-east"], "habitat_directions": ["north-west", "north-east", "south-west", "south-east"]}, {"id": 8, "type": "ag_plot", "label": "Soybeans", "margin_directions": ["north-west", "south-west"], "habitat_directions": []}, {"id": 9, "type": "ag_plot", "label": "Spring wheat", "margin_directions": ["north-east", "south-west", "south-east"], "habitat_directions": ["north-west", "north-east", "south-west", "south-east"]}]

Your farm: input: {"type": "FeatureCollection", "features": [{"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[8.91, 84.08], [8.11, 83.62], [0.0, 79.99], [0.0, 90.0], [2.75, 91.37], [8.91, 84.08]]]}, "properties": {"label": "Spring wheat", "type": "ag_plot", "id": 1, "yield": 1.67695696718, "nbs": [2, 3, 6]}}, {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[8.91, 84.08], [12.23, 84.61], [17.29, 72.11], [16.75, 70.32], [7.85, 72.79], [8.11, 83.62], [8.91, 84.08]]]}, "properties": {"label": "Oats", "type": "ag_plot", "id": 2, "yield": 1.5883539304, "nbs": [1, 3, 4, 5, 6, 7]}}, {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[14.11, 87.03], [12.23, 84.61], [8.91, 84.08], [2.75, 91.37], [13.35, 96.68], [14.11, 87.03]]]}, "properties": {"label": "Exposed land/barren", "type": "hab_plots", "id": 3, "yield": 2.4317488845399997, "nbs": [1, 2, 4, 8]}}, {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[12.23, 84.61], [14.11, 87.03], [29.47, 86.84], [31.5, 79.08], [17.29, 72.11], [12.23, 84.61]]]}, "properties": {"label": "Spring wheat", "type": "ag_plot", "id": 4, "yield": 2.5250394100899998, "nbs": [2, 3, 7, 8, 9]}}, {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[7.85, 72.79], [16.75, 70.32], [16.73, 65.0], [0.0, 65.0], [0.0, 72.61], [7.85, 72.79]]]}, "properties": {"label": "Spring wheat", "type": "ag_plot", "id": 5, "yield": 0.5, "nbs": [2, 6, 7]}}, {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[8.11, 83.62], [7.85, 72.79], [0.0, 72.61], [0.0, 79.99], [8.11, 83.62]]]}, "properties": {"label": "Corn", "type": "ag_plot", "id": 6, "yield": 0.5, "nbs": [1, 2, 5]}}, {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[16.75, 70.32], [17.29, 72.11], [31.5, 79.08], [45.32, 66.77], [40.0, 65.0], [16.73, 65.0], [16.75, 70.32]]]}, "properties": {"label": "Soybeans", "type": "ag_plot", "id": 7, "yield": 2.5250394100899998, "nbs": [2, 4, 5, 9]}}, {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[29.47, 86.84], [14.11, 87.03], [13.35, 96.68], [20.0, 100.0], [35.22, 100.0], [29.47, 86.84]]]}, "properties": {"label": "Canola/rapeseed", "type": "ag_plot", "id": 8, "yield": 0.5, "nbs": [3, 4, 9]}}, {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[31.5, 79.08], [29.47, 86.84], [35.22, 100.0], [45.0, 100.0], [55.0, 95.0], [55.0, 70.0], [45.32, 66.77], [31.5, 79.08]]]}, "properties": {"label": "Grassland", "type": "hab_plots", "id": 9, "yield": 1.39116522778, "nbs": [4, 7, 8]}}]}

Final Instructions: I want you to infer the logic from the examples and work through the inferred logic to predict intervention directions. Give me your best estimate as to where the interventions should be placed at each agricultural plot. Proceed based on the conceptual framework inferred from provided examples. Do not hallucinate. Come up with heuristics. Don't provide the full json but rather provide the python code to produce the json using the decided heuristics. Explain your reasoning and think step by step before providing the code. Handle all the features, i.e., plot ids. Don't create new variable names. Use margin_directions and habitat_directions for the predicted intervention geometries in the output. In the code no need to define the input json again, just load it from the file input.geojson.Save outputs to output.json. 

These are the crop prices in USD/Tonne: {'Soybeans': 370, 'Oats': 95, 'Corn': 190, 'Canola/rapeseed': 1100, 'Barley': 120, 'Spring wheat': 200}, and these are the costs (implementation costs one time and in USD/ha, and maintenance costs in USD/ha/year) : {'margin': {'implementation': 400,  'maintenance': 60}, 'habitat': {'implementation': 300, 'maintenance': 70}, 'agriculture': {'maintenance': 100}}.

