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

Crop prices from globiom regions, and small cli fix for multiple inheritance #115

Merged
merged 5 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
100 changes: 99 additions & 1 deletion examples/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,105 @@ setup_cultivation_costs:
cultivation_costs: 0

setup_crop_prices:
crop_prices: 200
crop_prices: FAO_stat
translate_crop_names:
cassava:
- cassava, fresh
citrus:
- lemons and lime
- oranges
- other citrus fruit, n.e.c.
- pomelos and grapefruits
- tangerines, mandarins, clementines
coffee:
- coffee, green
cocoa:
- cocoa beans
cotton:
- cotton lint, ginned
date palm:
- dates
groundnuts:
- groundnuts, excluding shelled
maize:
- maize (corn)
millet:
- millet
oil palm:
- palm oil
others annual:
- buckwheat
- cabbages
- cantaloupes and other melons
- carrots and turnips
- cauliflowers and broccoli
- chillies and peppers, green (capsicum spp. and pimenta spp.)
- cucumbers and gherkins
- green garlic
- lettuce and chicory
- linseed
- lupins
- mushrooms and truffles
- mustard seed
- onions and shallots, dry (excluding dehydrated)
- onions and shallots, green
- other beans, green
- other fruits, n.e.c.
- other vegetables, fresh n.e.c.
- peas, dry
- peas, green
- pumpkins, squash and gourds
- shorn wool, greasy, including fleece-washed shorn wool
- spinach
- strawberries
- tomatoes
- triticale
- unmanufactured tobacco
- vetches
others perennial:
- apples
- apricots
- artichokes
- asparagus
- blueberries
- cherries
- currants
- gooseberries
- hop cones
- kiwi fruit
- leeks and other alliaceous vegetables
- other berries and fruits of the genus vaccinium n.e.c.
- other stone fruits
- peaches and nectarines
- pears
- plums and sloes
- quinces
- raspberries
- sour cherries
- walnuts, in shell
pulses:
- bambara beans, dry
- beans, dry
- broad beans and horse beans, dry
- broad beans and horse beans, green
- chick peas, dry
- cow peas, dry
- lentils, dry
- lupins
- peas, dry
- peas, green
- pigeon peas, dry
- vetches
rapeseed:
- rape or colza seed
soybeans:
- soya beans
sugar beets:
- sugar beet
sugar cane:
- sugar cane
sunflower:
- sunflower seed

setup_population:

Expand Down
22 changes: 18 additions & 4 deletions examples/data_catalog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ gcam_electricity_rates:
path: economics/electricity_rates/GCAM_Electricity_Rates.csv
driver: csv
data_type: DataFrame
meta:
source_url: https://github.com/JGCRI/superwell
source_version: 1.0
unit: USD (2016)
gadm_level1:
crs: 4326
data_type: GeoDataFrame
Expand Down Expand Up @@ -549,15 +553,15 @@ ghs_pop_2020_54009_v2023a:
source_url: https://ghsl.jrc.ec.europa.eu/download.php?ds=pop
path: /scistor/ivm/data_catalogue/population/GHSL/GHS_POP/GHS_POP_E2020_GLOBE_R2023A_54009_100_V1_0.tif
FAO_crop_price:
path: crops/FAOSTAT_producer_price_lcu.csv
path: crops/FAOSTAT_data_en_9-27-2024.csv
driver: csv
data_type: DataFrame
meta:
category: crops
source_author: FAO
source_license: CC-BY-4.0
source_url: https://www.fao.org/faostat/en/#data/PP
source_version: Producer price in LCU
source_version: Producer price in USD per tonne
rename:
Year: year
Value: price_per_kg
Expand Down Expand Up @@ -786,9 +790,19 @@ soilgrids_2017_{variable}:
variable: ["BDTICM"]
unit_mult:
BDTICM_M_250m_ll: 0.01
GLOBIOM_regions:
GLOBIOM_regions_59:
data_type: DataFrame
driver: excel
path: GLOBIOM/Region_Country_Mapping.xlsx
meta:
source_url: https://www.isric.org/explore/soilgrids
kwargs:
sheet_name: Region59
GLOBIOM_regions_37:
data_type: DataFrame
driver: excel
path: GLOBIOM/Region_Country_Mapping.xlsx
meta:
source_url: https://www.isric.org/explore/soilgrids
source_url: https://www.isric.org/explore/soilgrids
kwargs:
sheet_name: Region37
108 changes: 100 additions & 8 deletions examples/update.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,100 @@
# setup_forcing:
# data_source: era5
# starttime: 2000-01-01
# endtime: 2023-12-31

