<jupyter_start><jupyter_text>Summer > 70<jupyter_code>ice_ds_201809 = xr.open_dataset(meanDir + "mercatorglorys12v1_gl12_mean_201809.nc")
with open('/scratch/DaanR/meshes/ico_mesh_hex_r7.pickle', 'rb') as meshPick:
    meshDict = pickle.load(meshPick)
myBinsOver70 = community.hexCountBins(meshDict['points'], 
                                np.degrees(meshDict['lons']), 
                                np.degrees(meshDict['lats']), 
                                meshDict['permutation'], 
                                meshDict['simplices'])
myMaskOver70 = community.hexMask(myBinsOver70, -180, 180, 60, 90)
myMaskOver70.growToLevel(4)
myBinsOver70.calculate_voronoi(myMaskOver70, innerMaskLevel=2, outerMaskLevel=3)
#myBins.add_regular_rim()
myBinsOver70.calculate_neighbors()
del meshDict
with open("oceanMask_no_rim.pickle", 'rb') as pickFile:
    myBinsOver70.oceanMask = pickle.load(pickFile)
myBinsOver70.oceanMask = np.logical_and(myBinsOver70.oceanMask, myBinsOver70.lats[myBinsOver70.mask[3]] > 70)
transMaskOver70 = myBinsOver70.lats[myBinsOver70.mask[3]][myBins.oceanMask] > 70
transMaskOver70
pset_201809 = xr.open_dataset(psetdir + "pset_Rcmems_Pico11_S2018-9-1_D90_DT20_ODT24.nc")
inDomain = pset_201809.lat[:,0]>70
outBounder = np.nonzero(pset_201809.lat[inDomain,:] <70)
n = pset_201809.lat[inDomain,:].shape[0]
terminalIndex = np.ones(n)*90
saved = set()
for i in range(outBounder.shape[1]):
    currPart = int(outBounder[0,i].values)
    if currPart not in saved:
        saved.update([currPart])
        terminalIndex[currPart] = int(outBounder[1, i])
lonlatInit = np.dstack((pset_201809.lon[inDomain, 0], pset_201809.lat[inDomain, 0]))
lonFinal = pset_201809.lon[inDomain, :].data[np.arange(n), terminalIndex.astype('int')]
latFinal = pset_201809.lat[inDomain, :].data[np.arange(n), terminalIndex.astype('int')]
lonlatFinal = np.dstack((lonFinal, latFinal))
transMat_20180301_over70 = community.transMat.from_lonlat(lonlatInit, 
                                                       lonlatFinal, 
                                                       countBins = myBinsOver70, 
                                                       mask = myBinsOver70.oceanMask)
transMat_20180301_over70.save_counter(matdir + f"masked_counter_Rcmems_Pico11_S2018-9-1_D90_DT20_ODT24_Cico7_over70subsel")
transMat_20180301_over70.save_network(netdir + f"masked_network_Rcmems_Pico11_S2018-9-1_D90_DT20_ODT24_Cico7_over70subsel.net")
transMat_20180301 = community.transMat.from_counter_npz(matdir + f"masked_counter_Rcmems_Pico11_S2018-9-1_D90_DT20_ODT24_Cico7.npz")
transMat_20180301_over70 = community.transMat.from_counter_npz(matdir + f"masked_counter_Rcmems_Pico11_S2018-9-1_D90_DT20_ODT24_Cico7_over70subsel.npz")<jupyter_output><empty_output><jupyter_text>What percentage of entries of the transition matrix with particles terminated below 70N is equal to the original transition matrix?<jupyter_code>np.sum(np.sum(transMat_20180301.data[transMaskOver70, :][:, transMaskOver70] == transMat_20180301_over70.data, axis=0) == np.ones(4344)*4344)/4344
plot.scatter_from_dataset(lonlatFinal[0,:,0], 
                          lonlatFinal[0,:,1], 
                          latRange = (60,90),
                          polar=True,
                          s=0.3)
np.expand-np.zeros_like(myBinsOver70.bindex).shape
ensembleCommunityID_201809_over70 = {}
codelengths_201809_over70 = []
globalMixing_201809_over70 = []
globalCoherence_201809_over70 = []

avg_mixing_201809_over70 = np.zeros_like(myBinsOver70.bindex)
avg_coherence_201809_over70 = np.zeros_like(myBinsOver70.bindex)
avg_boundary_201809_over70 = np.zeros_like(myBinsOver70.bindex)
boundaries_over70 = np.zeros((myBinsOver70.bindex.shape[0], 100))
avg_global_mixing_201809_over70 = 0
avg_global_coherence_201809_over70 = 0

