Showing posts with label Modelling. Show all posts
Showing posts with label Modelling. Show all posts

Friday, March 8, 2024

Modelling and Hydrological Modelling

These lecture are actually part of the 2024 course in Hydrological Modelling. However because they can be of some more general interest, I am grouping them also here. They try to review the concepts of modelling in general and when applied to hydrology. In the series of lectures there is also a concise overview of catchment processes. The first lecture image, see below, it a Maurizo Cattelan artwork entitled "A donkey among doctors" which is my attitude when I approach the topic. 


The final idea about the practice to do model is expressed in the paper and in the various posts that regard DARTHs which can be find here.  Among people that more reflected on Hydrological Modelling there is certainly Keith Beven [GS]. To get a glimpse of his contributions, please see this other post which contains some of his relevant papers. 

Wednesday, March 6, 2024

On Hydrological Models and their choice (and a use of the AboutHydrology mailing list)

Initially, I was captivated by the visuals that I could incorporate into my presentations. To my pleasant surprise, I discovered that the AboutHydrology mailing list served as a valuable data source. Remarkably, this platform has been active for approximately a decade (I need to verify the exact date of its inception) and has amassed a wealth of information.

Reproduced from Melsen, 2022

Subsequently, I came across two intriguing papers authored by Melsen, delving into the "sociology of selecting a hydrological model." These papers proved to be quite engaging. Additionally, there are other noteworthy publications exploring similar themes. Notably, among the more recent works, Hamilton et al., 2022, and Horton et al., 2023, deserve special mention.  Please find their citation below. In the paper you can easily recover previous relevant literature. 

References

Hamilton, Serena H., Carmel A. Pollino, Danial S. Stratford, Baihua Fu, and Anthony J. Jakeman. 2022. “Fit-for-Purpose Environmental Modeling: Targeting the Intersection of Usability, Reliability and Feasibility.” Environmental Modelling & Software 148 (February): 105278. https://doi.org/10.1016/j.envsoft.2021.105278.

Horton, Pascal, Bettina Schaefli, and Martina Kauzlaric. 2022. “Why Do We Have so Many Different Hydrological Models? A Review Based on the Case of Switzerland.” WIREs. Water 9 (1). https://doi.org/10.1002/wat2.1574.

Melsen, Lieke A. 2023. “The Modeling Toolkit: How Recruitment Strategies for Modeling Positions Influence Model Progress.” Frontiers in Water 5 (May). https://doi.org/10.3389/frwa.2023.1149590.


Wednesday, March 2, 2022

Models Classification according to their interfaceability (MaaA, MaaT, MaaS, MaaR, MaaC)

In the recent submitted manuscript about DARTHs (Digital eArth Twins of Hydrology) we delineated five categories of models in a possible increasing adaptability to be part of a DARTH or of a DARTH component:

  • MaaA,  Model as an Application
  • MaaT, Model as a Tool
  • MaaS, Model as a Service
  • MaaR, Model as a Resource 
  • MaaC, Model as a Commodity

I'll try to explain what the acronyms mean here below. The characteristics listed, it should be remarked, are not connected to the domain science contents of models but to to the software architecture  characteristics and requirements. 

Tom Hagen's photo click on it for more

MaaA - Model as an Application 

MaaA -  Model as Applications - Full fledged models that have close architecture, that includes the data formats and the visualization tools. What follows for MaaA is taken with little  modification from Rizzoli et al. (2006).

  1. A MaaA  bundles data,  algorithms  and  the  graphical  user  interface  of  a  model  in  an  application. This  makes the model very hard to re-use out of its original context. Most MaaTs are also monoliths composed by hundreds of thousands lines of code. 
  2.  A MaaA  works just on one operating system MS Windows, Mac OS or Linux. 
On MaaA, Knoben et al. (2021) provides the following description:

"These tools are typically provided as self-contained packages. Packages tend to be easy to use for their intended purpose but take time to understand and do not necessarily provide much flexibility to deviate from their intended purpose. Layering additional functions on top of an existing package or modifying a package’s source code is certainly possible, but can be outside the comfort zone of many users."

Other usual characteristics of MaaA are:
  • Applications  evolution  is  totally in the hands of the original developers. This is a good thing for intellectual property  rights  and  in  a  commercial  environment,  but this  is  absolutely  a  bad  thing  for  science  and  the  way  it  is  supposed  to  progress.  Independent  revisions  and  third-party  contributions are nearly impossible. 
  • MaaA often do not come with associated data sets for testing. Moreover, the adoption of object-oriented programming,  while  it  is  a  good  thing  for  model  reusability  and  portability,  it  makes  things more complex for testing, because of a number of problems such as observability in  virtual  method  calls  and  state  dependent  behaviour  of  objects.
  • The way they are coded  (as monolithic entities)  displays  a  strong  level  of  internal  cohesion,  and,  if  a  modeller  is  interested  in  reusing  a  particular  function  within  a  bigger  model,  they  can  find  it  very  hard  to  isolate  and extract it, given the strong dependencies existing in the source code parts. 
  • Their data formats  do not come from a community agreement  and, their developers  typically decide to have output data in a format relevant to their own application, which may not be a format that is widely used by others. It is cumbersome for developers to have their tools ingest multiple different data formats and such functionality is therefore somewhat rare (slightly modified from Knoben et al 2021). 
It could be observed that a MaaA could be evolved to eliminate the various characteristics  in the bullet list. In fact there exists a variety of MaaA which, especially recently, pursued such achievement (modular code, open to common data formats, separation between the graphical model interface and the rest of the code). 

MaaT - Model as a Tool (Mainly From Nativi et al., 2021)

In MaaT, differently from MaaA there areat least two level of abstraction: the interface is abstracted from the model, in a client-server way,  and the model is loosely coupled to the data. The interacting tools is distinct from the model itself and can eventually be changed. 

