Skip to content

Commit

Permalink
pushed fnms to charts.py
Browse files Browse the repository at this point in the history
  • Loading branch information
robfatland committed Jul 7, 2024
1 parent 66c09e9 commit 39a9361
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 50 deletions.
41 changes: 41 additions & 0 deletions book/chapters/charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,47 @@ def doy(theDatetime): return 1 + int((theDatetime - dt64(str(theDatetime)[0:4] +
def dt64_from_doy(year, doy): return dt64(str(year) + '-01-01') + td64(doy-1, 'D')
def day_of_month_to_string(d): return str(d) if d > 9 else '0' + str(d)


def ProfilerDepthChart(t0, t1, fnm):
'''
This is a very hardcoded function that generates a two-day span of profiles with some
annotations indicating what is going on, particularly with midnight / noon profiles.
'''
ds = xr.open_dataset(fnm).sel(time=slice(dt64(t0), dt64(t1))) # this is not profiler metadata. It is actual sensor data.
fig, axs = plt.subplots(figsize=(12,4), tight_layout=True)
axs.plot(ds.time, ds.z, marker='.', ms=11., color='k', mfc='r', linewidth='.0001')
axs.set(ylim = (-210., 0.), title='Shallow profiler depth over two days', ylabel='depth (m)', xlabel='Hours (UTM)')
axs.text(dt64('2021-12-31 22:15'), -184, 'AT')
axs.text(dt64('2021-12-31 22:05'), -193, 'REST')
axs.text(dt64('2022-01-01 07:40'), -205, 'midnight')
axs.text(dt64('2022-01-01 21:30'), -205, 'noon')
axs.text(dt64('2022-01-01 09:05'), -20, 'slow')
axs.text(dt64('2022-01-01 09:05'), -30, 'descent')
axs.text(dt64('2022-01-01 22:30'), -20, 'slow')
axs.text(dt64('2022-01-01 22:30'), -30, 'descent')
return True


def VisualizeProfiles(date_id, n_days, year_id, month_id, month_name, site_name, site_abbrev, datafnm):
'''
Plot profiles similar to ProfilerDepthChart: One day per row, supports many days,
wider and simpler layout. This is a backup diagnostic tool for looking at longer
time intervals.
'''
ds = xr.open_dataset('./data/rca/sensors/' + site_abbrev + '/' + datafnm)
fig, axs = plt.subplots(n_days, 1, figsize=(15,n_days), tight_layout=True)
for i in range(n_days):
daystring = str(i+1) if i > 8 else '0' + str(i+1)
time0 = dt64(year_id + '-' + month_id + '-' + daystring + 'T00:00:00')
time1 = dt64(year_id + '-' + month_id + '-' + daystring + 'T23:59:59')
dsDay = ds.sel(time=slice(time0, time1))
axs[i].plot(dsDay.time, dsDay.z, marker='.', markersize=3., color='k')
axs[i].set(ylim = (-200., 0.))
print('...' + month_name + ' ' + str(year_id) + ' ' + site_name + ' daily profiles...')
return True



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 versus y-depth.
Expand Down
62 changes: 12 additions & 50 deletions book/chapters/data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": {
"tags": []
},
Expand All @@ -263,8 +263,6 @@
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Jupyter Notebook running Python 3\n",
"\n",
"Jupyter Notebook running Python 3\n"
]
Expand All @@ -282,49 +280,16 @@
],
"source": [
"from matplotlib import pyplot as plt\n",
"from shallowprofiler import sensors\n",
"from shallowprofiler import *\n",
"from data import *\n",
"from charts import *\n",
"\n",
"print('\\nJupyter Notebook running Python {}'.format(sys.version_info[0]))\n",
"\n",
"\n",
"def ProfilerDepthChart(t0, t1, fnm):\n",
" ds = xr.open_dataset(fnm).sel(time=slice(dt64(t0), dt64(t1))) # this is not profiler metadata. It is actual sensor data.\n",
" fig, axs = plt.subplots(figsize=(12,4), tight_layout=True)\n",
" axs.plot(ds.time, ds.z, marker='.', ms=11., color='k', mfc='r', linewidth='.0001')\n",
" axs.set(ylim = (-210., 0.), title='Shallow profiler depth over two days', ylabel='depth (m)', xlabel='Hours (UTM)')\n",
" axs.text(dt64('2021-12-31 22:15'), -184, 'AT')\n",
" axs.text(dt64('2021-12-31 22:05'), -193, 'REST')\n",
" axs.text(dt64('2022-01-01 07:40'), -205, 'midnight')\n",
" axs.text(dt64('2022-01-01 21:30'), -205, 'noon')\n",
" axs.text(dt64('2022-01-01 09:05'), -20, 'slow')\n",
" axs.text(dt64('2022-01-01 09:05'), -30, 'descent')\n",
" axs.text(dt64('2022-01-01 22:30'), -20, 'slow')\n",
" axs.text(dt64('2022-01-01 22:30'), -30, 'descent')\n",
" return True\n",
" \n",
"\n",
"ProfilerDepthChart('2022-01-01', '2022-01-03', './data/rca/sensors/osb/ctd_jan22_conductivity.nc') # index [0] is arbitrary; any dataset will include z data\n",
"\n",
"\n",
"def VisualizeProfiles(date_id, n_days, year_id, month_id, month_name, site_name):\n",
" ds = xr.open_dataset('./data/rca/sensors/osb/ctd_jan22_conductivity.nc')\n",
" fig, axs = plt.subplots(n_days, 1, figsize=(15,n_days), tight_layout=True)\n",
"\n",
" for i in range(n_days):\n",
" daystring = str(i+1) if i > 8 else '0' + str(i+1)\n",
" time0 = dt64(year_id + '-' + month_id + '-' + daystring + 'T00:00:00')\n",
" time1 = dt64(year_id + '-' + month_id + '-' + daystring + 'T23:59:59')\n",
" dsDay = ds.sel(time=slice(time0, time1))\n",
" axs[i].plot(dsDay.time, dsDay.z, marker='.', markersize=3., color='k')\n",
" axs[i].set(ylim = (-200., 0.))\n",
"\n",
" print('...' + month_name + ' ' + str(year_id) + ' ' + site_name + ' daily profiles...')\n",
" return True\n",
"\n",
"\n",
"# Enable this code for a more expansive view of the January 2022 Oregon Slope Base shallow profiler depth history.\n",
"if False: VisualizeProfiles('jan22', 31, '2022', '01', 'January', 'Oregon Slope Base')\n"
"# Enable this code for a more expansive view of shallow profiler depth history.\n",
"if False: VisualizeProfiles('jan22', 31, '2022', '01', 'January', 'Oregon Slope Base', 'osb', 'ctd_jan22_conductivity.nc')"
]
},
{
Expand Down Expand Up @@ -378,7 +343,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"metadata": {
"tags": []
},
Expand Down Expand Up @@ -632,22 +597,19 @@
"[279 rows x 12 columns]"
]
},
"execution_count": 2,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from shallowprofiler import *\n",
"from charts import *\n",
"\n",
"profiles = ReadProfileMetadata()\n",
"profiles"
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"metadata": {
"tags": []
},
Expand All @@ -671,18 +633,18 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"[<matplotlib.lines.Line2D at 0x7f793ea27ad0>]"
"[<matplotlib.lines.Line2D at 0x7f6e531a2290>]"
]
},
"execution_count": 4,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
},
Expand Down Expand Up @@ -717,7 +679,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"metadata": {
"tags": []
},
Expand Down

0 comments on commit 39a9361

Please sign in to comment.