temp_list = [] with open( "data/step9_regional_builtuppop/regional_builtuppop_sorted_" + str(meshID) + ".csv", "r", encoding="utf-8") as input_file2: for line in input_file2: NewLine = line.strip() #NewLine = NewLine[:-1] NewLine = NewLine.strip().split(",") temp_list.append(NewLine) TotalCell += float(temp_list[AggloID][1]) GlobalAggloIDFullLIST[index].insert(0, TotalCell) GlobalAggloIDFullLIST.sort(reverse=True) filename = "data/step12_global_builtuppop/global_builtuppop_final_sorted.csv" metadata.writeout(GlobalAggloIDFullLIST, filename) #with open("data/step12_global_builtuppop/global_builtuppop_final_sorted.csv" , "w" , encoding="utf-8") as output_file: # for each_row in GlobalAggloIDFullLIST: # for each_field in each_row: # output_file.write(str(each_field)+",") # output_file.write("\n") print( "#####################\nPart 12.5 program END.\n#####################")
###### END ########################################################## ###################################################################### # GlobalAggloPOP # ###### START ######################################################### GlobalAggloINFO.insert(0, TotalPopulation) ###### END ########################################################## ###################################################################### # BigPicture = [[GlobalAggloINFO], [GlobalAggloINFO]] # ###### START ######################################################### BigPicture.append(GlobalAggloINFO) ###### END ########################################################## BigPicture.sort(reverse=True) for (NumOfGlobalAgglo, NumOfGlobalAggloINFO) in enumerate(BigPicture): ID = NumOfGlobalAgglo BigPicture[NumOfGlobalAgglo].insert(0, ID) filename = "data/step13_bigpicture_builtuppop/bigpicture_builtuppop.csv" metadata.writeout(BigPicture, filename) #with open("data/step13_bigpicture_builtuppop/bigpicture_builtuppop.csv" , "w") as output_file: # for each_row in BigPicture: # for each_field in each_row: # output_file.write(str(each_field)+",") # output_file.write("\n") print("#####################\nPart 13 program END.\n#####################")
ValueBuffer = position if check == 1: MarginalCellPosition.append(ValueBuffer) if len(MarginalCellPosition) != 0: OneMarginalAggloDATA.append(RegionalAggloIDENTITY) OneMarginalAggloDATA = OneMarginalAggloDATA + MarginalCellPosition buffer = OneMarginalAggloDATA[:] MarginalAgglomerationsLIST.append(buffer) #print("RegionalAggloIDENTITY\t",RegionalAggloIDENTITY) #print(OneMarginalAggloDATA) #print(MarginalAgglomerationsLIST) filename = "data/step10_marginal_builtuppop/marginal_builtuppop.csv" metadata.writeout(MarginalAgglomerationsLIST, filename) #with open("data/step10_marginal_builtuppop/marginal_builtuppop.csv" , "w" , encoding="utf-8") as output_file: # for each_row in MarginalAgglomerationsLIST: # for each_field in each_row: # output_file.write(str(each_field)+",") # output_file.write("\n") print("Discover in total " + str(len(MarginalAgglomerationsLIST)) + " of marginal agglomerations.") print( "#####################\nPart 10 program END. All agglomeration data is output.\n#####################" )
2] += ValueC totalpopadd += ValueC if tempPop[1][1] != 0: if BuiltupOrNotInformation[1][1] == 0: ValueD = tempPop[1][1] * (0.25 / 6.25) PopulationAssignedBuiltupMatrix[PopCoorY * 5 + 2][PopCoorX * 5 + 2] += ValueD totalpopadd += ValueD deviation = totalpopadd - sum([Q1pop, Q2pop, Q3pop, Q4pop]) if deviation != totalpopadd: if deviation >= 0.01: print(meshID, PopCoorY * 2, PopCoorX * 2, deviation) #print(count) #count += 1 filename = "data/step8_builtuppop_data/PopulationAssignedBuiltup_" + str( meshID) + ".csv" metadata.writeout(PopulationAssignedBuiltupMatrix, filename) #for each_row in RegionalAggloLIST: # for each_field in each_row: # (Y,X) = each_field # CellID = str(meshID)+"_"+str(Y)+"_"+str(X) #+"_"+str(DistributionMap[Y][X]) # output_file.write(str(CellID)+",") # output_file.write("\n") print("#####################\nPart 8 program END.\n#####################")
im.save("data/outputdata/step1_populationmap/populationmap_" + year + '.tif') print("Map is output") if __name__ == "__main__": while True: #query = input("Which year? : ") #if query != "quit": target = ["1995", "2000", "2005", "2010", "2015"] for year in target: query = year requestedpopmatrix = drawpopulationmatrix(query) filename = "data/outputdata/step1_populationmap/populationmap_" + str( query) + ".csv" metadata.writeout(requestedpopmatrix, filename) drawpopulationmap(requestedpopmatrix, year) break #elif query == "quit": # break print("#####################\nPart 1 program END. \n#####################")
for eachAggloDATA in NeededDATA: cellDATAs = eachAggloDATA[2:] for eachCell in cellDATAs: CellINFO = eachCell.split("_") meshID = int(CellINFO[0]) cellY = int(CellINFO[1]) cellX = int(CellINFO[2]) cellPopulation = float(CellINFO[3]) matrix[cellY][cellX] = cellPopulation #################### finalCSV = [] for Y in range(800): for X in range(800): A = int(cellNoConverter[Y][X]) B = float(matrix[Y][X]) if B != 0: finalCSV.append([A, B]) filename = "data/step15_GISBuiltupPOP/" + str( GlobalAggloID) + "_" + str(meshID) + "_builtuppop.csv" metadata.writeout(finalCSV, filename) elif query == "quit": break print("#####################\nPart 15 program END.\n#####################")
# for each_field in each_row: # output_file.write(str(each_field)+",") # output_file.write("\n") #print("Part12.1 is finished.") FinalGlobalAggloIDFullLIST = [] for TotalNumberOfGlobalAgglo in range(len(GlobalAggloIDFullLIST)): GlobalAggloINFO = GlobalAggloIDFullLIST[TotalNumberOfGlobalAgglo][1] if (GlobalAggloINFO in FinalGlobalAggloIDFullLIST) == False: FinalGlobalAggloIDFullLIST.append(GlobalAggloINFO) outputLIST = [] for rows in FinalGlobalAggloIDFullLIST: temp_row = [] for fields in rows: buffer = fields temp_row.append(buffer) outputLIST.append(temp_row) filename = "data/step12_global_builtuppop/global_builtuppop_final.csv" metadata.writeout(outputLIST, filename) #with open("data/step12_global_builtuppop/global_builtuppop_final.csv" , "w" , encoding="utf-8") as output_file: # for each_row in FinalGlobalAggloIDFullLIST: # for each_field in each_row: # output_file.write(str(each_field)+",") # output_file.write("\n") print("#####################\nPart 12 program END.\n#####################")
existence_checker = 0 #print("Discovery of inter-mesh agglomeration !") if (existence_checker == 0) or (existence_checker == -1): #print("C",str(existence_checker)) #print("Discovery of inter-mesh agglomeration !") #print(temp_result) adjcent_agglomerations.append(temp_result) existence_checker = -1 # here we should finished all scanning process # we can output our result #print(len(adjcent_agglomerations)) #for i in range(10): # print(adjcent_agglomerations[i]) filename = "data/step4_adjcent_agglomeration_data/adjcent_agglomerations.csv" metadata.writeout(adjcent_agglomerations, filename) #with open("data/adjcent_agglomeration_data/adjcent_agglomerations.csv" , "w") as output_file: # for each_row in adjcent_agglomerations: # for each_field in each_row: # output_file.write(str(each_field)+",") # output_file.write("\n") print( "#####################\nPart 4 program END. All Adjcent Agglomerations data are output.\n#####################" )
mesh = int(CellINFO[0]) Y = int(CellINFO[1]) X = int(CellINFO[2]) P = float(CellINFO[3]) RegionalAggloPopulation += P buffer = CellID RegionalAggloNewLIST.append(buffer) RegionalAggloNewLIST.insert(0, RegionalAggloPopulation) meshDATA.append(RegionalAggloNewLIST) meshDATA.sort(reverse=True) for index in range(len(meshDATA)): meshDATA[index].insert(0, index) filename = "data/step9_regional_builtuppop/regional_builtuppop_sorted_" + str( meshID) + ".csv" metadata.writeout(meshDATA, filename) #with open("data/step2_regional_agglomeration_data/agglomeration_sorted_"+str(meshID)+".csv" , "w" , encoding="utf-8") as output_file: # for each_row in meshDATA: # for each_field in each_row: # output_file.write(str(each_field)+",") # output_file.write("\n") print( "#####################\nPart 9.5 program END.\n#####################")
def defferentiate(universe): matrixLocalChange = [] matrixLocalZ = [] matrixLocalStddev = [[0 for i in range(5120)] for j in range(6240)] matrixLocalCV = [[0 for i in range(5120)] for j in range(6240)] matrixLocalCVcsv = [] for rows in range(6240): for fields in range(5120): condition1 = int(universe[1][rows][fields]) != 0 condition2 = int(universe[2][rows][fields]) != 0 condition3 = int(universe[3][rows][fields]) != 0 condition4 = int(universe[4][rows][fields]) != 0 conditionsum = condition1 or condition2 or condition3 or condition4 if conditionsum == True: CellYX = str(rows) + "_" + str(fields) changelist = [] for n in range(len(universe) - 1): before = universe[n][rows][fields] after = universe[n + 1][rows][fields] pplchange = int(after) - int(before) changelist.append(pplchange) #print(changelist) changemean = sum(changelist) / len(changelist) changevariantlist = [] for n in changelist: variant = (n - changemean)**2 changevariantlist.append(variant) samplestddev = (sum(changevariantlist) / (len(changelist) - 1))**(1 / 2) changezscore = [] for n in changelist: if samplestddev != 0: zscore = (n - changemean) / samplestddev changezscore.append(zscore) if changemean != 0: CV = (samplestddev * 100) / changemean matrixLocalCV[rows][fields] = round(CV, 12) CVcsv = [CellYX, CV / 100] matrixLocalCVcsv.append(CVcsv) matrixLocalStddev[rows][fields] = samplestddev changelist.insert(0, CellYX) changezscore.insert(0, CellYX) matrixLocalChange.append(changelist) matrixLocalZ.append(changezscore) #filenameChange = "data/outputdata/step2_populationdifference/LocalChange.csv" #metadata.writeout(matrixLocalChange,filenameChange) #filenameZ = "data/outputdata/step2_populationdifference/LocalZ.csv" #metadata.writeout(matrixLocalZ,filenameZ) #filenameS = "data/outputdata/step2_populationdifference/Localstddev.csv" #metadata.writeout(matrixLocalStddev,filenameS) filenameCV = "data/outputdata/step2_populationdifference/LocalCV.csv" metadata.writeout(matrixLocalCVcsv, filenameCV) #filenameStddev = "Localstddev" #drawmap(matrixLocalStddev,filenameStddev,2) filenameCV = "LocalCV" drawmap(matrixLocalCV, filenameCV, 1)
zmax = max(localzscore) matrixslopezmax[Y][X] = zmax sparezscoreinventory = globalzscore[:] sparezscoreinventory.sort() newzscoreinventory = [] storedlist = [] for item in sparezscoreinventory: if (item in storedlist) == False : buffer = item quantity = sparezscoreinventory.count(buffer) newzscoreinventory.append([buffer,quantity]) storedlist.append(buffer) filename = "data/step16_1stderivativeBuiltupPOP/GlobalAggloID_"+str(GlobalAggloID)+"_slopeinventory.csv" metadata.writeout(newzscoreinventory,filename) filenameslopezmax = "GlobalAggloID_" + str(GlobalAggloID) + "_slopezmax" drawmap(matrixslopezmax,filenameslopezmax) filenameslopemean = "GlobalAggloID_" + str(GlobalAggloID) + "_slopemean" drawmap_logistic(matrixslopemean,filenameslopemean) elif query == "quit": break print("#####################\nPart 16 program END.\n#####################")
#print(4, ScannedCells) #print(5, RegionalAgglo) #print(6, RegionalAggloLIST) RegionalAggloLIST.append(RegionalAgglo) #print(7, RegionalAggloLIST) Final_RegionalAggloLIST = [] for rows in RegionalAggloLIST : templist = [] for each_field in rows: (Y,X) = each_field CellID = str(meshID)+"_"+str(Y)+"_"+str(X)+"_"+str(DistributionMap[Y][X]) templist.append(CellID) Final_RegionalAggloLIST.append(templist) filename = "data/step9_regional_builtuppop/regional_builtuppop_" + str(meshID) + ".csv" metadata.writeout(Final_RegionalAggloLIST,filename) #for each_row in RegionalAggloLIST: # for each_field in each_row: # (Y,X) = each_field # CellID = str(meshID)+"_"+str(Y)+"_"+str(X) #+"_"+str(DistributionMap[Y][X]) # output_file.write(str(CellID)+",") # output_file.write("\n") print("#####################\nPart 9 program END.\n#####################")