However, a given implementation of the model runs on a specific server, and the interact with the model through the user interface.   In a MaaT  the models are preloaded on a specific machine. Besides, it is not possible to modify the interaction between the server and the client which is kept fixed by the user interface. 
Benefits include a strong control of the model use and execution (which could be useful to control what happens in a operational service).  There are limitations on the usability and  flexibility of the model, as well as its scalability due to the limitation of the specific server. Machine-to-machine interoperability (chaining capabilities) is not allowed. Knoben et al (2021), without knowing the acronym, defines MaaT well when talking of some web-based services: "... several of these tools are provided as web-based services. This can be appealing because, for example, data can be pre-downloaded to speed up model configuration and model simulations can be easily shared. The advantage of such approaches is that they can be combined with some  form of server-side data transformations (e.g., subsetting or averaging), which minimizes  data transfers. Storing the inputs for and outputs of large-domain simulations can, however, be cumbersome, and keeping pre-downloaded data up-to-date and sufficient for all user needs takes sustained, long-term effort. A further complication is that it is regrettably common that such web-based services require some form of manual interaction with the webpage, limiting opportunities to automate data acquisition tasks".  
In a MaaT there is a certain level of abstraction is implemented to make the data and the models loosely coupled but MaaTs do not necessarily provide tools for automation of data acquisition. However, it can be said that the models' core in a MaaT is agnostic with respect the data source and formats (for a detailed explanation see Knoben et al., 2021).  
In an open MaaT,  
  • model evolution should be in the hands of a community
  • models should come with an appropriate set of tests both for the informatics and the physics. 
  • a modular structure for the code should be the rule 
  • Tools for data brokering should be available 

MaaS - Model as a Service  (Mainly From Nativi et al., 2021 and David et al, 2014)

A “Model-as-a-Service” provides the capability to execute simulation models as a service. As Wikipedia reports: "In the contexts of software architecture, service-orientation and service-oriented architecture, the term service refers to a software functionality or a set of software functionalities (such as the retrieval of specified information or the execution of a set of operations) with a purpose that different clients can reuse for different purposes, together with the policies that should control its usage (based on the identity of the client requesting the service, for example)."
As for the previous case of MaaT, a given implementation of the analytical model runs on a specific server, but this time, APIs are exposed to interacting with the model. Therefore, interoperability consists of machine-to-machine interaction through a published API, e.g., for a run configuration and execution. Nevertheless, it is not possible to move the model and make it run on a different machine (without having to "manually" install the model and its managing software on these machines).  Concerns deal with a still limited flexibility and possible scalability issues (depending on the server capacities). To note, this time, the existence of possible concerns for less control on the model (re-)use.

There are two main usage patterns: (i) The model can be pre-deployed, has a well-known service endpoint, and is supported by supplemental data services. This is quite common for operational models used in a production environment. Moreover, (ii) the model can be dynamically deployed from the client before execution (implying that a MaaS is made up of a pool of modelling components that can be linked just before run time with a scripting language). Model service development for research purposes needs such a behavior. Both approaches address a different workflow, need for availability and security. A certain model execution method may also be specified in such a service.

MaaR - Model as a Resource 

The interoperability level resamples the same patterns used for any other shared digital resource, like a dataset.  
  • This time, the model itself (and not a given implementation) is accessed through a resource-oriented interface, i.e., API and 
  • a software infrastructure layer manages (with some constraints whose invasiveness should not be relevant) a set of compliant models
  • That allows to effectively move the model and make it run on the machine that best performs for a specific use case. 
Cloud services can distribute the model runs on various architectures (like cloud services, high performance computing machines, multicore machines, cluster of computers) dynamically adapting the request of resources to the demand. 
There are clear benefits in terms of flexibility, scalability, and interoperability. The main concerns, maybe,  are about the model sound utilization.

MaaC - Models as a Commodity

They are MaaS or MaaR that in addition have some controls on the Science and their explanation. 

Differently from the other, previous, classifications the Model as a Commodity definition does not imply information technology issues but programming and  science issues that are related to the DARTHs working. Are  MaaC models a mass-produced unspecialized product (the meaning of commodity) ? They are obviously not but their use inside Digital Earth Twins, once they will be produced, will be like they were such. The most of the people who will access it, will do for taking decision on other aspects of science and social life. Therefore the hydrological modelling in DARTHs has to acquire some features that make their use more safe and less prone to introduce fake information in the public. This is envisioned in providing DARTHs with error (uncertainty) estimations for all the quantities hindcasted and forecasted.  The topic is difficult one with a large amount of literature (e.g. Beven, 2016), often difficult and obscure (e.g. Nearing et al., 2016) and the requirement here of having a quantification of uncertainty does not enter the dispute of the origin of errors, while staying on Cox (1946) statement that "Purely empirically, probability and statistics can, of course, describe anything from observations to model residuals regardless of the actual sources of uncertainty as an expression of our reasonable expectations" (taken from Beven, 2016) that, at least an empirical estimation of the error on the base of recorded data is possible. 
Because modelling require a first phase of training/calibration/ on the past, them error of modelling must include an analytic performance over the past data of the model. Therefore a MaaC is  a MaaS or a MaaR provided with error estimations on any of the quantity hindcasted or forecasted, a warning for the use of any quantity and a major effort for modellers. 

The MaaCs inherit form MaaS and MaaR their composable structure, however with a purpose.  Components are self-contained building blocks, modules or units of code. Each well designed component usually implements a single modeling concept. Multiple algorithms can be implemented within the same component or in various components, and inserted in modeling solutions as alternatives, thus opening the way to compare, inside the same chain of tools, different approaches. This respond also to a science requirement, i.e. the idea that model should be used in DARTHs as hypothesis to be tested among various possibilities (Clark et al, 2011). This flexibility will be usually not directly available to the more unaware end-users, but will be certainly useful for scientists to provide more reliable modelling. Therefore MaaC requires tools for supporting the workflow of hypothesis testing.  These tools are usually provided at "literate computing" workflows, as those explained in Rigon et al. 2021. 

DARTHs in their essentials are modeling infrastructures that deploy the MaaC paradigm.

References

Beven, Keith. 2016. “Facets of Uncertainty: Epistemic Uncertainty, Non-Stationarity, Likelihood, Hypothesis Testing, and Communication.” Hydrological Sciences Journal 61 (9): 1652–65.

Clark, Martyn P., Dmitri Kavetski, and Fabrizio Fenicia. 2011. “Pursuing the Method of Multiple Working Hypotheses for Hydrological Modeling.” Water Resources Research 47 (9). https://doi.org/10.1029/2010wr009827.

Cox, R. T.,1946. Probability, frequency and reasonableexpectation.American   Journal   of   Physics,  14,  1–13.doi:10.1119/1.1990764

