1 |
#!/usr/bin/env python |
---|
2 |
""" |
---|
3 |
Mock-up timeseries for bogue |
---|
4 |
""" |
---|
5 |
|
---|
6 |
import os, sys |
---|
7 |
import datetime, time |
---|
8 |
import pycdf |
---|
9 |
import numpy |
---|
10 |
|
---|
11 |
sys.path.append('/home/haines/nccoos/raw2proc') |
---|
12 |
del(sys) |
---|
13 |
|
---|
14 |
from pylab import colorbar, figure, savefig, setp, getp |
---|
15 |
from matplotlib.dates import DayLocator, HourLocator, DateFormatter, date2num, num2date |
---|
16 |
from procutil import dt2es, es2dt |
---|
17 |
|
---|
18 |
# ---- on cromwell load data |
---|
19 |
#if load_data: |
---|
20 |
print ' ... loading data for graph' |
---|
21 |
ncFile='/home/haines/data/nccoos/level1/bogue/adcp/bogue_adcp_2008_01.nc' |
---|
22 |
nc = pycdf.CDF(ncFile) |
---|
23 |
ncvars = nc.variables() |
---|
24 |
print ncvars |
---|
25 |
es = nc.var('time')[:] |
---|
26 |
units = nc.var('time').units |
---|
27 |
dt = [es2dt(e) for e in es] |
---|
28 |
dn = date2num(dt) |
---|
29 |
z = nc.var('z')[:] |
---|
30 |
wd = nc.var('water_depth')[:] |
---|
31 |
en = nc.var('en')[:] |
---|
32 |
u = nc.var('u')[:] |
---|
33 |
v = nc.var('v')[:] |
---|
34 |
# nc.close() |
---|
35 |
|
---|
36 |
# ---- open a new figure |
---|
37 |
fig = figure(figsize=(11, 8)) |
---|
38 |
|
---|
39 |
# ----- top plot |
---|
40 |
ax = fig.add_subplot(4,1,1) |
---|
41 |
ax.plot_date(dt, en, fmt='b-') |
---|
42 |
|
---|
43 |
# this is superfluous, since the autoscaler should get it right, but |
---|
44 |
# use date2num and num2date to to convert between dates and floats if |
---|
45 |
# you want; both date2num and num2date convert an instance or sequence |
---|
46 |
ax.set_xlim( dt[0], dt[-1] ) |
---|
47 |
setp(ax.xaxis, label_position='top') |
---|
48 |
ax.set_ylabel(nc.var('en').standard_name) |
---|
49 |
setp(ax, xlabel='Time') |
---|
50 |
|
---|
51 |
# The hour locator takes the hour or sequence of hours you want to |
---|
52 |
# tick, not the base multiple |
---|
53 |
|
---|
54 |
ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
55 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
56 |
# ax.xaxis.set_major_formatter( DateFormatter('%d') ) |
---|
57 |
setp(ax, xticklabels=['']) |
---|
58 |
|
---|
59 |
# ----- middle plot |
---|
60 |
ax = fig.add_subplot(4,1,2) |
---|
61 |
ax.plot_date(dt, wd, fmt='b-') |
---|
62 |
ax.set_ylabel(nc.var('water_depth').standard_name) |
---|
63 |
ax.set_xlim( dt[0], dt[-1] ) |
---|
64 |
ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
65 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
66 |
# ax.xaxis.set_major_formatter( DateFormatter('%d') ) |
---|
67 |
setp(ax, xticklabels=['']) |
---|
68 |
setp(ax, xlabel='') |
---|
69 |
|
---|
70 |
# ----- middle plot |
---|
71 |
ax = fig.add_subplot(4,1,3) |
---|
72 |
ax.pcolor(dn, z, u.transpose(), vmin=numpy.nanmin(u), vmax=numpy.nanmax(u)) |
---|
73 |
ax.plot_date(dt, wd, fmt='k-') |
---|
74 |
ax.set_ylabel(nc.var('u').standard_name) |
---|
75 |
ax.set_ylim(2,10) |
---|
76 |
ax.set_xlim(dt[0], dt[-1]) |
---|
77 |
ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
78 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
79 |
# ax.xaxis.set_major_formatter( DateFormatter('%d') ) |
---|
80 |
setp(ax, xticklabels=['']) |
---|
81 |
setp(ax, xlabel='') |
---|
82 |
# colorbar() |
---|
83 |
|
---|
84 |
# ----- bottom plot |
---|
85 |
ax = fig.add_subplot(4,1,4) |
---|
86 |
ax.pcolor(dn, z, v.transpose(), vmin=numpy.nanmin(v), vmax=numpy.nanmax(v)) |
---|
87 |
ax.plot_date(dt, wd, fmt='k-') |
---|
88 |
ax.set_ylabel(nc.var('v').standard_name) |
---|
89 |
ax.set_ylim(2,10) |
---|
90 |
ax.set_xlim(dt[0], dt[-1]) |
---|
91 |
ax.xaxis.set_major_locator( DayLocator(range(2,32,2)) ) |
---|
92 |
ax.xaxis.set_minor_locator( HourLocator(range(0,25,12)) ) |
---|
93 |
ax.xaxis.set_major_formatter( DateFormatter('%d') ) |
---|
94 |
# setp(ax, xticklabels=['']) |
---|
95 |
setp(ax, xlabel='Time') |
---|
96 |
# colorbar() |
---|
97 |
|
---|
98 |
fig.subplots_adjust(left=0.1, bottom=0.1, right=0.9, top=0.9) |
---|
99 |
|
---|
100 |
savefig('test_bogue_plot.png') |
---|
101 |
os.system('ls') |
---|
102 |
os.system('scp -r *.png haines@pitot.marine.unc.edu:/afs/isis.unc.edu/depts/marine/workspace/haines/public_html/nccoos/test') |
---|
103 |
|
---|