setup_SPEI:
calibration_period_start: 2000-01-01
calibration_period_end: 2020-12-31
setup_crop_prices:
crop_prices: FAO_stat
translate_crop_names:
cassava:
- cassava, fresh
citrus:
- lemons and lime
- oranges
- other citrus fruit, n.e.c.
- pomelos and grapefruits
- tangerines, mandarins, clementines
coffee:
- coffee, green
cocoa:
- cocoa beans
cotton:
- cotton lint, ginned
date palm:
- dates
groundnuts:
- groundnuts, excluding shelled
maize:
- maize (corn)
millet:
- millet
oil palm:
- palm oil
others annual:
- buckwheat
- cabbages
- cantaloupes and other melons
- carrots and turnips
- cauliflowers and broccoli
- chillies and peppers, green (capsicum spp. and pimenta spp.)
- cucumbers and gherkins
- green garlic
- lettuce and chicory
- linseed
- lupins
- mushrooms and truffles
- mustard seed
- onions and shallots, dry (excluding dehydrated)
- onions and shallots, green
- other beans, green
- other fruits, n.e.c.
- other vegetables, fresh n.e.c.
- peas, dry
- peas, green
- pumpkins, squash and gourds
- shorn wool, greasy, including fleece-washed shorn wool
- spinach
- strawberries
- tomatoes
- triticale
- unmanufactured tobacco
- vetches
others perennial:
- apples
- apricots
- artichokes
- asparagus
- blueberries
- cherries
- currants
- gooseberries
- hop cones
- kiwi fruit
- leeks and other alliaceous vegetables
- other berries and fruits of the genus vaccinium n.e.c.
- other stone fruits
- peaches and nectarines
- pears
- plums and sloes
- quinces
- raspberries
- sour cherries
- walnuts, in shell
pulses:
- bambara beans, dry
- beans, dry
- broad beans and horse beans, dry
- broad beans and horse beans, green
- chick peas, dry
- cow peas, dry
- lentils, dry
- lupins
- peas, dry
- peas, green
- pigeon peas, dry
- vetches
rapeseed:
- rape or colza seed
soybeans:
- soya beans
sugar beets:
- sugar beet
sugar cane:
- sugar cane
sunflower:
- sunflower seed
15 changes: 11 additions & 4 deletions geb/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,18 @@ def multi_level_merge(dict1, dict2):
return dict1


def parse_config(config_path):
def parse_config(config_path, current_directory=None):
"""Parse config."""
if current_directory is None:
current_directory = Path.cwd()

if isinstance(config_path, dict):
config = config_path
else:
config = yaml.load(open(config_path, "r"), Loader=yaml.FullLoader)
config = yaml.load(
open(current_directory / config_path, "r"), Loader=yaml.FullLoader
)
current_directory = current_directory / Path(config_path).parent

if "inherits" in config:
inherit_config_path = config["inherits"]
Expand All @@ -60,16 +66,17 @@ def parse_config(config_path):
inherit_config_path = os.path.expandvars(inherit_config_path)
# if inherits is not an absolute path, we assume it is relative to the config file
if not Path(inherit_config_path).is_absolute():
inherit_config_path = Path(config_path).parent / config["inherits"]
inherit_config_path = current_directory / config["inherits"]
inherited_config = yaml.load(
open(inherit_config_path, "r"),
Loader=yaml.FullLoader,
)
current_directory = current_directory / Path(inherit_config_path).parent
del config[
"inherits"
] # remove inherits key from config to avoid infinite recursion
config = multi_level_merge(inherited_config, config)
config = parse_config(config)
config = parse_config(config, current_directory=current_directory)
return config


Expand Down
Loading