Skip to content

Commit

Permalink
Merge branch 'testing'
Browse files Browse the repository at this point in the history
A minimal examples gallery is now being generated using the
sphinx-gallery plugin.
  • Loading branch information
Kevin Hallock committed Dec 12, 2019
2 parents 02bf553 + acb79a7 commit 7254d93
Show file tree
Hide file tree
Showing 13 changed files with 495 additions and 314 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/_build/
/auto_examples/
14 changes: 14 additions & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# .readthedocs.yml
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

submodules:
include:
- data
recursive: true

conda:
environment: conda_environment.yml
160 changes: 0 additions & 160 deletions Plots/Contours/Filled/Georeferenced/NCL_coneff_16.ipynb

This file was deleted.

154 changes: 0 additions & 154 deletions Plots/Contours/Lines/NCL_conOncon_1.ipynb

This file was deleted.

83 changes: 83 additions & 0 deletions Plots/Contours/NCL_conOncon_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
"""
==========
conOncon_1
==========
Plots/Contours/Lines
"""

import numpy as np
import xarray as xr


import matplotlib.pyplot as plt
import matplotlib.ticker as tic
from matplotlib.ticker import ScalarFormatter


from pprint import pprint
ds = xr.open_dataset('../../data/netcdf_files/mxclim.nc')
U = ds.U[0,:,:]
V = ds.V[0,:,:]

plt.rcParams['figure.figsize'] = [20, 20]
fig, ax = plt.subplots()
fig.suptitle('Ensemble Average 1987-89', fontsize=22, fontweight='bold', y=0.94)

#
# y axis is log scale
#
plt.yscale('log')


p = U.plot.contour(ax=ax, levels=16, colors='red', extend='neither')
ax.clabel(p, inline=1, fontsize=14)
ax.set_ylim(ax.get_ylim()[::-1])



p = V.plot.contour(ax=ax, levels=16, colors='blue', extend='neither')
ax.clabel(p, inline=1, fontsize=14)
ax.set_ylim(ax.get_ylim()[::-1])
ax.yaxis.set_major_formatter(ScalarFormatter())
plt.title('') # Someone (xarray?) generates their own title



#
# Hard code the y-axis (pressure) level tic locations. Necessary?
#
ax.yaxis.set_minor_locator(plt.FixedLocator([30,50,70, 150, 200, 250, 300, 400, 500, 700, 850]))

#
# Change formatter or else we tick values formatted in exponential form
#
ax.yaxis.set_major_formatter(ScalarFormatter())
ax.yaxis.set_minor_formatter(ScalarFormatter())

#
# Tweak label sizes, etc.
#
ax.yaxis.label.set_size(20)
ax.xaxis.label.set_size(20)
ax.tick_params('both', length=20, width=2, which='major', labelsize=20)
ax.tick_params('both', length=10, width=1, which='minor', labelsize=20)

#
# This is how we get the y-axis on the right side plotted to show geopotential height.
# Currently we're using bogus values for height 'cause we haven't figured out how to make this work.
#
dummy = 10
axRHS = ax.twinx()
mn, mx = ax.get_ylim()
axRHS.set_ylim(mn*dummy, mx*dummy)
axRHS.set_ylabel('Height (km)')
axRHS.yaxis.label.set_size(20)


#
# add a title to the plot axes. What happens if xarray data set doesn't have long_name and units?
#
ax.set_title(U.long_name + ' (' + U.units+')', fontsize=18, loc='left')


plt.show()
89 changes: 89 additions & 0 deletions Plots/Contours/NCL_coneff_16.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
"""
=========
coneff_16
=========
Plots/Contours/Filled/Georeferenced
"""

import numpy as np
import xarray as xr
import cartopy.crs as ccrs
from cartopy.mpl.geoaxes import GeoAxes
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter

import matplotlib.pyplot as plt
import matplotlib.ticker as tic
from util.make_byr_cmap import make_byr_cmap


from pprint import pprint
ds = xr.open_dataset('../../data/netcdf_files/uv300.nc')
U = ds.U[1,:,:]

plt.rcParams['figure.figsize'] = [20, 10]
fig = plt.figure()
fig.suptitle('Color contours mask filled land', fontsize=22, fontweight='bold')

projection = ccrs.PlateCarree()
ax = plt.axes(projection=projection)

#
# Use global map, which leaves a gap at end of plot. This data set isn't truly global.
#
ax.set_global()
ax.coastlines()

#
# Hard-code tic values. This assumes data are global
#
ax.set_xticks(np.linspace(-180, 180, 13), crs=projection)
ax.set_yticks(np.linspace(-90, 90, 7), crs=projection)

#
# Use cartopy's lat and lon formatter to get tic values displayed in degrees
#
lon_formatter = LongitudeFormatter(zero_direction_label=True)
lat_formatter = LatitudeFormatter()
ax.xaxis.set_major_formatter(lon_formatter)
ax.yaxis.set_major_formatter(lat_formatter)

#
# Tweak minor tic marks. Set spacing so we get nice round values (10 degrees). Again, assumes global data
#
ax.tick_params(labelsize=16)
ax.minorticks_on()
ax.xaxis.set_minor_locator(tic.AutoMinorLocator(n=3))
ax.yaxis.set_minor_locator(tic.AutoMinorLocator(n=3))
ax.tick_params('both', length=20, width=2, which='major')
ax.tick_params('both', length=10, width=1, which='minor')

#
# Import an NCL colormap
#
newcmp = make_byr_cmap()


#
# Plot the data. Note, min and max contour levels are hard-coded. plot.contour's automatic contour value selector produces
# fractional values. Yuck
#
p = U.plot.contourf(ax=ax, vmin=-16.0, vmax=44, levels=16, cmap=newcmp, add_colorbar=False, transform=projection, extend='neither')

cbar = plt.colorbar(p, orientation='horizontal', shrink=0.5)
cbar.ax.tick_params(labelsize=16)

#
# Disable axis labels provided by xarray (I think)
#
ax.set_xlabel('')
ax.set_ylabel('')

#
# add a title to the plot axes. What happens if xarray data set doesn't have long_name and units?
#
ax.set_title(U.long_name + ' (' + U.units+')', fontsize=18, loc='left')
plt.title('') # Someone (xarray?) generates their own title



plt.show()
6 changes: 6 additions & 0 deletions Plots/Contours/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. _contour_examples:

.. _contour-examples-index:

Contour
=======

0 comments on commit 7254d93

Please sign in to comment.