for i in list(aggregate): lnd['clst'].iloc[i] = currIx # Sao Tome (Release) ---------------------------------------------------------- currIx = currIx + 1 for i in list(notAggregate): lnd['clst'].iloc[i] = currIx currIx = currIx + 1 # Inaccesible ----------------------------------------------------------------- for i in list(notAccessible): lnd['clst'].iloc[i] = currIx currIx = currIx + 1 ############################################################################### # Checking Aggregation ############################################################################### clusters = list(lnd['clst']) aggMat = monet.aggregateLandscape(psiN, clusters) ############################################################################### # Export ############################################################################### lnd.to_csv(PTH_ROT+rid+'_v2_coords.csv', index=False) np.savetxt(PTH_ROT+rid+'_v2_migmat.csv', aggMat, delimiter=",") ############################################################################### # Export Map ############################################################################### clstIDs = list(sorted(set(lnd['clst']))) centroid = [] groupings = [] for clstID in clstIDs: tmpDF = lnd[lnd['clst'] == clstID] centroid.append([np.mean(i) for i in (tmpDF['lon'], tmpDF['lat'])]) groupings.append(list(tmpDF['id']))
########################################################################### distPath = PATH + PLACE + "_DST_" + str( CLST_METHOD) + "_" + namePad + ".csv" distMat = monet.calculateDistanceMatrix(latlongs, distFun=vn.vincenty) * 1000 # np.savetxt(distPath, distMat.astype(int), fmt='%i', delimiter=',') # heat = sns.heatmap(distMat, annot=False) # heat.get_figure().savefig(PATH + PLACE + "DIST.png", dpi=500) ########################################################################### # Export migration matrix ########################################################################### migrPath = PATH + PLACE + "_MIG_" + str( CLST_METHOD) + "_" + namePad + ".csv" zeroInflation = pow(lifeStayProb, adultMortality) migrMat = monet.zeroInflatedExponentialMigrationKernel( distMat, params=monet.AEDES_EXP_PARAMS, zeroInflation=zeroInflation) monet.testMarkovMatrix(migrMat) # np.savetxt(migrPath, migrMat, delimiter=',') # heat = sns.heatmap(migrMat, annot=False) # heat.get_figure().savefig(PATH + "MIGR.png", dpi=500) ############################################################################## # Export aggregated migration matrix ############################################################################## aggrPath = PATH + PLACE + "_AGG_" + str( CLST_METHOD) + "_" + namePad + ".csv" aggrCPath = PATH + PLACE + "_AGC_" + str(CLST_METHOD) + namePad + ".csv" aggrMat = monet.aggregateLandscape(migrMat, clusters) monet.testMarkovMatrix(aggrMat) np.savetxt(aggrPath, aggrMat, delimiter=',') np.savetxt(aggrCPath, centroids, delimiter=',')
else: clstID = clusters[i - mxNOI - 1] land.append([ cList[i][0], cList[i][1], cList[i][2], clstID + shftRef, centroids[clstID][0], centroids[clstID][1] ]) # Validate that cluster lists match each other test = [] for i in range(0, len(cList)): test.append(landClst[i] == land[i][3]) # print(all(test)) ####################################################################### # Aggregate ####################################################################### # print(migrMat.shape[0] == len(landClst)) aggrMat = monet.aggregateLandscape(migrMat, landClst) ####################################################################### # Export ####################################################################### # Define filenames lbls = clst outRepPath = PATH + OUT + "C" + str(clst).rjust(6, '0') aux.createFolder(outRepPath) placeName = LATLONGS.split("/")[1].split(".")[0].split("_")[0] filenames = outRepPath + "/" + placeName + "_" + str(rep).rjust(4, '0') # Export files np.savetxt(filenames + "_A.csv", aggrMat, delimiter=',') df = pd.DataFrame( land, columns=['ID', 'Lat', 'Lon', 'Cluster', 'CLat', 'CLon']) df.to_csv(filenames + "_I.csv", index=False)