diff --git a/book/chapters/charts.py b/book/chapters/charts.py index 5691db6..7271f01 100644 --- a/book/chapters/charts.py +++ b/book/chapters/charts.py @@ -18,13 +18,14 @@ def day_of_month_to_string(d): return str(d) if d > 9 else '0' + str(d) def ChartSensor(p, xrng, pidcs, A, Az, Albl, Acolor, Aleg, wid, hgt, z0=-200., z1=0.): """ - Make a stack of charts with one horizontal axis. - The data are in DataArrays: A, Az. pIdcs are row indices for the profile - Dataframe, i.e. a choice of which profiles to plot by index. + Make a stack of charts with one horizontal axis versus y-depth. + The data are in DataArrays A and Az. + pIdcs are row indices of the profile Dataframe: A choice of which profiles to plot + by index. The dataframe gives bounding times for the profile/mode selected. p pandas Dataframe of indexed profile timestamps - xrng list of 2-lists: low-to-high values for the two sensors - pIdcs indices within p to use in generating a sequence of paired charts + xrng 2-list: low, high values for the sensor + pIdcs list of indices within p to use in generating a sequence of paired charts A xarray Dataset: source data of type A Az xarray Dataset: depth data for sensor A Albl string: label for sensor A @@ -51,7 +52,9 @@ def ChartSensor(p, xrng, pidcs, A, Az, Albl, Acolor, Aleg, wid, hgt, z0=-200., z fig, axs = plt.subplots(ncharts, 1, figsize=(wid, hgt*ncharts), tight_layout=True) # profile table p has column headers 'a0z', 'a0t' and so on for r and d - # We are interested in the time columns to constrain data selection + # We are interested in the time columns to constrain data selection. + # These correspond to which "leg" is stipulated: rest, ascent or descent. + # Given these are versus-depth charts: the rest option doesn't make much sense. if Aleg == 'rest': keyA = ('r0t', 'r1t') elif Aleg == 'ascent': keyA = ('a0t', 'a1t') else: keyA = ('d0t', 'd1t') @@ -59,7 +62,7 @@ def ChartSensor(p, xrng, pidcs, A, Az, Albl, Acolor, Aleg, wid, hgt, z0=-200., z # The subsequent code is 'loop over charts: plot each chart: A' # For this we need both a profile index into the profile dataframe p (from the - # passed list pidcs[] *and* a chart index 0, 1, 2, ... These are respectively + # pidcs[] list *and* a chart index 0, 1, 2, ... These are respectively # pidx and i. for i in range(ncharts): @@ -71,27 +74,30 @@ def ChartSensor(p, xrng, pidcs, A, Az, Albl, Acolor, Aleg, wid, hgt, z0=-200., z if do_one: axs.plot( Ax, Ay, ms = 4., color=Acolor, mfc=Acolor) else: axs[i].plot( Ax, Ay, ms = 4., color=Acolor, mfc=Acolor) - # axis ranges + # set the chart title if i == 0: if do_one: axs.set(title = Albl + ' (' + Acolor + ')') else: axs[i].set(title = Albl + ' (' + Acolor + ')') # Set axis ranges from passed list of pairs xrng[][] - if do_one: axs.set( xlim = (xrng[0][0], xrng[0][1]), ylim = (z0, z1)) - else: axs[i].set( xlim = (xrng[0][0], xrng[0][1]), ylim = (z0, z1)) + if do_one: axs.set( xlim = (xrng[0], xrng[1]), ylim = (z0, z1)) + else: axs[i].set( xlim = (xrng[0], xrng[1]), ylim = (z0, z1)) # chart time label - ascent_start_time = 'Start UTC: ' + str(tA0) + profile_start_time = 'Start UTC: ' + str(tA0) delta_t = tA0-dt64(tA0.date()) - if delta_t > midn0 and delta_t < midn1: ascent_start_time += " MIDNIGHT local" - if delta_t > noon0 and delta_t < noon1: ascent_start_time += " NOON local" - xlabel = xrng[0][0] + 0.2*(xrng[0][1] - xrng[0][0]) + if delta_t > midn0 and delta_t < midn1: profile_start_time += " MIDNIGHT local" + if delta_t > noon0 and delta_t < noon1: profile_start_time += " NOON local" + xlabel = xrng[0] + 0.2*(xrng[1] - xrng[0]) ylabel = -10 - if do_one: axs.text(xlabel, ylabel, ascent_start_time) - else: axs[i].text(xlabel, ylabel, ascent_start_time) + if do_one: axs.text(xlabel, ylabel, profile_start_time) + else: axs[i].text(xlabel, ylabel, profile_start_time) return fig, axs +def ChartOneSensor(p, xrng, pidcs, A, Az, Albl, Acolor, Aleg, wid, hgt, z0=-200., z1=0.): + return ChartSensor(p, xrng, pidcs, A, Az, Albl, Acolor, Aleg, wid, hgt, z0=-200., z1=0.) + def ChartTwoSensors(p, xrng, pidcs, A, Az, Albl, Acolor, Aleg, \ B, Bz, Blbl, Bcolor, Bleg, \ diff --git a/book/chapters/data2.ipynb b/book/chapters/data2.ipynb index 7f0f70f..4b9a93e 100755 --- a/book/chapters/data2.ipynb +++ b/book/chapters/data2.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 25, + "execution_count": 1, "id": "8aa370ef-3ab8-4cf3-bf13-96a783e342f9", "metadata": { "tags": [] @@ -14,7 +14,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 2, "id": "2228ec14-bbdb-429b-b19a-49d273c67dbd", "metadata": { "tags": [] @@ -37,7 +37,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 3, "id": "c57ef9be-6c75-4d0f-8c9a-a554283e2185", "metadata": { "tags": [] @@ -49,7 +49,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 4, "id": "61658874-bc3f-45b0-918e-4eef06312e17", "metadata": { "tags": [] @@ -111,7 +111,7 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 5, "id": "e2f40d77-b640-4f7b-9d7b-48ea8c977ad1", "metadata": { "tags": [] @@ -149,9 +149,11 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "id": "82406a7f-1ccf-4c5f-a759-393fb3199919", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "# use ds.sel( to narrow the time window dim" @@ -159,7 +161,7 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 7, "id": "a56bc2c6-e16d-49ee-b3cc-8166935f0c42", "metadata": { "tags": [] @@ -562,10 +564,10 @@ " summary: Dataset Generated by Stream Engine fr...\n", " time_coverage_end: 2024-06-28T11:13:24.862212608\n", " time_coverage_start: 2014-10-06T22:05:23.269171200\n", - " title: Data produced by Stream Engine versio...