import numpy as np import scikits.hydroclimpy as hydro import scikits.hydroclimpy.enso as enso import scikits.hydroclimpy.io.usgs as usgs import scikits.hydroclimpy.plotlib as cpl """ Let's import the streamflow data for the North Oconee River in Athens, GA. The corresponding USGS code of the gage is '02217770'. """ series = usgs.load_usgs_flows('02217770') """ Let's create a figure and add a subplot. """ fig = cpl.figure() fsp = fig.add_subplot(111) """ Let's call the :func:`plot_fdc` function to plot the corresponding flow duration curve. By default, the curve is plotted on the current subplot. We can also select a particular subplot with the :keyword:`subplot` parameter. We will use the additional parameters ``lw`` to specify the linewidth of the curve, ``ls`` for the linestyle, ``c`` for the color, and ``zorder`` for the priority order. """ cpl.plot_fdc(series, subplot=fsp, lw=2, ls='-', c='k', zorder=10) """ Let's add the FDCs for each water year. By default, the multiple curves are drawn using a linewidth of 0.8 and a grey color. """
def plot_jma_vs_oni_comparison(freq='M'): """ Plots the comparison of ONI vs JMAI ENSO indices at the given frequency. """ # Check that we have a valid frequency freq = climpy.check_freq(freq) # Get the ENSO indices: annual for 12 months period, monthly on a monthly basis JMAi = JMA.indices(full_year=False, reference_season='NDJ', minimum_size=6) ONIi = ONI.indices(full_year=False, reference_season=None, minimum_size=5) # Convert to the new frequency if freq != climpy._c.FR_MTH: JMAi = np.round_(JMAi.convert(freq, func=ma.mean)) ONIi = np.round_(ONIi.convert(freq, func=ma.mean)) # Convert the indices to a Nx12 series (N the nb of years) JMAi = JMAi.convert('A') ONIi = ONIi.convert('A') # JMAi = JMAi[JMAi.year >= 1900] ONIi = ONIi[ONIi.year >= 1900] # j_colors = get_colormatrix(JMAi) o_colors = get_colormatrix(ONIi) # fig = cpl.figure(num=1, figsize=(13, 5)) fig.clear() fsp = fig.add_axes([0.05, 0.1, 0.85, 0.85]) (nrows, ncols) = j_colors.shape edgecolors = 'none' # j_vert = np.array([[((i, j + 1), (i, j), (i + 1, j)) for i in range(ncols)] for j in range(nrows)]).reshape(-1, 3, 2) j_coll = matplotlib.collections.PolyCollection(j_vert, facecolors=j_colors.ravel(), edgecolors=edgecolors) fsp.add_collection(j_coll) #............................................ o_vert = np.array([[((i, j + 1), (i + 1, j + 1), (i + 1, j)) for i in range(ncols)] for j in range(nrows)]).reshape(-1, 3, 2) o_coll = matplotlib.collections.PolyCollection(o_vert, facecolors=o_colors.ravel(), edgecolors=edgecolors) fsp.add_collection(o_coll) #............................................ xy_vert = [((i, 0), (i, nrows)) for i in range(0, ncols, 12)] xy_vert += [((0, j), (ncols, j)) for j in range(nrows)] xy_coll = matplotlib.collections.LineCollection(xy_vert, colors='k') fsp.add_collection(xy_coll) #............................................ fsp.xaxis.set_major_locator(cpl.MultipleLocator(12)) fsp.set_xticks(np.arange(0, ncols, 12) + 6) fsp.set_xticklabels(["%02i" % i for i in range(12)]) fsp.set_xlim(0, ncols) #............................................ fsp.set_yticks(np.arange(0, nrows) + 0.5) fsp.set_yticklabels(["%i" % (i * 10 + 1900) for i in range(nrows + 1)]) fsp.set_ylim(0, nrows) fsp.set_ylim(fsp.get_ylim()[::-1]) add_plot_legend(fig, lableft='JMA', labright='ONI') cpl.show() return fig
import numpy as np import scikits.hydroclimpy as hydro import scikits.hydroclimpy.enso as enso import scikits.hydroclimpy.io.usgs as usgs import scikits.hydroclimpy.plotlib as cpl ONI = enso.load_oni() series = usgs.load_usgs_flows('02217770').fill_missing_dates() series = enso.set_ensoindicator(series, ONI) fig = cpl.figure() fsp = fig.add_subplot(111) cpl.plot_fdc(series, plot_enso=True, marker='o', markersize=6, ax=fsp) cpl.plot_fdc(series, plot_enso=True, starting_month=4, ax=fsp) fsp.legend() fsp.set_ylabel("Flows (cfs)", fontweight='bold') fig.suptitle("Flow duration curve for the North Oconee River at Athens, GA", fontweight="bold", fontsize=12)
def plot_jma_vs_jma_comparison(freq='M'): """ Plots the comparison of monthly and annual indices for the JMA index. The monthly indices are defined for each month using Nov-Jan as reference season and a minimum of 6 consecutive months in the same ENSO conditions. The annual indices are defined for each period of 12 months, starting in Oct., using Oct-Dec as reference season and a minimum of 6 consecutive months in the same ENSO conditions Parameters ---------- freq : {int, string} Valid frequency specifier. """ # Check that we have a valid frequency freq = climpy.check_freq(freq) # Get the ENSO indices: annual for 12 months period, monthly on a monthly basis logger.debug("Get ENSO JMAI...") annual = JMA.set_indices(full_year=True, reference_season='OND', minimum_size=6) monthly = JMA.set_indices(full_year=False, reference_season='NDJ', minimum_size=6) # Convert to the new frequency if freq != climpy._c.FR_MTH: annual = np.round_(annual.convert(freq, func=ma.mean)) monthly = np.round_(monthly.convert(freq, func=ma.mean)) # Convert the indices to a Nx12 series (N the nb of years) annual = annual.convert('A') monthly = monthly.convert('A') # Trim to select only the data after 1900. annual = annual[annual.year >= 1900] monthly = monthly[monthly.year >= 1900] # Get the colors # logger.debug("Get color matrices") # a_colors = get_colormatrix(annual) # m_colors = get_colormatrix(monthly) # edegecolors = 'none' ensomap = ENSOmap # logger.debug("Prepare figure...") fig = cpl.figure(num=1, figsize=(13, 5)) fig.clear() fsp = fig.add_axes([0.05, 0.1, 0.85, 0.85]) (nrows, ncols) = annual.shape #a_colors.shape logger.debug("Get vertices #1...") # Get the vertices of the polygons corresponding to standard indices a_vert = np.array([[((i, j + 1), (i, j), (i + 1, j)) for i in range(ncols)] for j in range(nrows)]) a_vert.shape = (-1, 3, 2) # Create a PolyCollection for the polygons. a_coll = matplotlib.collections.PolyCollection(a_vert, norm=ENSOmap) fsp.add_collection(a_coll) # Same process, this time with the monthly indices logger.debug("Get vertices #2...") m_vert = np.array([[((i, j + 1), (i + 1, j + 1), (i + 1, j)) for i in range(ncols)] for j in range(nrows)]) m_vert.shape = (-1, 3, 2) m_coll = matplotlib.collections.PolyCollection(m_vert, norm=ENSOmap) fsp.add_collection(m_coll) # Plot the underlying grid. logger.debug("Plot grid...") xy_vert = [((i, 0), (i, nrows)) for i in range(0, ncols, 12)] xy_vert += [((0, j), (ncols, j)) for j in range(nrows)] xy_coll = matplotlib.collections.LineCollection(xy_vert, colors='k') fsp.add_collection(xy_coll) fsp.grid(True, which='minor', ls=':', c='#999999', lw=0.5) # Set the ticks on the logger.debug("Set ticks...") fsp.xaxis.set_major_locator(cpl.MultipleLocator(12)) fsp.xaxis.set_minor_locator(cpl.MultipleLocator(1)) fsp.set_xticks(np.arange(0, ncols, 12) + 6, minor=False) fsp.set_xticklabels(["%02i" % i for i in range(10)]) fsp.set_xlim(0, ncols) #............................................ fsp.set_yticks(np.arange(0, nrows) + 0.5) fsp.set_yticklabels(["%i" % (i * 10 + 1900) for i in range(nrows + 1)]) fsp.set_ylim(0, nrows) fsp.set_ylim(fsp.get_ylim()[::-1]) #............................................ logger.debug("Add legend") add_plot_legend(fig) # #cpl.show() return fig