I have a text file containing latitude and temperature values for points around the globe. I would like to take the average of all the temperature points between a specified latitude interval (i.e. every degree, from the South to the North Pole). This is the code I have so far:
data_in = genfromtxt('temperatures.txt', usecols = (0,1))
lat = data_in[:,0]
temp = data_in[:,1]
in_1N = np.where((lat>=0) & (lat<=1)) # outputs an array of indexes for all latitudes between 0°-1° North
temp_1N = temp[in_1N] # outputs an array of temperature values between 0°-1° North
avg_1N = np.nanmean(temp_1N) # works out the average of temperatures between 0°-1° North
plt.scatter(1, avg_1N) # plots the average temperature against the latitude interval
plt.show()
How could I improve this code, so it can be implemented 180 times to cover the Earth between -90°S and 90°N? Thanks
