def Compute_HRUs_Semidistributed_Hillslope(covariates,mask,nclusters,hydrobloks_info): time0 = time.time() dem = covariates['demns'] res = hydrobloks_info['dx'] hillslope_info = hydrobloks_info['hillslope_info'] nclusters = hillslope_info['nhillslopes'] #characteristic hillslope #Calculate mfd accumulation area mfd_area = terrain_tools.ttf.calculate_mfd_acc(dem,res,1) mfd_area[mask == 0] = 0.0 #Calculate mfd topographic index mfd_ti = np.log(mfd_area/res/covariates['cslope']) #Calculate d8 accumulation area (area,fdir) = terrain_tools.ttf.calculate_d8_acc(dem,res) area[mask == 0] = 0.0 #Define the channels channels = terrain_tools.ttf.calculate_channels(area,10**6,3*10**7,fdir) #Define the basins basins = terrain_tools.ttf.delineate_basins(channels,mask,fdir) #Define the depth to channel depth2channel = terrain_tools.ttf.calculate_depth2channel(channels,basins,fdir,dem) #Define the hillslopes hillslopes = terrain_tools.ttf.calculate_hillslopesd8(channels,basins,fdir) #Calculate the hillslope properties latitude = covariates['lats'].T longitude = covariates['lons'].T hp = terrain_tools.calculate_hillslope_properties(hillslopes,dem, basins,res,latitude.T,longitude.T,depth2channel) #Cluster the hillslopes (hillslopes_clusters,nhillslopes) = terrain_tools.cluster_hillslopes(hp,hillslopes,nclusters) #Create the hrus '''covariates = {#'depth2channel':{'data':depth2channel,'nbins':nclusters_tiles}, #'clay':{'data':covariates['clay'],'nbins':hillslope_info['clay']}, 'ndvi':{'data':covariates['ndvi'],'nbins':hillslope_info['ndvi']}, #'ti':{'data':mfd_ti,'nbins':hillslope_info['ti']}, 'acc':{'data':area,'nbins':10}, #'depth2channel':{'data':depth2channel,'nbins':10 }''' covariates = {#'depth2channel':{'data':depth2channel}, #'clay':{'data':covariates['clay']}, #'sand':{'data':covariates['sand']}, #'ndvi':{'data':covariates['ndvi']}, #'ksat':{'data':np.log10(covariates['SATDK'])}, #'refsmc':{'data':covariates['REFSMC']}, #'slope':{'data':covariates['cslope']}, #'smcmax':{'data':covariates['MAXSMC']}, #'d2c':{'data':depth2channel}, #'acc':{'data':np.log10(area)}, 'ti':{'data':mfd_ti}, } hrus = terrain_tools.create_tiles_kmeans(hillslopes_clusters,covariates,100) #hrus = terrain_tools.create_nd_histogram(hillslopes_clusters,covariates)-1 hrus = hrus.astype(np.float32) hrus[channels > 0] = np.max(hrus) + 1 nhrus = int(np.max(hrus) + 1) print '%d hrus' % (nhrus),time.time() - time0 return (hrus,nhrus)
def Compute_HRUs_Semidistributed_Basin(covariates,mask,nclusters,hydrobloks_info): time0 = time.time() dem = covariates['demns'] res = hydrobloks_info['dx'] basin_info = hydrobloks_info['basin_info'] nbasins = basin_info['nbasins'] #characteristic hillslope ntiles = basin_info['nclusters'] #Calculate mfd accumulation area mfd_area = terrain_tools.ttf.calculate_mfd_acc(dem,res,1) mfd_area[mask == 0] = 0.0 #Calculate mfd topographic index mfd_ti = np.log(mfd_area/res/covariates['cslope']) #Calculate d8 accumulation area (area,fdir) = terrain_tools.ttf.calculate_d8_acc(dem,res) area[mask == 0] = 0.0 #Define the channels channels = terrain_tools.ttf.calculate_channels(area,10**6,10**6,fdir) #Define the basins basins = terrain_tools.ttf.delineate_basins(channels,mask,fdir) #Calculate the basin properties lats = np.linspace(0,1,basins.shape[0]) lons = np.linspace(0,1,basins.shape[1]) (latitude,longitude) = np.meshgrid(lats,lons) bp = terrain_tools.calculate_basin_properties(basins,res,latitude.T,longitude.T,fdir) #Reduce the number of basins to the desired number basins = terrain_tools.reduce_basin_number(basins,bp,nbasins) #Define the depth to channel depth2channel = terrain_tools.ttf.calculate_depth2channel(channels,basins,fdir,dem) #Compute the accumulated values (acc_ksat,fdir) = terrain_tools.ttf.calculate_d8_acc_alt(dem,res,covariates['SATDK']) (acc_slope,fdir) = terrain_tools.ttf.calculate_d8_acc_alt(dem,res,covariates['cslope']) #(acc_ndvi,fdir) = terrain_tools.ttf.calculate_d8_acc_alt(dem,res,covariates['ndvi']) #Determine how many neighboring cells converge to this one neighbor_count = terrain_tools.ttf.calculate_d8_acc_neighbors(dem,res,np.ones(dem.shape)) neighbor_sti = terrain_tools.ttf.calculate_d8_acc_neighbors(dem,res,covariates['sti']) neighbor_sti[neighbor_count > 0] = neighbor_sti[neighbor_count > 0]/neighbor_count[neighbor_count > 0] covariates = {#'depth2channel':{'data':depth2channel}, #'clay':{'data':covariates['clay']}, #'sand':{'data':covariates['sand']}, #'ndvi':{'data':acc_ndvi/area}, 'ndvi':{'data':covariates['ndvi']}, #'nlcd':{'data':covariates['nlcd']}, 'ksat_alt':{'data':np.log10(900*acc_ksat/area)}, 'ksat':{'data':np.log10(covariates['SATDK'])}, #'slope':{'data':np.log10(covariates['cslope'])}, #'slope_alt':{'data':900*acc_slope/area}, 'neighbor_count':{'data':neighbor_count}, #'neighbor_sti':{'data':neighbor_sti}, #'refsmc':{'data':covariates['REFSMC']}, #'slope':{'data':covariates['cslope']}, #'smcmax':{'data':covariates['MAXSMC']}, #'d2c':{'data':depth2channel}, 'acc':{'data':np.log10(area)}, #'sti':{'data':covariates['sti']}, #'lats':{'data':covariates['lats']}, #'lons':{'data':covariates['lons']}, } hrus = terrain_tools.create_tiles_kmeans(basins,covariates,ntiles) #hrus = terrain_tools.create_nd_histogram(basins,covariates)-1 hrus = hrus.astype(np.float32) hrus[hrus < 0] = -9999 #hrus[channels > 0] = np.max(hrus) + 1 #nhrus = int(np.max(hrus) + 1) nhrus = int(np.max(hrus) + 1) print '%d hrus' % (nhrus),time.time() - time0 return (hrus,nhrus)