David, Olaf, Wes Lloyd, Ken Rojas, Mazdak Arabi, Frank Geter, James Ascough, Tim Green, G. Leavesley, and Jack Carlson. 2014. “Modeling-as-a-Service (MaaS) Using the Cloud Services Innovation Platform (CSIP).” In International Congress on Environmental Modelling and Software. scholarsarchive.byu.edu. https://scholarsarchive.byu.edu/iemssconference/2014/Stream-A/30/.

Knoben, Wouter Johannes Maria, Martyn P. Clark, Jerad Bales, Andrew Bennett, S. Gharari, Christopher B. Marsh, Bart Nijssen, et al. 2021. “Community Workflows to Advance Reproducibility in Hydrologic Modeling: Separating Model-Agnostic and Model-Specific Configuration Steps in Applications of Large-Domain Hydrologic Models.” Earth and Space Science Open Archive. https://doi.org/10.1002/essoar.10509195.1.

Nativi, Stefano, Paolo Mazzetti, and Max Craglia. 2021. “Digital Ecosystems for Developing Digital Twins of the Earth: The Destination Earth Case.” Remote Sensing 13 (11): 2119.

Nearing, Grey S., Yudong Tian, Hoshin V. Gupta, Martyn P. Clark, Kenneth W. Harrison, and Steven V. Weijs. 2016. “A Philosophical Basis for Hydrological Uncertainty.” Hydrological Sciences Journal 61 (9): 1666–78.

Rigon, Riccardo, Giuseppe Formetta, Marialaura Bancheri, Niccolò Tubini, Concetta D’Amato, Olaf David, and Christian Massari. 2022. “HESS Opinions: Participatory Digital Earth Twin Hydrology Systems (DARTHs) for Everyone: A Blueprint for Hydrologists.” Hydrology and Earth System Sciences Discussions, 1–38.

Rizzoli, A. E., M. G. E. Svensson, E. Rowe, M. Donatelli, R. M. Muetzelfeldt, T. van der Wal, F. K. van Evert, and F. Villa. 2006. “Modelling Framework (SeamFrame) Requirements.” SEAMLESS.

Tuesday, February 22, 2022

Is your modelling system adapt to be part of a digital Twin for Hydrology ?

Recently we submitted a paper to HESSD for discussing how Digital Twin can serve a better doing of Hydrology.  As you can see below, we named the Digital twins for hydrology DARTHs. The discussion paper is: 

Rigon, Riccardo, Giuseppe Formetta, Marialaura Bancheri, Niccolò Tubini, Concetta D’Amato, Olaf David, and Christian Massari. 2022. “HESS Opinions: Participatory Digital Earth Twin Hydrology Systems (DARTHs) for Everyone: A Blueprint for Hydrologists.” Hydrology and Earth System Sciences Discussions, 1–38.

and if you want to contribute with your opinion, the discussion is open until March 14.  If you want to grasp quickly what DARTHs are, you can take five minutes to read to the previous post here (DARTHs cheat sheet). 

As part of the review process, one of the reviewers, dr. Marc Hrachowitz (GS) that we thanks for his comments and suggestions, asked for giving examples of exiting modelling platform or systems that could satisfy part of the requirements that DARTHs, according to us, must have. However, the operation of judging elements of modelling systems of other researchers is always a slippery matter because one usually know just superficially what the systems provided by others actually do.  Therefore  I and co-authors have decided to issue a questionnaire where part of the questions are on characteristics that DARTHs should have.  Developes and users are asked to answer about their systems or models so to have a first hand information.  It could be noticed that we are not asking which processes the models aim to simulate because the hydrology (the physics, chemistry, biology) of the model is not actually the topic here. In the questionnaire the main topic is more about the infrastructure capability and some additional features that should be present.

As Authors of the paper, we know that our own systems do not satisfy the DARTHs' requirements and therefore don't be worry about if your system does not accomplish all. With the questionnaire we try to put a first brick towards them by trying to make researchers reflect on the steps they should do in future developments to converge to build a DARTH component. 

The results of the questionnaire which will remain upon until March 14 2022 will be made public as supplemental material of the paper.  The survey can be found by clicking on the image above.

You can view the partial results of the survey here.

Friday, November 6, 2020

The State-of-Art and the perspectives for next GEOframe research

These are the contents of an e-mail I sent to a friend and colleague to push forward our collaboration. Despite it has been written to a specific person, I think some of the topics can be on general interest for the topics it covers. At least for who is interested in Hydrological Modelling.

Dear Friend,
 
I am trying to simplify here the objectives of my research in order to see where we can find convergence of aims and goals.

Overall, I want to pursue a tight connection between the theory of hydrological processes and their sound (replicable, robust, reliable) implementations (see also here for other explanations). Actually, I work both on the theory and on the implementation. Soon in my career, I realized that a poor implementation of a correct theory often produces wrong results and moreover its incorrect falsification brings credits to flawed ideas (the case of  "tranchant" judgments on Richards equation, based on unreliable integrators is one of the cases). I also grew the idea that, differently from some other colleagues, I wanted to build not just doing-programming but programming-system products (e.g. - Brooks, 1975), i.e. reusable software on which other people can build new knowledge (yes, the idea that building on each others shoulders, and working that way, possibly having the couple of smart intuitions, we can arrive where only the giants, usually arrive). 


My main goal is to build better models than those existing, more controllable, and less prone to devastating bugs. My research tends to be more “methodological” than applied. It is exactly this approach that moved me towards OMS3. It, in comparison with other options, followed by successful colleagues, presents a clean design, support for models’ controllability, encapsulation of modelling solutions, easy and ordered reuse of modules, intrinsic documentation with annotations, support to technical issues, like parallelization and calibration, without overwhelming the hydrologist concentrated on physics. Besides, a wise use of components, could help to dose information to the users and set it visible only when and where required.

Coming to the practice of my research, I focused mainly to two types of models, those I call Hydrological Dynamical Systems (HDSys), mainly based on the solution of multiple coupled non-linear, non-autonomous, ordinary differential equations, and those that have the space variables explicit and solve partial differential equations. From a different perspective, my goal has been to cover entirely the various aspects of the hydrological budget (often including terrain and soil/sediment) not only focusing, as traditional models do, one some or one of the aspects, like discharge or evaporation, or infiltration, or groundwater. Coupling the water with the energy budget, has been an objective of both the types of modelling, especially, but not only, because temperature is easily measurable, even from remote sensing. Tracers, Nutrient and pollutants, were never deeply considered, except recently, but they are part of my modelling tools since many years.

