Giter Club home page Giter Club logo

pywest's Introduction

pyWEST

Python scripts for water quality simulators in WEST (MIKE DHI).

  • Sensitivity analysis
  • Model Inference/Calibration
  • Automated simulation with control over inputs and model parameters

Dependencies

  • Ironpython
  • Python 2.7
  • TornadoNet

Set-up

  • Install Ironpython and set environment variable (ipy).

  • Install python 2.7 with the following libraries: numpy, pandas, os, time, timeit, json, shutil and sys

  • Download Parallel_WESTRunningPyWrapper.py and RunModel.py and set them in a project folder under \AutomatedCall\

Description

  • RunModel.py Is an IronPython script which interfaces with Tornado.net in order to call a WEST experiment.

  • Parallel_WESTRunningPyWrapper.py Python class which calls RunModel.py in parallel. Management of model resources. - Atributes:

              - self.InstanceNames = List the Model names
              - self.OccupationList = boolean list, 1 for occupied node, 0 for free
              - self.NumberofInstances = Number of total Model sessions (should not be higher than the number of local licenses or computer cores)
              - self.Paths = Project directory Path
              - self.threads_active = Number of threads initiated
    

Operation Automated_Call.py

  • Instanciate n models with:

    ModelInstance = ModelInstances(['Model_1', 'Model_2', 'Model_n'], modelPath = "<ProjectFolder>", modelInternalName = 'Model_dummy_1.Dynamic.ObjEval.Exp')

    You can also run one model in parallel at different processors:

    ModelInstances(['Model_dummy_1'], modelPath = "<ProjectFolder>", modelInternalName = 'Model_dummy_1.Dynamic.ObjEval.Exp')
  • Set Parameter values: e.g

    Timelist = {'StartTime':0,'StopTime':15}
    Parameterlist = {'n':0.07, 'KBODs':0.55, 'KLmin':0.1, 'KO2':1.6, 'SOD':1} 

    A Parameterlist is formed by a dictionary of parameter values. An entry of the form:

    • 'param' :value will set all parameters sharing the same name (even if it has been declared as a Top-level parameter) to the value specified.
    • 'param@submodel' :value will set the parameter 'param' only in the block model 'submodel'. This allows for local specifications.
    • 'param@Manipulated':value sets a manipulated variable value which doesn't carry any declared input. There is the option 'param@Manipulated#submodel':value to make the change only at submodel level.
    • 'param@Multiplier':value works by ofsetting its current saved value by a multiplyier value.
    • 'param@Multiplier':value works by ofsetting its current saved value by a multiplyier value.
    • 'inputname@Intput': Declare change of input file. Inputs should be added as: InputName@Input_DirectoryOfInputSamples Inputs in the directory should be labelled as Inputname_id (and all should be as txt)
  • Run Model:

    ModelInstance.model_run(Parameterlist, Timelist)

    Note: each call to model_run will use the next available Model instance in an availability basis. This will open a call in the background. The execution of the program will be halted until all simulations are finished.

  • Read outputs:

    output = ReadOutput('Model_dummy_1.Dynamic_water_quality.Simul.1.out.txt', ModelInstance.InstanceNames[0], TimeWindowStart = '01-01-2012 00:00:00', variable = '.River_5.DO')

    Note: Simulations produced by calling .model_run(Parameterlist, Timelist) store all output files in a new folder \SimulationOutput\ModelName\Sim_i. Each Sim_i contains: All output files from the WEST experiment which has .out. in their names. A txt file containing all iternal parameter values in the model <Internal_parameters.out.txt> and a file containing all changed parameter values from the Parameterlist in <External_parameters.txt>.

Operation Uncertainty_propagation2.py

This script automatizes a parameter sampling scheme provided by:

SamplingLayout = pd.read_csv('\pyWEST\500SamplesUP.txt', index_col = [0])

An example for the format is found at pyWEST\500SamplesUP.txt

The script performs a simulation for each row in the layout. It will call in parallel as many simulations as resources allocated through the parameter TreadingPool at:

ModelInstance.model_run(Parameterlist, Timelist, ThreadingPool = 4, ParamDatabase = os.path.join(repPath, '500SamplesUPReduced.txt'))

The function Read_SA_outputVariable loads the selected variable from the output folder.

Extra:

Notebooks

Included two jupyter notebooks containing:

  • Bayesian_Inference_Example.ipynb : Examples and tutorial to perform bayesian parameter inference to a West model.
  • Calibration_Example.ipynb : A tutorial for perform model calibration with scipy.minimize

pywest's People

Contributors

argantonio65 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.