Skip to content

Commit

Permalink
Merge branch 'master' into joss
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorb1 committed Nov 8, 2023
2 parents 7872c61 + 21afaef commit 084b5c8
Show file tree
Hide file tree
Showing 12 changed files with 264 additions and 137 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ on: [push, pull_request]
jobs:
build:

runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11"]
os: [ubuntu-latest, windows-latest]

steps:
- uses: actions/checkout@v3
Expand Down
46 changes: 33 additions & 13 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,46 @@
otoole: OSeMOSYS tools for energy work
==================================================

.. image:: https://coveralls.io/repos/github/OSeMOSYS/otoole/badge.svg?branch=master&kill_cache=1
:target: https://coveralls.io/github/OSeMOSYS/otoole?branch=master
.. image:: https://joss.theoj.org/papers/e93a191ae795b171beff782a68fdc467/status.svg
:target: https://joss.theoj.org/papers/e93a191ae795b171beff782a68fdc467
:alt: JOSS status

.. image:: https://readthedocs.org/projects/otoole/badge/?version=latest
:target: https://otoole.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status
.. image:: https://img.shields.io/pypi/v/otoole.svg
:target: https://pypi.org/project/otoole/
:alt: PyPI

.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/psf/black
:alt: Code Style

.. image:: https://joss.theoj.org/papers/e93a191ae795b171beff782a68fdc467/status.svg
:target: https://joss.theoj.org/papers/e93a191ae795b171beff782a68fdc467
:alt: JOSS status
.. image:: https://img.shields.io/badge/python-3.9_|_3.10_|_3.11-blue.svg
:target: https://crate.io/packages/otoole/
:alt: Python Version

A Python toolkit to support use of OSeMOSYS
.. image:: https://img.shields.io/badge/License-MIT-green.svg
:target: https://opensource.org/licenses/MIT
:alt: License

|
.. image:: https://coveralls.io/repos/github/OSeMOSYS/otoole/badge.svg?branch=master&kill_cache=1
:target: https://coveralls.io/github/OSeMOSYS/otoole?branch=master
:alt: Code Coverage

.. image:: https://github.com/OSeMOSYS/otoole/actions/workflows/python.yaml/badge.svg?branch=master
:target: https://github.com/OSeMOSYS/otoole/actions/workflows/python.yaml
:alt: GitHub CI

.. image:: https://readthedocs.org/projects/otoole/badge/?version=latest
:target: https://otoole.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status

Description
===========

OSeMOSYS tools for energy work, or otoole, is a Python package
which provides a command-line interface for users of OSeMOSYS. The aim of the
package is to provide commonly used pre- and post-processing steps for OSeMOSYS.
to support the users of OSeMOSYS. The aim of the package is to provide commonly
used pre- and post-processing steps for OSeMOSYS.

**otoole** aims to support different ways of storing input data and results,
including csv files and Excel workbooks, as well as different implementations
Expand Down Expand Up @@ -53,5 +71,7 @@ Contributing

New ideas and bugs `should be submitted <https://github.com/OSeMOSYS/otoole/issues/new>`_
to the repository issue tracker. Please do contribute by discussing and developing these
ideas further. To contribute directly to the documentation of code development, please see
the contribution guidelines document.
ideas further.

To contribute directly to the code and documentation development, please see
the `contribution guidelines <https://otoole.readthedocs.io/en/latest/contributing.html>`_.
20 changes: 19 additions & 1 deletion docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,20 @@ Run the following command, where the RES will be saved as the file ``res.png``::

$ otoole viz res excel simplicity.xlsx res.png config.yaml

2. View the RES
.. WARNING::
If you encounter a ``graphviz`` dependency error, install it on your system
from the graphviz_ website (if on Windows) or via the command::

sudo apt install graphviz # if on Ubuntu
brew install graphviz # if on Mac

To check that ``graphviz`` installed correctly, run ``dot -V`` to check the
version::

~$ dot -V
dot - graphviz version 2.43.0 (0)

1. View the RES
~~~~~~~~~~~~~~~
Open the newly created file, ``res.png`` and the following image should be
displayed
Expand Down Expand Up @@ -311,8 +324,12 @@ The MathProg datafile describing this model can be found on the
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Create a configuration validation ``yaml`` file::

# on UNIX
$ touch validate.yaml

# on Windows
> type nul > validate.yaml

