Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register projection windrose #39

Merged
merged 2 commits into from
Aug 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ before_install:
- "sh -e /etc/init.d/xvfb start"

script:
- flake8 --ignore=E501 windrose samples tests
- nosetests tests --verbose
- flake8 --ignore=E501 windrose samples tests
37 changes: 19 additions & 18 deletions samples/example_subplots.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import click

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't click python2 only?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

http://click.pocoo.org/5/python3/
I think Python 3 support in click is enough for what I'm doing.

I didn't faced any problem with my version

$ python --version
Python 3.5.2 :: Anaconda 4.1.1 (x86_64)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair enough. I apparently only remembered the bottom parts of that page but not the top.


import datetime
import pandas as pd

import numpy as np
from matplotlib import pyplot as plt
import matplotlib.cm as cm

from windrose import WindroseAxes
import windrose # noqa

pd.set_option('max_rows', 10)

Expand All @@ -34,8 +37,11 @@ def tuple_position(i, nrows, ncols):
return i_sheet, i_row, i_col


def main():
df_all = pd.read_csv("samples/sample_wind_poitiers.csv", parse_dates=['Timestamp'])
@click.command()
@click.option("--filename", default="samples/sample_wind_poitiers.csv", help="Input filename")
@click.option("--year", default=2014, help="Year")
def main(filename, year):
df_all = pd.read_csv(filename, parse_dates=['Timestamp'])
df_all = df_all.set_index('Timestamp')

f_year = get_by_func('year')
Expand All @@ -47,26 +53,21 @@ def main():

print(df_all)

year = 2014

nrows, ncols = 3, 4
margin_pct = 0.1
margin_pct_x, margin_pct_y = margin_pct, margin_pct
width, height = (1.0 - margin_pct_x) / ncols, (1.0 - margin_pct_y) / nrows
fig = plt.figure()
bins = np.arange(0.01, 8, 1)

fig.suptitle("Wind speed - %d" % year)
for month in range(1, 13):
df = df_all.loc[year].loc[(year, month)]
i_sheet, i_row, i_col = tuple_position(month - 1, nrows, ncols)
assert i_sheet == 0
bins = np.arange(0.01, 8, 1)
ax = fig.add_subplot(nrows, ncols, month, projection='windrose')
title = datetime.datetime(year, month, 1).strftime("%b")
ax.set_title(title)
try:
df = df_all.loc[year].loc[(year, month)]
except KeyError:
continue
direction = df['direction'].values
var = df['speed'].values

fig = plt.gcf()
rect = [i_col * width + margin_pct_x / 2, 1 - (i_row + 1) * height - margin_pct_y / 2, width, height] # [left, bottom, width, height]
ax = WindroseAxes(fig, rect, rmax=1000)
# ax.set_title(month)
fig.add_axes(ax)
# ax.contour(direction, var, bins=bins, colors='black', lw=3)
ax.contourf(direction, var, bins=bins, cmap=cm.hot)
ax.contour(direction, var, bins=bins, colors='black')
Expand Down
3 changes: 3 additions & 0 deletions windrose/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@
clean, clean_df, # noqa
plot_windrose_np, plot_windrose_df, plot_windrose, # noqa
FIGSIZE_DEFAULT, DPI_DEFAULT, D_KIND_PLOT) # noqa

from matplotlib.projections import register_projection
register_projection(WindroseAxes)
1 change: 1 addition & 0 deletions windrose/windrose.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class WindroseAxes(PolarAxes):
Create a windrose axes

"""
name = 'windrose'

def __init__(self, *args, **kwargs):
"""
Expand Down