I have downloaded the CMIP5 climate model HadGEM2-CC in a nc file. I know how to extract data for a given longitude and latitude, now I would like to do it over a range of longitude and latitude rather than individually extract data.
How do I do it for a longitude range and latitude range of: 0 to 90 and 50 to 80, respectively? Below is my code:
tcmodel = Dataset(path + '/treeFrac_Lmon_HadGEM2-CC_rcp85_r2i1p1_203012-205511.nc')
print(tcmodel.variables.keys())
lon = tcmodel.variables['lon']
lat = tcmodel.variables['lat']
time = tcmodel.variables['time']
tc = tcmodel.variables['treeFrac']
print(tcmodel.dimensions.items())
lon_array = lon[:]
lat_array = lat[:]
time_array = time[:]
date = datetime.datetime(1959, 12, 1)
tc_array = tc[:,:,:]
time = []
for i in time_array:
time.append(date + datetime.timedelta(i))
time = np.array(time, dtype = 'datetime64')
k = [245:257]
i = np.abs(lon_array - 90).argmin() #This I would like to change to a range
j = np.abs(lat_array - 80).argmin() #This I would like to change to a range
tc_time = tc_array[k,j,i]
How can I do it for the range of longitude and latitude?