Skip to content

Commit

Permalink
Merge pull request #332 from SuperDARN/ehn/elevation-inferno
Browse files Browse the repository at this point in the history
EHN: Elevation Default to 'inferno' and Fix `cm.get_cmap` Depreciation
  • Loading branch information
carleyjmartin authored Jun 23, 2023
2 parents 795980c + c4fade7 commit f952996
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 53 deletions.
50 changes: 25 additions & 25 deletions pydarn/plotting/color_maps.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import matplotlib.colors as mcol
import matplotlib
import packaging

if packaging.version.parse(matplotlib.__version__) < \
packaging.version.parse('3.7.0'):
from matplotlib import cm
else:
from matplotlib import colormaps as cm


class PyDARNColormaps():
PYDARN_VELOCITY =\
mcol.LinearSegmentedColormap.from_list("pydarn_velocity",
["darkred", "r",
'pink', "b", "darkblue"])
PYDARN_INFERNO = cm.get_cmap('inferno')
PYDARN_PLASMA = cm.get_cmap('plasma')
PYDARN_PLASMA_R = cm.get_cmap('plasma_r')
PYDARN_VELOCITY = matplotlib.colors.LinearSegmentedColormap.from_list(
"pydarn_velocity", ["darkred", "r", 'pink', "b",
"darkblue"])

PYDARN_VIRIDIS = matplotlib.colors.LinearSegmentedColormap.from_list(
"pydarn_viridis", ["indigo", "midnightblue",
"navy", "mediumblue",
"teal", "mediumseagreen",
"limegreen", "yellowgreen",
"yellow", "gold"])

PYDARN_VIRIDIS =\
mcol.LinearSegmentedColormap.from_list("pydarn_viridis",
["indigo", "midnightblue",
"navy", "mediumblue",
"teal",
"mediumseagreen",
"limegreen", "yellowgreen",
"yellow", "gold"])
PYDARN = matplotlib.colors.LinearSegmentedColormap.from_list("pydarn",
["midnightblue", "darkblue", "mediumblue", "rebeccapurple",
"purple", "darkmagenta", "mediumvioletred", "crimson", "red",
"orangered", "darkorange", "orange", "gold"])

