#https://code.zmaw.de/projects/cdo cmd = 'cdo remapcon,'+gridfile +' '+ infile+' '+datafile os.system(cmd) #Step 2 read data and locate coherent regions ######################################################## nc = Dataset(datafile) latv = nc.variables['lat_vertices'][:,:] + np.pi/2 # shift range to (0,pi) lonv = nc.variables['lon_vertices'][:,:] indat = nc.variables['lsm'][:,:,:] indat = indat.reshape((1,indat.shape[2])) #drop unused dimension on lsm (format for aggregate() is 2D with time as shape[0]) nc.close() #build map of nearest neighbours nn = structure.nind(datafile,1) #with thresh=0.5 this gives blobs of size [406, 127, 89, 70, 39, 3, 3, 3, 2, 2, 1, 1] #nn = structure.nind(datafile,10) #enormous radius gives one big blob #set thresh (land are coded as 1 and sea is 0 in 'lsm' variable. thresh = 0.5 morethan = True blobs = structure.aggregate(indat, nn, thresh, morethan=morethan, verbose=True) #Step 3 plot the results ############################################################################ #create colormap (and normalisation funtion for lookups on blob size) #cmap = mpc.LinearSegmentedColormap.from_list(name='mycmap', colors=['m','r','y','w','g','c','b']) #cnorm = mpc.Normalize(vmin=np.min(blobs[1]), vmax=np.max(blobs[1])) # #simple lookup works better if we're just plotting the first n-largest blobs cmap = mpc.ListedColormap(['b','r','y','w','g','c','k'])
cmd = 'cdo remapcon,' + gridfile + ' ' + infile + ' ' + datafile os.system(cmd) #Step 2 read data and locate coherent regions ######################################################## nc = Dataset(datafile) latv = nc.variables['lat_vertices'][:, :] + np.pi / 2 # shift range to (0,pi) lonv = nc.variables['lon_vertices'][:, :] indat = nc.variables['lsm'][:, :, :] indat = indat.reshape( (1, indat.shape[2]) ) #drop unused dimension on lsm (format for aggregate() is 2D with time as shape[0]) nc.close() #build map of nearest neighbours nn = structure.nind( datafile, 1 ) #with thresh=0.5 this gives blobs of size [406, 127, 89, 70, 39, 3, 3, 3, 2, 2, 1, 1] #nn = structure.nind(datafile,10) #enormous radius gives one big blob #set thresh (land are coded as 1 and sea is 0 in 'lsm' variable. thresh = 0.5 morethan = True blobs = structure.aggregate(indat, nn, thresh, morethan=morethan, verbose=True) #Step 3 plot the results ############################################################################ #create colormap (and normalisation funtion for lookups on blob size) #cmap = mpc.LinearSegmentedColormap.from_list(name='mycmap', colors=['m','r','y','w','g','c','b']) #cnorm = mpc.Normalize(vmin=np.min(blobs[1]), vmax=np.max(blobs[1])) # #simple lookup works better if we're just plotting the first n-largest blobs cmap = mpc.ListedColormap(['b', 'r', 'y', 'w', 'g', 'c', 'k'])
lonc = nc.variables['lon'][:] land = nc.variables['lsm'][:, :, :] land = land.reshape((1, land.shape[2])) nc.close() #dummy five years worth of data initialized to zero indat = np.zeros((60, 2562)) #dummy some structure into the array ############################## #start with a patch at theta=0, phi=0 of radius 1 (i.e. 7 cells on the north, prime meridian) #then move it east one cell at each timestep then drop straight #back again to the surface at south pole #find neighbours (for lookup) nn = structure.nind(datafile, 1) #nn = structure.nind(datafile,2) #nn = structure.nind(datafile,3) ts = np.arange(0, indat.shape[0]) #first loop up cnt = 0 for t in ts: if 0.0 + 4 * t < 180: wpt = structure.phitheta2cell(0, 0.0 + 4 * t, latc, lonc) nni = nn[wpt] for ni in nni: indat[t, ni] = 1.0 cnt = cnt + 1 #then back down
lonc = nc.variables['lon'][:] land = nc.variables['lsm'][:,:,:] land = land.reshape((1,land.shape[2])) nc.close() #dummy five years worth of data initialized to zero indat = np.zeros((60,2562)) #dummy some structure into the array ############################## #start with a patch at theta=0, phi=0 of radius 1 (i.e. 7 cells on the north, prime meridian) #then move it east one cell at each timestep then drop straight #back again to the surface at south pole #find neighbours (for lookup) nn = structure.nind(datafile,1) #nn = structure.nind(datafile,2) #nn = structure.nind(datafile,3) ts = np.arange(0,indat.shape[0]) #first loop up cnt = 0 for t in ts: if 0.0+4*t < 180: wpt = structure.phitheta2cell(0, 0.0+4*t, latc, lonc) nni = nn[wpt] for ni in nni: indat[t,ni] = 1.0 cnt = cnt+1 #then back down