For a community to grow around the previous ideas, some key tools are still missing. The points below summarize: i) what I envision is needed from different perspectives/users; ii) what futures OMS developments should potentially consider. Some of these points are already being reached with the work we did, some are planned to be implemented, for some others we need your support to reach a critical mass and make them happen.

Power User side:
  • Smoothing out some part of the process to deploy a modelling solution to a specific concrete catchment. With students of the GWSs and Hydrological modelling class the two processes of extracting the HRU and interpolating the data were instructive but too much detailed and cumbersome.
  • Using the console is easy and usually hassle-free. However, because we use mostly Jupyter notebooks for the treatment and analysis of inputs and outputs this is a further environment to learn. Using Docker and the command line inside Jupyter could be a choice but with Docker we had hard times on Windows. A console inside Jupyter would be the best choice.
  • In general, a convergence of our tools with those tools people use the most, as Jupyter, decrease the learning curve and developer commitment to bring in and maintain tools.
  • Some ancillary tools for “joining” catchment studied by different people are required
  • calibration revealed to be a time-consuming effort that needs parallelization and speed-up.
  • Probably a server or a “hub” to store and retrieve the collective work, including parameterisations, inputs and so on.
  • Manage the possibility of having multiple treatments of the same catchments would also be required sometimes in the future.

For institutional user
  • Connections to Delft-Fews could be an option to investigate.
  • Our group needs also to experiment with CSIP .
  • A distribution of all the material and the code, through some tool like Anaconda would be desirable.
  • They need dedicated interfaces. For they, modifying parameters and models structure should be not be an option as for researchers or power users
  • Scalability of the computing effort should be the standard (and this should include Net3)

Developers: 

  • Source code should be available on public repository like Github
  • To improve developer appropriate/specific documentation for them should be a continuous effort

Potential developer/researchers

  • When they come from Environmental Engineering or sciences, they usually are familiar with Python, R or Matlab. They do not have notions of OO programming, nor of basic software engineering background. Therefore, appropriate material providing all of this knowledge should be produced. I started with a Java for Hydrologist 101 but I am far to have completed it.
  • They are not comfortable to use tools like Git, Github, Docker, Unit tests, and other commons tools which are necessary for software carpentry and collaborative work. Therefore, some training course on these should be also provided .

The above is more a wish list which we are keeping in mind. Frankly we do not have yet the all the competence to treat them all. As you see I did not list any machine learning tool: but this does not mean that we are not looking to them. For the moment is just safe for us to concentrate to enhance and bring to an optimal state what we have and publish that ten of papers that we have in production on he work we have already done. We are looking for resources though and, resources arriving, we could also think to statistical/machine learning methods to be introduced. One thing to be remarked is that GEOframe-NewAGE can easily replace PRMS. The module we have, usually, are different from those PRMS has, but implementing them the very same way PRMS does should be VERY easy, if this is the goal. A greater integration with AGEs would be also advisable. The main differences to be treated for compatibility are the IO. For now, we often stick with complex data formats but abstract the algorithms from them is an objective we have in mind. Mostly we had to follow our way so far to be sufficiently comprehensive. To be sincere, IMHO, some parameterisation of the processes inside AGEs are simply old hydrology, not currently supported by researchers but, yes, still in use by practitioners (which worldwide use SWAT, though). In all I mentioned I forgot to mention the work by Daniele Dalla Torre that ported SWMM to OMS3. That is a thread that is, at present in a dead end but it can come back alive any time.

Below, I give further information on: i) the reasons why we use OMS; ii) the new components I mentioned before or we are going to develop.

When I arrived to OMS3, my most recent achievement was a stable version of GEOtop, a model that solves the water and energy budget, as its foundational paper told. After 15 years, GEOtop remains quite unique in the panorama of “process-based” models. It in fact includes what is usually present in other process-based models, i.e. an integrator of Richards, Groundwater and Surface water equations, with what usually appears in soil, vegetation, atmosphere models. Besides it has a solid model for snow height evolution, used operationally all over the Alps, and freezing soil, which constitutes a third type of process-based model usually cared by a different scientific community. I’ve certainly sinned arrogantly in doing what others still not do, even with much larger resources, and I will probably go to hell for that. GEOtop has a decently extended literature and I could have capitalized better its treasures, but I preferred to move on, because while I was getting GEOtop stable I’ve been also touching its limits.

Its monolitic structure made of thousands lines of code, made it not easily modifiable and improvable with incoming research and understanding.

Its ambition to cover all the areas of hydrological modelling have made exploding the number of input parameters a fact that most researchers found overwhelming. Introducing competing ideas to model some of the processes became practically impossible and any science advancement nullified.

That’s why I was looking from an intrinsically modular system that could resolve the above issues and boost collaborative work, and that’s why I moved to OMS3 in 2008.
I would have stick with that GEOtop objective but in the same year had quite unexpectedly financial support for studying the management of draughts of river Adige. GEOtop was impractical for that use because of its inability to be calibrated and some flaws in its subsurface-surface water interactions. Necessity brought to the implementation of GEOframe New Age version 0.

In the subsequent decade I and collaborators worked on the GEOframe model perspective, faster to calibrate and, nevertheless quite complete from the point of view of processes integration. For many ancillary parts of the system, it was reinventing the wheel again from scratch but this finally produced the mature product that GEOframe-NewAGE is today. It was conceived for using the natural spatial fractal - graph-like structure of rivers for distributing spatially the hydrologic response unit (HRU) physics and computation. The main driving idea behind GEOframe is that we do computation on a graph nodes which exchange mass and energy according to the interactions among parts described by graph's connections. These nodes can be spatially distinct entities, like hillslopes and HRU, or concurrent processes like discharge and transpiration. In principle an engine under the hood is responsible for distributing the computation along the graph, while the hydrologist takes care of describing the processes with the appropriate degree of refinement. This had a first implementation with Net3 but I believe can be improved in several directions. Before Net3, sure, river networks were schematized as graph, but their topology was hardcoded and no variation was possible in the spatial structure of the model without disrupting the whole. With Net3 the topological structure of the connections can be modified just before the run time, inserting or eliminating human infrastructures, diversions, new nodes of calculation, lakes, reservoirs.

