Skip to content

Commit

Permalink
Add numpy import and enhance error handling in metering.py
Browse files Browse the repository at this point in the history
  • Loading branch information
chagenvik committed Jan 7, 2025
1 parent 98d9717 commit ba6fbda
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pvtlib/metering.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"""

from math import sqrt, pi
import numpy as np

#%% Venturi equations
def calculate_flow_venturi(D, d, dP, rho1, C=None, epsilon=None):
Expand Down Expand Up @@ -131,6 +132,10 @@ def calculate_expansibility_venturi(P1, dP, beta, kappa):
P2 = P1 - (dP/1000) # Convert dP from mbar to bar
tau = P2/P1

# Isentropic exponent cannot be equal to 1, as it would result in division by zero. Return NaN in this case.
if kappa==1:
return np.nan

# Calculate expansibility factor
epsilon = sqrt((kappa*tau**(2/kappa)/(kappa-1))*((1-beta**4)/(1-beta**4*tau**(2/kappa)))*(((1-tau**((kappa-1)/kappa))/(1-tau))))

Expand Down Expand Up @@ -320,6 +325,9 @@ def calculate_beta_V_cone(D, dc):
'''

if D<=0.0:
raise Exception('ERROR: Negative diameter input. Diameter (D) must be a float greater than zero')

beta = sqrt(1-((dc**2)/(D**2)))

return beta

0 comments on commit ba6fbda

Please sign in to comment.