PYDARN =\
mcol.LinearSegmentedColormap.from_list("pydarn", ["midnightblue",
"darkblue",
"mediumblue",
"rebeccapurple",
"purple",
"darkmagenta",
"mediumvioletred",
"crimson", "red",
"orangered",
"darkorange",
"orange", "gold"])
8 changes: 4 additions & 4 deletions pydarn/plotting/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,11 @@ def plot_fan(cls, dmap_data: List[dict], ax=None, ranges: List = [],
# Colour table and max value selection depending on parameter plotted
# Load defaults if none given
if cmap is None:
cmap = {'p_l': 'plasma', 'v': PyDARNColormaps.PYDARN_VELOCITY,
cmap = {'p_l': PyDARNColormaps.PYDARN_PLASMA,
'v': PyDARNColormaps.PYDARN_VELOCITY,
'w_l': PyDARNColormaps.PYDARN_VIRIDIS,

'elv': PyDARNColormaps.PYDARN}
cmap = plt.cm.get_cmap(cmap[parameter])
'elv': PyDARNColormaps.PYDARN_INFERNO}
cmap = cmap[parameter]

# Set background to transparent - avoids carry over
# does not interfere with the fov color if chosen
Expand Down
9 changes: 4 additions & 5 deletions pydarn/plotting/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,10 @@ def plot_grid(cls, dmap_data: List[dict], record: int = 0,
# Colour table and max value selection depending on
# parameter plotted Load defaults if none given
if cmap is None:
cmap = {'vector.pwr.median': 'plasma',
'vector.vel.median': 'plasma_r',
'vector.wdt.median':
PyDARNColormaps.PYDARN_VIRIDIS}
cmap = plt.cm.get_cmap(cmap[parameter])
cmap = {'vector.pwr.median': PyDARNColormaps.PYDARN_PLASMA,
'vector.vel.median': PyDARNColormaps.PYDARN_PLASMA_R,
'vector.wdt.median': PyDARNColormaps.PYDARN_VIRIDIS}
cmap = cmap[parameter]

# Setting zmin and zmax
defaultzminmax = {'vector.pwr.median': [0, 50],
Expand Down
10 changes: 5 additions & 5 deletions pydarn/plotting/maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,12 @@ def plot_mapdata(cls, dmap_data: List[dict], ax=None,
date = time2datetime(dmap_data[record])

if cmap is None:
cmap = {MapParams.FITTED_VELOCITY: 'plasma_r',
MapParams.MODEL_VELOCITY: 'plasma_r',
MapParams.RAW_VELOCITY: 'plasma_r',
MapParams.POWER: 'plasma',
cmap = {MapParams.FITTED_VELOCITY: PyDARNColormaps.PYDARN_PLASMA_R,
MapParams.MODEL_VELOCITY: PyDARNColormaps.PYDARN_PLASMA_R,
MapParams.RAW_VELOCITY: PyDARNColormaps.PYDARN_PLASMA_R,
MapParams.POWER: PyDARNColormaps.PYDARN_PLASMA,
MapParams.SPECTRAL_WIDTH: PyDARNColormaps.PYDARN_VIRIDIS}
cmap = plt.cm.get_cmap(cmap[parameter])
cmap = cmap[parameter]
# Setting zmin and zmax
defaultzminmax = {MapParams.FITTED_VELOCITY: [0, 1000],
MapParams.MODEL_VELOCITY: [0, 1000],
Expand Down
26 changes: 12 additions & 14 deletions pydarn/plotting/rtp.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import warnings

from datetime import datetime, timedelta
from matplotlib import dates, colors, cm, ticker
from matplotlib import dates, colors, ticker
from typing import List

from pydarn import (RangeEstimation, check_data_type,
Expand Down Expand Up @@ -154,7 +154,7 @@ def plot_range_time(cls, dmap_data: List[dict], parameter: str = 'v',
colorbar_label: str
the label that appears next to the color bar
Default: ''
cmap: str or matplotlib.cm
cmap: matplotlib.colormaps
matplotlib colour map
https://matplotlib.org/tutorials/colors/colormaps.html
Default: PyDARNColormaps.PYDARN_VELOCITY
Expand Down Expand Up @@ -201,7 +201,7 @@ def plot_range_time(cls, dmap_data: List[dict], parameter: str = 'v',
matplotlib object from pcolormesh
cb: matplotlib.colorbar
matplotlib color bar
cmap: matplotlib.cm
cmap: matplotlib.colormaps
matplotlib color map object
time_axis: list
list representing the x-axis datetime objects
Expand Down Expand Up @@ -410,15 +410,13 @@ def plot_range_time(cls, dmap_data: List[dict], parameter: str = 'v',
"set zmin and zmax in the functions"
" options".format(zmax))
norm = norm(zmin, zmax)
if isinstance(cmap, str):
cmap = cm.get_cmap(cmap)
else:
# need to do this as matplotlib 3.5 will
# not all direct mutations of the object
cmaps = {'p_l': copy.copy(cm.get_cmap('plasma')),
if cmap is None:
# If cmap is not None then cmap should have read in a
# colormap object already - error from matplotlib is instructive
cmaps = {'p_l': PyDARNColormaps.PYDARN_PLASMA,
'v': PyDARNColormaps.PYDARN_VELOCITY,
'w_l': PyDARNColormaps.PYDARN_VIRIDIS,
'elv': PyDARNColormaps.PYDARN}
'elv': PyDARNColormaps.PYDARN_INFERNO}
cmap = cmaps[parameter]

# set the background color, this needs to happen to avoid
Expand Down Expand Up @@ -880,10 +878,10 @@ def plot_summary(cls, dmap_data: List[dict],
dictionary of matplotlib color maps for the summary
range time parameter plots.
https://matplotlib.org/tutorials/colors/colormaps.html
Default: {'p_l': 'plasma',
Default: {'p_l': PyDARNColormaps.PYDARN_PLASMA,
'v': PyDARNColormaps.PYDARN_VELOCITY,
'w_l': PyDARNColormaps.PYDARN_VIRIDIS,
'elv': PyDARNColormaps.PYDARN}
'elv': PyDARNColormaps.PYDARN_INFERNO}
note: to reverse the color just add _r to the string name
lines: dict or str
dictionary of time-series line colors.
Expand Down Expand Up @@ -979,10 +977,10 @@ def plot_summary(cls, dmap_data: List[dict],
line.update(lines)
else:
line.update({k: lines for k, v in line.items()})
cmap = {'p_l': 'plasma',
cmap = {'p_l': PyDARNColormaps.PYDARN_PLASMA,
'v': PyDARNColormaps.PYDARN_VELOCITY,
'w_l': PyDARNColormaps.PYDARN_VIRIDIS,
'elv': PyDARNColormaps.PYDARN}
'elv': PyDARNColormaps.PYDARN_INFERNO}
if isinstance(cmaps, dict):
cmap.update(cmaps)
else:
Expand Down

0 comments on commit f952996

Please sign in to comment.