Net3 opened also to the possibility for different researchers to work simultaneously on different part the catchments (actually of the graph) enabling the possibility for a sort of “crowd modelling action” to cover the whole Earth with GEOframe based modelling performed by a crowd of researchers or simply trained people. Clearly for this an infrastructural work is still missing but potentially it could provide a collective works that highly surpasses the present global scale hydrological applications which are based on rough characterization of parameters and scanty local reanalysis of data which is not possible, even for large research groups. The first application of this modeling strategy will be the application of the model to the river Adige, separated in a thousand or more HRU of which we have, so far, some work done by the students of my course of Hydrological Modelling. River Adige is relatively small (10^4 square kilometers) but a variety of climate situations and anthropic activities and settlements that make it very challenging to be modeled. Eventually the simulations will be extended to the whole Alps and beyond.

From the point of view of interacting components, GEOframe has many: the traditional set of tools coming from Hydrologis for terrain analysis; a set of Krigings for interpolation of hydrometeorological variables, the estimation of shortwave and longwave radiation including shadows and topography effects, interception of rainfall by canopies, three simplified models for snow water equivalent modelling, various tools for reservoirs-like modelling (a la PRMS), Muskingham-Cunge and 1d deSaint Venant propagation, Priestley-Taylor, Penman-Monteith and a new model called Prospero which implements a revision due to Penman-Monteith by Schymanski and Or. All the models can make use of LUCA and PSO tools for calibration and the dedicated papers constitute a guideline for their use.
Giuseppe and I just hired a coupled of Ph.D. student and, they, among the other stuff, will work on data assimilation and possibly on some OMS issues.
Did I abandoned then process based modeling? Not at all, the original plane to build the new GEOtop 4.0 is actually very alive.
The nucleus are the tools growing around WHETGEO. At present we have:
  • An integration of Richards 1D with and without temperature, decoupled and coupled with the Energy budget (return the soil temperature profile)
  • An integration of Richards equation 2D (hillslope profile, for instance). No coupling with the energy budget yet.

These tools make leverage on terrain analysis, radiation estimation, interpolation of data, estimation of Evaporation and Transpiration already present in GEOframe but have a gridded domain instead that an HRU separation. With respect to GEOtop, the integration algorithms are completely redesigned around the Newton-Casuli-Zanolli (NCZ) algorithm for Richards, and an appropriate implementation of the grids where topology and geometry are separated. In GEOtop a more traditional Newton-Krylov (NK) algorithm was used whose convergence is not granted a priori and the equations were written for a structured (regular) grid which causes artifacts into the results. Using appropriate design patterns, a twofold objective was obtained: to make room for changes in parameterisations of the equations and, and to maintain as simple as possible (but not too simple) the contents of the inputs. The use of standard formats like NetCDF for outputs contained the number of otherwise exploding output files. The input and output format were decoupled from the algorithms though, in order to maintain flexibility for changing the outputs format. As seen many components developed for GEOframe-NewAGE could be reused for WHETGEO and, in fact, in the foreseen future, also the Net3 infrastructure could be possible used to aggregate various hillslopes simulated by independent WHETGEO runs.
Because I have experience with them and notwithstanding the opinion of many colleagues, I do not see in fact that the lumped reservoir models can cope with those processes which have a well definite spatial history. Remote data is a new frontier and, besides, WHETGEO is fully able to exploit them.

Evolving Prospero will bring into WHETGEO green waters and vegetation and GEOtop 4.0 will be much greener than GEOtop 3.0. This achievemente is almost there. Carbon cycle evolution, forestry and crop, will be a set of ODEs attached to sites, either described as a grid cell or a HRU. Their mathematics is quite the same that for HDSys, with just a different interpretation of the parameters. Transport of tracers and pollutants, via the advection dispersion equation is also almost obtained, because these equations belong to the same family of the heterogeneous transport of heat in porous media that we have already implemented.
Giuseppe in his magic hat has already setup models for hillslope stability analysis that just wait for the 2D and 3D WHETGEO to be tested (the first) and fully implemented (the second). But the 3D solution is more a problem of drawing the grid than everything else with respect the 2D solver.
A possible threat to this WHETGEO is its computational burden. The algorithms are efficient but a high-resolution three-dimensional grid has potentially millions of nodes and simulations are time consuming. Parallelizing its core routines in a way that does not clash with the other forms of parallelism present if OMS3 will be a challenge.
Therefore, what I foresee in the next years is these tools to get maturity and to be used by a potentially large set of users. GEOtop 4.0, built on WHETGEO, Prospero, and other tools would be a really operational tool for instance for landslide risk early warning; for the detailed soil moisture account for precision, regenerative agriculture; for small catchments runoff and sediment production (the latter a feature to be implemented), and obviously would be a great tool for studying any aspect of the critical zone, in any climate past present or future. At the present we cannot foresee when we could add accurate modules for snow (like those or better than those already in GEOtop) but the modules already present in GEOframe could be used easily on a pixel base to surrogate them. Calibration tools for WHETGEO process-based modules, I think, will require some adjustment of the calibration tools now present in OMS3 and we did not try anything about yet.
This mail was pretty long but, I hope it serves to clarify my point of view and the legacy I have with my previous research, I also included Tim in the mail, because I thin he can be interested on many of the research I exposed. Thanks to the friendship we have, I hope the way to strengh our past collaboration in a few future objectives where we can find reciprocal satisfaction.

All the best,

ric (and the guys)

Tuesday, September 15, 2020

DevOps - Or about streamlining what is needed to do modelling carpentry

This morning I learnt a new word: DevOps, which seems to be the contraction of software Development and IT Operations. I.ve got it from the presentation my former student Daniele Dalla Torre gave at the Biennial iEMMs 2020 conference (find his presentation and others about his work here). He captured my attention with the following picture you find below


Wikipedia comes to help in understanding what exactly this means by listing the following items:

  1. Coding – code development and review, source code management tools, code merging.
  2. Building – continuous integration tools, build status.
  3. Testing – continuous testing tools that provide quick and timely feedback on business risks.
  4. Packaging – artifact repository, application pre-deployment staging.
  5. Releasing – change management, release approvals, release automation.
  6. Configuring – infrastructure configuration and management, infrastructure as code tools.
  7. Monitoring – applications performance monitoring, end-user experience.

