Skip to content

Commit

Permalink
Code formatting (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
scls19fr committed Oct 27, 2018
1 parent 675b7c1 commit a06c57d
Show file tree
Hide file tree
Showing 14 changed files with 540 additions and 379 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ before_install:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"

install:
- python setup.py install

script:
- if [[ $TEST_TARGET == 'default' ]]; then
pytest --verbose tests ;
Expand Down
80 changes: 40 additions & 40 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
#
import os
import sys
sys.path.insert(0, os.path.abspath('../windrose'))

sys.path.insert(0, os.path.abspath("../windrose"))


# -- General configuration ------------------------------------------------
Expand All @@ -31,36 +32,32 @@
# 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.intersphinx',
'sphinx.ext.napoleon',
]
extensions = ["sphinx.ext.autodoc", "sphinx.ext.intersphinx", "sphinx.ext.napoleon"]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
source_suffix = '.rst'
source_suffix = ".rst"

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General information about the project.
project = 'windrose'
copyright = '2018, Lionel Roubeyrie & Sebastien Celles'
author = 'Lionel Roubeyrie & Sebastien Celles'
project = "windrose"
copyright = "2018, Lionel Roubeyrie & Sebastien Celles"
author = "Lionel Roubeyrie & Sebastien Celles"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = ''
version = ""
# The full version, including alpha/beta/rc tags.
release = ''
release = ""

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

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False
Expand All @@ -87,7 +84,7 @@
# a list of builtin themes.
#
# html_theme = 'alabaster'
html_theme = 'sphinx_rtd_theme'
html_theme = "sphinx_rtd_theme"

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

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
#
# This is required for the alabaster theme
# refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars
html_sidebars = {
'**': [
'about.html',
'navigation.html',
'relations.html', # needs 'show_related': True theme option to display
'searchbox.html',
'donate.html',
"**": [
"about.html",
"navigation.html",
"relations.html", # needs 'show_related': True theme option to display
"searchbox.html",
"donate.html",
]
}


# -- Options for HTMLHelp output ------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'windrosedoc'
htmlhelp_basename = "windrosedoc"


# -- Options for LaTeX output ---------------------------------------------
Expand All @@ -128,15 +125,12 @@
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
Expand All @@ -146,19 +140,21 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'windrose.tex', 'windrose Documentation',
'Lionel Roubeyrie \\& Sebastien Celles', 'manual'),
(
master_doc,
"windrose.tex",
"windrose Documentation",
"Lionel Roubeyrie \\& Sebastien Celles",
"manual",
)
]


# -- Options for manual page output ---------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'windrose', 'windrose Documentation',
[author], 1)
]
man_pages = [(master_doc, "windrose", "windrose Documentation", [author], 1)]


# -- Options for Texinfo output -------------------------------------------
Expand All @@ -167,12 +163,16 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'windrose', 'windrose Documentation',
author, 'windrose', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"windrose",
"windrose Documentation",
author,
"windrose",
"One line description of project.",
"Miscellaneous",
)
]


interpshinx_mapping = {
"matplotlib": ('http://matplotlib.org', None),
}
interpshinx_mapping = {"matplotlib": ("http://matplotlib.org", None)}
105 changes: 74 additions & 31 deletions samples/example_animate.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import traceback

import matplotlib

# matplotlib.use("Agg")
import matplotlib.pyplot as plt
import matplotlib.animation
Expand All @@ -30,26 +31,26 @@

import datetime

from windrose import (WindroseAxes, FIGSIZE_DEFAULT, DPI_DEFAULT)
from windrose import WindroseAxes, FIGSIZE_DEFAULT, DPI_DEFAULT

logging.Formatter.converter = time.gmtime
logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=logging.DEBUG)
logging.basicConfig(format="%(asctime)s %(levelname)s %(message)s", level=logging.DEBUG)
logger = logging.getLogger(__name__)

pd.set_option('max_rows', 10)
pd.set_option("max_rows", 10)

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


def get_by_func(by=None, by_func=None):
if by is None and by_func is None:
by = 'MS'
by = "MS"

if by in ['year', 'yearly', 'Y']:
if by in ["year", "yearly", "Y"]:
return lambda dt: dt.year
elif by in ['month', 'monthly', 'MS']: # MS: month start
elif by in ["month", "monthly", "MS"]: # MS: month start
return lambda dt: (dt.year, dt.month)
elif by in ['day', 'daily', 'D']:
elif by in ["day", "daily", "D"]:
return lambda dt: (dt.year, dt.month, dt.day)
elif by is None and by_func is not None:
return by_func
Expand All @@ -60,8 +61,8 @@ def get_by_func(by=None, by_func=None):
def generate(df_all, func, copy=True):
if copy:
df_all = df_all.copy()
df_all['by'] = df_all.index.map(func)
df = df_all.reset_index().set_index(['by', df_all.index.name])
df_all["by"] = df_all.index.map(func)
df = df_all.reset_index().set_index(["by", df_all.index.name])
for by_val in df.index.levels[0]:
yield df.loc[by_val]

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


