Skip to content

Commit f23f123

Browse files
authored
Update grid calls & run tests on develop (#226)
* Update calls to grid formatting * run on develop
1 parent e591600 commit f23f123

File tree

6 files changed

+79
-36
lines changed

6 files changed

+79
-36
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ on:
44
push:
55
branches:
66
- master
7-
- Develop
7+
- develop
88
pull_request:
99
branches:
1010
- master
11-
- Develop
11+
- develop
1212

1313
jobs:
1414
conda-build:

mhkit/river/graphics.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,18 @@ def _xy_plot(x, y, fmt='.', label=None, xlabel=None, ylabel=None, title=None,
3232

3333
ax.plot(x, y, fmt, label=label, markersize=7)
3434

35-
ax.grid(b=True, which='both')
35+
ax.grid()
3636

37-
if label:
38-
ax.legend()
39-
if xlabel:
40-
ax.set_xlabel(xlabel)
41-
if ylabel:
42-
ax.set_ylabel(ylabel)
43-
if title:
44-
ax.set_title(title)
37+
if label: ax.legend()
38+
if xlabel: ax.set_xlabel(xlabel)
39+
if ylabel: ax.set_ylabel(ylabel)
40+
if title: ax.set_title(title)
4541

4642
plt.tight_layout()
4743

4844
return ax
4945

46+
5047
def plot_flow_duration_curve(D, F, label=None, ax=None):
5148
"""
5249
Plots discharge vs exceedance probability as a Flow Duration Curve (FDC)
@@ -81,6 +78,7 @@ def plot_flow_duration_curve(D, F, label=None, ax=None):
8178

8279
return ax
8380

81+
8482
def plot_velocity_duration_curve(V, F, label=None, ax=None):
8583
"""
8684
Plots velocity vs exceedance probability as a Velocity Duration Curve (VDC)
@@ -114,6 +112,7 @@ def plot_velocity_duration_curve(V, F, label=None, ax=None):
114112

115113
return ax
116114

115+
117116
def plot_power_duration_curve(P, F, label=None, ax=None):
118117
"""
119118
Plots power vs exceedance probability as a Power Duration Curve (PDC)
@@ -147,6 +146,7 @@ def plot_power_duration_curve(P, F, label=None, ax=None):
147146

148147
return ax
149148

149+
150150
def plot_discharge_timeseries(Q, label=None, ax=None):
151151
"""
152152
Plots discharge time-series
@@ -168,11 +168,19 @@ def plot_discharge_timeseries(Q, label=None, ax=None):
168168
ax : matplotlib pyplot axes
169169
170170
"""
171-
ax = _xy_plot(Q.index, Q, fmt='-', label=label, xlabel='Time',
172-
ylabel='Discharge [$m^3/s$]', ax=ax)
171+
ax = _xy_plot(
172+
Q.index,
173+
Q,
174+
fmt='-',
175+
label=label,
176+
xlabel='Time',
177+
ylabel='Discharge [$m^3/s$]',
178+
ax=ax
179+
)
173180

174181
return ax
175182

183+
176184
def plot_discharge_vs_velocity(D, V, polynomial_coeff=None, label=None, ax=None):
177185
"""
178186
Plots discharge vs velocity data along with the polynomial fit

mhkit/river/resource.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ def exceedance_probability(D):
5959
F = F.to_frame('F') # for matlab
6060

6161
return F
62-
62+
63+
6364
def polynomial_fit(x, y, n):
6465
"""
6566
Returns a polynomial fit for y given x of order n
@@ -180,6 +181,7 @@ def velocity_to_power(V, polynomial_coefficients, cut_in, cut_out):
180181

181182
return P
182183

184+
183185
def energy_produced(P, seconds):
184186
"""
185187
Returns the energy produced for a given time period provided

mhkit/tests/river/test_resource.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ def setUpClass(self):
3333
def tearDownClass(self):
3434
pass
3535

36+
3637
def test_Froude_number(self):
3738
v = 2
3839
h = 5
3940
Fr = river.resource.Froude_number(v, h)
4041
self.assertAlmostEqual(Fr, 0.286, places=3)
4142

43+
4244
def test_exceedance_probability(self):
4345
# Create arbitrary discharge between 0 and 8(N=9)
4446
Q = pd.Series(np.arange(9))
@@ -49,6 +51,7 @@ def test_exceedance_probability(self):
4951
self.assertEqual(f.min().values , 10. )
5052
self.assertEqual(f.max().values , 90. )
5153

54+
5255
def test_polynomial_fit(self):
5356
# Calculate a first order polynomial on an x=y line
5457
p, r2 = river.resource.polynomial_fit(np.arange(8), np.arange(8),1)
@@ -69,6 +72,7 @@ def test_discharge_to_velocity(self):
6972
V = river.resource.discharge_to_velocity(Q, p)
7073
self.assertAlmostEqual(np.sum(10*Q - V['V']), 0.00, places=2 )
7174

75+
7276
def test_velocity_to_power(self):
7377
# Calculate a first order polynomial on an DV_Curve x=y line 10 times greater than the Q values
7478
p, r2 = river.resource.polynomial_fit(np.arange(9), 10*np.arange(9),1)
@@ -118,6 +122,7 @@ def test_plot_flow_duration_curve(self):
118122

119123
self.assertTrue(isfile(filename))
120124

125+
121126
def test_plot_power_duration_curve(self):
122127
filename = abspath(join(plotdir, 'river_plot_power_duration_curve.png'))
123128
if isfile(filename):
@@ -131,6 +136,7 @@ def test_plot_power_duration_curve(self):
131136

132137
self.assertTrue(isfile(filename))
133138

139+
134140
def test_plot_velocity_duration_curve(self):
135141
filename = abspath(join(plotdir, 'river_plot_velocity_duration_curve.png'))
136142
if isfile(filename):
@@ -144,10 +150,10 @@ def test_plot_velocity_duration_curve(self):
144150

145151
self.assertTrue(isfile(filename))
146152

153+
147154
def test_plot_discharge_timeseries(self):
148155
filename = abspath(join(plotdir, 'river_plot_discharge_timeseries.png'))
149-
if isfile(filename):
150-
os.remove(filename)
156+
if isfile(filename): os.remove(filename)
151157

152158
plt.figure()
153159
river.graphics.plot_discharge_timeseries(self.data['Q'])
@@ -156,6 +162,7 @@ def test_plot_discharge_timeseries(self):
156162

157163
self.assertTrue(isfile(filename))
158164

165+
159166
def test_plot_discharge_vs_velocity(self):
160167
filename = abspath(join(plotdir, 'river_plot_discharge_vs_velocity.png'))
161168
if isfile(filename):
@@ -168,6 +175,7 @@ def test_plot_discharge_vs_velocity(self):
168175

169176
self.assertTrue(isfile(filename))
170177

178+
171179
def test_plot_velocity_vs_power(self):
172180
filename = abspath(join(plotdir, 'river_plot_velocity_vs_power.png'))
173181
if isfile(filename):

mhkit/tidal/graphics.py

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,15 @@ def _initialize_polar(ax=None, metadata=None, flood=None, ebb=None):
8383
return ax
8484

8585

86-
def plot_rose(directions, velocities, width_dir, width_vel, metadata=None,
87-
flood=None, ebb=None):
86+
def plot_rose(
87+
directions,
88+
velocities,
89+
width_dir,
90+
width_vel,
91+
metadata=None,
92+
flood=None,
93+
ebb=None
94+
):
8895
"""
8996
Creates a polar histogram. Direction angles from binned histogram must
9097
be specified such that 0 degrees is north.
@@ -173,9 +180,15 @@ def plot_rose(directions, velocities, width_dir, width_vel, metadata=None,
173180
return ax
174181

175182

176-
def plot_joint_probability_distribution(directions, velocities, width_dir,
177-
width_vel, metadata=None,
178-
flood=None, ebb=None):
183+
def plot_joint_probability_distribution(
184+
directions,
185+
velocities,
186+
width_dir,
187+
width_vel,
188+
metadata=None,
189+
flood=None,
190+
ebb=None
191+
):
179192
"""
180193
Creates a polar histogram. Direction angles from binned histogram must
181194
be specified such that 0 is north.
@@ -315,8 +328,15 @@ def plot_current_timeseries(directions, velocities, principal_direction,
315328
xlabel='Time', ylabel='Velocity [$m/s$]', ax=ax)
316329
return ax
317330

318-
def tidal_phase_probability(directions, velocities, flood, ebb,
319-
bin_size=0.1, ax=None):
331+
332+
def tidal_phase_probability(
333+
directions,
334+
velocities,
335+
flood,
336+
ebb,
337+
bin_size=0.1,
338+
ax=None
339+
):
320340
'''
321341
Discretizes the tidal series speed by bin size and returns a plot
322342
of the probability for each bin in the flood or ebb tidal phase.
@@ -353,17 +373,17 @@ def tidal_phase_probability(directions, velocities, flood, ebb,
353373
assert isinstance(ebb, (int, float)), \
354374
'ebb must be of type int or float'
355375
assert isinstance(bin_size, (int, float)), \
356-
'bin_size must be of type int or float'
376+
'bin_size must be of type int or float'
357377
assert flood >=0 and flood <=360,\
358378
'flood must be between 0 and 360 degrees'
359379
assert ebb >=0 and ebb <=360,\
360-
'ebb must be between 0 and 360 degrees'
380+
'ebb must be between 0 and 360 degrees'
361381
assert bin_size >=0 ,\
362-
'bin_size must be greater than 0'
363-
382+
'bin_size must be greater than 0'
383+
364384
if ax==None:
365385
fig, ax = plt.subplots(figsize=(12, 8))
366-
386+
367387
isEbb = _flood_or_ebb(directions, flood, ebb)
368388

369389
decimals = round(bin_size/0.1)
@@ -394,13 +414,18 @@ def tidal_phase_probability(directions, velocities, flood, ebb,
394414
plt.ylim(0,1.0)
395415
plt.legend()
396416
plt.grid(linestyle=':')
397-
417+
398418
return ax
399-
400419

401420

402-
def tidal_phase_exceedance(directions, velocities, flood, ebb,
403-
bin_size=0.1, ax=None):
421+
def tidal_phase_exceedance(
422+
directions,
423+
velocities,
424+
flood,
425+
ebb,
426+
bin_size=0.1,
427+
ax=None
428+
):
404429
'''
405430
Returns a stacked area plot of the exceedance probability for the
406431
flood and ebb tidal phases.

mhkit/wave/graphics.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ def plot_compendium(Hs, Tp, Dp, buoy_title=None, ax=None):
601601
pHs.set_ylim(0,8)
602602
pHs.tick_params(axis='y', which='major', labelsize=12, right='off')
603603
pHs.set_ylabel('Hs [m]', fontsize=18)
604-
pHs.grid(b=True, which='major', color='b', linestyle='--')
604+
pHs.grid(color='b', linestyle='--')
605605

606606
pHs2 = pHs.twinx()
607607
pHs2.set_ylim(0,25)
@@ -611,13 +611,13 @@ def plot_compendium(Hs, Tp, Dp, buoy_title=None, ax=None):
611611
# Peak Period, Tp
612612
pTp.set_ylim(0,28)
613613
pTp.set_ylabel('Tp [s]', fontsize=18)
614-
pTp.grid(b=True, which='major', color='b', linestyle='--')
614+
pTp.grid(color='b', linestyle='--')
615615

616616

617617
# Direction, Dp
618618
pDp.set_ylim(0,360)
619619
pDp.set_ylabel('Dp [deg]', fontsize=18)
620-
pDp.grid(b=True, which='major', color='b', linestyle='--')
620+
pDp.grid(color='b', linestyle='--')
621621
pDp.set_xlabel('Day', fontsize=18)
622622

623623
# Set x-axis tick interval to every 5 days
@@ -736,7 +736,7 @@ def plot_boxplot(Hs, buoy_title=None):
736736
bp.tick_params(axis='x', which='major', labelsize=12, top='off')
737737

738738
# Plot horizontal gridlines onto top subplot
739-
bp.grid(axis='x', which='major', color='b', linestyle='-', alpha=0.25)
739+
bp.grid(axis='x', color='b', linestyle='-', alpha=0.25)
740740

741741
# Remove tickmarks from bottom subplot
742742
bp2.axes.get_xaxis().set_visible(False)

0 commit comments

Comments
 (0)