The figure contains some further information by annotating some tools. Also note that he intelligently added "Plan". So the steps are actually 8, not 7. Planning in his figure is under the OSF , the Open Science Framework, the place where we upload the material of our projects, literature, thinking. Some other colleagues use Slack for this, but on the latter I do not have much experience. Certainly a place where all the material regarding a project and the interactions among people is preserved is necessary. In Coding he puts Git. Github is the public repository where all of our software is uploaded. Git is a "Control Version System" (CVS), a place where  researchers upload the versions and modification of their software, maintaining. Ghere exist other, like, for instance, Mercurial, but we use Git.  There is actually a misuse of Git among my students. While it is thought to be used continuously along the process of development, they use it only at the end of the process, to upload a reasonable version of their work. I think it does not exploit the good of a CVS but that is the state-of-art at the moment. When you have written your software (in contemporary practice is quite obvious that you used a IDE for doing it - Eclipse, Netbeans or IntelliJ in our case) you have to build your software, which means, compiling and assembling it in some executable.  Naive and simple building is made inside the IDEs but complex software building needs a builder. Our chain of tools uses Gradle, whose symbol is a small elephant. In turn, Gradle means learning a further DSL language, for making the build. Testing means two things: preparing tests for assessing the correctness of the code and running the tests. Also this practice is not so common in scientific practice. One reason is that our models usually have complex outputs which is difficult to characterize but this happens mostly because hydrologists are ignorant of good software building practice. For instance, in the Figure is mentioned JUNIT 5 which is quite a natural choice for who is working with Java. If the software pass its tests, it is supposed to be packaged in a releaseTravis CI symbolized by the a mustachioed face should do this pass. In fact, I believe it does only part of the job, which goes back to run the test and providing a final compiled version of the code. Actually this sort of packaging is not completely operational, since the software can be eventually brought to a computer and installed in it with the right switch for working. Docker  (the whale in Deploy) simplify it by providing a standard client to any computer (with some problem for MS Windows, indeed). It works fine in my Mac Computer, and calling it from within Jupyter lab notebooks provides a nice solution. However, I feel the problem of the distribution of the software (through a tool like Anaconda's conda can be)  and treating all the dependencies among the libraries, is still an open question.  Configurations and maintenance of the code and the details of configurations of the software is the further step. 

Finally comes the application performance management (APM) is the monitoring and management of performance and availability of software applications. APM strives to detect and diagnose complex application performance problems to maintain an expected level of service. APM is "the translation of IT metrics into business meaning ([i.e.] value)." This latter maybe is not so central in scientific applications for which other types of tests, screening and case studies are probably more relevant. 

Tuesday, March 17, 2020

About Hydrological Models


Starting from some philosophy I try to give an idea of what a scientific model is, on the example and limitations of the Galileian approach. I claim that hydrology is mostly a science where you have to move away from experiments and you have the deduct the models from observations more than experiments. This introduces some difficulties and arrive to the arrive to the conclusion that we do models of the data and models of the models of the data. Because of the presence of multiple phenomena interacting, hydrology gain a space in the science of complexity. But yet we do not know how to characterize it, if we do not use the classical mechanics and/or the usual thermodynamics. As a matter of facts, we have to deal with an entire zoo of models born with different scopes and evolved sometimes erratically.But at this point is where we do stand.
Please find the slides here, and  the Vimeo video where I comment them here (an older YouTube video  here).  I also makes a little summary of the talk here.
These slides can ideally be followed by those I used during the 2020 GEOframe Winter School:

Monday, February 3, 2020

4 Researchers Who Want to Develop Hydrological Models Without Reinventing the Wheel

Maybe you can save efforts and you do not need to reinvent the wheel. Therefore I wrote about our project that lasts since almost fifteen years. We use an open infrastructure, the Object Modelling System v. 3 and developed an open system, called GEOframe that has unmatched capabilities to be expanded while not wasting the old work done and maintaining your independence as developer.

The best way to understand OMS and see how it works is probably to give a look to the material of our last winter School on our system GEOframe. Specifically, this is the page of introduction to OMS. But also starting from installations of the material can give insights.
There you can find links to the OMS v3 pages at CSU and original material. Our choice of OMS and Java was long meditated. This was my assessment almost ten years ago. This is instead the assessment made by NIWA six years ago.

Here  you can find some thinking about the choice of programming  languages. We use, in practice, a mix of Python and Java. Python for treating and visualizing data. Java for writing our models.
When properly used Java is not so slow (twice slower of well written C++) and was favored by having an incredible suite of tools helping proper programming, project building and code maintenance that make the experience to develop in C++ a poor one. Python (specifically some of its libraries) and the Jupyter lab are instead a very nice experience for treating data and, besides, is supported by a vibrant community of developers, even among hydrologists, who really make the experience better and better everyday. Python is also becoming a “lingua franca” among scientists and this makes less difficult and steep to share results. I have a couple of pages to introduce Python to hydrologists that you can access starting from here. For what regards of Java one can start from here.
In any case Java is not mandatory for the use of OMS. Also FORTRAN and C++ codes can be used: NIWA did it with FORTRAN, but we never tried it.

OMS code is distributed with the MIT Open Source license. It is not available on a public repository though, but Olaf David, its chief architect, gave us access to it and does not have problem to give it to others. I recognize that this is a limitation but with more users, it would not be so difficult to get a branch of the source code in a public repository, I guess.
Our own source code is at the GEOframe components Github repository. The software is under GPL3 and the repository is open to anyone willing to collaborate.

The structure of the OMS allows to easily add components with any type of licence, the one more suited to you, and does not oblige you to release the software under the GPLv3 license.
Worth to mention is that OMS has a server side companion, CSIP of which you can find any information here.

Once Olaf David mentioned to me that the overall cost of OMS was closely 10 million of dollars. From my side I guess i invested around 1 million and more on developing GEOframe and its ancestors, Just to give a measure of the investment needed for such an enterprise. But building on top of them is now much less expensive and much more immediate.
Our current task are finishing the 1D-2D-3D solving of Richards equation (extended to treat groundwater and surface waters) and its coupling with the energy budget, evaporation and vegetation dynamics. This would replace our older GEOtop in two years, except for snow modelling for which we do not have started anything so far. We have also ongoing work for hillslope stability and a well established set of tools for doing lumped modelling, including the estimation of travel times and tracers/pollutants concentrations. Some other developments, more on the side of informatics were done by a former students of mine and are reported in his Ph.D. Dissertation. It contains also some work on neural networks.
For the future, an effort should be made to bring OMS to Java 9, which, I think, could make the code more understandable. Classes are a good thing but understanding the connection between them is what matters. Java 9 Modules should help to get the code more clean, and Gradle should do the rest for external libraries.  A few years go I started to dig into the code. I could not complete the task for my limited time but I believe one Java programmer can master OMS3 code in six intense months or so.  I also envision that, having a good project, OMS could be completely embedded in Jupyter lab making it usable through it making its use more familiar to a multitude of users. 

Obviously, we are willing to give any help, if you join us. I hope this information can help you to make your decisions.

Wednesday, January 15, 2020

Tuesday, May 7, 2019

On Hydrological models structure

In many papers that deal with semi-distributed hydrological modelling, it is argued about the models structure, a topic which becomes even more relevant when people talk about uncertainty and attribute to the model structure an error that is named epistemic error. But what is the model structure is rarely discussed in depth. Butts et al. (2004) discussed it citing the book by K. Beven (GS): “Beven (2000) breaks down the development of a hydrological model into the following steps:
  1. The Perceptual model: deciding on the processes
  2. The Conceptual model: deciding on the equations
  3. The Procedural model: developing the model code
  4. Model calibration: getting values of parameters
  5. Model validation: confirming applicability and accuracy”
To these phases Clark et al (2011) also add:
     6. Characterizing the model uncertainty
which is a requirement that certainly contemporary modelling demands. 

Evidently, the concepts that are relevant for defining what a model structure is are the first two: "The selection of specific perceptual and conceptual models determines the model structure. " However, when parameters of the model are fixed, they also become part of the model structure. Models often are continuous function of parameters, nevertheless different classes of parameters, especially in non linear models, can trigger qualitatively different dynamics.
Model structure includes a whole range of choices and assumptions made by the modeller either explicitly or implicitly in applying a hydrological model. Examples of different model structures include:
  • different process choices and descriptions
  • coupling of the processes
  • numerical discretisation
  • representations of the spatial variability-zones, grids, sub-catchments, etc.
  • element scale and sub-grid process representations including distribution functions, different degrees of lumping, effective parameterisation, etc.
  • interpretations and classifications of soil type, geology land use cover, vegetation, etc.
There is a great variety of models and mathematical approaches to cope with the above issues. For limiting the discussion, let’s assume to concentrate on those models which are implemented as systems of ordinary differential equations. These models differs, in practice for:
  1. the number of equation (let’s called them places according to our classification of such systems)
  2.  the interactions between places (represented by the relative adjacency matrix)
  3. the form of fluxes laws
  4. the values parameters assume
In particular, point (1) above deals both with the number of processes and the discretisation of the landscape in hydrologic units in space (called representative elementary watersheds REW, e.g. Reggiani et al., 1999 or Hydrologic response units, HRUs, Burges and Kampf, 2008). A recent tradition tried to build a heuristic about how to select appropriately these elements (e.g. Clark et al., 2011; Fenicia et al., 2011, Fenicia et al., 2014, Fenicia et al., 2016).
Once these hydrologic heuristics are applied, we eventually find ourselves with the nude set of equations, and it could be interesting to see if there exist methods that can discover and classify the main properties of the dynamical systems which depends on their structure. This problem, indeed, has received a lot of attention in system and control theory (see for e.g. Ljung, 1999 and references therein), mostly to autonomous linear systems.

Some of the aspects, in this case is the discover of T-invariants and P-invariants, or, in a less obscure language, of loops and set of correlated quantities that remains globally (i.e. their sum) stationary (i.e. Gilbert and Heiner, 2006). Other aspects regards reachability, i.e. the prior understanding if a certain distribution of the state variables can be obtained. All these aspect are well dealt within traditional books in system and control theory. Unfortunately the resulting structure of hydrological models is usually non-autonomous (the system are open) and non-linear. All aspects that make investigations more complicate, but probably not unfeasible. A lot of digging in literature and research is necessary though.

References


Tuesday, February 5, 2019

Again on Modelling. On modelling and data.

I was invited to talk to Ph.D students at the 2019 Warredoc School on data rich Hydrology. This follows other more or less opinionated talks I give at the GEOframe Winter School, and complete them. In hindsight I actually scratched the surface of the topic. I would have made a more substantial contribution if I had added examples with GEOframe for clarifying "where do datasets integrate best in models".  Never mind: there is then still matter for the next reflections and investigations.
Notwithstanding, I hope you will find my contribution interesting and useful. Click on the Figure to access the presentation.

Friday, November 25, 2016

Python resources for Hydrologists

Python is a modern object oriented language. Occasionally I wrote about it in my posts, also for remarking that I went in a different direction. However, I cannot deny the evidence that more and more people are choosing it, and there are good reasons, as their language of choice for doing research and hydrological applications. In fact since 2017, I am using it in place of R for scripting and data managing. Below you will find a list of resources. Please do not hesitate to bring my attention to yours or others' contributions which I have not yet in my group.

Motivations for Python use, over other choices, can be found in this blog post or in this paper.

To understand how to start you can follow Python programming for hydrology students that starts with indicating how to install it.

For who wants to start with Python (for hydrologists), I suggest to give a look to my blog post Python general resources. For others, please give a look below.

Python is especially use as a glue for existing program, either written in C or FORTRAN. We have the cases of
  • CFM is a programming library to create hydrological models. Although written in C++, it has a Python interface 
  • ESMF regridding has been interfaced with Python ESMPy
  • GRASS GIS has been interfaced with Python
  • Python is also interfaced to gvSIG, as you can see here
  • HPGL a High Performance Geostatistics Library. Written in C++ is glued together by Python 
  • MODFLOW the groundwater model is interfaced by FloPy. Documentation and other information is here
  • PcRaster - Is a collection of software targeted at the development and deployment of spatio-temporal environmental models. It has a python interface which is constantly being enhanced. 
  • OpenHydrology is a library of open source hydrological software written in Python to operate as packages under an umbrella interface 
  • PyHSPF Python extensions to the Hydrological Simulation Program in Fortran (HSPF
  • PyQGIS: A Python interface to QGIS 
  • RhessysWorkflow  RHESSysWorkflows provides Python scripts for building RHESSys models. Other Pythonic material on RHESSys can be found here.
  • UWHydro tools for connecting University of Washington hydrological models, and, in particolar, the VIC driver PythonDriver

In the reign of hydrologic applications entirely written in Python, we remind:

  • ANUGA 2 - package for modelling dam breaks, riverine flooding, storm-surge or tsunamis. In Python and C. 
  • EcoHydrolib provides a series of Python scripts for performing ecohydrology data preparation workflows. 
  • evaplib: Python library containing functions for calculation of evaporation rates. Functions include Penman open water evaporation, Makkink reference evaporation, Priestley Taylor evaporation Penman Monteith (1965) evaporation and FAO's Penman Monteith ET0 reference evaporation for short, well-watered grass. In addition there is a function to calculate the sensible heat flux from temperature fluctuation measurements. View documentation of evaplib module functions. Module documentation is also available as a PDF document. Author: M.J. Waterloo. 
  • A GLUE, Generalised Likelihood Uncertainty Estimation (GLUE) developed by Framework Joost Delsman, at Deltares, 2011 
  • Groundwater flow modelling manual for Python written by Vincent post 
  • Hydro-conductor: A set of Python scripts and modules written to couple a hydrologic model with a regional glacier model
  • ODMToolsPython and ODMTools ODMTools is a python application for managing observational data using the Observations Data Model. ODMTools allows you to query, visualize, and edit data stored in an Observations Data Model (ODM) database.ODMTools was originally developed as part of the CUAHSI Hydrologic Information System. YOu can find a presentation about here
  • PyETo is a package for calculating reference/potential evapotranspiration (ETo). 
  • Python script for rectangular Piper plot (version December 2014): Python script for plotting chemical data in a rectangular python plot (see image) according to Ray and Mukherjee (2008) Groundwater 46(6): 893-896. Also download the example data file watersamples.txt. Author: B.M. van Breukelen. 
  • Python script for multiple Stiff plots (version June 2011): Python script for preparing multiple Stiff diagrammes (see image). Also download the example data file watersamples.txt. Author: B.M. van Breukelen. 
  • Haran Kiruba tools for hydrology Not really clear what he does. 
  • USEPA site contains various python (and other languages) tools, including an interface to Epanet and SWMM (a connection to swmmtoolbox is also avilable here). 
  • Also USGS has its python tools
  • sMAP 2.0 is a tutorial will cover how to retrieve data from a sMAP archiver using Python. 
  • ulmo clean, simple and fast access to public hydrology and climatology data 


Specific hydrological Hydrological Models are enumerated below.

  • EXP-HYDRO Model is a catchment scale hydrological model that operates at a daily time-step. 
  • Landlab Landlab is a python-based modeling environment that allows scientists and students to build numerical landscape models. Designed for disciplines that quantify earth surface dynamics such as geomorphology, hydrology, glaciology, and stratigraphy, it can also be used in related fields. 
  • LHMP - lumped hydrological models playground - tiny docker container with complete environment for predictions.
  • PyCatch is a component based hydrological model of catchments built within the PCRaster Python framework. The code is here. A related paper, here
  • PyTOPKAPI is a BSD licensed Python library implementing the TOPKAPI Hydrological model (Liu and Todini, 2002). The model is a physically-based and fully distributed hydrological model, which has already been successfully applied in several countries around the world 
  • SPHY. See for details on model and publications (HESS, Nature, etc) here. Just recently a new paper on climate change and mountain hydrology in PloS came out, using SPHY model, more info here.
  • Topoflow a python hydrologic model by Scott Peckham 
  • WOFpy is an implementation of CUAHSI's Water One Flow service stack in python 
  • wflow is a distributed hydrological model platform that currently includes two models: the wflow_sbm model (derived from the topog_sbm soil concept) and the wflow_hbv model which is a distributed version of the HBV model. This is actully part of a larger Deltares project called OpenStream

GIS capabilities are also present:


Also tools to deal with Meteorology:

  • meteolib: Python library containing meteorological functions for calculation of atmospheric vapour pressures, air density, latent heat of vapourisation, heat capacity at constant pressure, psychrometric constant, day length, extraterrestrial radiation input, potential temperature and wind vector. The documentation for this module is presented at here (meteolib module functions web site). Functions to convert event-based data records to equidistant time-spaced records (event2time) and to convert date values to day-of-year values (date2doy) are now in a separate meteo_util module. Documentation is presented here (meteo_util module functions web site). Module documentation is also available as a PDF document. Author: M.J. Waterloo. 
  • MetPy is An Open Source Python Toolkit for Meteorology 
  • Melodist (MEteoroLOgical observation time series DISaggregation Tool) is an open-source software package written in Python for temporally downscaling (disaggregating) daily meteorological time series to hourly data. It is documented in a GMD paper by Forster et al., 2016. 
  • Various resources for meteorology can be found in the pyaos blog
Statistical and data analysis tools are abundant
  • CUAHSI time series viewer
  • The basic cheatshit
  • NetCDF file operations are available here. However, there is also txt2netcdf which containsvarious Python functions for importing text into NetCDF data files (creating files, adding variables, listing structure, etc.), developed by Ko van Huissteden. 
  • Pandas is an open source, BSD-licensed library providing high-performance, easy-to-use data structures and data analysis tools for the Python programming language. (A short tutorial is also here
  • Extreme distribution (from scipy.stats) is here
  • An example of use of Pandas for analysing time series 
Visualisation is well served
  • ggplot is a plotting system for Python based on R's ggplot2 and the Grammar of Graphics. It is built for making profressional looking, plots quickly with minimal code. 
  • An impressive tour of Python possibilities in this field is given by “Regress to Impress” 
  • VisTrails an open-source scientific workflow and provenance management system that supports data exploration and visualization. Its website is here
  • uvcmetrics metrics aka diagnostics for comparing models with observations or each other. This is part of the Uv-CDAT website which contains also other visualisation tools. 
Tools for dealing with uncertainty and sensitivity analysis
Yet another repository of Python models and resources
A final comment

I am actually impressed by the quality of the contributions in Python. I think there is not anymore reason to use commercial program like Matlab in Universities (see this review here). What Matlab does, also Python does. Compared to R, it has a much more clear sintax and is, certainly, a better language. So I would suggest to use it with students (or R). I like R but I never built program on it, because its object orientation is really poor. Python is better and, as it is known its syntax is clean. Python is great to link FORTRAN and C/C++ native libraries, so actually many uses it to assembled libraries they wrote in those more performant languages.
As you know, however, my group uses Java as its principal programming language. Java, in comparison with Python, is less immediate and more verbose, but it allows to build many framework to work with, and is usually faster than Python. Probably because, Java is supported by magnificent building tools (Maven, Gradle) that allow to manage large projects in a way that probably cannot be done in Python.