Last active
July 4, 2018 03:32
-
-
Save monocongo/da6f9500173a33d207fee4002ad169cd to your computer and use it in GitHub Desktop.
The below code causes an error with Numba. The issue appears to be around the variables PV and V, i.e. if we comment out line 70 the error does not occur. This code is a minimal complete example of the issue that is occuring when executing a larger Python file from which this code was extracted.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numba | |
import numpy as np | |
@numba.jit | |
def _pdsi_from_zindex(Z): | |
## INITIALIZE PDSI AND PHDI CALCULATIONS | |
# V is the sum of the Uw (Ud) values for the current and previous months of an | |
# established dry (wet) spell and is used in calculating the Pe value for a month. | |
V = 0.0 | |
Pe = 0.0 # the probability that the current wet or dry spell has ended in a month | |
X1 = 0.0 # the severity index value for an incipient wet spell for a month | |
X2 = 0.0 # the severity index value for an incipient dry spell for a month | |
X3 = 0.0 # the severity index value of the current established wet or dry spell for a month | |
number_of_months = Z.shape[0] | |
# initialize arrays | |
PX1 = np.zeros((number_of_months,)) | |
PX2 = np.zeros((number_of_months,)) | |
PX3 = np.zeros((number_of_months,)) | |
PPe = np.zeros((number_of_months,)) | |
X = np.zeros((number_of_months,)) | |
PMDI = np.zeros((number_of_months,)) | |
# loop over all months in the dataset, calculating PDSI and PHDI for each | |
for k in range(number_of_months): | |
pass | |
if (Pe == 100) or (Pe == 0): # no abatement underway | |
if abs(X3) <= 0.5: # drought or wet spell ends | |
# PV is the preliminary V value and is used in operational calculations. | |
PV = 0 | |
elif X3 > 0.5: # Wet spell underway | |
if Z[k] >= 0.15: # Wet spell intensifies | |
pass | |
else: # Wet spell starts to abate, and it may end. | |
pass | |
elif X3 < -0.5: # Drought underway | |
if Z[k] <= -0.15: # Drought intensifies | |
pass | |
else: # Drought starts to abate, and it may end. | |
pass | |
else: # Abatement underway | |
if X3 > 0: # Wet spell underway | |
pass | |
else: # Drought underway | |
pass | |
## Assign V, Pe, X1, X2, and X3 for use with the next month | |
V = PV | |
Pe = PPe[k] | |
X1 = PX1[k] | |
X2 = PX2[k] | |
X3 = PX3[k] | |
# round values to four decimal places | |
for values in [X1, X2, X3, Pe, V, X, PX1, PX2, PX3, PPe]: | |
values = np.around(values, decimals=4) | |
# return the computed variables | |
return X, PMDI | |
#----------------------------------------------------------------------------------------------------------------------- | |
if __name__ == '__main__': | |
z = np.array([ | |
-1.020, 1.631, -0.828, 1.453, 0.802, -8.602, 0.291, 0.476, 0.226, 1.368, 0.415, -0.219, \ | |
0.856, -0.302, -0.738, -0.703, -0.040, 8.376, -0.183, -1.259, 0.575, -1.228, 0.569, 0.011, \ | |
-0.029, 0.975, -1.302, 0.602, -0.698, 0.716, 2.791, -2.360, 2.602, 0.977, -0.908, 0.132]) | |
_pdsi_from_zindex(z) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment