text
stringlengths
81
112k
Initialise a *HydPy* project based on the given XML configuration file agreeing with `HydPyConfigMultipleRuns.xsd`. We use the `LahnH` project and its rather complex XML configuration file `multiple_runs.xml` as an example (module |xmltools| provides information on interpreting this fil...
Evaluate any valid Python expression with the *HydPy* server process and get its result. Method |HydPyServer.POST_evaluate| serves to test and debug, primarily. The main documentation on module |servertools| explains its usage. def POST_evaluate(self) -> None: """Evaluate any valid Pyt...
Stop and close the *HydPy* server. def GET_close_server(self) -> None: """Stop and close the *HydPy* server.""" def _close_server(): self.server.shutdown() self.server.server_close() shutter = threading.Thread(target=_close_server) shutter.deamon = True s...
Get the types of all current exchange items supposed to change the values of |Parameter| objects. def GET_parameteritemtypes(self) -> None: """Get the types of all current exchange items supposed to change the values of |Parameter| objects.""" for item in state.parameteritems: ...
Get the types of all current exchange items supposed to change the values of |StateSequence| or |LogSequence| objects. def GET_conditionitemtypes(self) -> None: """Get the types of all current exchange items supposed to change the values of |StateSequence| or |LogSequence| objects.""" f...
Get the types of all current exchange items supposed to return the values of |Parameter| or |Sequence| objects or the time series of |IOSequence| objects. def GET_getitemtypes(self) -> None: """Get the types of all current exchange items supposed to return the values of |Parameter| or |...
Change the current simulation |Timegrid|. def POST_timegrid(self) -> None: """Change the current simulation |Timegrid|.""" init = hydpy.pub.timegrids.init sim = hydpy.pub.timegrids.sim sim.firstdate = self._inputs['firstdate'] sim.lastdate = self._inputs['lastdate'] stat...
Get the values of all |ChangeItem| objects handling |Parameter| objects. def GET_parameteritemvalues(self) -> None: """Get the values of all |ChangeItem| objects handling |Parameter| objects.""" for item in state.parameteritems: self._outputs[item.name] = item.value
Get the values of all |ChangeItem| objects handling |StateSequence| or |LogSequence| objects. def GET_conditionitemvalues(self) -> None: """Get the values of all |ChangeItem| objects handling |StateSequence| or |LogSequence| objects.""" for item in state.conditionitems: self...
Get the values of all |Variable| objects observed by the current |GetItem| objects. For |GetItem| objects observing time series, |HydPyServer.GET_getitemvalues| returns only the values within the current simulation period. def GET_getitemvalues(self) -> None: """Get the values ...
Assign the |StateSequence| or |LogSequence| object values available for the current simulation start point to the current |HydPy| instance. When the simulation start point is identical with the initialisation time point and you did not save conditions for it beforehand, the "original" i...
Save the |StateSequence| and |LogSequence| object values of the current |HydPy| instance for the current simulation endpoint. def GET_save_conditionvalues(self) -> None: """Save the |StateSequence| and |LogSequence| object values of the current |HydPy| instance for the current simulation endpoi...
Save the values of those |ChangeItem| objects which are handling |Parameter| objects. def GET_save_parameteritemvalues(self) -> None: """Save the values of those |ChangeItem| objects which are handling |Parameter| objects.""" for item in state.parameteritems: state.parameter...
Get the previously saved values of those |ChangeItem| objects which are handling |Parameter| objects. def GET_savedparameteritemvalues(self) -> None: """Get the previously saved values of those |ChangeItem| objects which are handling |Parameter| objects.""" dict_ = state.parameteritemva...
ToDo: extend functionality and add tests def GET_save_modifiedconditionitemvalues(self) -> None: """ToDo: extend functionality and add tests""" for item in state.conditionitems: state.modifiedconditionitemvalues[self._id][item.name] = \ list(item.device2target.values())[0].v...
ToDo: extend functionality and add tests def GET_savedmodifiedconditionitemvalues(self) -> None: """ToDo: extend functionality and add tests""" dict_ = state.modifiedconditionitemvalues.get(self._id) if dict_ is None: self.GET_conditionitemvalues() else: for name...
Save the values of all current |GetItem| objects. def GET_save_getitemvalues(self) -> None: """Save the values of all current |GetItem| objects.""" for item in state.getitems: for name, value in item.yield_name2value(state.idx1, state.idx2): state.getitemvalues[self._id][nam...
Get the previously saved values of all |GetItem| objects. def GET_savedgetitemvalues(self) -> None: """Get the previously saved values of all |GetItem| objects.""" dict_ = state.getitemvalues.get(self._id) if dict_ is None: self.GET_getitemvalues() else: for name...
Save the current simulation period. def GET_save_timegrid(self) -> None: """Save the current simulation period.""" state.timegrids[self._id] = copy.deepcopy(hydpy.pub.timegrids.sim)
Get the previously saved simulation period. def GET_savedtimegrid(self) -> None: """Get the previously saved simulation period.""" try: self._write_timegrid(state.timegrids[self._id]) except KeyError: self._write_timegrid(hydpy.pub.timegrids.init)
Trim the value(s) of a |Variable| instance. Usually, users do not need to apply function |trim| directly. Instead, some |Variable| subclasses implement their own `trim` methods relying on function |trim|. Model developers should implement individual `trim` methods for their |Parameter| or |Sequenc...
Return some "numerical accuracy" to be expected for the given floating point value(s) (see method |trim|). def _get_tolerance(values): """Return some "numerical accuracy" to be expected for the given floating point value(s) (see method |trim|).""" tolerance = numpy.abs(values*1e-15) if hasattr(tole...
Return a function usable as a comparison method for class |Variable|. Pass the specific method (e.g. `__eq__`) and the corresponding operator (e.g. `==`) as strings. Also pass either |numpy.all| or |numpy.any| for aggregating multiple boolean values. def _compare_variables_function_generator( me...
Return a valid string representation for the given |Variable| object. Function |to_repr| it thought for internal purposes only, more specifically for defining string representations of subclasses of class |Variable| like the following: >>> from hydpy.core.variabletools import to_repr, Variable ...
Raises a |RuntimeError| if at least one of the required values of a |Variable| object is |None| or |numpy.nan|. The descriptor `mask` defines, which values are considered to be necessary. Example on a 0-dimensional |Variable|: >>> from hydpy.core.variabletools import Variable >...
Average the actual values of the |Variable| object. For 0-dimensional |Variable| objects, the result of method |Variable.average_values| equals |Variable.value|. The following example shows this for the sloppily defined class `SoilMoisture`: >>> from hydpy.core.variabletools i...
Get a sub-mask of the mask handled by the actual |Variable| object based on the given arguments. See the documentation on method |Variable.average_values| for further information. def get_submask(self, *args, **kwargs) -> masktools.CustomMask: """Get a sub-mask of the mask handled by t...
A list with comments for making string representations more informative. With option |Options.reprcomments| being disabled, |Variable.commentrepr| is empty. def commentrepr(self) -> List[str]: """A list with comments for making string representations more informative. ...
Insert a table in a given worksheet. Args: p_workSheet (openpyxl.worksheet.worksheet.Worksheet): the worksheet where the table will be inserted. Defaults to None. p_headerDict (collections.OrderedDict): an ordered dict that contains table header columns. Notes: ...
Return the header of a regular or auxiliary parameter control file. The header contains the default coding information, the import command for the given model and the actual parameter and simulation step sizes. The first example shows that, if you pass the model argument as a string, you have to take ...
Assign docstrings to the constants handled by |Constants| to make them available in the interactive mode of Python. def _prepare_docstrings(self, frame): """Assign docstrings to the constants handled by |Constants| to make them available in the interactive mode of Python.""" if config.U...
Call method |Parameter.update| of all "secondary" parameters. Directly after initialisation, neither the primary (`control`) parameters nor the secondary (`derived`) parameters of application model |hstream_v1| are ready for usage: >>> from hydpy.models.hstream_v1 import * >>>...
Write the control parameters to file. Usually, a control file consists of a header (see the documentation on the method |get_controlfileheader|) and the string representations of the individual |Parameter| objects handled by the `control` |SubParameters| object. The main functi...
Try to return the parameter values from the auxiliary control file with the given name. Things are a little complicated here. To understand this method, you should first take a look at the |parameterstep| function. def _get_values_from_auxiliaryfile(self, auxfile): """Try to return th...
The actual initial value of the given parameter. Some |Parameter| subclasses define another value for class attribute `INIT` than |None| to provide a default value. Let's define a parameter test class and prepare a function for initialising it and connecting the resulting instance to a...
Factor to adjust a new value of a time-dependent parameter. For a time-dependent parameter, its effective value depends on the simulation step size. Method |Parameter.get_timefactor| returns the fraction between the current simulation step size and the current parameter step size. ...
Change and return the given value(s) in accordance with |Parameter.get_timefactor| and the type of time-dependence of the actual parameter subclass. .. testsetup:: >>> from hydpy import pub >>> del pub.timegrids For the same conversion factor returned by method...
The inverse version of method |Parameter.apply_timefactor|. See the explanations on method Parameter.apply_timefactor| to understand the following examples: .. testsetup:: >>> from hydpy import pub >>> del pub.timegrids >>> from hydpy.core.parametertools impor...
Try to find a compressed parameter value representation and return it. |Parameter.compress_repr| raises a |NotImplementedError| when failing to find a compressed representation. .. testsetup:: >>> from hydpy import pub >>> del pub.timegrids For the fol...
Works as |Parameter.compress_repr|, but returns a string with constant names instead of constant values. See the main documentation on class |NameParameter| for further information. def compress_repr(self) -> str: """Works as |Parameter.compress_repr|, but returns a string with...
Works as |Parameter.compress_repr|, but alternatively tries to compress by following an external classification. See the main documentation on class |ZipParameter| for further information. def compress_repr(self) -> Optional[str]: """Works as |Parameter.compress_repr|, but alternativel...
Update the actual simulation values based on the toy-value pairs. Usually, one does not need to call refresh explicitly. The "magic" methods __call__, __setattr__, and __delattr__ invoke it automatically, when required. Instantiate a 1-dimensional |SeasonalParameter| object: ...
Perform a linear value interpolation for the given `date` and return the result. Instantiate a 1-dimensional |SeasonalParameter| object: >>> from hydpy.core.parametertools import SeasonalParameter >>> class Par(SeasonalParameter): ... NDIM = 1 ... TYPE = float ...
Update subclass of |RelSubweightsMixin| based on `refweights`. def update(self) -> None: """Update subclass of |RelSubweightsMixin| based on `refweights`.""" mask = self.mask weights = self.refweights[mask] self[~mask] = numpy.nan self[mask] = weights/numpy.sum(weights)
A user-defined value to be used instead of the value of class constant `INIT`. See the main documentation on class |SolverParameter| for more information. def alternative_initvalue(self) -> Union[bool, int, float]: """A user-defined value to be used instead of the value of class ...
Reference the actual |Indexer.timeofyear| array of the |Indexer| object available in module |pub|. >>> from hydpy import pub >>> pub.timegrids = '27.02.2004', '3.03.2004', '1d' >>> from hydpy.core.parametertools import TOYParameter >>> toyparameter = TOYParameter(None) >...
Support for custom company premises model with developer friendly validation. def get_premises_model(): """ Support for custom company premises model with developer friendly validation. """ try: app_label, model_name = PREMISES_MODEL.split('.') except ValueError: raise Impro...
Allows to access global request and read a timestamp from query. def get_now(): """ Allows to access global request and read a timestamp from query. """ if not get_current_request: return datetime.datetime.now() request = get_current_request() if request: openinghours_now = requ...
Returns QuerySet of ClosingRules that are currently valid def get_closing_rule_for_now(location): """ Returns QuerySet of ClosingRules that are currently valid """ now = get_now() if location: return ClosingRules.objects.filter(company=location, s...
Is the company currently open? Pass "now" to test with a specific timestamp. Can be used stand-alone or as a helper. def is_open(location, now=None): """ Is the company currently open? Pass "now" to test with a specific timestamp. Can be used stand-alone or as a helper. """ if now is None: ...
Returns the next possible opening hours object, or (False, None) if location is currently open or there is no such object I.e. when is the company open for the next time? def next_time_open(location): """ Returns the next possible opening hours object, or (False, None) if location is currently open...
A |numpy| |numpy.ndarray| with equal weights for all segment junctions.. >>> from hydpy.models.hstream import * >>> parameterstep('1d') >>> states.qjoints.shape = 5 >>> states.qjoints.refweights array([ 0.2, 0.2, 0.2, 0.2, 0.2]) def refweights(self): """A |n...
Add a directory and optionally its path. def add(self, directory, path=None) -> None: """Add a directory and optionally its path.""" objecttools.valid_variable_identifier(directory) if path is None: path = directory setattr(self, directory, path)
Absolute path pointing to the available working directories. >>> from hydpy.core.filetools import FileManager >>> filemanager = FileManager() >>> filemanager.BASEDIR = 'basename' >>> filemanager.projectdir = 'projectname' >>> from hydpy import repr_, TestIO >>> with Test...
Names and paths of the available working directories. Available working directories are those beeing stored in the base directory of the respective |FileManager| subclass. Folders with names starting with an underscore are ignored (use this for directories handling additional data files...
Name of the current working directory containing the relevant files. To show most of the functionality of |property| |FileManager.currentdir| (unpacking zip files on the fly is explained in the documentation on function (|FileManager.zip_currentdir|), we first prepare a |FileManager| ...
Absolute path of the current working directory. >>> from hydpy.core.filetools import FileManager >>> filemanager = FileManager() >>> filemanager.BASEDIR = 'basename' >>> filemanager.projectdir = 'projectname' >>> from hydpy import repr_, TestIO >>> with TestIO(): ...
Names of the files contained in the the current working directory. Files names starting with underscores are ignored: >>> from hydpy.core.filetools import FileManager >>> filemanager = FileManager() >>> filemanager.BASEDIR = 'basename' >>> filemanager.projectdir = 'projectname'...
Absolute path names of the files contained in the current working directory. Files names starting with underscores are ignored: >>> from hydpy.core.filetools import FileManager >>> filemanager = FileManager() >>> filemanager.BASEDIR = 'basename' >>> filemanager.projectd...
Pack the current working directory in a `zip` file. |FileManager| subclasses allow for manual packing and automatic unpacking of working directories. The only supported format is `zip`. To avoid possible inconsistencies, origin directories and zip files are removed after packing or unp...
Read all network files of the current working directory, structure their contents in a |selectiontools.Selections| object, and return it. def load_files(self) -> selectiontools.Selections: """Read all network files of the current working directory, structure their contents in a |selectiontools....
Save the |Selection| objects contained in the given |Selections| instance to separate network files. def save_files(self, selections) -> None: """Save the |Selection| objects contained in the given |Selections| instance to separate network files.""" try: currentpath = self.c...
Delete the network files corresponding to the given selections (e.g. a |list| of |str| objects or a |Selections| object). def delete_files(self, selections) -> None: """Delete the network files corresponding to the given selections (e.g. a |list| of |str| objects or a |Selections| object).""" ...
Return the namespace of the given file (and eventually of its corresponding auxiliary subfiles) as a |dict|. By default, the internal registry is cleared when a control file and all its corresponding auxiliary files have been loaded. You can change this behaviour by passing `False` for...
Read the control parameters from the given path (and its auxiliary paths, where appropriate) and store them in the given |dict| object `info`. Note that the |dict| `info` can be used to feed information into the execution of control files. Use this method only if you are comple...
Save the given text under the given control filename and the current path. def save_file(self, filename, text): """Save the given text under the given control filename and the current path.""" if not filename.endswith('.py'): filename += '.py' path = os.path.join(sel...
Read and return the content of the given file. If the current directory is not defined explicitly, the directory name is constructed with the actual simulation start date. If such an directory does not exist, it is created immediately. def load_file(self, filename): """Read and return...
Save the given text under the given condition filename and the current path. If the current directory is not defined explicitly, the directory name is constructed with the actual simulation end date. If such an directory does not exist, it is created immediately. def save_file(self, f...
Load data from an "external" data file an pass it to the given |IOSequence|. def load_file(self, sequence): """Load data from an "external" data file an pass it to the given |IOSequence|.""" try: if sequence.filetype_ext == 'npy': sequence.series = sequence.a...
Write the date stored in |IOSequence.series| of the given |IOSequence| into an "external" data file. def save_file(self, sequence, array=None): """Write the date stored in |IOSequence.series| of the given |IOSequence| into an "external" data file. """ if array is None: array...
Prepare a new |NetCDFInterface| object for reading data. def open_netcdf_reader(self, flatten=False, isolate=False, timeaxis=1): """Prepare a new |NetCDFInterface| object for reading data.""" self._netcdf_reader = netcdftools.NetCDFInterface( flatten=bool(flatten), isolate=bool(...
Prepare a new |NetCDFInterface| object for writing data. def open_netcdf_writer(self, flatten=False, isolate=False, timeaxis=1): """Prepare a new |NetCDFInterface| object for writing data.""" self._netcdf_writer = netcdftools.NetCDFInterface( flatten=bool(flatten), isolate=bool(...
Adjust the given precipitation values. Required control parameters: |NHRU| |KG| Required input sequence: |Nied| Calculated flux sequence: |NKor| Basic equation: :math:`NKor = KG \\cdot Nied` Example: >>> from hydpy.models.lland import * >>> paramet...
Adjust the given air temperature values. Required control parameters: |NHRU| |KT| Required input sequence: |TemL| Calculated flux sequence: |TKor| Basic equation: :math:`TKor = KT + TemL` Example: >>> from hydpy.models.lland import * >>> parameters...
Calculate reference evapotranspiration after Turc-Wendling. Required control parameters: |NHRU| |KE| |KF| |HNN| Required input sequence: |Glob| Required flux sequence: |TKor| Calculated flux sequence: |ET0| Basic equation: :math:`ET0 = KE \\cdot ...
Correct the given reference evapotranspiration and update the corresponding log sequence. Required control parameters: |NHRU| |KE| |WfET0| Required input sequence: |PET| Calculated flux sequence: |ET0| Updated log sequence: |WET0| Basic equations: :...
Calculate land use and month specific values of potential evapotranspiration. Required control parameters: |NHRU| |Lnk| |FLn| Required derived parameter: |MOY| Required flux sequence: |ET0| Calculated flux sequence: |EvPo| Additional requirements: |...
Calculate stand precipitation and update the interception storage accordingly. Required control parameters: |NHRU| |Lnk| Required derived parameter: |KInz| Required flux sequence: |NKor| Calculated flux sequence: |NBes| Updated state sequence: |Inzp| ...
Calculate interception evaporation and update the interception storage accordingly. Required control parameters: |NHRU| |Lnk| |TRefT| |TRefN| Required flux sequence: |EvPo| Calculated flux sequence: |EvI| Updated state sequence: |Inzp| Basic equatio...
Calculate the frozen part of stand precipitation. Required control parameters: |NHRU| |TGr| |TSp| Required flux sequences: |TKor| |NBes| Calculated flux sequence: |SBes| Examples: In the first example, the threshold temperature of seven hydrological ...
Calculate the potential snowmelt. Required control parameters: |NHRU| |Lnk| |GTF| |TRefT| |TRefN| |RSchmelz| |CPWasser| Required flux sequence: |TKor| Calculated fluxes sequence: |WGTF| Basic equation: :math:`WGTF = max(GTF \\cdot (TKor - T...
Calculate the actual amount of water melting within the snow cover. Required control parameters: |NHRU| |Lnk| Required flux sequences: |SBes| |WGTF| Calculated flux sequence: |Schm| Updated state sequence: |WATS| Basic equations: :math:`\\frac{dWATS}{dt...
Calculate the actual water release from the snow cover. Required control parameters: |NHRU| |Lnk| |PWMax| Required flux sequences: |NBes| Calculated flux sequence: |WaDa| Updated state sequence: |WAeS| Basic equations: :math:`\\frac{dWAeS}{dt} = NBes - ...
Calculate the actual water release from the snow cover. Required control parameters: |NHRU| |Lnk| |NFk| |GrasRef_R| Required state sequence: |BoWa| Required flux sequences: |EvPo| |EvI| Calculated flux sequence: |EvB| Basic equations: :math:...
Calculate the amount of base flow released from the soil. Required control parameters: |NHRU| |Lnk| |Beta| |FBeta| Required derived parameter: |WB| |WZ| Required state sequence: |BoWa| Calculated flux sequence: |QBB| Basic equations: :math:`...
Calculate the first inflow component released from the soil. Required control parameters: |NHRU| |Lnk| |NFk| |DMin| Required derived parameter: |WB| Required state sequence: |BoWa| Calculated flux sequence: |QIB1| Basic equation: :math:`QIB1 = DMi...
Calculate the first inflow component released from the soil. Required control parameters: |NHRU| |Lnk| |NFk| |DMin| |DMax| Required derived parameter: |WZ| Required state sequence: |BoWa| Calculated flux sequence: |QIB2| Basic equation: :mat...
Calculate direct runoff released from the soil. Required control parameters: |NHRU| |Lnk| |NFk| |BSf| Required state sequence: |BoWa| Required flux sequence: |WaDa| Calculated flux sequence: |QDB| Basic equations: :math:`QDB = \\Bigl \\lbrace ...
Update soil moisture and correct fluxes if necessary. Required control parameters: |NHRU| |Lnk| Required flux sequence: |WaDa| Updated state sequence: |BoWa| Required (and eventually corrected) flux sequences: |EvB| |QBB| |QIB1| |QIB2| |QDB| ...
Aggregate the amount of base flow released by all "soil type" HRUs and the "net precipitation" above water areas of type |SEE|. Water areas of type |SEE| are assumed to be directly connected with groundwater, but not with the stream network. This is modelled by adding their (positive or negative) "net...
Aggregate the amount of the first interflow component released by all HRUs. Required control parameters: |NHRU| |FHRU| Required flux sequence: |QIB1| Calculated state sequence: |QIGZ1| Basic equation: :math:`QIGZ1 = \\Sigma(FHRU \\cdot QIB1)` Example: ...
Aggregate the amount of the second interflow component released by all HRUs. Required control parameters: |NHRU| |FHRU| Required flux sequence: |QIB2| Calculated state sequence: |QIGZ2| Basic equation: :math:`QIGZ2 = \\Sigma(FHRU \\cdot QIB2)` Example: ...
Aggregate the amount of total direct flow released by all HRUs. Required control parameters: |Lnk| |NHRU| |FHRU| Required flux sequence: |QDB| |NKor| |EvI| Calculated flux sequence: |QDGZ| Basic equation: :math:`QDGZ = \\Sigma(FHRU \\cdot QDB) + ...
Seperate total direct flow into a small and a fast component. Required control parameters: |A1| |A2| Required flux sequence: |QDGZ| Calculated state sequences: |QDGZ1| |QDGZ2| Basic equation: :math:`QDGZ2 = \\frac{(QDGZ-A2)^2}{QDGZ+A1-A2}` :math:`QDGZ1 = Q...
Perform the runoff concentration calculation for base flow. The working equation is the analytical solution of the linear storage equation under the assumption of constant change in inflow during the simulation time step. Required derived parameter: |KB| Required flux sequence: |QBGZ|...
Perform the runoff concentration calculation for the first interflow component. The working equation is the analytical solution of the linear storage equation under the assumption of constant change in inflow during the simulation time step. Required derived parameter: |KI1| Required st...
Perform the runoff concentration calculation for the second interflow component. The working equation is the analytical solution of the linear storage equation under the assumption of constant change in inflow during the simulation time step. Required derived parameter: |KI2| Required s...
Perform the runoff concentration calculation for "slow" direct runoff. The working equation is the analytical solution of the linear storage equation under the assumption of constant change in inflow during the simulation time step. Required derived parameter: |KD1| Required state sequence:...
Perform the runoff concentration calculation for "fast" direct runoff. The working equation is the analytical solution of the linear storage equation under the assumption of constant change in inflow during the simulation time step. Required derived parameter: |KD2| Required state sequence:...
Calculate the final runoff. Note that, in case there are water areas, their |NKor| values are added and their |EvPo| values are subtracted from the "potential" runoff value, if possible. This hold true for |WASSER| only and is due to compatibility with the original LARSIM implementation. Using land ...