for run in range(1, 101):
    myBinsOver70.load_communities(comdir + f"ensemble_masked_network_Rcmems_Pico11_S2018-9-1_D90_DT20_ODT24_Cico7_over70subsel_mt2/masked_network_Rcmems_Pico11_S2018-9-1_D90_DT20_ODT24_Cico7_over70subsel_mt2_multirunN{run}.clu")
    ensembleCommunityID_201809_over70[run-1] = myBinsOver70.communityID
    codelengths_201809_over70.append(myBinsOver70.codelength)
    
    myBinsOver70.find_adjacency();
    avg_boundary_201809_over70 = avg_boundary_201809_over70 + myBinsOver70.flag_on_boundary();
    myBinsOver70.color_communities();
    avg_coherence_201809_over70 = avg_coherence_201809_over70 + myBinsOver70.calculate_coherence_ratio(transMat_20180301_over70);
    avg_mixing_201809_over70 = avg_mixing_201809_over70 + myBinsOver70.calculate_mixing(transMat_20180301_over70);
    avg_global_coherence_201809_over70 = avg_global_coherence_201809_over70 + myBinsOver70.calculate_global_coherence()
    avg_global_mixing_201809_over70 = avg_global_mixing_201809_over70 + myBinsOver70.calculate_global_mixing()
    globalMixing_201809_over70.append(myBinsOver70.globalMixing)
    globalCoherence_201809_over70.append(myBinsOver70.globalCoherenceRatio)
    boundaries_over70[:, run-1] = myBinsOver70.onBoundary
    
avg_mixing_201809_over70 = avg_mixing_201809_over70/100
avg_coherence_201809_over70 = avg_coherence_201809_over70/100
avg_boundary_201809_over70 = avg_boundary_201809_over70/100
avg_global_mixing_201809_over70 = avg_global_mixing_201809_over70/100
avg_global_coherence_201809_over70 = avg_global_coherence_201809_over70/100
print("Average Global Coherence Ratio", avg_global_coherence_201809_over70)
print("Average Global Mixing Parameter", avg_global_mixing_201809_over70)
with open("average_boundary_ensemble_masked_network_Rcmems_Pico11_S2018-9-1_D90_DT20_ODT24_Cico7_mt2.pickle", "rb") as pickFile:
    avg_boundary_201809 = pickle.load(pickFile)
svDomainMask70 = np.logical_and(myBinsOver70.svDomainMask, (myBinsOver70.svTriCenterLats > 70)[myBinsOver70.svSimplices[:,0]])
fig, ax = plot.triangular_field_from_dataset(myBinsOver70.svTriLons, 
                                             myBinsOver70.svTriLats, 
                                             myBinsOver70.svSimplices[svDomainMask70],
                                             avg_boundary_201809_over70[myBinsOver70.hexBindex][myBinsOver70.svSimplices[:,0][svDomainMask70]], 
                                             lonRange = (-180, 180),
                                             latRange = (60, 90),
                                             land = True,
                                             colormap = 'viridis', vmin=0, vmax=1,
                                             size = (5,5),
#                                             export = f"{comName}.png",
                                             cbar=True,
                                             polar = True,
                                             units = "boundary occurrence"
                                            )
ax.contour(ice_ds_201809.longitude, ice_ds_201809.latitude[1680:], ice_ds_201809.siconc[0, 1680:, :], levels=np.array([0.15]), colors='white', transform=ccrs.PlateCarree())
plt.savefig(f"figures/average_boundary_ensemble_masked_network_Rcmems_Pico11_S2018-9-1_D90_DT20_ODT24_Cico7_over70subsel_mt2.png", dpi=300, bbox_inches='tight')
std_degeneracy = np.mean(np.std(boundaries_over70[myBinsOver70.oceanMask], axis=1))
mask_exceed_boundary_std = np.abs(avg_boundary_201809 - avg_boundary_201809_over70)>(np.std(boundaries_over70, axis=1))
avg_boundary_201809_over70_significant = np.where(mask_exceed_boundary_std, (avg_boundary_201809 - avg_boundary_201809_over70), np.nan)
avg_boundary_201809_over70_significant = np.ma.masked_array(avg_boundary_201809_over70_significant, np.isnan(avg_boundary_201809_over70_significant))
fig, ax = plot.triangular_field_from_dataset(myBinsOver70.svTriLons, 
                                             myBinsOver70.svTriLats, 
                                             myBinsOver70.svSimplices[svDomainMask70],
                                             avg_boundary_201809_over70_significant[myBinsOver70.hexBindex][myBinsOver70.svSimplices[:,0][svDomainMask70]], 
                                             lonRange = (-180, 180),
                                            latRange = (60, 90),
                                            land = True,
                                            colormap = cc.cm.bkr, vmin=-1, vmax=1,
                                            size = (5,5),
#                                             export = f"{comName}.png",
                                            cbar=True,
                                            polar = True,
                                            units = "boundary occurrence difference"
                                            )
plt.savefig(f"figures/difference_in_average_boundary_ensemble_masked_network_Rcmems_Pico11_S2018-9-1_D90_DT20_ODT24_Cico7_over70subsel_mt2_significant", dpi=300, bbox_inches='tight')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08905109489051095, 'fraction_numerical': 0.10791690061763054, 'mean_word_length': 2.951197870452529, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 58, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '452453', 'license': 'MIT', 'n_tokens_mistral': 3662, 'n_tokens_neox': 3006, 'n_words': 303, 'path': 'community_detection/moving_boundary.ipynb', 'repo_name': 'pelperscience/arctic-connectivity', 'size': '8905'}