Skip to content

Commit

Permalink
Promoted the main plotting functions to top-level functions
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancescAlted committed Nov 11, 2016
1 parent bf9709b commit 97d5b61
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
5 changes: 3 additions & 2 deletions reflexible/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
======
JFB: John F Burkhart <jfburkhart@gmail.com>
FA: Francesc Alted <faltet@gmail.com>
CONTRIBUTORS
============
Expand Down Expand Up @@ -107,7 +108,7 @@ def print_versions():
from .data_structures import (Header, Command, Release,
ReleasePoint, Ageclass)
from .utils import Structure, CacheDict

from .base_read import read_trajectories, read_partpositions

from .flexpart import Flexpart
from .plotting import (plot_sensitivity, plot_at_level, plot_totalcolumn,
plot_trajectory)
13 changes: 5 additions & 8 deletions reflexible/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def plot_totalcolumn(H, data=None,
return figure


def get_figure(fig=None, ax=None, m=None, map_region=None,
def _get_figure(fig=None, ax=None, m=None, map_region=None,
map_par=None, fig_par=None, image=None):
"""Returns a matplotlib figure based on the parameters.
Expand All @@ -135,13 +135,10 @@ def get_figure(fig=None, ax=None, m=None, map_region=None,
This is so as to be able to reuse figures. This saves a huge amount of
time, as creating then basemap instance can be time consuming.
.. note::
Generally you won't use this function directly.
USAGE::
>>> fig = get_figure()
>>> fig = _get_figure()
or
>>> fig = get_figure(map_region='polarcat')
>>> fig = _get_figure(map_region='polarcat')
Returns
This will return the "FIG" object, which has attributes: `fig`, `ax`,
Expand Down Expand Up @@ -280,7 +277,7 @@ def plot_sensitivity(H, data,
try:
figure = _figure_cache[figure_key]
except KeyError:
figure = _figure_cache[figure_key] = get_figure(
figure = _figure_cache[figure_key] = _get_figure(
map_region=map_region, map_par=map_par, fig_par=fig_par)

if overlay is False:
Expand Down Expand Up @@ -559,7 +556,7 @@ def plot_trajectory(H, T, rel_i,
try:
figure = _figure_cache[figure_key]
except KeyError:
figure = _figure_cache[figure_key] = get_figure(
figure = _figure_cache[figure_key] = _get_figure(
map_region=map_region, map_par=map_par, fig_par=fig_par)

# Get fig info and make active
Expand Down
12 changes: 6 additions & 6 deletions reflexible/tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import os
import itertools
import pytest
import matplotlib.pyplot as plt

import reflexible as rf
import reflexible.plotting as pf


# tuples locating test data, nested(True) and global(False)
Expand All @@ -19,7 +19,7 @@
# Small test on color maps
def test_flexpart_colormap():
from matplotlib.colors import ListedColormap
assert isinstance(pf._gen_flexpart_colormap(), ListedColormap)
assert isinstance(rf.plotting._gen_flexpart_colormap(), ListedColormap)


class Dataset:
Expand Down Expand Up @@ -53,18 +53,18 @@ def test_quickplot(self, tmpdir):
tc = self.H.C[k].total_column
dr = [tc.min(), tc.max()]
if self.H.nested:
pf.plot_sensitivity(self.H, tc, data_range=dr,
rf.plot_sensitivity(self.H, tc, data_range=dr,
map_region='svalbard')
# Create a temporary file for the PNG output
p = tmpdir.join('stads_{0}-{1}_nested.png'.format(*k))
png_file = str(p.realpath())
pf.plt.savefig(png_file)
plt.savefig(png_file)
assert p.size() > 0 # check that PNG file has some content
else:
pf.plot_sensitivity(self.H, tc, data_range=dr,
rf.plot_sensitivity(self.H, tc, data_range=dr,
map_region='north_atlantic')
# Create a temporary file for the PNG output
p = tmpdir.join('stads_{0}-{1}.png'.format(*k))
png_file = str(p.realpath())
pf.plt.savefig(png_file)
plt.savefig(png_file)
assert p.size() > 0 # check that PNG file has some content

0 comments on commit 97d5b61

Please sign in to comment.