Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maurice_paper_2_main #129

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
251461f
Global wind atlas available again
WMLKalthof Oct 8, 2024
45ddd9d
Added GLOPOP farmer info, global risk aversion + GLOPOP variability
WMLKalthof Oct 9, 2024
2f48472
Merge remote-tracking branch 'origin/main' into maurice_paper_2
WMLKalthof Oct 10, 2024
4e40e9f
global time/risk preferences, global irrigation sources
WMLKalthof Oct 15, 2024
58e65d0
Save for model restart
WMLKalthof Oct 15, 2024
a41e5d6
Bug fixes in prices set up
WMLKalthof Oct 16, 2024
2e009ca
Added ability to change to all crops with SEUT
WMLKalthof Oct 16, 2024
2f80500
Irr expansion, efficiency, all crop switching
WMLKalthof Oct 24, 2024
c2c6cf5
Bug fixes, updated URLs
WMLKalthof Oct 24, 2024
e438b59
updating MIRCA2000 maps
WMLKalthof Oct 28, 2024
01431f1
irrigation efficiency total changes
WMLKalthof Oct 28, 2024
09a6d55
Changes for local use
WMLKalthof Oct 30, 2024
c652f52
Updated MIRCA2000 setup for crops and irrigation
WMLKalthof Nov 1, 2024
c71dd38
Farmers abstraction from river cell other than local cell
WMLKalthof Nov 5, 2024
255b1d2
Prep calibration and input data
WMLKalthof Nov 15, 2024
f68fff8
Irrigation eff right start and relations
WMLKalthof Nov 15, 2024
a5546ac
Lower threshold for hydraulic conductivity error
WMLKalthof Nov 15, 2024
bb4773e
bug fixes farmer setup
WMLKalthof Nov 15, 2024
8170894
Merge remote-tracking branch 'origin/main' into maurice_paper_2_main
WMLKalthof Nov 15, 2024
17c8430
ruff changes, water balance and crop switching
WMLKalthof Nov 28, 2024
8ed31d4
removed test mirca upload
WMLKalthof Nov 28, 2024
0204aa3
ruff changes
WMLKalthof Nov 28, 2024
7fd2141
Merge branch 'main' into maurice_paper_2_main
WMLKalthof Nov 28, 2024
dbbc91a
ruff fix
WMLKalthof Nov 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions examples/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,20 @@ setup_irrigation_sources:

setup_create_farms_simple:

setup_household_characteristics:

setup_crops_from_source:
source: MIRCA2000

determine_crop_area_fractions:

setup_farmer_crop_calendar:
year: 2000
reduce_crops: true
replace_base: false

setup_farmer_characteristics_simple:
risk_aversion_mean: 2
risk_aversion_standard_deviation: 1
discount_rate: 0.05
interest_rate: 0.05
irrigation_choice:
canal: 80
well: 20

setup_cultivation_costs:
cultivation_costs: 0

setup_crop_prices:
crop_prices: FAO_stat
Expand Down
35 changes: 35 additions & 0 deletions geb/HRUs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,33 @@
import numpy as np
import zarr.convenience
from geb.workflows import AsyncForcingReader
from scipy.spatial import cKDTree

try:
import cupy as cp
except (ModuleNotFoundError, ImportError):
pass


def determine_nearest_river_cell(river_grid, HRU_to_grid):
threshold = 15
valid_mask = river_grid != -9999

valid_indices = np.argwhere(valid_mask)
valid_values = river_grid[valid_mask]

above_threshold_mask = valid_values > threshold
above_threshold_indices = valid_indices[above_threshold_mask]
above_threshold_indices_in_valid = np.flatnonzero(above_threshold_mask)

tree = cKDTree(above_threshold_indices)
distances, indices_in_above = tree.query(valid_indices)

nearest_indices_in_valid = above_threshold_indices_in_valid[indices_in_above]

return nearest_indices_in_valid[HRU_to_grid]


def load_grid(filepath, layer=1, return_transform_and_crs=False):
if filepath.suffix == ".tif":
warnings.warn("tif files are now deprecated. Consider rebuilding the model.")
Expand Down Expand Up @@ -568,6 +588,11 @@ def __init__(self, data, model) -> None:
self.data.get_save_state_path(), "HRU.unmerged_HRU_indices.npz"
)
)["data"]
self.nearest_river_grid_cell = np.load(
os.path.join(
self.data.get_save_state_path(), "HRU.nearest_river_grid_cell.npz"
)
)["data"]
else:
(
self.land_use_type,
Expand All @@ -577,12 +602,22 @@ def __init__(self, data, model) -> None:
self.grid_to_HRU,
self.unmerged_HRU_indices,
) = self.create_HRUs()

river_grid = load_grid(
self.model.files["grid"]["routing/kinematic/upstream_area"]
)

self.nearest_river_grid_cell = determine_nearest_river_cell(
river_grid, self.HRU_to_grid
)

self.register_initial_data("HRU.land_use_type")
self.register_initial_data("HRU.land_use_ratio")
self.register_initial_data("HRU.land_owners")
self.register_initial_data("HRU.HRU_to_grid")
self.register_initial_data("HRU.grid_to_HRU")
self.register_initial_data("HRU.unmerged_HRU_indices")
self.register_initial_data("HRU.nearest_river_grid_cell")
if self.model.use_gpu:
self.land_use_type = cp.array(self.land_use_type)
BaseVariables.__init__(self)
Expand Down
Loading