Skip to content

Commit

Permalink
Merge pull request #5 from kmuehlbauer/master
Browse files Browse the repository at this point in the history
Python 2/3 Compatibility
  • Loading branch information
kmuehlbauer committed Feb 24, 2016
2 parents 4f37374 + db40ae3 commit 554bd73
Show file tree
Hide file tree
Showing 73 changed files with 3,683 additions and 3,554 deletions.
12 changes: 6 additions & 6 deletions README.md
Expand Up @@ -2,19 +2,19 @@

**To anyone who wants to use a bleeding edge version of wradlib from this repository:**

wradlib uses [Codeship](http://www.codeship.io) for Continuous Integration. This means that once new code is pushed to the wradlib repository, Codeship runs a suite of tests. In case the tests run without failure, a new documentation will be built and pushed to the [wradlib documentation website](http://wradlib.bitbucket.org/).
wradlib uses [Travis CI](https://travis-ci.org/) for Continuous Integration. This means that once new code is pushed to the wradlib repository, Travis runs a suite of tests. In case the tests run without failure, a new documentation will be built and pushed to the [wradlib documentation website](http://wradlib.github.io/wradlib-docs).

Below you see the Codeship Status of wradlib. A red status indicates that the current revision of wradlib did not pass the tests successfully. You should be aware of that. then again, you should be aware that a green Codeship status is not a guarantee that the latest revision is bug free. It just means that our tests did not find any bugs.
Below you see the Travis Status of wradlib. A red status indicates that the current revision of wradlib did not pass the tests successfully. You should be aware of that. then again, you should be aware that a green Travis status is not a guarantee that the latest revision is bug free. It just means that our tests did not find any bugs.

## Codeship Status ##
## Build Status ##

[ ![Codeship Status for wradlib/wradlib](https://www.codeship.io/projects/5d3d6180-135f-0132-d079-1e5862c1e42f/status)](https://www.codeship.io/projects/33315)
[![Build Status](https://travis-ci.org/wradlib/wradlib.svg?branch=master)](https://travis-ci.org/wradlib/wradlib)

### Documentation ###

For further information on wradlib (Gettings started, library reference, development setup, ...), please see our homepage:

http://wradlib.bitbucket.org
http://wradlib.github.io/wradlib-docs


### User forum ###
Expand All @@ -23,4 +23,4 @@ In order to stay tuned, we recommend that you register to the [wradlib user foru

### Found any bugs or want to add wishes ###

Create an issue [here](https://bitbucket.org/wradlib/wradlib/issues?status=new&status=open)
Create an issue [here](https://github.com/wradlib/wradlib/issues)
12 changes: 10 additions & 2 deletions doc/source/community.rst
Expand Up @@ -6,9 +6,17 @@ How to contribute to wradlib?

We need your help to enhance the capabilities of wradlib! Is there an algorithm you would consider useful? Please **provide code (in any programming language) or documentation**. We will it a try to integrate this algorithm in wradlib.

However, **there is an even better way:** Start a `Pull Request <http://confluence.atlassian.com/display/BITBUCKET/Fork+a+Repo,+Compare+Code,+and+Create+a+Pull+Request>`_! *(Step 1)* `Fork <http://bitbucket.org/wradlib/wradlib/fork>`_ your own wradlib repository from the `main wradlib repo <http://bitbucket.org/wradlib/wradlib>`_. *(Step 2)* Implement your changes into the forked repository. Test your code. *(Step 3)* Now you want to feed these changes back into the main wradlib development branch? Start a `Pull Request <http://confluence.atlassian.com/display/BITBUCKET/Fork+a+Repo,+Compare+Code,+and+Create+a+Pull+Request>`_! We will review your changes. On approval, we will merge your fork back into the main wradlib branch. Now everyone can benefit from your improvements. A step-by-step tutorial for a pull request can be found `here <http://confluence.atlassian.com/display/BITBUCKET/Fork+a+Repo,+Compare+Code,+and+Create+a+Pull+Request>`_.
However, **there is an even better way:** Start a `Pull Request <http://confluence.atlassian.com/display/BITBUCKET/Fork+a+Repo,+Compare+Code,+and+Create+a+Pull+Request>`_!

Finally, you are welccome to **contribute examples of your own wradlib applications** in our :doc:`recipes <recipes>` section. There, you will also find a guide on how to submit your recipes to the wradlib documentation pages.
* **Step 1:** `Fork <http://bitbucket.org/wradlib/wradlib/fork>`_ your own wradlib repository from the `main wradlib repo <http://bitbucket.org/wradlib/wradlib>`_.
* **Step 2:** Implement your changes into the forked repository. Test your code.
* **Step 3:** Now you want to feed these changes back into the main wradlib development branch? Start a `Pull Request <http://confluence.atlassian.com/display/BITBUCKET/Fork+a+Repo,+Compare+Code,+and+Create+a+Pull+Request>`_!
* **Step 4:** We will review your changes. On approval, we will merge your fork back into the main wradlib branch.
* **Step 5:** Now everyone can benefit from your improvements.

A step-by-step tutorial for a pull request can be found `here <http://confluence.atlassian.com/display/BITBUCKET/Fork+a+Repo,+Compare+Code,+and+Create+a+Pull+Request>`_.

Finally, you are welcome to **contribute examples of your own wradlib applications** in our :doc:`recipes <recipes>` section. There, you will also find a guide on how to submit your recipes to the wradlib documentation pages.


Users
Expand Down
13 changes: 13 additions & 0 deletions doc/source/conf.py
Expand Up @@ -26,6 +26,7 @@
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc',
'sphinx.ext.napoleon',
'sphinx.ext.todo',
'sphinx.ext.coverage',
#'sphinx.ext.pngmath',
Expand Down Expand Up @@ -262,3 +263,15 @@
('index', 'wradlib', u'wradlib Documentation',
[u'Maik Heistermann, Stefan Jacobi, Thomas Pfaff'], 1)
]

# Napoleon settings
napoleon_google_docstring = True
napoleon_numpy_docstring = True
napoleon_include_private_with_doc = False
napoleon_include_special_with_doc = False
napoleon_use_admonition_for_examples = False
napoleon_use_admonition_for_notes = False
napoleon_use_admonition_for_references = False
napoleon_use_ivar = False
napoleon_use_param = True
napoleon_use_rtype = False
6 changes: 3 additions & 3 deletions doc/source/dev_setup.rst
Expand Up @@ -3,7 +3,7 @@ For Developers

Setup
-----
The section :doc:`gettingstarted` will provide you with detailed guidance on how to install wradlib and the required dependencies for different operating systems (MS Windows, Linux, Mac OS). On MS Windows, each release of wradlib should work with a certain version of Python(x,y). wradlib 0.3.0 has been tested with Python(x,y) 2.7.9.0.
The section :doc:`gettingstarted` will provide you with detailed guidance on how to install wradlib and the required dependencies for different operating systems (MS Windows, Linux, Mac OS). On MS Windows, each release of wradlib should work with a certain version of Python(x,y). wradlib |release| has been tested with Python(x,y) 2.7.9.0. on Windows and anaconda 2.7.10 and 3.5 on linux-64.

As a developer, though, you should rather link into wradlib's version control. This way, it will be easier for you to track chagnes and to contribute your changes to wradlib's main respository (see next section). Just install `Mercurial <http://mercurial.selenic.com/>`_, then clone the wradlib repository to your local system by executing the following command in your shell: ``hg clone https://bitbucket.org/wradlib/wradlib``. Do not forget to set the ``PYTHONPATH`` to point to the corresponding directory.

Expand All @@ -15,14 +15,14 @@ Everyone can contribute to the developement of wradlib by using the Fork and Pul

Building the docs
-----------------
In order to build the documentation, you need to satisfy a few more dependencies which are mainly related to Sphinx. These are specified in the `requirements.txt <https://bitbucket.org/wradlib/wradlib/src/default/requirements.txt>`_.
In order to build the documentation, you need to satisfy a few more dependencies which are mainly related to Sphinx. These are specified in the `requirements.txt <https://bitbucket.org/wradlib/wradlib/src/default/requirements.txt>`_ and `requirements_devel.txt <https://bitbucket.org/wradlib/wradlib/src/default/requirements_devel.txt>`_.

Once these requirements are met, you can open a console window in the folder wradlib/doc and execute ``make html``. This will give you the latest documentation under the wradlib/doc/build/html directory. Simply open the index.html file to view the documentation.


Testing
-------
wradlib uses the `unittest <http://pythontesting.net/framework/unittest/unittest-introduction/>`_ framework. New functions should come with corresponding unittests in the ``wradlib/wradlib/tests`` directory. Just have a look at `available tests <https://bitbucket.org/wradlib/wradlib/src/default/wradlib/tests>`_ to get an idea. In addition, examples and docstrings are a good way to compine testing and documentation. Have a look at the `examples <https://bitbucket.org/wradlib/wradlib/src/default/examples>`_ in order to get an idea on how to set these up correctly. In the docstrings, the ``Examples`` section will be tested by our testing framework. This could look like this::
wradlib uses the `unittest <http://pythontesting.net/framework/unittest/unittest-introduction/>`_ framework. New functions should come with corresponding unittests in the ``wradlib/wradlib/tests`` directory. Just have a look at `available tests <https://bitbucket.org/wradlib/wradlib/src/default/wradlib/tests>`_ to get an idea. In addition, examples and docstrings are a good way to combine testing and documentation. Have a look at the `examples <https://bitbucket.org/wradlib/wradlib/src/default/examples>`_ in order to get an idea on how to set these up correctly. In the docstrings, the ``Examples`` section will be tested by our testing framework. This could look like this::

def foo(a):
"""Docstring to be evaluated by doctest
Expand Down
7 changes: 5 additions & 2 deletions doc/source/gettingstarted.rst
Expand Up @@ -59,7 +59,7 @@ Installation under Linux
------------------------

Installing Manually
^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^

This way no dependency checking is done and you need to make sure yourself that all dependencies (see below) are met.

Expand All @@ -70,7 +70,7 @@ This way no dependency checking is done and you need to make sure yourself that
This will install wradlib to your site-packages or dist-packages folder.

Installing via easy_install
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^

Open a terminal and run:

Expand All @@ -85,6 +85,9 @@ Be aware that with easy_install we can only look for python-module dependencies.
For example the numpy module itself depends on some other libraries, which need to be present in order for the module to compile properly after being downloaded by easy_install. We have no control over these dependencies and it is rather hard to give a complete overview.

Therefore we recommend trying to satisfy the dependencies using your favorite package management system.

Since python environments as Enthought Python or Anaconda Python have ermerged and matured in the past, we also recommend to use these environments.

As an example we give all packages necessary to successfully install wradlib on a Ubuntu Linux 12.04 (thanks to Diego Civera from the wradlib-users mailing list for pioneering this).

Satisfying wradlib dependencies using apt-get on Ubuntu 12.04 LTS (precise pangolin)
Expand Down
68 changes: 36 additions & 32 deletions doc/source/pyplots/tutorial_zonal_statistics.py
Expand Up @@ -55,16 +55,15 @@ def testplot(cats, catsavg, xy, data,
ax1.add_collection(coll)
cb = plt.colorbar(pm, ax=ax1, shrink=0.5)
cb.set_label("(mm/h)")
ax1.set_ylim(ax.get_ylim())
ax1.set_xlim(ax.get_xlim())
plt.xlabel("GK2 Easting")
plt.ylabel("GK2 Northing")
plt.title("Original radar rain sums")
#plt.draw()
plt.draw()
plt.tight_layout()


def ex_tutorial_zonal_statistics():

# Get RADOLAN grid coordinates
grid_xy_radolan = wradlib.georef.get_radolan_grid(900, 900)
x_radolan = grid_xy_radolan[:, :, 0]
Expand All @@ -83,12 +82,12 @@ def ex_tutorial_zonal_statistics():
projection_target=proj_gk)

# Open shapefile (already in GK2)
shpfile = '../../../examples/data/agger/agger_merge.shp'
shpfile = "../../../examples/data/agger/agger_merge.shp"
dataset, inLayer = wradlib.io.open_shape(shpfile)
cats, keys = wradlib.georef.get_shape_coordinates(inLayer)

# Read and prepare the actual data (RADOLAN)
f = '../../../examples/data/radolan/raa01-sf_10000-1406100050-dwd---bin.gz'
f = "../../../examples/data/radolan/raa01-sf_10000-1406100050-dwd---bin.gz"
data, attrs = wradlib.io.read_RADOLAN_composite(f, missing=np.nan)
sec = attrs['secondary']
data.flat[sec] = np.nan
Expand All @@ -111,13 +110,16 @@ def ex_tutorial_zonal_statistics():

t1 = dt.datetime.now()


# Create instance of type ZonalDataPoint from source grid and catchment array
zd = wradlib.zonalstats.ZonalDataPoint(xy_, cats, srs=proj_gk, buf=500.)
# dump to file
#zd.dump_vector('test_zonal_points_cart')
# Create instance of type GridPointsToPoly from zonal data object
obj1 = wradlib.zonalstats.GridPointsToPoly(zd)
try:
# Create instance of type GridPointsToPoly from zonal data file
obj1 = wradlib.zonalstats.GridPointsToPoly('test_zonal_points_cart')
except:
# Create instance of type ZonalDataPoint from source grid and catchment array
zd = wradlib.zonalstats.ZonalDataPoint(xy_, cats, srs=proj_gk, buf=500.)
# dump to file
zd.dump_vector('test_zonal_points_cart')
# Create instance of type GridPointsToPoly from zonal data object
obj1 = wradlib.zonalstats.GridPointsToPoly(zd)

isecs1 = obj1.zdata.isecs
t2 = dt.datetime.now()
Expand All @@ -128,8 +130,8 @@ def ex_tutorial_zonal_statistics():

t3 = dt.datetime.now()

print "Approach #1 (create object) takes: %f seconds" % (t2 - t1).total_seconds()
print "Approach #1 (compute average) takes: %f seconds" % (t3 - t2).total_seconds()
print("Approach #1 (create object) takes: %f seconds" % (t2 - t1).total_seconds())
print("Approach #1 (compute average) takes: %f seconds" % (t3 - t2).total_seconds())

# Just a test for plotting results with zero buffer
zd2 = wradlib.zonalstats.ZonalDataPoint(xy_, cats, buf=0)
Expand Down Expand Up @@ -179,14 +181,18 @@ def ex_tutorial_zonal_statistics():
projection_source=proj_stereo,
projection_target=proj_gk)


# Create instance of type ZonalDataPoly from source grid and
# catchment array
zd = wradlib.zonalstats.ZonalDataPoly(grdverts, cats, srs=proj_gk)
# dump to file
#zd.dump_vector('test_zonal_poly_cart')
# Create instance of type GridPointsToPoly from zonal data object
obj3 = wradlib.zonalstats.GridCellsToPoly(zd)
try:
# Create instance of type GridCellsToPoly from zonal data file
obj3 = wradlib.zonalstats.GridCellsToPoly('test_zonal_poly_cart')
except Exception as e:
print(e)
# Create instance of type ZonalDataPoly from source grid and
# catchment array
zd = wradlib.zonalstats.ZonalDataPoly(grdverts, cats, srs=proj_gk)
# dump to file
zd.dump_vector('test_zonal_poly_cart')
# Create instance of type GridPointsToPoly from zonal data object
obj3 = wradlib.zonalstats.GridCellsToPoly(zd)

t2 = dt.datetime.now()

Expand All @@ -196,13 +202,17 @@ def ex_tutorial_zonal_statistics():

t3 = dt.datetime.now()

print "Approach #2 (create object) takes: %f seconds" % (t2 - t1).total_seconds()
print "Approach #2 (compute average) takes: %f seconds" % (t3 - t2).total_seconds()
print("Approach #2 (create object) takes: %f seconds" % (t2 - t1).total_seconds())
print("Approach #2 (compute average) takes: %f seconds" % (t3 - t2).total_seconds())

# Target polygon patches
trg_patches = [patches.Polygon(item, True) for item in obj3.zdata.trg.data]


# Plot average rainfall and original data
testplot(trg_patches, avg3, xy, data,
title="Catchment rainfall mean (GridCellsToPoly)")
testplot(trg_patches, var3, xy, data, levels=np.arange(0, np.max(var3), 1.),
title="Catchment rainfall variance (GridCellsToPoly)")

# Illustrate results for an example catchment i
i = 6 # try any index between 0 and 13
Expand Down Expand Up @@ -232,13 +242,7 @@ def ex_tutorial_zonal_statistics():
bbox = wradlib.zonalstats.get_bbox(cats[i][:, 0], cats[i][:, 1])
plt.xlim(bbox["left"]-2000, bbox["right"]+2000)
plt.ylim(bbox["bottom"]-2000, bbox["top"]+2000)
#plt.draw()

# Plot average rainfall and original data
testplot(trg_patches, avg3, xy, data,
title="Catchment rainfall mean (GridCellsToPoly)")
testplot(trg_patches, var3, xy, data, levels=np.arange(0, np.max(var3), 1.),
title="Catchment rainfall variance (GridCellsToPoly)")
plt.draw()

# Compare estimates
maxlim = np.max(np.concatenate((avg1, avg3)))
Expand Down

0 comments on commit 554bd73

Please sign in to comment.