Reputation:
Can someone explain why I am getting this error?
from netCDF4 import Dataset
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
datapath = r"C:\Users\matth\Downloads\MYD04_L2_v6.0_110E155E_045S010S.A2010_calcv2_dod_flg1.nc"
f = Dataset(datapath)
for i in range(0, 30):
dod = f.variables['dod_modis_flg1'][i]
dod[dod == 0] = np.nan
def nan_if(arr, value):
return np.where(arr == value, np.nan, arr)
mean = np.nanmean([nan_if(dod, -9.99)])
print(mean)
#print(np.nanmax(dod))
#print(np.nanmin([nan_if(dod, -9.99)]))
dod_high = dod[(dod > mean) & (dod != 0)]
anomalies = []
for val in dod_high:
if val > mean:
#print(anomalies)
dod_high_indices1 = np.where((dod > mean) & (dod != 0))
dod_high_indices2 = np.array(np.where((dod > mean) & (dod != 0))).T
anomalies_ind = []
for ind in dod_high_indices2:
anomalies_ind.append(ind)
print(np.asarray(anomalies_ind))
OUTPUT:
%run "C:/Users/matth/dod_anomalies.py"
File "C:\Users\matth\dod_anomalies.py", line 26
dod_high_indices1 = np.where((dod > mean) & (dod != 0))
^
IndentationError: expected an indented block
It seems to me that the indentation of my code is correct... for some reason, I keep on getting this error.
Upvotes: 0
Views: 2760
Reputation: 875
Python is expecting something after
if val > mean:
It ignores the commented block. If you have an empty if statement like that, just put in pass, so python knows that it is there.
if val>mean:
#print(anomalies)
pass
Upvotes: 3
Reputation: 280237
An if
needs a body, and in
for val in dod_high:
if val > mean:
#print(anomalies)
a comment doesn't count. You could make the body pass
, or comment out the if
(or the whole loop), but in context, it seems like you might have more serious problems. Even uncommented, that print
would only ever have printed []
.
Upvotes: 1