diff options
author | tlatorre <tlatorre@uchicago.edu> | 2020-05-11 10:30:39 -0500 |
---|---|---|
committer | tlatorre <tlatorre@uchicago.edu> | 2020-05-11 10:30:39 -0500 |
commit | 15fc972c89a4366a06755daeedaac52f91762ecd (patch) | |
tree | 9a5dbea7787cef9946473787e9a3996f24cd2898 /utils/plot-atmospheric-fluxes | |
parent | 651cbe5d261a6d29b4dec7c38b65c0eac5431363 (diff) | |
download | sddm-15fc972c89a4366a06755daeedaac52f91762ecd.tar.gz sddm-15fc972c89a4366a06755daeedaac52f91762ecd.tar.bz2 sddm-15fc972c89a4366a06755daeedaac52f91762ecd.zip |
update utils/ folder to make a python package called sddm
This commit adds an sddm python package to the utils/ folder. This allows me to
consolidate code used across all the various scripts. This package is now
installed by default to /home/tlatorre/local/lib/python2.7/site-packages so you
should add the following to your .bashrc file:
export PYTHONPATH=$HOME/local/lib/python2.7/site-packages/:$PYTHONPATH
before using the scripts installed to ~/local/bin.
Diffstat (limited to 'utils/plot-atmospheric-fluxes')
-rwxr-xr-x | utils/plot-atmospheric-fluxes | 128 |
1 files changed, 2 insertions, 126 deletions
diff --git a/utils/plot-atmospheric-fluxes b/utils/plot-atmospheric-fluxes index fb4861d..7dafbbb 100755 --- a/utils/plot-atmospheric-fluxes +++ b/utils/plot-atmospheric-fluxes @@ -6,132 +6,8 @@ http://www-pnp.physics.ox.ac.uk/~barr/fluxfiles/0403i/index.html. from __future__ import print_function, division import numpy as np import os - -def splitext(path): - """ - Like os.path.splitext() except it returns the full extension if the - filename has multiple extensions, for example: - - splitext('foo.tar.gz') -> 'foo', '.tar.gz' - """ - full_root, full_ext = os.path.splitext(path) - while True: - root, ext = os.path.splitext(full_root) - if ext: - full_ext = ext + full_ext - full_root = root - else: - break - - return full_root, full_ext - -# Taken from https://raw.githubusercontent.com/mwaskom/seaborn/c73055b2a9d9830c6fbbace07127c370389d04dd/seaborn/utils.py -def despine(fig=None, ax=None, top=True, right=True, left=False, - bottom=False, offset=None, trim=False): - """Remove the top and right spines from plot(s). - - fig : matplotlib figure, optional - Figure to despine all axes of, default uses current figure. - ax : matplotlib axes, optional - Specific axes object to despine. - top, right, left, bottom : boolean, optional - If True, remove that spine. - offset : int or dict, optional - Absolute distance, in points, spines should be moved away - from the axes (negative values move spines inward). A single value - applies to all spines; a dict can be used to set offset values per - side. - trim : bool, optional - If True, limit spines to the smallest and largest major tick - on each non-despined axis. - - Returns - ------- - None - - """ - # Get references to the axes we want - if fig is None and ax is None: - axes = plt.gcf().axes - elif fig is not None: - axes = fig.axes - elif ax is not None: - axes = [ax] - - for ax_i in axes: - for side in ["top", "right", "left", "bottom"]: - # Toggle the spine objects - is_visible = not locals()[side] - ax_i.spines[side].set_visible(is_visible) - if offset is not None and is_visible: - try: - val = offset.get(side, 0) - except AttributeError: - val = offset - _set_spine_position(ax_i.spines[side], ('outward', val)) - - # Potentially move the ticks - if left and not right: - maj_on = any( - t.tick1line.get_visible() - for t in ax_i.yaxis.majorTicks - ) - min_on = any( - t.tick1line.get_visible() - for t in ax_i.yaxis.minorTicks - ) - ax_i.yaxis.set_ticks_position("right") - for t in ax_i.yaxis.majorTicks: - t.tick2line.set_visible(maj_on) - for t in ax_i.yaxis.minorTicks: - t.tick2line.set_visible(min_on) - - if bottom and not top: - maj_on = any( - t.tick1line.get_visible() - for t in ax_i.xaxis.majorTicks - ) - min_on = any( - t.tick1line.get_visible() - for t in ax_i.xaxis.minorTicks - ) - ax_i.xaxis.set_ticks_position("top") - for t in ax_i.xaxis.majorTicks: - t.tick2line.set_visible(maj_on) - for t in ax_i.xaxis.minorTicks: - t.tick2line.set_visible(min_on) - - if trim: - # clip off the parts of the spines that extend past major ticks - xticks = ax_i.get_xticks() - if xticks.size: - firsttick = np.compress(xticks >= min(ax_i.get_xlim()), - xticks)[0] - lasttick = np.compress(xticks <= max(ax_i.get_xlim()), - xticks)[-1] - ax_i.spines['bottom'].set_bounds(firsttick, lasttick) - ax_i.spines['top'].set_bounds(firsttick, lasttick) - newticks = xticks.compress(xticks <= lasttick) - newticks = newticks.compress(newticks >= firsttick) - ax_i.set_xticks(newticks) - - xticks_minor = [t for t in ax_i.get_xticks(minor=True) if firsttick < t < lasttick] - ax_i.set_xticks(xticks_minor,minor=True) - - yticks = ax_i.get_yticks() - if yticks.size: - firsttick = np.compress(yticks >= min(ax_i.get_ylim()), - yticks)[0] - lasttick = np.compress(yticks <= max(ax_i.get_ylim()), - yticks)[-1] - ax_i.spines['left'].set_bounds(firsttick, lasttick) - ax_i.spines['right'].set_bounds(firsttick, lasttick) - newticks = yticks.compress(yticks <= lasttick) - newticks = newticks.compress(newticks >= firsttick) - ax_i.set_yticks(newticks) - - yticks_minor = [t for t in ax_i.get_yticks(minor=True) if firsttick < t < lasttick] - ax_i.set_yticks(yticks_minor,minor=True) +from sddm.plot import despine +from sddm import splitext # Data is in the form: Fluxes in bins of neutrino energy (equally spaced bins # in logE with 10 bins per decade with the low edge of the first bin at 100 |