Giter VIP home page Giter VIP logo

python-subgrid's Introduction

Python wrapper for the 3di subgrid library

Setup

We need the compiled Fortran subgrid library. There are a couple of common locations (like /usr/lib/) where we look for it.

A convention on linux is to install the library into /opt/3di/. This lcoation is found by default, too.

In case you have an alternative location, you can set the SUBGRID_PATH environment variable:

$ export SUBGRID_PATH=/home/user/svn/3di/trunk/subgridf90/src/.libs

(On windows the command is set instead of export).

Ubuntu install of the Fortran library

If the most recently released version is good enough, you can use the ubuntu package instructions to get the latest version of the subgrid library.

Mostly-standard compilation of the Fortran library on Ubuntu

For the python wrapper we of course need the actual subgrid Fortran library so that we can wrap it. A mostly standard installation on ubuntu (which is also used on the jenkins test server and on the demo website) uses the standard ubuntu netcdf packages and fortran:

$ sudo apt-get install libnetcdf-dev \
  libnetcdf6 \
  gfortran \
  libshp-dev \
  libgdal1-dev

For the python netcdf library compilation we need another package:

$ sudo apt-get install libhdf5-serial-dev

We also need the fortrangis library. We can compile it by hand (and add a couple of dependencies), but using the "ubuntu install" mentioned above is handier. Just do an apt-get install fortrangis after you set up the ubuntu repository.

And we use the regular configure/make/make install steps with two changes:

$ ./autogen.sh  # Try it without. If something breaks, run it.
$ FCFLAGS="-I/usr/include -g -O0" ./configure --prefix=/opt/3di --with-gdal
$ make
$ make install

The two changes:

  • FCFLAGS to let fortran find the ubuntu netcdf packages.
  • A --prefix to install it into /opt/3di/.

Usage

There are two ways to use the wrapper. A handy way is as a context manager, so with a with statement:

with SubgridWrapper(mdu='/full/path/model.mdu') as subgrid:
    # subgrid is the actual fortran library.
    subgrid.something()

The second way is by calling start and stop yourself and using the library attribute to access the Fortran library:

wrapper = SubgridWrapper(mdu='/full/path/model.mdu')
wrapper.start()
wrapper.library.something()
...
wrapper.stop()

Note: Without the mdu argument, no model is loaded and you're free to use the library as you want.

Automatic tests

The code is tested on http://jenkins.3di.lizard.net. The libsubgrid.so that is used there is the one from the last successful build of subgridf90, which is placed in /opt/3di/.

The functional tests need testcases. Run update_testcases.sh to check them out and test them. The tests find them automatically, so a simple bin/test is enough.

You can symlink those directories next to this README. You can also set the SCENARIO_BASEDIR environment variable. Either set it globally or run the tests like this, for instance:

$ SCENARIO_BASEDIR=/some/directory bin/test

If the scenarios cannot be found, the functional model tests are skipped, btw.

python-subgrid's People

Contributors

arthurvd avatar jackha avatar jsmits avatar martijn-siemerink avatar reinout avatar siggyf avatar

Watchers

 avatar  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.