GithubHelp home page GithubHelp logo

csdms / bmi-example-python Goto Github PK

View Code? Open in Web Editor NEW
11.0 10.0 21.0 818 KB

An example of wrapping a model written in Python with a BMI

Home Page: https://bmi.readthedocs.io

License: MIT License

Python 90.18% Makefile 9.82%
bmi python csdms

bmi-example-python's People

Contributors

benvanwerkhoven avatar mcflugen avatar mdpiper avatar mwtoews avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bmi-example-python's Issues

Incorrect signature for BMI initialize method

According to the BMI spec, the filename argument for the BMI initialize method must not be optional and must be a string. Right now BmiHeat.initialize accepts either None, a file-like object, or a string. I think this should be changed so that it only accepts a string that is a path to a configuration file.

i.e.

def initialize(self, filename: str):
    with open(filename) as file_obj:
        self._model = Heat.from_file_like(file_obj)
    ...

Actually, in looking at what's there now, I think there's also a bug. Heat.from_file_like must take a stream, not a string

i.e.

Heat.from_file_like(file_obj.read())

should be

Heat.from_file_like(file_obj)

Include more packages in separate requirements files

Should we expand the set of requirements files for this repository? I'm thinking about four separate files.

requirements.txt -- packages needed to install with pip install -e .

  • numpy
  • scipy
  • pyyaml
  • bmipy

requirements-dev.txt -- developer packages used with the repo Makefile

  • make
  • build
  • twine
  • flake8
  • black
  • isort

requirements-testing.txt -- packages used for running tests

  • coveralls
  • pytest
  • pytest-cov
  • six
  • bmi-tester

requirements-examples.txt -- packages used for running examples

  • notebook

The set_value function should redimensionalize flattened input array

In this example, the current set_value implementation is:

def set_value(self, var_name, src):
"""Set model values.
Parameters
----------
var_name : str
Name of variable as CSDMS Standard Name.
src : array_like
Array of new values.
"""
val = self.get_value_ptr(var_name)
val[:] = src

A problem arises when the model variable referenced by get_value_ptr is dimensional--the input src argument is flattened, by definition, while the val variable is dimensional. This raises an exception with a message like

ValueError: could not broadcast input array from shape (48,) into shape (8,6)

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.