@click.command()
@click.option("--filename", default="samples/sample_wind_poitiers.csv", help="Input filename")
@click.option(
"--filename", default="samples/sample_wind_poitiers.csv", help="Input filename"
)
@click.option("--exit_at", default=0, help="premature exit (int) - must be > 1")
@click.option("--by", default='month', help="Animate by (year, month, day...)")
@click.option("--by", default="month", help="Animate by (year, month, day...)")
@click.option("--rmax", default=1000, help="rmax")
@click.option("--filename_out", default="windrose_animation.mp4", help="Output filename")
@click.option(
"--filename_out", default="windrose_animation.mp4", help="Output filename"
)
@click.option("--dpi", default=DPI_DEFAULT, help="Dot per inch for plot generation")
@click.option("--figsize", default=S_FIGSIZE_DEFAULT, help="Figure size x,y - default=%s" % S_FIGSIZE_DEFAULT)
@click.option("--fps", default=7, help="Number of frame per seconds for video generation")
@click.option(
"--figsize",
default=S_FIGSIZE_DEFAULT,
help="Figure size x,y - default=%s" % S_FIGSIZE_DEFAULT,
)
@click.option(
"--fps", default=7, help="Number of frame per seconds for video generation"
)
@click.option("--bins_min", default=0.01, help="Bins minimum value")
@click.option("--bins_max", default=20, help="Bins maximum value")
@click.option("--bins_step", default=2, help="Bins step value")
@click.option("--fontname", default="Courier New", help="Font name")
def main(filename, exit_at, by, rmax, dpi, figsize, fps, bins_min, bins_max, bins_step, fontname, filename_out):
def main(
filename,
exit_at,
by,
rmax,
dpi,
figsize,
fps,
bins_min,
bins_max,
bins_step,
fontname,
filename_out,
):
# convert figsize (string like "8,9" to a list of float [8.0, 9.0]
figsize = figsize.split(",")
figsize = map(float, figsize)
Expand All @@ -92,10 +116,10 @@ def main(filename, exit_at, by, rmax, dpi, figsize, fps, bins_min, bins_max, bin

# Read CSV file to a Pandas DataFrame
df_all = pd.read_csv(filename)
df_all['Timestamp'] = pd.to_datetime(df_all['Timestamp'])
df_all = df_all.set_index('Timestamp')
df_all["Timestamp"] = pd.to_datetime(df_all["Timestamp"])
df_all = df_all.set_index("Timestamp")

df_all.index = df_all.index.tz_localize('UTC').tz_convert('UTC')
df_all.index = df_all.index.tz_localize("UTC").tz_convert("UTC")

dt_start = df_all.index[0]
dt_end = df_all.index[-1]
Expand All @@ -106,20 +130,28 @@ def main(filename, exit_at, by, rmax, dpi, figsize, fps, bins_min, bins_max, bin
First dt: %s
Last dt: %s
td: %s
Slides: %d""" % (dt_start, dt_end, td, Nslides)
Slides: %d""" % (
dt_start,
dt_end,
td,
Nslides,
)
logger.info(msg)

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

# Create figure
fig = plt.figure(figsize=figsize, dpi=dpi, facecolor='w', edgecolor='w')
fig = plt.figure(figsize=figsize, dpi=dpi, facecolor="w", edgecolor="w")

# Create a video writer (ffmpeg can create MPEG files)
FFMpegWriter = matplotlib.animation.writers['ffmpeg']
metadata = dict(title='windrose', artist='windrose',
comment="""Made with windrose
http://www.github.com/scls19fr/windrose""")
FFMpegWriter = matplotlib.animation.writers["ffmpeg"]
metadata = dict(
title="windrose",
artist="windrose",
comment="""Made with windrose
http://www.github.com/scls19fr/windrose""",
)
writer = FFMpegWriter(fps=fps, metadata=metadata)

dt_start_process = datetime.datetime.now()
Expand All @@ -133,23 +165,34 @@ def main(filename, exit_at, by, rmax, dpi, figsize, fps, bins_min, bins_max, bin
msg = """ Slide %s/%s
From %s
to %s
td %s""" % (i + 1, Nslides, dt1, dt2, td)
td %s""" % (
i + 1,
Nslides,
dt1,
dt2,
td,
)
logger.info(msg)
remaining = Nslides - (i + 1)
now = datetime.datetime.now()
td_remaining = (now - dt_start_process) / (i + 1) * remaining
logger.info(""" Expected
logger.info(
""" Expected
time: %s
end at: %s
""" % (td_remaining, now + td_remaining))
"""
% (td_remaining, now + td_remaining)
)

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

try:
ax = WindroseAxes.from_ax(fig=fig, rmax=rmax) # scatter, bar, box, contour, contourf
ax = WindroseAxes.from_ax(
fig=fig, rmax=rmax
) # scatter, bar, box, contour, contourf

direction = df['direction'].values
var = df['speed'].values
direction = df["direction"].values
var = df["speed"].values

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

ax.contourf(direction, var, bins=bins, cmap=cm.hot)
ax.contour(direction, var, bins=bins, colors='black', lw=3)
ax.contour(direction, var, bins=bins, colors="black", lw=3)

ax.set_legend()

Expand Down
Loading

0 comments on commit a06c57d

Please sign in to comment.