xarray-contrib / xarray-simlab

Xarray extension and framework for computer model simulations
http://xarray-simlab.readthedocs.io
BSD 3-Clause "New" or "Revised" License
73 stars 9 forks source link

Add command line interface #27

Open benbovy opened 6 years ago

benbovy commented 6 years ago

Besides Python API, a command line interface would be nice to have for things like:

As reference, see, e.g., the command line scripts implemented in distributed based on click: https://github.com/dask/distributed/tree/master/distributed/cli

See also how to add it in conda packages as entry points: https://github.com/conda-forge/distributed-feedstock/blob/master/recipe/meta.yaml

Chilipp commented 6 years ago

Hey!

nice presentation today at EGU. I would like to suggest the model-organization package for this issue.

Besides it's automated command line API (see the example in the docs), this module organizes experiments and makes the configuration accessible and clearly arranged. One simple implementation would be

from model_organization import ModelOrganizer
import xsimlab

class XSimlabOrganizer(ModelOrganizer):

    commands = ModelOrganizer.commands[:]
    commands.insert(commands.index('init') + 1, 'run')

    def run(self, ...):
        """Run the model"""
        in_ds = xsimlab.create_setup(model=..., ...)
        out_ds = in_ds.xsimlab.run(model=...)
        out_ds.to_netcdf(self.exp_dir + 'output.nc')

if you save this into a file named model.py, this could then be run via

python model.py run # ... any arguments

See the docs for more information about the model-organization framework.

benbovy commented 6 years ago

Thanks for the suggestion @Chilipp ! I haven't really looked into existing solutions for automating cmd line interface yet but I'll look into your package.

Chilipp commented 6 years ago

Sure, just a hint 😉