calliope-project / calliope

A multi-scale energy systems modelling framework

Home Page:https://www.callio.pe

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unhelpful error when forgetting 'file=' for resource specification

sjvrijn opened this issue · comments

Problem description

When I was trying to set up a simple minimal model, I got the following error:

Error in check_model_data, ~/.pyenv/versions/calliope/lib/python3.11/site-packages/calliope/preprocess/checks.py:739
'>' not supported between instances of 'str' and 'int'

My first debugging efforts showed that the error occurred when demand.csv values had been loaded as strings instead of floats.
After a lot of confusion and searching, I managed to find that I had forgotten file= for my wind_resource specification instead, i.e.,

techs:
    offwind:
        ...
        constraints:
            resource: wind_resource.csv

instead of

techs:
    offwind:
        ...
        constraints:
            resource: file=wind_resource.csv

As a new user, this was very discouraging. If the error message could be improved for such a case, that would be very helpful.

Full output of `calliope run model.yaml --debug`
$ calliope run model.yaml --debug
Version 0.6.10
Calliope 0.6.10 starting at 2023-07-25 11:08:48

[2023-07-25 11:08:48] INFO     Model: initialising
[2023-07-25 11:08:48] INFO     Model: preprocessing stage 1 (model_run)
[2023-07-25 11:08:48] INFO     Model: preprocessing stage 2 (model_data)
Traceback (most recent call last):
  File "~/.pyenv/versions/calliope/lib/python3.11/site-packages/calliope/cli.py", line 85, in format_exceptions
    yield
  File "~/.pyenv/versions/calliope/lib/python3.11/site-packages/calliope/cli.py", line 278, in run
    model = _run_setup_model(model_file, scenario, model_format, override_dict)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/.pyenv/versions/calliope/lib/python3.11/site-packages/calliope/cli.py", line 211, in _run_setup_model
    model = Model(model_file, scenario=scenario, override_dict=override_dict)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/.pyenv/versions/calliope/lib/python3.11/site-packages/calliope/core/model.py", line 79, in __init__
    self._init_from_model_run(model_run, debug_data)
  File "~/.pyenv/versions/calliope/lib/python3.11/site-packages/calliope/core/model.py", line 130, in _init_from_model_run
    self._model_data = final_timedimension_processing(_model_data)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/.pyenv/versions/calliope/lib/python3.11/site-packages/calliope/preprocess/time.py", line 267, in final_timedimension_processing
    model_data, final_check_comments, warns, errors = checks.check_model_data(
                                                      ^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/.pyenv/versions/calliope/lib/python3.11/site-packages/calliope/preprocess/checks.py", line 739, in check_model_data
    if any(model_data.resource.sel(loc_techs_finite_resource=loc_tech).values > 0):
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: '>' not supported between instances of 'str' and 'int'

Steps to reproduce the problem

files to reproduce

model.yaml:

import:
    - 'model_config/locations.yaml'
    - 'model_config/techs.yaml'

model:
    name: 'some minimum model'
    timeseries_data_path: 'timeseries_data'

run:
    solver: glpk
    objective_options: {'cost_class': {"monetary": 1} }

model_config/techs.yaml

techs:
    gas:
        essentials:
            name: 'gas'
            parent: supply
            carrier_out: power
        constraints:
            resource: inf
            energy_cap_max: 460
        costs:
            monetary:
                om_con: 0.04

    offwind:
        essentials:
            name: 'offwind'
            parent: supply
            carrier_out: power
        constraints:
            resource: file=wind_resource.csv  # removing 'file=' here causes an error when loading demand?!
        costs:
            monetary:
                om_con: 0.005

    demandpower:
        essentials:
            name: 'demandpower'
            parent: demand
            carrier: power

    actransmission:
        essentials:
            name: 'actransmission'
            parent: transmission
            carrier: power

model_config/locations.yaml

locations:
    windlocation:
        techs:
            offwind:
    city:
        techs:
            gas:
            demandpower:
                constraints:
                    resource: file=demand.csv
links:
    windlocation,city:
        techs:
            actransmission:
                constraints:
                    energy_cap_max: 400
demand.csv
,city
2020-01-01 00:00:00,-467.5408
2020-01-01 01:00:00,-445.4432
2020-01-01 02:00:00,-426.0224
2020-01-01 03:00:00,-414.5648
2020-01-01 04:00:00,-397.1376
2020-01-01 05:00:00,-365.0048
2020-01-01 06:00:00,-365.2400
2020-01-01 07:00:00,-372.1728
2020-01-01 08:00:00,-398.2912
2020-01-01 09:00:00,-428.8784
2020-01-01 10:00:00,-462.5120
2020-01-01 11:00:00,-475.2464
2020-01-01 12:00:00,-468.3024
2020-01-01 13:00:00,-462.6800
2020-01-01 14:00:00,-461.6384
2020-01-01 15:00:00,-629.4240
2020-01-01 16:00:00,-675.6464
2020-01-01 17:00:00,-684.2480
2020-01-01 18:00:00,-675.0416
2020-01-01 19:00:00,-654.8032
2020-01-01 20:00:00,-647.3776
2020-01-01 21:00:00,-654.0080
2020-01-01 22:00:00,-626.0640
2020-01-01 23:00:00,-592.2288
wind_resource.csv
,windlocation
2020-01-01 00:00:00,1447.2
2020-01-01 01:00:00,1447.2
2020-01-01 02:00:00,1447.2
2020-01-01 03:00:00,1447.2
2020-01-01 04:00:00,1447.2
2020-01-01 05:00:00,1447.2
2020-01-01 06:00:00,1447.2
2020-01-01 07:00:00,1447.2
2020-01-01 08:00:00,1447.2
2020-01-01 09:00:00,1447.2
2020-01-01 10:00:00,1446.9479
2020-01-01 11:00:00,1445.6401
2020-01-01 12:00:00,1401.5435
2020-01-01 13:00:00,1402.4218
2020-01-01 14:00:00,1351.7336
2020-01-01 15:00:00,1168.1503
2020-01-01 16:00:00,982.2615
2020-01-01 17:00:00,817.8503
2020-01-01 18:00:00,562.3877
2020-01-01 19:00:00,573.5871
2020-01-01 20:00:00,560.1478
2020-01-01 21:00:00,557.9080
2020-01-01 22:00:00,571.3473
2020-01-01 23:00:00,593.5242

Calliope version

$ calliope --version
Version 0.6.10