OSeMOSYS / OSeMOSYS_GNU_MathProg

The GNU MathProg implementation of OSeMOSYS
Apache License 2.0
9 stars 14 forks source link

TechnologyToStorage and TechnologyFromStorage - Mode of operation not correctly assigned #80

Open EmiFej opened 2 years ago

EmiFej commented 2 years ago

I am using @tniet's model file with storage equations to run my model. When trying to run the pre-processing script, I encounter an issue where instead of returning the technology and mode of operation for technologies which are connected to the storage via TechnologyToStorage and TechnologyFromStorage, the script instead returns Technology and Storage. The model has 2 modes of operation [1, 2]. Below is an example, where RSCWTRS1UC is the technology connected to the RSSUVAC1 storage via TechnologyToStorage:

Screenshot 2022-04-27 at 21 10 06

When I added the print statements below (for storage, values, and storage_to) it all seems fine.

if param_current == 'TechnologyToStorage':
    if not line.startswith(mode_list[0]):
        storage = line.split(' ')[0]
        print(storage)
        values = line.rstrip().split(' ')[1:]
        print(values)
        for i in range(0, len(mode_list)):
            if values[i] != '0':
                storage_to.append(tuple([storage, tech, mode_list[i]]))
                print(storage_to)

However, when I add a print statement to:

print(f"data all is {data_all}")
for tech, mode in data_all:
    print(f"tech mode are {tech} {mode}")

the output from the picture above appears and it is clear that something is not working. Any suggestions as to why this is happening and how I could potentially solve it would be highly appreciated.

tniet commented 2 years ago

Hi @EmiFej - can you also post the structure of the model file? I'm wondering if the file is read in wrongly because of the way the parameter is formatted. Also wonder if you can compare the structure of the code for something like InputActivityRatio vs. TechToStorage? Does it work without anything in the TechToStorage parameter? @abhishek0208 - do you have any ideas what's going wrong?

willu47 commented 2 years ago

Could you provide a minimal reproducible example that reproduces this bug? Isolating the pieces in the data file that causes this behaviour will make solving the bug easier.

EmiFej commented 2 years ago

Hi @tniet , everything else seems to be working fine from what I can see. The structure follows the Momani format, but the data file is written using a text editor, and not Momani. The input and output activity ratios are written differently from the TechnologyToStorage and TechnologyFromStorage.

Screenshot 2022-05-12 at 16 06 18 Screenshot 2022-05-12 at 16 05 52

In the picture below, we see the TechnologyToStorage which connects the river segment BACWTRS6DR to the storage it fills up BASVISEG. As the picture suggests, the river segment should feed water into the storage in mode of operation 1, and it fills it up with 1 unit of water (lines 17796-17798).

Screenshot 2022-05-12 at 16 05 27

However, when plotting the technologies and their respective modes of operation from the Pre_processing script, the output is shown as this:

tech mode are RSPHYDMHI5 2 tech mode are BACWTRS6DR BASVISEG tech mode are BAPCOSCHO0 1

The script treats the storage, in this case BASVISEG, as a mode of operation connected to the technology, in this case the river segment BACWTRS6DR

So the final output from the preprocess file gives output that look like this: set MODEperTECHNOLOGY[BACWTRS6DR]:= 1 BASVISEG;

Instead of this for example, a technology without storage: set MODEperTECHNOLOGY[BACWTCT2DR]:= 1;

tniet commented 2 years ago

Hi @EmiFej - I think you've clearly identified the problem. The format you use for TechnologyToStorage is read in incorrectly. This is likely the format you use rather than the script being incorrect. I suggest you install MoManI and enter some data into TechnologyToStorage, download the executable and check what format MoManI produces in its data file. If you replicate this format the script will likely work correctly.

EmiFej commented 2 years ago

Hi @tniet. I asked a colleague to provide me with a simple model that has been created using MoManI. It was a simple use case developed for the EMB3RS project. The TechnologyToStorage and TechnologyFromStorage seem to be written out just as they are in my model.

Example:

Screenshot 2022-05-13 at 16 23 05

Using this new data file, the same issue appears as in my model. When plotting out "technology and mode", it gives technology and storage. And when you write out "storage and mode", it does it correctly, as in my case. Picture attached below. The SINK1 is a technology, while STOA is the storage.

Screenshot 2022-05-13 at 16 27 59

Data file attached: data.txt

tniet commented 2 years ago

Hey @EmiFej - it's clear that the script is reading this format incorrectly. You'll have to dig into the script and see how it reads things in, and what changes you can make to have it read those parameters correctly. You might also want to ask @abhishek0208 as he's the original author of the script and might be able to give you a quick fix.