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

attributes are not read as valid outputControl.txt value when using pysumma.Simulation() #167

Open
bartvanosnabrugge opened this issue Sep 14, 2022 · 2 comments

Comments

@bartvanosnabrugge
Copy link

The following outputControl file throws errors (outputControl.txt).

The problem seems to be in the lines:

hruId
latitude
longitude

When these variables (lines) are omitted, the Simulation object loads without errors.

`---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/tmp/ipykernel_27996/1849484293.py in
1 # Create a model instance
----> 2 s = ps.Simulation(executable, file_manager)

~/venvs/hydromt-env/lib/python3.8/site-packages/pysumma/simulation.py in init(self, executable, filemanager, initialize, config_dir)
63 self.status = 'Uninitialized'
64 if initialize:
---> 65 self.initialize()
66
67 def initialize(self):

~/venvs/hydromt-env/lib/python3.8/site-packages/pysumma/simulation.py in initialize(self)
77 self.status = 'Initialized'
78 self.decisions = self.manager.decisions
---> 79 self.output_control = self.manager.output_control
80 self.trial_params = self.manager.trial_params
81 self.force_file_list = self.manager.force_file_list

~/venvs/hydromt-env/lib/python3.8/site-packages/pysumma/file_manager.py in output_control(self)
66 p1 = self.get_value('settingsPath')
67 p2 = self.get_value('outputControlFile')
---> 68 self._output_control = OutputControl(p1, p2)
69 return self._output_control
70

~/venvs/hydromt-env/lib/python3.8/site-packages/pysumma/output_control.py in init(self, dirpath, filepath)
86
87 def init(self, dirpath, filepath=None):
---> 88 super().init(OutputControlOption, dirpath, filepath)
89
90 def set_option(self, name=None, period=None, sum=0, instant=1,

~/venvs/hydromt-env/lib/python3.8/site-packages/pysumma/option.py in init(self, optiontype, dir, name)
122 self.header = []
123 self.options = []
--> 124 self.read(os.path.abspath(self.original_path / self.file_name))
125
126 def set_option(self):

~/venvs/hydromt-env/lib/python3.8/site-packages/pysumma/option.py in read(self, path)
151 self.header.append(line)
152 elif not line.startswith('!') and isnt_empty:
--> 153 self.options.append(self.OptionType(
154 *self.get_constructor_args(line)))
155 self.opt_count += 1

~/venvs/hydromt-env/lib/python3.8/site-packages/pysumma/output_control.py in init(self, var, period, sum, instant, mean, variance, min, max, mode)
31 self.period = period
32 else:
---> 33 self.period = int(period)
34 self.sum = int(sum)
35 self.instant = int(instant)

TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'`

outputControl.txt

@arbennett
Copy link
Member

Thanks for reporting this! Where did this outputControl.txt file come from - was it a newer or older version of SUMMA? While I understand the use case and can see how we'd handle this in pysumma it feels like a bad design decision to have conditional formatting that is not documented in the official file spec (https://summa.readthedocs.io/en/latest/input_output/SUMMA_input/#output-control-file). Before we make any changes to the pysumma codebase I think it would be good to revisit if this is the right syntax to use in SUMMA itself.

@bartvanosnabrugge
Copy link
Author

I took the outputControl.txt file from CWARHM: outputControl.txt

Then I use the file in my summa-plugin for the hydromt model builder package, but the file doesn't change (only copied).

The idea of the hydromt-summa plugin is that you can build summa models from scratch based on global data (or local data) from the command line (as well as other models that have a plug in).

I started writing my own input-output code for reading and writing summa model files, but then realized that pysumma existed and that it is likely more future proof to use the pysumma API, then when I tried reading a model that I built with the plug-in, I got the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants