Skip to content

Commit a06c57d

Browse files
author
scls19fr
authored
Code formatting (#107)
1 parent 675b7c1 commit a06c57d

File tree

14 files changed

+540
-379
lines changed

14 files changed

+540
-379
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ before_install:
2828
- "export DISPLAY=:99.0"
2929
- "sh -e /etc/init.d/xvfb start"
3030

31+
install:
32+
- python setup.py install
33+
3134
script:
3235
- if [[ $TEST_TARGET == 'default' ]]; then
3336
pytest --verbose tests ;

docs/conf.py

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
#
2020
import os
2121
import sys
22-
sys.path.insert(0, os.path.abspath('../windrose'))
22+
23+
sys.path.insert(0, os.path.abspath("../windrose"))
2324

2425

2526
# -- General configuration ------------------------------------------------
@@ -31,36 +32,32 @@
3132
# Add any Sphinx extension module names here, as strings. They can be
3233
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3334
# ones.
34-
extensions = [
35-
'sphinx.ext.autodoc',
36-
'sphinx.ext.intersphinx',
37-
'sphinx.ext.napoleon',
38-
]
35+
extensions = ["sphinx.ext.autodoc", "sphinx.ext.intersphinx", "sphinx.ext.napoleon"]
3936

4037
# Add any paths that contain templates here, relative to this directory.
41-
templates_path = ['_templates']
38+
templates_path = ["_templates"]
4239

4340
# The suffix(es) of source filenames.
4441
# You can specify multiple suffix as a list of string:
4542
#
46-
source_suffix = '.rst'
43+
source_suffix = ".rst"
4744

4845
# The master toctree document.
49-
master_doc = 'index'
46+
master_doc = "index"
5047

5148
# General information about the project.
52-
project = 'windrose'
53-
copyright = '2018, Lionel Roubeyrie & Sebastien Celles'
54-
author = 'Lionel Roubeyrie & Sebastien Celles'
49+
project = "windrose"
50+
copyright = "2018, Lionel Roubeyrie & Sebastien Celles"
51+
author = "Lionel Roubeyrie & Sebastien Celles"
5552

5653
# The version info for the project you're documenting, acts as replacement for
5754
# |version| and |release|, also used in various other places throughout the
5855
# built documents.
5956
#
6057
# The short X.Y version.
61-
version = ''
58+
version = ""
6259
# The full version, including alpha/beta/rc tags.
63-
release = ''
60+
release = ""
6461

6562
# The language for content autogenerated by Sphinx. Refer to documentation
6663
# for a list of supported languages.
@@ -72,10 +69,10 @@
7269
# List of patterns, relative to source directory, that match files and
7370
# directories to ignore when looking for source files.
7471
# This patterns also effect to html_static_path and html_extra_path
75-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
72+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
7673

7774
# The name of the Pygments (syntax highlighting) style to use.
78-
pygments_style = 'sphinx'
75+
pygments_style = "sphinx"
7976

8077
# If true, `todo` and `todoList` produce output, else they produce nothing.
8178
todo_include_todos = False
@@ -87,7 +84,7 @@
8784
# a list of builtin themes.
8885
#
8986
# html_theme = 'alabaster'
90-
html_theme = 'sphinx_rtd_theme'
87+
html_theme = "sphinx_rtd_theme"
9188

9289
# Theme options are theme-specific and customize the look and feel of a theme
9390
# further. For a list of options available for each theme, see the
@@ -98,28 +95,28 @@
9895
# Add any paths that contain custom static files (such as style sheets) here,
9996
# relative to this directory. They are copied after the builtin static files,
10097
# so a file named "default.css" will overwrite the builtin "default.css".
101-
html_static_path = ['_static']
98+
html_static_path = ["_static"]
10299

103100
# Custom sidebar templates, must be a dictionary that maps document names
104101
# to template names.
105102
#
106103
# This is required for the alabaster theme
107104
# refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars
108105
html_sidebars = {
109-
'**': [
110-
'about.html',
111-
'navigation.html',
112-
'relations.html', # needs 'show_related': True theme option to display
113-
'searchbox.html',
114-
'donate.html',
106+
"**": [
107+
"about.html",
108+
"navigation.html",
109+
"relations.html", # needs 'show_related': True theme option to display
110+
"searchbox.html",
111+
"donate.html",
115112
]
116113
}
117114

118115

119116
# -- Options for HTMLHelp output ------------------------------------------
120117

121118
# Output file base name for HTML help builder.
122-
htmlhelp_basename = 'windrosedoc'
119+
htmlhelp_basename = "windrosedoc"
123120

124121

125122
# -- Options for LaTeX output ---------------------------------------------
@@ -128,15 +125,12 @@
128125
# The paper size ('letterpaper' or 'a4paper').
129126
#
130127
# 'papersize': 'letterpaper',
131-
132128
# The font size ('10pt', '11pt' or '12pt').
133129
#
134130
# 'pointsize': '10pt',
135-
136131
# Additional stuff for the LaTeX preamble.
137132
#
138133
# 'preamble': '',
139-
140134
# Latex figure (float) alignment
141135
#
142136
# 'figure_align': 'htbp',
@@ -146,19 +140,21 @@
146140
# (source start file, target name, title,
147141
# author, documentclass [howto, manual, or own class]).
148142
latex_documents = [
149-
(master_doc, 'windrose.tex', 'windrose Documentation',
150-
'Lionel Roubeyrie \\& Sebastien Celles', 'manual'),
143+
(
144+
master_doc,
145+
"windrose.tex",
146+
"windrose Documentation",
147+
"Lionel Roubeyrie \\& Sebastien Celles",
148+
"manual",
149+
)
151150
]
152151

153152

154153
# -- Options for manual page output ---------------------------------------
155154

156155
# One entry per manual page. List of tuples
157156
# (source start file, name, description, authors, manual section).
158-
man_pages = [
159-
(master_doc, 'windrose', 'windrose Documentation',
160-
[author], 1)
161-
]
157+
man_pages = [(master_doc, "windrose", "windrose Documentation", [author], 1)]
162158

163159

164160
# -- Options for Texinfo output -------------------------------------------
@@ -167,12 +163,16 @@
167163
# (source start file, target name, title, author,
168164
# dir menu entry, description, category)
169165
texinfo_documents = [
170-
(master_doc, 'windrose', 'windrose Documentation',
171-
author, 'windrose', 'One line description of project.',
172-
'Miscellaneous'),
166+
(
167+
master_doc,
168+
"windrose",
169+
"windrose Documentation",
170+
author,
171+
"windrose",
172+
"One line description of project.",
173+
"Miscellaneous",
174+
)
173175
]
174176

175177

176-
interpshinx_mapping = {
177-
"matplotlib": ('http://matplotlib.org', None),
178-
}
178+
interpshinx_mapping = {"matplotlib": ("http://matplotlib.org", None)}

samples/example_animate.py

Lines changed: 74 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import traceback
2121

2222
import matplotlib
23+
2324
# matplotlib.use("Agg")
2425
import matplotlib.pyplot as plt
2526
import matplotlib.animation
@@ -30,26 +31,26 @@
3031

3132
import datetime
3233

33-
from windrose import (WindroseAxes, FIGSIZE_DEFAULT, DPI_DEFAULT)
34+
from windrose import WindroseAxes, FIGSIZE_DEFAULT, DPI_DEFAULT
3435

3536
logging.Formatter.converter = time.gmtime
36-
logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=logging.DEBUG)
37+
logging.basicConfig(format="%(asctime)s %(levelname)s %(message)s", level=logging.DEBUG)
3738
logger = logging.getLogger(__name__)
3839

39-
pd.set_option('max_rows', 10)
40+
pd.set_option("max_rows", 10)
4041

4142
S_FIGSIZE_DEFAULT = ",".join(map(str, FIGSIZE_DEFAULT))
4243

4344

4445
def get_by_func(by=None, by_func=None):
4546
if by is None and by_func is None:
46-
by = 'MS'
47+
by = "MS"
4748

48-
if by in ['year', 'yearly', 'Y']:
49+
if by in ["year", "yearly", "Y"]:
4950
return lambda dt: dt.year
50-
elif by in ['month', 'monthly', 'MS']: # MS: month start
51+
elif by in ["month", "monthly", "MS"]: # MS: month start
5152
return lambda dt: (dt.year, dt.month)
52-
elif by in ['day', 'daily', 'D']:
53+
elif by in ["day", "daily", "D"]:
5354
return lambda dt: (dt.year, dt.month, dt.day)
5455
elif by is None and by_func is not None:
5556
return by_func
@@ -60,8 +61,8 @@ def get_by_func(by=None, by_func=None):
6061
def generate(df_all, func, copy=True):
6162
if copy:
6263
df_all = df_all.copy()
63-
df_all['by'] = df_all.index.map(func)
64-
df = df_all.reset_index().set_index(['by', df_all.index.name])
64+
df_all["by"] = df_all.index.map(func)
65+
df = df_all.reset_index().set_index(["by", df_all.index.name])
6566
for by_val in df.index.levels[0]:
6667
yield df.loc[by_val]
6768

@@ -71,19 +72,42 @@ def count(df_all, func):
7172

7273

7374
@click.command()
74-
@click.option("--filename", default="samples/sample_wind_poitiers.csv", help="Input filename")
75+
@click.option(
76+
"--filename", default="samples/sample_wind_poitiers.csv", help="Input filename"
77+
)
7578
@click.option("--exit_at", default=0, help="premature exit (int) - must be > 1")
76-
@click.option("--by", default='month', help="Animate by (year, month, day...)")
79+
@click.option("--by", default="month", help="Animate by (year, month, day...)")
7780
@click.option("--rmax", default=1000, help="rmax")
78-
@click.option("--filename_out", default="windrose_animation.mp4", help="Output filename")
81+
@click.option(
82+
"--filename_out", default="windrose_animation.mp4", help="Output filename"
83+
)
7984
@click.option("--dpi", default=DPI_DEFAULT, help="Dot per inch for plot generation")
80-
@click.option("--figsize", default=S_FIGSIZE_DEFAULT, help="Figure size x,y - default=%s" % S_FIGSIZE_DEFAULT)
81-
@click.option("--fps", default=7, help="Number of frame per seconds for video generation")
85+
@click.option(
86+
"--figsize",
87+
default=S_FIGSIZE_DEFAULT,
88+
help="Figure size x,y - default=%s" % S_FIGSIZE_DEFAULT,
89+
)
90+
@click.option(
91+
"--fps", default=7, help="Number of frame per seconds for video generation"
92+
)
8293
@click.option("--bins_min", default=0.01, help="Bins minimum value")
8394
@click.option("--bins_max", default=20, help="Bins maximum value")
8495
@click.option("--bins_step", default=2, help="Bins step value")
8596
@click.option("--fontname", default="Courier New", help="Font name")
86-
def main(filename, exit_at, by, rmax, dpi, figsize, fps, bins_min, bins_max, bins_step, fontname, filename_out):
97+
def main(
98+
filename,
99+
exit_at,
100+
by,
101+
rmax,
102+
dpi,
103+
figsize,
104+
fps,
105+
bins_min,
106+
bins_max,
107+
bins_step,
108+
fontname,
109+
filename_out,
110+
):
87111
# convert figsize (string like "8,9" to a list of float [8.0, 9.0]
88112
figsize = figsize.split(",")
89113
figsize = map(float, figsize)
@@ -92,10 +116,10 @@ def main(filename, exit_at, by, rmax, dpi, figsize, fps, bins_min, bins_max, bin
92116

93117
# Read CSV file to a Pandas DataFrame
94118
df_all = pd.read_csv(filename)
95-
df_all['Timestamp'] = pd.to_datetime(df_all['Timestamp'])
96-
df_all = df_all.set_index('Timestamp')
119+
df_all["Timestamp"] = pd.to_datetime(df_all["Timestamp"])
120+
df_all = df_all.set_index("Timestamp")
97121

98-
df_all.index = df_all.index.tz_localize('UTC').tz_convert('UTC')
122+
df_all.index = df_all.index.tz_localize("UTC").tz_convert("UTC")
99123

100124
dt_start = df_all.index[0]
101125
dt_end = df_all.index[-1]
@@ -106,20 +130,28 @@ def main(filename, exit_at, by, rmax, dpi, figsize, fps, bins_min, bins_max, bin
106130
First dt: %s
107131
Last dt: %s
108132
td: %s
109-
Slides: %d""" % (dt_start, dt_end, td, Nslides)
133+
Slides: %d""" % (
134+
dt_start,
135+
dt_end,
136+
td,
137+
Nslides,
138+
)
110139
logger.info(msg)
111140

112141
# Define bins
113142
bins = np.arange(bins_min, bins_max, bins_step)
114143

115144
# Create figure
116-
fig = plt.figure(figsize=figsize, dpi=dpi, facecolor='w', edgecolor='w')
145+
fig = plt.figure(figsize=figsize, dpi=dpi, facecolor="w", edgecolor="w")
117146

118147
# Create a video writer (ffmpeg can create MPEG files)
119-
FFMpegWriter = matplotlib.animation.writers['ffmpeg']
120-
metadata = dict(title='windrose', artist='windrose',
121-
comment="""Made with windrose
122-
http://www.github.com/scls19fr/windrose""")
148+
FFMpegWriter = matplotlib.animation.writers["ffmpeg"]
149+
metadata = dict(
150+
title="windrose",
151+
artist="windrose",
152+
comment="""Made with windrose
153+
http://www.github.com/scls19fr/windrose""",
154+
)
123155
writer = FFMpegWriter(fps=fps, metadata=metadata)
124156

125157
dt_start_process = datetime.datetime.now()
@@ -133,23 +165,34 @@ def main(filename, exit_at, by, rmax, dpi, figsize, fps, bins_min, bins_max, bin
133165
msg = """ Slide %s/%s
134166
From %s
135167
to %s
136-
td %s""" % (i + 1, Nslides, dt1, dt2, td)
168+
td %s""" % (
169+
i + 1,
170+
Nslides,
171+
dt1,
172+
dt2,
173+
td,
174+
)
137175
logger.info(msg)
138176
remaining = Nslides - (i + 1)
139177
now = datetime.datetime.now()
140178
td_remaining = (now - dt_start_process) / (i + 1) * remaining
141-
logger.info(""" Expected
179+
logger.info(
180+
""" Expected
142181
time: %s
143182
end at: %s
144-
""" % (td_remaining, now + td_remaining))
183+
"""
184+
% (td_remaining, now + td_remaining)
185+
)
145186

146187
title = " From %s\n to %s" % (dt1, dt2)
147188

148189
try:
149-
ax = WindroseAxes.from_ax(fig=fig, rmax=rmax) # scatter, bar, box, contour, contourf
190+
ax = WindroseAxes.from_ax(
191+
fig=fig, rmax=rmax
192+
) # scatter, bar, box, contour, contourf
150193

151-
direction = df['direction'].values
152-
var = df['speed'].values
194+
direction = df["direction"].values
195+
var = df["speed"].values
153196

154197
# ax.scatter(direction, var, alpha=0.2)
155198
# ax.set_xlim([-bins[-1], bins[-1]])
@@ -162,7 +205,7 @@ def main(filename, exit_at, by, rmax, dpi, figsize, fps, bins_min, bins_max, bin
162205
# ax.contour(direction, var, cmap=cm.hot, lw=3, bins=bins)
163206

164207
ax.contourf(direction, var, bins=bins, cmap=cm.hot)
165-
ax.contour(direction, var, bins=bins, colors='black', lw=3)
208+
ax.contour(direction, var, bins=bins, colors="black", lw=3)
166209

167210
ax.set_legend()
168211

0 commit comments

Comments
 (0)