Assignment #07: writing a python package

This time, all groups will send me their solution to the programming task (one .zip file per group) and I will provide feedback for each solution.

The deadline for submission is 03.06.2018

The visclim package

I've written a small package called visclim. Its design is based on the dummy template package, but this time it really does something.

Download the zipped package from here and extract it. Read the README and the package requirements first.

Now install it in development mode. If you are working on your own computer:

pip install -e .

From the root directory. If you are working on the university computer, do:

pip install --user -e .

Try the command line interface (cruvis -h) from a terminal. Now explore setup.py: can you identify what makes the command available from the terminal? Where is the code executing the command cruvis?

Familiarize yourself with the tool. Can you understand what the role of each function is?

Can you run the tests successfully? Probably not. Somewhere in cfg.py, a hard coded path is pointing to a non-existing directory.

If you are working on your own computer, change the path to a local folder of yours and download the necessary data:

Careful! The total decompressed output is about 6GB large.

If you are working on the university computer, a folder containing the data is available at:

/scratch/c707/c7071047/data-scipro/

Careful! This is a subset of the data (Central Europe): the tools works for these locations, but not globally.

Make sure you are able to run the command succesfully before going on. For example, cruvis -l 12 47 should work fine and display a page in your browser.

Assignment #07-01: make the tool more robust

Here are a couple of smaller tasks to get you started:

  • The hard coded path in cfg.py is very ugly. At the same time, we really need the CRU data for the tool to run! Add a safety check in the code in order to make sure the files are available. If the CRU files are not available, print the following message and exit the program:

    The CRU files are not available on this system. For cruvis to work properly, please create a file called ".cruvis" in your HOME directory, and indicate the path to the CRU directory in it.

  • Add a small function in cfg.py which parses this new .cruvis file and uses the given directory in place of the hard-coded one. Tip: you could make good use of os.path.expanduser for this function.

  • Selecting a location over the oceans will raise a very uninformative python error message. Make the write_html function more robust: if the data contains NaNs, print a warning and exit the program.

Assignment #07-02: make the tool better

Now you should be ready to contribute to this great package! Add one simple functionality to it. It can be anything you want, as long as it makes you write some code. Here are some ideas if you don't have any:

  • you could add a plot of the 1901-2016 timeseries for this grid point, and make a trend analysis for the period.
  • you could add a new command to the tool called uibkvis, which instead plots the data from the UIBK weather stations. You can rely heavily on your work from week 03! You'll have to document its command line options of course.
  • you could add an option to cruvis, which accepts a city name instead of the lon and lat of the point. You could use the file shipped with the package for this (world_cities.csv).
  • you could add a new tool which compares the data at two locations.
  • you could parse any other data you'd find interesting from the web.
  • ...

Some tasks are more difficult than others. I don't mind if you take an easy one, as long as you write something on your own. You are working as a group, so split the tasks between the group members!

Back to the table of contents