def process_calc(bAuthenticate): # connect to MongoDB client = MongoClient() db = client[database] # DB authentication if required if bAuthenticate: bLoggedIn = db.authenticate(username, password, source=source_database) else: bLoggedIn = True if bLoggedIn: logger.info("Authenticated") pd = db.Project.find_one({"project_code":"MFW001_0-010 Metro Paris-Ligne 15_T2A"}) if pd: logger.info("Project %s found", pd["project_name"]) p = Project(db, pd) p.load() found_domains = Domain.find(db, {"project_id": p._id}) for dom in found_domains: d = Domain(db, dom) d.load() asets = db.AlignmentSet.find({"domain_id": d._id}) for aset in asets: a_set = AlignmentSet(db, aset) a_set.load() #sCode = a_set.item["code"] als = Alignment.find(db, {"alignment_set_id":a_set._id}).sort("PK", 1) cnt = 0. cnt_tot = als.count() for al in als: a = Alignment(db, al) a.setProject(p.item) a.load() cnt+=1. sys.stdout.write("\r{:5s} pk= {:.0f} progress= {:.0%}".format(a_set.item["code"], a.item["PK"], cnt/cnt_tot )) sys.stdout.flush() a.perform_calc(str(datetime.now())) else: logger.error("Authentication failed")
def plot_data(bAuthenticate, sPath): # connect to MongoDB client = MongoClient() db = client[database] # DB authentication if required if bAuthenticate: bLoggedIn = db.authenticate(username,password,source=source_database) else: bLoggedIn = True # cambio font size mpl.rcParams.update({'font.size': 6}) if bLoggedIn: logger.info("Logged in") pd = db.Project.find_one({"project_code":"MFW001_0-010 Metro Paris-Ligne 15_T2A"}) if pd: logger.info("Project %s found" % pd["project_name"]) p = Project(db, pd) p.load() found_domains = Domain.find(db, {"project_id": p._id}) for dom in found_domains: dm = Domain(db,dom) dm.load() # Example of query asets = db.AlignmentSet.find({"domain_id": dm._id}) for aset in asets: a_set = AlignmentSet(db,aset) a_set.load() sCode = a_set.item["code"] als = db.Alignment.find({"alignment_set_id":a_set._id},{"PK":True,"P_TAMEZ":True,"COB":True,"P_EPB":True,"P_WT":True,"BLOWUP":True, "PH":True, "DEM":True,"SETTLEMENT_MAX":True, \ "TILT_MAX":True, "EPS_H_MAX":True, "VOLUME_LOSS":True, "K_PECK":True, "REFERENCE_STRATA":True, "SETTLEMENTS":True, "SENSIBILITY":True, "DAMAGE_CLASS":True, "VULNERABILITY":True, \ "CONSOLIDATION_VALUE":True, "gamma_face":True, "gamma_tun":True, "sensibility_vbr_pk":True, "vibration_speed_mm_s_pk":True, "damage_class_vbr_pk":True, "vulnerability_vbr_pk":True}).sort("PK", 1) a_list = list(als) pks = [] pklabel = [] pkxticks = [] for d in a_list: pk_value = round(d['PK']/10., 0) *10. pks.append(pk_value) hundreds = int(pk_value-int(pk_value/1000.)*1000) if hundreds%100 == 0: pkxticks.append(pk_value) pklabel.append("%d+%03d" % (int(pk_value/1000.),hundreds )) if sCode=='smi': d_press = 0.5 # bar tra calotta e asse d_press_wt = 0.35 else: d_press = 0.7 # bar tra calotta e asse d_press_wt = 0.5 # scalo di fattore 100 # p_wts =[d['P_WT']/100 - d_press_wt for d in a_list] p_wts = [(max(0., d['P_WT']/100. - d_press_wt)) for d in a_list] # scalo di fattore 100 p_epms =[max(0., d['P_EPB']/100. - d_press) for d in a_list] # scalo di fattore 100 p_tamezs=[max(0., d['P_TAMEZ']/100. - d_press) for d in a_list] cobs =[max(0., d['COB']/100. - d_press) for d in a_list] # scalo di fattore 100 blowups =[max(0., d['BLOWUP']/100. - d_press) for d in a_list] # amplifico di fattore 100 volume_losss =[d['VOLUME_LOSS']*100. for d in a_list] k_pecks =[d['K_PECK'] for d in a_list] # amplifico di fattore 1000 max_settlements =[d['SETTLEMENT_MAX']*1000. for d in a_list] tilts =[d['TILT_MAX']*1000. for d in a_list] epshs =[d['EPS_H_MAX']*1000. for d in a_list] consolidations =[d['CONSOLIDATION_VALUE'] for d in a_list] sensibilities =[d['SENSIBILITY'] for d in a_list] damages =[d['DAMAGE_CLASS'] for d in a_list] vulnerabilities =[d['VULNERABILITY'] for d in a_list] young_tuns =[d['gamma_tun'] for d in a_list] young_faces =[d['gamma_face'] for d in a_list] sensibility_vbr_pks =[d['sensibility_vbr_pk'] for d in a_list] vibration_speed_mm_s_pks =[d['vibration_speed_mm_s_pk'] for d in a_list] damage_class_vbr_pks =[d['damage_class_vbr_pk'] for d in a_list] vulnerability_vbr_pks =[d['vulnerability_vbr_pk'] for d in a_list] # "sensibility_vbr_pk":True, "vibration_speed_mm_s_pk":True, "damage_class_vbr_pk":True, "vulnerability_vbr_pk":True # # plot # fig = plt.figure() # fig.set_size_inches(12, 3.54) # plt.plot(pks,young_tuns, label='E_TUN - GPa') # plt.plot(pks,young_faces, label='E_FACE - GPa') # y_min = math.floor(min(min(young_tuns),min(young_faces))/1.)*1. # y_max = math.ceil(max(max(young_tuns),max(young_faces))/1.)*1. # my_aspect = 50./(abs(y_max-y_min)/9.) # 50 m di profilo sono 1 cm in tavola, in altezza ho 9 cm a disposizione # plt.axis([max(pks),min(pks),y_min,y_max]) # plt.xticks(pkxticks, pklabel, rotation='vertical') # ax = plt.gca() # ax.set_aspect(my_aspect) # start, stop = ax.get_ylim() # ticks = np.arange(start, stop + 1., 1.) # ax.set_yticks(ticks) # #ax.grid(True) # plt.legend() # #fig.set_dpi(1600) # outputFigure(sPath, ("profilo_young_%s.svg" % sCode)) # logger.info("profilo_young.svg plotted in %s" % sPath) # plt.show() fig = plt.figure() fig.set_size_inches(12, 3.54) #plt.plot(pks,cobs, label='COB - bar') plt.plot(pks,p_epms, label='P_EPB - bar') plt.plot(pks,blowups, label='BLOWUP - bar') plt.plot(pks,p_wts, label='P_WT - bar') plt.plot(pks,p_tamezs, label='P_TAMEZ - bar') y_min = math.floor(min(min(p_wts),min(cobs), min(p_epms), min(blowups))/.5)*.5-.5 y_max = math.ceil(max(max(p_wts),max(cobs), max(p_epms), max(blowups))/.5)*.5+.5 my_aspect = 50./(abs(y_max-y_min)/9.) # 50 m di profilo sono 1 cm in tavola, in altezza ho 9 cm a disposizione plt.axis([max(pks),min(pks),y_min,y_max]) plt.xticks(pkxticks, pklabel, rotation='vertical') ax = plt.gca() ax.set_aspect(my_aspect) start, stop = ax.get_ylim() ticks = np.arange(start, stop + .5, .5) ax.set_yticks(ticks) #ax.grid(True) plt.legend() #fig.set_dpi(1600) outputFigure(sPath, ("profilo_pressioni_%s.svg" % sCode)) logger.info("profilo_pressioni.svg plotted in %s" % sPath) plt.show() # """ plt.plot(pks,volume_losss, label='VL percent') plt.plot(pks,k_pecks, label='k peck') y_min = math.floor(min(min(volume_losss), min(k_pecks))/.05)*.05-.05 y_max = math.ceil(max(max(volume_losss), max(k_pecks))/.05)*.05+.05 plt.axis([max(pks),min(pks),y_min,y_max]) plt.xticks(pkxticks, pklabel, rotation='vertical') ax = plt.gca() my_aspect = 50./(abs(y_max-y_min)/9.0) # 50 m di profilo sono 1 cm in tavola, in altezza ho 9 cm a disposizione ax.set_aspect(my_aspect) start, stop = ax.get_ylim() ticks = np.arange(start, stop + .05, .05) ax.set_yticks(ticks) #ax.grid(True) #plt.legend() #fig.set_dpi(1600) outputFigure(sPath, ("profilo_peck_%s.svg" % sCode)) logger.info("profilo_peck.svg plotted in %s" % sPath) plt.show() plt.plot(pks,max_settlements, label='SETTLEMENT_MAX (mm)') y_min = 0. # math.floor(min(max_settlements))-1. y_max = 30. # math.ceil(max(max_settlements))+1. plt.axis([max(pks),min(pks),y_min,y_max]) plt.xticks(pkxticks, pklabel, rotation='vertical') ax = plt.gca() my_aspect = 50./(abs(y_max-y_min)/4.5) # 50 m di profilo sono 1 cm in tavola, in altezza ho 9 cm a disposizione ax.set_aspect(my_aspect) start, stop = ax.get_ylim() ticks = np.arange(start, stop + 5., 5.) ax.set_yticks(ticks) #ax.grid(True) #plt.legend() #fig.set_dpi(1600) outputFigure(sPath, ("profilo_cedimenti_%s.svg" % sCode)) logger.info("profilo_cedimenti.svg plotted in %s" % sPath) plt.show() plt.plot(pks,tilts, label='BETA (0/00)') plt.plot(pks,epshs, label='EPS_H (0/00)') y_min = 0. # math.floor(min(max_settlements))-1. y_max = 3.5 # math.ceil(max(max_settlements))+1. plt.axis([max(pks),min(pks),y_min,y_max]) plt.xticks(pkxticks, pklabel, rotation='vertical') ax = plt.gca() my_aspect = 50./(abs(y_max-y_min)/4.5) # 50 m di profilo sono 1 cm in tavola, in altezza ho 9 cm a disposizione ax.set_aspect(my_aspect) start, stop = ax.get_ylim() ticks = np.arange(start, stop + .5, .5) ax.set_yticks(ticks) #ax.grid(True) #plt.legend() #fig.set_dpi(1600) outputFigure(sPath, ("profilo_distorsioni_%s.svg" % sCode)) logger.info("profilo_distorsioni.svg plotted in %s" % sPath) plt.show() plt.plot(pks,sensibilities, label='SENSIBILITY (1-3)') y_min = -0.5 y_max = 3.5 plt.axis([max(pks),min(pks),y_min,y_max]) plt.xticks(pkxticks, pklabel, rotation='vertical') ax = plt.gca() my_aspect = 50./(abs(y_max-y_min)/3.) # 50 m di profilo sono 1 cm in tavola, in altezza ho 9 cm a disposizione ax.set_aspect(my_aspect) #start, stop = ax.get_ylim() #ticks = np.arange(start, stop + 1., 1.) ticks =[0., 1., 2., 3.] ax.set_yticks(ticks) #ax.grid(True) #plt.legend() #fig.set_dpi(1600) outputFigure(sPath, ("profilo_sensibilita_%s.svg" % sCode)) logger.info("profilo_sensibilita.svg plotted in %s" % sPath) plt.show() plt.plot(pks,damages, label='DAMAGE CLASS (1-3)') y_min = -0.5 y_max = 3.5 plt.axis([max(pks),min(pks),y_min,y_max]) plt.xticks(pkxticks, pklabel, rotation='vertical') ax = plt.gca() my_aspect = 50./(abs(y_max-y_min)/3.) # 50 m di profilo sono 1 cm in tavola, in altezza ho 9 cm a disposizione ax.set_aspect(my_aspect) #start, stop = ax.get_ylim() #ticks = np.arange(start, stop + 1., 1.) ticks =[0., 1., 2., 3.] ax.set_yticks(ticks) #ax.grid(True) #plt.legend() #fig.set_dpi(1600) outputFigure(sPath, ("profilo_danni_%s.svg" % sCode)) logger.info("profilo_danni.svg plotted in %s" % sPath) plt.show() plt.plot(pks,vulnerabilities, label='VULNERABILITY (1-3)') y_min = -0.5 y_max = 3.5 plt.axis([max(pks),min(pks),y_min,y_max]) plt.xticks(pkxticks, pklabel, rotation='vertical') ax = plt.gca() my_aspect = 50./(abs(y_max-y_min)/3.) # 50 m di profilo sono 1 cm in tavola, in altezza ho 9 cm a disposizione ax.set_aspect(my_aspect) #start, stop = ax.get_ylim() #ticks = np.arange(start, stop + 1., 1.) ticks =[0., 1., 2., 3.] ax.set_yticks(ticks) #ax.grid(True) #plt.legend() #fig.set_dpi(1600) outputFigure(sPath, ("profilo_vulnerabilita_%s.svg" % sCode)) logger.info("profilo_vulnerabilita.svg plotted in %s" % sPath) plt.show() plt.plot(pks,consolidations, label='CONSOLIDATION (0-1)') y_min = -0.3 y_max = 1.3 plt.axis([max(pks),min(pks),y_min,y_max]) plt.xticks(pkxticks, pklabel, rotation='vertical') ax = plt.gca() my_aspect = 50./(abs(y_max-y_min)/1.) # 50 m di profilo sono 1 cm in tavola, in altezza ho 9 cm a disposizione ax.set_aspect(my_aspect) #start, stop = ax.get_ylim() #ticks = np.arange(start, stop + 1., 1.) ticks =[0., 1.] ax.set_yticks(ticks) #ax.grid(True) #plt.legend() #fig.set_dpi(1600) outputFigure(sPath, ("profilo_consolidamenti_%s.svg" % sCode)) logger.info("profilo_consolidamenti.svg plotted in %s" % sPath) plt.show() plt.plot(pks,sensibility_vbr_pks, label='SENSIBILITY VBR (1-3)') y_min = -0.5 y_max = 3.5 plt.axis([max(pks),min(pks),y_min,y_max]) plt.xticks(pkxticks, pklabel, rotation='vertical') ax = plt.gca() my_aspect = 50./(abs(y_max-y_min)/3.) # 50 m di profilo sono 1 cm in tavola, in altezza ho 9 cm a disposizione ax.set_aspect(my_aspect) ticks =[0., 1., 2., 3.] ax.set_yticks(ticks) outputFigure(sPath, ("profilo_sensibilita_vbr_%s.svg" % sCode)) logger.info("profilo_sensibilita_vbr.svg plotted in %s" % sPath) plt.show() plt.plot(pks,damage_class_vbr_pks, label='DAMAGE CLASS (1-3)') y_min = -0.5 y_max = 3.5 plt.axis([max(pks),min(pks),y_min,y_max]) plt.xticks(pkxticks, pklabel, rotation='vertical') ax = plt.gca() my_aspect = 50./(abs(y_max-y_min)/3.) # 50 m di profilo sono 1 cm in tavola, in altezza ho 9 cm a disposizione ax.set_aspect(my_aspect) ticks =[0., 1., 2., 3.] ax.set_yticks(ticks) outputFigure(sPath, ("profilo_danno_vbr_%s.svg" % sCode)) logger.info("profilo_danno_vbr.svg plotted in %s" % sPath) plt.show() plt.plot(pks,vulnerability_vbr_pks, label='VULNERABILITY (1-3)') y_min = -0.5 y_max = 3.5 plt.axis([max(pks),min(pks),y_min,y_max]) plt.xticks(pkxticks, pklabel, rotation='vertical') ax = plt.gca() my_aspect = 50./(abs(y_max-y_min)/3.) # 50 m di profilo sono 1 cm in tavola, in altezza ho 9 cm a disposizione ax.set_aspect(my_aspect) ticks =[0., 1., 2., 3.] ax.set_yticks(ticks) outputFigure(sPath, ("profilo_vulnerabilita_vbr_%s.svg" % sCode)) logger.info("profilo_vulnerabilita_vbr.svg plotted in %s" % sPath) plt.show() plt.plot(pks,vibration_speed_mm_s_pks, label='VIBRATION SPEED (mm/s)') y_min = -0.5 y_max = 12.5 plt.axis([max(pks),min(pks),y_min,y_max]) plt.xticks(pkxticks, pklabel, rotation='vertical') ax = plt.gca() my_aspect = 50./(abs(y_max-y_min)/3.) # 50 m di profilo sono 1 cm in tavola, in altezza ho 9 cm a disposizione ax.set_aspect(my_aspect) ticks =[0., 2., 3., 5., 6., 9., 12.] ax.set_yticks(ticks) outputFigure(sPath, ("profilo_velocita_vbr_%s.svg" % sCode)) logger.info("profilo_velocita_vbr.svg plotted in %s" % sPath) plt.show() """ sensibility_vbr_pks =[d['sensibility_vbr_pk'] for d in a_list] vibration_speed_mm_s_pks =[d['vibration_speed_mm_s_pk'] for d in a_list] damage_class_vbr_pks =[d['damage_class_vbr_pk'] for d in a_list] vulnerability_vbr_pks =[d['vulnerability_vbr_pk'] for d in a_list] """ # """ logger.info("plot_data terminated!") else: logger.error("Authentication failed")
def plot_data(bAuthenticate, sPath): # connect to MongoDB client = MongoClient() db = client[database] ##################################################### GIS SETUP driver = ogr.GetDriverByName("ESRI Shapefile") # create the spatial reference, EPSG3949 RGF93 / CC49 - http://spatialreference.org/ref/epsg/3949/ # xMin,yMin 1653513.80,8175914.21 : xMax,yMax 1659996.62,8177877.58 srs = osr.SpatialReference() srs.ImportFromEPSG(3949) # DB authentication if required if bAuthenticate: bLoggedIn = db.authenticate(username,password,source=source_database) else: bLoggedIn = True if bLoggedIn: logger.info("Logged in") pd = db.Project.find_one({"project_code":"MFW001_0-010 Metro Paris-Ligne 15_T2A"}) if pd: logger.info("Project %s found" % pd["project_name"]) p = Project(db, pd) p.load() found_domains = Domain.find(db, {"project_id": p._id}) for dom in found_domains: d = Domain(db,dom) d.load() # Example of query # asets = db.AlignmentSet.find({"$and":[{"domain_id": d._id},{"code": "main_01"}]}) asets = db.AlignmentSet.find({"$and":[{"domain_id": d._id}]}) for aset in asets: a_set = AlignmentSet(db,aset) a_set.load() sCode = a_set.item["code"] # GIS create the data source shpfname=os.path.join(sPath,"gis","smt_%s.shp" % sCode) if os.path.exists(shpfname): os.remove(shpfname) data_source = driver.CreateDataSource(shpfname) layer = data_source.CreateLayer("subsidence", srs, ogr.wkbPoint) # Add the GIS fields we're interested in field_name = ogr.FieldDefn("Name", ogr.OFTString) field_name.SetWidth(24) layer.CreateField(field_name) field_type = ogr.FieldDefn("Type", ogr.OFTString) field_type.SetWidth(24) layer.CreateField(field_type) field_align = ogr.FieldDefn("Alignment", ogr.OFTString) field_align.SetWidth(24) layer.CreateField(field_align) layer.CreateField(ogr.FieldDefn("PK", ogr.OFTInteger)) layer.CreateField(ogr.FieldDefn("Distance", ogr.OFTInteger)) layer.CreateField(ogr.FieldDefn("Latitude", ogr.OFTReal)) layer.CreateField(ogr.FieldDefn("Longitude", ogr.OFTReal)) layer.CreateField(ogr.FieldDefn("Elevation", ogr.OFTInteger)) layer.CreateField(ogr.FieldDefn("COB", ogr.OFTReal)) layer.CreateField(ogr.FieldDefn("BLOWUP", ogr.OFTReal)) layer.CreateField(ogr.FieldDefn("SETTLEMENT", ogr.OFTReal)) # layer.CreateField(ogr.FieldDefn("DATETIME", ogr.OFTDateTime)) # GIS end #als = db.Alignment.find({"$and":[{"alignment_set_id":a_set._id},{"PK":{"$gt":2128568}},{"PK":{"$lt":2129768}}]},{"PK":True,"COB":True,"BLOWUP":True, "PH":True, "DEM":True,"SETTLEMENT_MAX":True, "VOLUME_LOSS":True, "REFERENCE_STRATA":True, "SETTLEMENTS":True}).sort("PK", 1) als = db.Alignment.find({"alignment_set_id":a_set._id},{"PK":True,"COB":True,"BLOWUP":True, "PH":True, "DEM":True,"SETTLEMENT_MAX":True, "VOLUME_LOSS":True, "REFERENCE_STRATA":True, "SETTLEMENTS":True}).sort("PK", 1) a_list = list(als) pks =[d['PK'] for d in a_list] # scalo di fattore 100 cobs =[d['COB']/100 for d in a_list] # scalo di fattore 100 blowups =[d['BLOWUP']/100 for d in a_list] # amplifico di fattore 100 max_settlements =[d['SETTLEMENT_MAX']*100 for d in a_list] phs =[d['PH']['coordinates'][2] for d in a_list] dems =[d['DEM']['coordinates'][2] for d in a_list] pkys =[d['PH']['coordinates'][1] for d in a_list] pkxs =[d['PH']['coordinates'][0] for d in a_list] # punti medi pmidx = [] pmidy = [] # punti a distanza 20 e 40 keys, dictValues = processSettlements(a_list) pkxs_d_1 = defaultdict(list) pkys_d_1 = defaultdict(list) pkzs_d_1 = defaultdict(list) pkxs_d_2 = defaultdict(list) pkys_d_2 = defaultdict(list) pkzs_d_2 = defaultdict(list) mypoints = np.zeros((0,2)) myvalues = np.zeros(0,'f') pcalc_x = [] pcalc_y = [] pcalc_z = [] for i,x in enumerate(pkxs): if i==0: pass else: p1 = (pkxs[i-1],pkys[i-1]) p2 = (pkxs[i],pkys[i]) pm = mid_point(p1,p2) pmidx.append(pm[0]) pmidy.append(pm[1]) for key in keys: val = dictValues[key][i-1] if key == 0.0: # pass mypoints = np.append(mypoints,[[pkxs[i-1],pkys[i-1]]],axis=0) myvalues = np.append(myvalues,[val],axis=0) pcalc_x.append(pkxs[i-1]) pcalc_y.append(pkys[i-1]) pcalc_z.append(val) # GIS 1.1 feature = ogr.Feature(layer.GetLayerDefn()) feature.SetField("Name", "PK %f %d" % (pks[i-1],0)) feature.SetField("Type", "Central") feature.SetField("Alignment", str(sCode)) feature.SetField("Distance",0) feature.SetField("PK", int(pks[i-1])) feature.SetField("Latitude", pkys[i-1]) feature.SetField("Longitude", pkxs[i-1]) feature.SetField("Elevation", phs[i-1]) feature.SetField("COB", cobs[i-1]) feature.SetField("SETTLEMENT", val) feature.SetField("BLOWUP", blowups[i-1]) # feature.SetField("DATETIME", str(datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3])) wkt = "POINT(%f %f)" % (float(pkxs[i-1]) , float(pkys[i-1])) # Create the point from the Well Known Txt point = ogr.CreateGeometryFromWkt(wkt) # Set the feature geometry using the point feature.SetGeometry(point) # Create the feature in the layer (shapefile) layer.CreateFeature(feature) # Destroy the feature to free resources feature.Destroy() # GIS 1.1 end else: ret_d = pfromdistance_p1(p1,p2,key) x1 = ret_d[0][0] x2 = ret_d[1][0] y1 = ret_d[0][1] y2 = ret_d[1][1] pkxs_d_1[key].append(x1) pkxs_d_2[key].append(x2) pkys_d_1[key].append(y1) pkys_d_2[key].append(y2) mypoints = np.append(mypoints,[[x1,y1]],axis=0) pcalc_x.append(x1) pcalc_y.append(y1) pcalc_z.append(val) myvalues = np.append(myvalues,[val],axis=0) mypoints = np.append(mypoints,[[x2,y2]],axis=0) pcalc_x.append(x2) pcalc_y.append(y2) pcalc_z.append(val) myvalues = np.append(myvalues,[val],axis=0) # GIS 1.1 feature = ogr.Feature(layer.GetLayerDefn()) feature.SetField("Name", "PK %f +%d" % (pks[i-1],int(key))) feature.SetField("Type", "Distance") feature.SetField("Alignment", str(sCode)) feature.SetField("Distance",int(key)) feature.SetField("PK", int(pks[i-1])) feature.SetField("Latitude", y1) feature.SetField("Longitude", x1) feature.SetField("Elevation", phs[i]) feature.SetField("COB", cobs[i]) feature.SetField("SETTLEMENT", val) feature.SetField("BLOWUP", blowups[i]) #feature.SetField("DATETIME", str(datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3])) wkt = "POINT(%f %f)" % (float(x1) , float(y1)) # Create the point from the Well Known Txt point = ogr.CreateGeometryFromWkt(wkt) # Set the feature geometry using the point feature.SetGeometry(point) # Create the feature in the layer (shapefile) layer.CreateFeature(feature) # Destroy the feature to free resources feature.Destroy() feature = ogr.Feature(layer.GetLayerDefn()) feature.SetField("Name", "PK %f -%d" % (pks[i],int(key))) feature.SetField("Type", "Distance") feature.SetField("Alignment", str(sCode)) feature.SetField("Distance",int(key)) feature.SetField("PK", int(pks[i])) feature.SetField("Latitude", y2) feature.SetField("Longitude", x2) feature.SetField("Elevation", dems[i]) feature.SetField("COB", cobs[i]) feature.SetField("SETTLEMENT", val) feature.SetField("BLOWUP", blowups[i]) #feature.SetField("DATETIME", str(datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3])) wkt = "POINT(%f %f)" % (float(x2) , float(y2)) # Create the point from the Well Known Txt point = ogr.CreateGeometryFromWkt(wkt) # Set the feature geometry using the point feature.SetGeometry(point) # Create the feature in the layer (shapefile) layer.CreateFeature(feature) # Destroy the feature to free resources feature.Destroy() # GIS 1.1 end x_min, x_max, y_min, y_max = layer.GetExtent() data_source.Destroy() ############### END GIS min_x = min(pcalc_x) min_y = min(pcalc_y) max_x = max(pcalc_x) max_y = max(pcalc_y) # Interpolazione ...forse non è la cosa giusta da fare logger.info("x range %d" % (max_x - min_x) ) logger.info("y range %d" % (max_y - min_y) ) gx, gy = np.mgrid[min_x:max_x,min_y:max_y] m_interp_cubic = griddata(mypoints, myvalues, (gx, gy),method='nearest') # plot fig = plt.figure() plt.title("Profilo %s" % sCode) ### visualizza gli strati di riferimento # fillBetweenStrata(a_list) ################################################ plt.plot(pks,phs, linewidth=2,label='Tracciato') plt.plot(pks,dems, linewidth=2,label='DEM' ) plt.plot(pks,cobs, label='COB / 100') plt.plot(pks,blowups, label='BLOWUP / 100') plt.plot(pks,max_settlements, label='SETTLEMENT_MAX * 100') plt.axis([min(pks),max(pks),min(phs)-10,max(dems)+10]) plt.legend() outputFigure(sPath, "profilo_%s.svg" % a_set.item["code"]) logger.info("profilo_%s.png plotted in %s" % (a_set.item["code"], sPath)) plt.close(fig) fig = plt.figure() # stampa planimetria plt.title("Planimetria") # filtro a zero tutto qeullo che sta sotto # m_interp_cubic[ m_interp_cubic < 0.0] = 0.0 clevels = np.arange(0., 0.04, 0.001) cmap = LinearSegmentedColormap.from_list(name="Custom CMap", colors =["white", "blue", "red"], N=11) contours = plt.contourf(gx, gy, m_interp_cubic,cmap = cm.jet, extend='both', levels=clevels) cp = plt.contour(gx, gy, m_interp_cubic,linewidths=0.5,colors='k',levels=clevels) # GIS create the data source attr_name = "SETTLEMENT" shpfname=os.path.join(sPath,"gis","contour_%s.shp" % sCode) if os.path.exists(shpfname): os.remove(shpfname) dst_ds = driver.CreateDataSource(shpfname) dst_layer = dst_ds.CreateLayer("contour_subsidence", srs, ogr.wkbPolygon) # Add the GIS fields we're interested in dst_layer.CreateField(ogr.FieldDefn(attr_name, ogr.OFTReal)) field_align = ogr.FieldDefn("Alignment", ogr.OFTString) field_align.SetWidth(24) dst_layer.CreateField(field_align) field_level = ogr.FieldDefn("LevelID", ogr.OFTString) field_level.SetWidth(24) dst_layer.CreateField(field_level) # dst_layer.CreateField(ogr.FieldDefn("DATETIME", ogr.OFTDateTime)) # GIS end for level in range(len(contours.collections)): paths = contours.collections[level].get_paths() for path in paths: feat_out = ogr.Feature( dst_layer.GetLayerDefn()) feat_out.SetField( attr_name, contours.levels[level] ) feat_out.SetField("Alignment", str(sCode)) feat_out.SetField("LevelID", str(level)) #feat_out.SetField("DATETIME", str(datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3])) pol = ogr.Geometry(ogr.wkbPolygon) ring = None for i in range(len(path.vertices)): point = path.vertices[i] if path.codes[i] == 1: if ring != None: pol.AddGeometry(ring) ring = ogr.Geometry(ogr.wkbLinearRing) ring.AddPoint_2D(point[0], point[1]) pol.AddGeometry(ring) feat_out.SetGeometry(pol) if dst_layer.CreateFeature(feat_out) != 0: print "Failed to create feature in shapefile.\n" exit( 1 ) feat_out.Destroy() """ # Create the destination tiff data source raster_fn=os.path.join(sPath,"smt_%s.tif" % sCode) if os.path.exists(raster_fn): os.remove(raster_fn) # Define pixel_size and NoData value of new raster pixel_size = 1 NoData_value = -9999 x_res = int((max_x - min_x) / pixel_size) y_res = int((max_y - min_y) / pixel_size) target_ds = gdal.GetDriverByName('GTiff').Create(raster_fn, x_res, y_res, 1, gdal.GDT_Float32) target_ds.SetGeoTransform((x_min, pixel_size, 0, y_max, 0, -pixel_size)) band = target_ds.GetRasterBand(1) band.WriteArray(m_interp_cubic) outRasterSRS = osr.SpatialReference() outRasterSRS.ImportFromEPSG(3949) outRaster.SetProjection(outRasterSRS.ExportToWkt()) outband.FlushCache() """ plt.colorbar() plt.plot(pkxs,pkys, "g-",label='Tracciato %s' % a_set.item["code"]) plt.plot(pkxs,pkys, "g.") # Punti medi plt.plot(pmidx,pmidy, "gx") for key in keys: pkzs_d_1[key] = dictValues[key] pkzs_d_2[key] = dictValues[key] plt.plot(pkxs_d_1[key],pkys_d_1[key], "w.", ms=1) plt.plot(pkxs_d_2[key],pkys_d_2[key], "w.", ms=1) array_x = np.asarray(pcalc_x) array_y = np.asarray(pcalc_y) array_z = np.asarray(pcalc_z) plt.axis("equal") outputFigure(sPath, "tracciato_%s.svg" % a_set.item["code"], format="svg") logger.info("tracciato_%s.png plotted in %s" % (a_set.item["code"], sPath)) #plt.show() plt.close(fig) logger.info("plot_data terminated!") else: logger.error("Authentication failed")
formatter = logging.Formatter('%(asctime)s %(name)-12s %(levelname)-8s %(message)s') fh.setFormatter(formatter) logger.addHandler(fh) # reading config file sCFGName = 'smt.cfg' smtConfig = ConfigParser.RawConfigParser() smtConfig.read(sCFGName) # setup DB parameter host = smtConfig.get('MONGODB','host') database = smtConfig.get('MONGODB','database') source_database = smtConfig.get('MONGODB','source_database') username = smtConfig.get('MONGODB','username') password = smtConfig.get('MONGODB','password') # connect to MongoDB client = MongoClient() db = client[database] # DB authentication db.authenticate(username,password,source=source_database) # Search for project_code = "MFW001_0-010 Metro Paris-Ligne 15_T2A" pd = db.Project.find_one({"project_code":"MFW001_0-010 Metro Paris-Ligne 15_T2A"}) p = Project(db, pd) p.load() found_domains = Domain.find(db, {"project_id": p._id}) for dom in found_domains: d = Domain(db,dom) d.load() # Example of aggregation aggrList = Alignment.aggregate_by_strata(db, d._id) for ii in aggrList: print ii