3. Create ``FUEL`` Codes
~~~~~~~~~~~~~~~~~~~~~~~~
Create the fuel codes and descriptions in the validation configuration file::
Expand Down Expand Up @@ -486,3 +503,4 @@ will also flag it as an isolated fuel. This means the fuel is unconnected from t
.. _CPLEX: https://www.ibm.com/products/ilog-cplex-optimization-studio/cplex-optimizer
.. _Anaconda: https://www.anaconda.com/
.. _Gurobi: https://www.gurobi.com/
.. _graphviz: https://www.graphviz.org/download/
19 changes: 14 additions & 5 deletions src/otoole/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ def convert(self, input_filepath: str, output_filepath: str, **kwargs: Dict):

class Strategy(ABC):
"""
Arguments
---------
user_config : dict, default=None
Expand All @@ -139,10 +138,20 @@ def _add_dtypes(self, config: Dict):
dtypes = {}
for column in details["indices"] + ["VALUE"]:
if column == "VALUE":
dtypes["VALUE"] = details["dtype"]
dtypes["VALUE"] = (
details["dtype"] if details["dtype"] != "int" else "int64"
)
else:
dtypes[column] = config[column]["dtype"]
dtypes[column] = (
config[column]["dtype"]
if config[column]["dtype"] != "int"
else "int64"
)
details["index_dtypes"] = dtypes
elif details["type"] == "set":
details["dtype"] = (
details["dtype"] if details["dtype"] != "int" else "int64"
)
return config

@property
Expand Down Expand Up @@ -491,8 +500,8 @@ def _check_index_dtypes(
except ValueError: # ValueError: invalid literal for int() with base 10:
df = df.dropna(axis=0, how="all").reset_index()
for index, dtype in config["index_dtypes"].items():
if dtype == "int":
df[index] = df[index].astype(float).astype(int)
if dtype == "int64":
df[index] = df[index].astype(float).astype("int64")
else:
df[index] = df[index].astype(dtype)
df = df.set_index(config["indices"])
Expand Down
2 changes: 1 addition & 1 deletion src/otoole/results/result_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ def discount_factor(
if regions and years:
discount_rate["YEAR"] = [years]
discount_factor = discount_rate.explode("YEAR").reset_index(level="REGION")
discount_factor["YEAR"] = discount_factor["YEAR"].astype(int)
discount_factor["YEAR"] = discount_factor["YEAR"].astype("int64")
discount_factor["NUM"] = discount_factor["YEAR"] - discount_factor["YEAR"].min()
discount_factor["RATE"] = discount_factor["VALUE"] + 1
discount_factor["VALUE"] = (
Expand Down
4 changes: 2 additions & 2 deletions src/otoole/results/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def read_model(self, file_path: Union[str, TextIO]) -> pd.DataFrame:
df["INDEX"] = df["INDEX"].map(lambda x: x.split("]")[0])
df = (
df[["ID", "NUM", "NAME", "INDEX"]]
.astype({"ID": str, "NUM": int, "NAME": str, "INDEX": str})
.astype({"ID": str, "NUM": "int64", "NAME": str, "INDEX": str})
.reset_index(drop=True)
)

Expand Down Expand Up @@ -425,7 +425,7 @@ def read_solution(
data = (
data[["ID", "NUM", "STATUS", "PRIM", "DUAL"]]
.astype(
{"ID": str, "NUM": int, "STATUS": str, "PRIM": float, "DUAL": float}
{"ID": str, "NUM": "int64", "STATUS": str, "PRIM": float, "DUAL": float}
)
.reset_index(drop=True)
)
Expand Down
14 changes: 12 additions & 2 deletions src/otoole/write_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,12 @@ def _write_parameter(
df = self._form_parameter(df, default)
handle.write("param default {} : {} :=\n".format(default, parameter_name))
df.to_csv(
path_or_buf=handle, sep=" ", header=False, index=True, float_format="%g"
path_or_buf=handle,
sep=" ",
header=False,
index=True,
float_format="%g",
lineterminator="\n",
)
handle.write(";\n")

Expand All @@ -171,7 +176,12 @@ def _write_set(self, df: pd.DataFrame, set_name, handle: TextIO):
"""
handle.write("set {} :=\n".format(set_name))
df.to_csv(
path_or_buf=handle, sep=" ", header=False, index=False, float_format="%g"
path_or_buf=handle,
sep=" ",
header=False,
index=False,
float_format="%g",
lineterminator="\n",
)
handle.write(";\n")

Expand Down
Loading

0 comments on commit 084b5c8

Please sign in to comment.