Skip to content

Commit

Permalink
modify examples according to new API
Browse files Browse the repository at this point in the history
  • Loading branch information
sashank27 committed Jan 8, 2020
1 parent c40e9f6 commit dd4cfdc
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 24 deletions.
4 changes: 2 additions & 2 deletions examples/computer_vision_techniques/off_limb_enhance.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@
# We set the normalization of the new map to be the same as the original map
# to compare the two.
scaled_map = sunpy.map.Map(aia.data * scale_factor, aia.meta)
scaled_map.plot_settings['norm'] = ImageNormalize(stretch=aia.plot_settings['norm'].stretch,
vmin=aia.data.min(), vmax=aia.data.max())
scaled_map.norm = ImageNormalize(stretch=aia.norm.stretch,
vmin=aia.data.min(), vmax=aia.data.max())

###############################################################################
# Let's plot the results
Expand Down
4 changes: 2 additions & 2 deletions examples/plotting/hmi_synoptic_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@

###############################################################################
# Let's also fix the plot settings
syn_map.plot_settings['cmap'] = 'hmimag'
syn_map.plot_settings['norm'] = plt.Normalize(-1500, 1500)
syn_map.cmap = 'hmimag'
syn_map.norm = plt.Normalize(-1500, 1500)

###############################################################################
# Let's plot the results
Expand Down
6 changes: 3 additions & 3 deletions examples/plotting/map_editcolormap.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
aiamap = sunpy.map.Map(AIA_171_IMAGE)

###############################################################################
# All plot settings for a map are stored in the `plot_settings` attribute.
# The Colormap and Normalization attributes for a map are accessed as a property of the map.
# How a Map is displayed is determined by its colormap, which sets the colors
# , and the normalization, which sets how data values are translated to colors.
# Lets replace the colormap and normalization.
aiamap.plot_settings['cmap'] = plt.get_cmap('Greys_r')
aiamap.plot_settings['norm'] = colors.LogNorm(100, aiamap.max())
aiamap.cmap = plt.get_cmap('Greys_r')
aiamap.norm = colors.LogNorm(100, aiamap.max())

###############################################################################
# To see all of the colormaps SunPy provides see `sunpy.visualization.colormaps`.
Expand Down
8 changes: 5 additions & 3 deletions examples/sunpy_other_packages/reprojection_aia_euvi_mosaic.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,11 @@

######################################################################
# To display the output we construct a new map using the new array and our
# generated header. We also borrow the plot settings from the AIA map.
# generated header. We also borrow the Colormap and Normalization attributes from the AIA map.

outmap = sunpy.map.Map((array, header))
outmap.plot_settings = maps[0].plot_settings
outmap.cmap = maps[0].cmap
outmap.norm = maps[0].norm

outmap.plot()
plt.show()
Expand Down Expand Up @@ -183,7 +184,8 @@
# little.

outmap = sunpy.map.Map((array, header))
outmap.plot_settings = maps[0].plot_settings
outmap.cmap = maps[0].cmap
outmap.norm = maps[0].norm
outmap.nickname = 'AIA + EUVI/A + EUVI/B'

plt.figure(figsize=(10, 5))
Expand Down
8 changes: 4 additions & 4 deletions examples/sunpy_other_packages/reprojection_align_aia_hmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@

map_aia, map_hmi = [m.resample((1024, 1024)*u.pix) for m in sunpy.map.Map(sorted(files))]
# Why do we have to do this?
map_hmi.plot_settings['cmap'] = "hmimag"
map_hmi.plot_settings['norm'] = plt.Normalize(-2000, 2000)
map_hmi.cmap = "hmimag"
map_hmi.norm = plt.Normalize(-2000, 2000)

######################################################################
# Plot both images side by side.
Expand All @@ -74,8 +74,8 @@
# Construct an output map and set some nice plotting defaults.

out_hmi = sunpy.map.Map(output, map_aia.wcs)
out_hmi.plot_settings['cmap'] = "hmimag"
out_hmi.plot_settings['norm'] = plt.Normalize(-1500, 1500)
out_hmi.cmap = "hmimag"
out_hmi.norm = plt.Normalize(-1500, 1500)

fig = plt.figure()
ax1 = fig.add_subplot(1, 2, 1, projection=map_aia)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@
# to the AIA image.

outmap = sunpy.map.Map(output, out_header)
outmap.plot_settings = map_stereo.plot_settings
outmap.cmap = map_stereo.cmap
outmap.norm = map_stereo.norm

fig = plt.figure()
ax1 = fig.add_subplot(1, 2, 1, projection=map_aia)
Expand Down Expand Up @@ -149,7 +150,8 @@
# We generate the output map and plot it next to the original image.

outmap = sunpy.map.Map((output, mars_header))
outmap.plot_settings = map_aia.plot_settings
outmap.cmap = map_aia.cmap
outmap.norm = map_aia.norm

fig = plt.figure()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@

array, footprint = reproject_interp(aia_map, out_wcs, shape_out=shape_out)
outmap = sunpy.map.Map((array, header))
outmap.plot_settings = aia_map.plot_settings
outmap.cmap = aia_map.cmap
outmap.norm = aia_map.norm

###############################################################################
# Plot the result.
Expand Down
4 changes: 2 additions & 2 deletions sunpy/map/compositemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,8 @@ def plot(self, axes=None, annotate=True, # pylint: disable=W0613
params = {
"origin": "lower",
"extent": x_range + y_range,
"cmap": m.plot_settings['cmap'],
"norm": m.plot_settings['norm'],
"cmap": m.cmap,
"norm": m.norm,
"alpha": m.alpha,
"zorder": m.zorder,
}
Expand Down
7 changes: 4 additions & 3 deletions sunpy/map/mapbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ class GenericMap(NDData):
Colormap of the map image. Defaults to 'grey'
norm : `matplotlib.colors.Normalize`
Normalization function used. Defaults to None
plot_settings : dict, optional
Plot settings (Deprecated, will be removed in 2.1)
plot_settings : `dict`, optional
Keyword arguments to be passed to `~matplotlib.pyplot.imshow`
(Deprecated, will be removed in 2.1)
Other Parameters
----------------
**kwargs :
Expand Down Expand Up @@ -204,7 +205,7 @@ def __init__(self, data, header, cmap='gray', norm=None, plot_settings=None, **k
if plot_settings:
self.plot_settings = plot_settings
warnings.warn("Handling of ``plot_settings`` is deprecated."
"Subsequently, setting ``plot_settings`` will have no effect on the plot."
"Subsequently setting ``plot_settings`` will have no effect on the plot."
"Pass the plot specific settings to either ``.peek()`` or ``.show()``",
DeprecationWarning)
if 'norm' in self.plot_settings:
Expand Down
4 changes: 2 additions & 2 deletions sunpy/map/mapsequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ def updatefig(i, im, annotate, ani_data, removes):
removes.pop(0).remove()

im.set_array(ani_data[i].data)
im.set_cmap(ani_data[i].plot_settings['cmap'])
im.set_cmap(ani_data[i].cmap)

norm = deepcopy(ani_data[i].plot_settings['norm'])
norm = deepcopy(ani_data[i].norm)
# The following explicit call is for bugged versions of Astropy's
# ImageNormalize
norm.autoscale_None(ani_data[i].data)
Expand Down

0 comments on commit dd4cfdc

Please sign in to comment.