Skip to content

Commit

Permalink
metadata, py: placeholders for regional mappings, methods
Browse files Browse the repository at this point in the history
  • Loading branch information
khaeru committed May 17, 2017
1 parent b74d4c4 commit e8cb360
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Contents
- are named to match the keys in `models.yaml`,
- contain model-specific metadata, including but not limited to:
- `regions.yaml`: regional aggregation.
- `scenarios.yaml`: descriptions of scenarios submitted to each iTEM workshop.
- `item_config_example.yaml` — an example configuration file.
- `python/` — Python code for accessing & maintaining the database. See [`python/README.md`](https://github.com/transportenergy/database/blob/master/python/README.md).
- `R/` — R code for accessing & maintaining the database. See [`R/README.md`](https://github.com/transportenergy/database/blob/master/R/README.md).
Expand Down
Empty file added data/model/bp/regions.yaml
Empty file.
Empty file.
Empty file added data/model/gcam/regions.yaml
Empty file.
Empty file added data/model/get/regions.yaml
Empty file.
Empty file added data/model/message/regions.yaml
Empty file.
Empty file added data/model/momo/regions.yaml
Empty file.
Empty file added data/model/regions.yaml
Empty file.
Empty file added data/model/roadmap/regions.yaml
Empty file.
Empty file added data/model/shell/regions.yaml
Empty file.
18 changes: 17 additions & 1 deletion python/item/model/__main__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from click import Argument, Command, Group

from item.model import process_raw
from item.model.dimensions import list_pairs
from item.model.dimensions import (
list_pairs,
make_regions_csv,
make_regions_yaml,
)
from item.model.plot import plot_all_item1


Expand All @@ -26,4 +30,16 @@ def add(fn, *params):
Argument(['out_file'], default='pairs.txt'),
)

add(make_regions_csv,
Argument(['models'], help='List of models to output'),
Argument(['out_file']),
)

add(make_regions_yaml,
Argument(['in_file']),
Argument(['country'], help='IN_FILE column with country codes'),
Argument(['region'], help='IN_FILE column with region names'),
Argument(['out_file']),
)

add(plot_all_item1)
13 changes: 13 additions & 0 deletions python/item/model/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def _rename(colname):

def select(data, *args, **kwargs):
"""Select from *data*."""
# Process arguments
if len(args) > 1:
raise ValueError(("can't determine dimensions for >1 positional "
"arguments: {}").format(' '.join(args)))
Expand All @@ -168,6 +169,13 @@ def select(data, *args, **kwargs):
if len(args) and dims['variable'] is None:
dims['variable'] = set(args)

# Code to this point is generic (doesn't depend on the format of *data*)

if isinstance(data, xr.Dataset) or isinstance(data, dict):
# TODO write methods for these other data types
raise NotImplementedError

# pandas.DataFrame
# Construct a boolean mask
keep = None
for d, v in dims.items():
Expand All @@ -182,4 +190,9 @@ def select(data, *args, **kwargs):
return data[keep]


def squash_scenarios(data):
"""Replace the per-model scenario names with categories."""
raise NotImplementedError


load()
10 changes: 10 additions & 0 deletions python/item/model/dimensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,14 @@ def load_template(version):
return result


def make_regions_csv(out_file, models):
"""Produce a CSV *out_file* with a country→region map for *models*."""
raise NotImplementedError


def make_regions_yaml(in_file, country, region, out_file):
"""Convert a country→region map from CSV *in_file* to YAML *out_file*."""
raise NotImplementedError


load()

0 comments on commit e8cb360

Please sign in to comment.