def ttdb_reduce(self,tt,l_lim,u_lim,zlim=[]): (zorig,x_orig,y_orig)=ll.LLtoUTM(23, self.lat0, self.lon0) (zorig,x_l,y_l)=ll.LLtoUTM(23, l_lim[0], l_lim[1]) (zorig,x_u,y_u)=ll.LLtoUTM(23, u_lim[0], u_lim[1]) x_l=(x_l-x_orig)/1000.; y_l=(y_l-y_orig)/1000. x_u=(x_u-x_orig)/1000.; y_u=(y_u-y_orig)/1000. nx_ini=int((x_l-self.x0)/self.dx); ny_ini=int((y_l-self.y0)/self.dy) nx_fin=int((x_u-self.x0)/self.dx); ny_fin=int((y_u-self.y0)/self.dy) self.x0=x_l-self.x0; self.y0=y_l-self.y0 if zlim: nz_ini=int((zlim[0]-self.z0)/self.dz) nz_fin=int((zlim[1]-self.z0)/self.dz) self.z0=zlim[0]-self.z0 else: nz_ini=0; nz_fin=self.nz nx_new=nx_fin-nx_ini; ny_new=ny_fin-ny_ini; nz_new=nz_fin-nz_ini; tt_new={} for key in tt.keys(): t_arr=tt[key].reshape(self.nx,self.ny,self.nz) tt_new[key]=t_arr[nx_ini:nx_fin,ny_ini:ny_fin,nz_ini:nz_fin].reshape(nx_new*ny_new*nz_new) self.nx=nx_new; self.ny=ny_new; self.nz=nz_new self.x0=0.; self.y0=0. self.x = self.x0+(num.arange(0,self.nx)*self.dx) self.y = self.y0+(num.arange(0,self.ny)*self.dy) self.z = self.z0+(num.arange(0,self.nz)*self.dz) self.nxyz=self.nx*self.ny*self.nz self.lat0=l_lim[0] self.lon0=l_lim[1] return tt_new
def tplot(ifig): fig = plt.figure(figsize=(10.0, 15.0)) ax = plt.subplot(111) lat_evs = [] lon_evs = [] frae_evs = [] seme_evs = [] nrm = Normalize(vmin=3., vmax=7.0) cmap = plt.cm.get_cmap('RdBu', 20) z0, e0, n0 = LatLongUTMconversion.LLtoUTM(23, 39.090667, 17.100000) f = open('test' + str(ifig) + '.txt', 'r') f.readline() for line in f: toks = line.split() lat_ev, lon_ev, seme, frae = eval(toks[1]), eval(toks[2]), eval( toks[-3]), eval(toks[-1]) z, e, n = LatLongUTMconversion.LLtoUTM(23, lat_ev, lon_ev) lat_evs.append(n - n0) lon_evs.append(e - e0) seme_evs.append(seme) frae_evs.append(frae) f.close() xst = num.zeros(4) yst = num.zeros(4) yst[0] = 39.168111 xst[0] = 17.097250 yst[1] = 39.057294 xst[1] = 17.075408 yst[2] = 39.024306 xst[2] = 17.199000 yst[3] = 38.994306 xst[3] = 17.150306 for i in range(4): z, es, ns = LatLongUTMconversion.LLtoUTM(23, yst[i], xst[i]) ax.scatter(es - e0, ns - n0, c='#eed54f', marker='v', s=200, zorder=3, linewidth=0.5) ax.scatter(lon_evs, lat_evs, c=seme_evs, cmap=cmap) plt.grid('on') plt.savefig('figure' + str(ifig) + '.eps') return None
def __catalogue_creation(self, filename): fout = os.path.join(self.output_path, filename) nev, mev = num.shape(self.locations) evids = (self.input).events print('Location process completed, number of located events: %d ' % (nev)) catalogue = [] with open(fout + '.txt', 'w') as f: f.write('Id Lat Lon Depth Station(s) Ts-Tp Tp\n') for i in range(nev): lat, lon = LatLongUTMconversion.UTMtoLL( 23, self.locations[i, 1] + (self.input).origin[1], self.locations[i, 0] + (self.input).origin[0], (self.input).origin[2]) depth = self.locations[i, 2] / 1000 event = evids[i] t_string = ' ' for sta in (self.input).sel_sta: if sta in (self.input).data[event].keys(): tsp = (self.input).data[event][sta][-1] tid = (self.input).data[event][sta][0] t_string = t_string + sta + ' %5.3f ' % (tsp) + str( tid) + ' ' f.write(event + ' ' + '%6.4f ' % (lat) + ' ' + '%6.4f ' % (lon) + ' ' + '%3.1f ' % (depth) + ' ' + t_string + '\n') catalogue.append([event, lat, lon, depth]) self.catalogue = num.array(catalogue)
def read_catalogue(filename, hobj): e0, n0, z0 = hobj.origin[0], hobj.origin[1], hobj.origin[2] x_evs = [] y_evs = [] z_evs = [] evtsps = {} #Id Id Lat Lon Depth Error Station(s) Date Tp Ts-Tp Station(s) Date Tp Ts-Tp f = open(filename, 'r') f.readline() for line in f: toks = line.split() lat_ev, lon_ev, dep_ev = eval(toks[1]), eval(toks[2]), eval(toks[3]) sta_name1, tsp_sta1 = toks[4], eval(toks[5]) sta_name2, tsp_sta2 = toks[8], eval(toks[9]) z, e, n = LatLongUTMconversion.LLtoUTM(23, lat_ev, lon_ev) x_evs.append(e - e0) y_evs.append(n - n0) z_evs.append(dep_ev * 1000) if (sta_name1 not in evtsps.keys()) and (sta_name2 not in evtsps.keys()): evtsps[sta_name1] = [] evtsps[sta_name2] = [] evtsps[sta_name1].append(tsp_sta1) evtsps[sta_name2].append(tsp_sta2) f.close() x_evs = num.array(x_evs) y_evs = num.array(y_evs) z_evs = num.array(z_evs) return x_evs, y_evs, z_evs, evtsps
def conversion(latmin, latmax, lonmin, lonmax, border, spacing, filename): zone,xmin,ymin=ll.LLtoUTM(23,latmin,lonmin) zone,xmax,ymax=ll.LLtoUTM(23,latmax,lonmax) nx=int((xmax-xmin)/spacing) ny=int((ymax-ymin)/spacing) xax=num.arange(0,nx)*spacing yax=num.arange(0,ny)*spacing f=open(filename,'r') points=[] for line in f: toks=line.split() lonobs,latobs,elvobs=eval(toks[0]),eval(toks[1]),eval(toks[2]) if (latobs>latmin-border and latobs<latmax+border) and (lonobs>lonmin-border and lonobs<lonmax+border): zone,xobs,yobs=ll.LLtoUTM(23,latobs,lonobs) points.append([xobs-xmin,yobs-ymin,elvobs]) points=num.array(points) return points, xax, yax
def TraiteData(data_float): print "->conversion des donnees en UTM" coords = [] for line_data in data_float: latitude = dmd_to_dd(line_data[1]) longitude = dmd_to_dd(line_data[2]) (zone, est, nord) = LLUC.LLtoUTM(23, latitude, longitude) coords.append([line_data[0], est, nord, line_data[3]]) return coords
def catalogue_creation(self, evids, origin, nref, filename, output_path): fout=os.path.join(output_path,filename) nev,mev=num.shape(self.locations) print('number of located events',nev) with open(filename,'w') as f: f.write('Id Lat Lon Depth \n') for i in range(nev): lat,lon=LatLongUTMconversion.UTMtoLL(23, self.locations[i,1]+origin[1], self.locations[i,0]+origin[0],origin[2]) if evids[i]!='REFERENCE': event=evids[i].strftime('%Y%m%dT%H%M%S.%f') f.write(event +' '+str(lat)+' '+str(lon)+' '+str(self.locations[i,2]/1000)+'\n')
def read_catalogue(self,data_path,catalogue_file): cat_file=os.path.join(data_path,catalogue_file) with open(cat_file, 'r') as f: catlocs=[] for line in f: toks=line.split() otime, lat, lon, depth=toks[0], eval(toks[1]), eval(toks[2]), eval(toks[5])*km z,e,n=LatLongUTMconversion.LLtoUTM(23, lat, lon) catlocs.append([e-self.origin[0],n-self.origin[1],depth]) catloc=num.array(catlocs) return catloc
def __read_evfile(input_file): with open(input_file, 'r') as f: toks = f.readline().split(';') z0, e0, n0 = LatLongUTMconversion.LLtoUTM(23, eval( toks[1]), eval(toks[2])) #order lat lon try: depth0 = eval(toks[3]) * km except: depth0 = 0. refor = (e0, n0, z0, depth0) refevid = [] events = [] evtsp = {} references = [] for line in f: toks = line.split(';') if toks[0][0] == '#': evid = toks[0] evtsp[evid] = {} evdate = toks[1][0:10] if toks[0][1] == 'R': z, e, n = LatLongUTMconversion.LLtoUTM( 23, eval(toks[2]), eval(toks[3]), z0) # order lat lon depth = eval(toks[4]) * km refevid.append(evid) references.append([e - e0, n - n0, depth]) else: events.append(evid) else: sta = toks[0] if toks[1] == 'na' or toks[2] == 'na': continue tp = datetime.datetime.strptime(evdate + 'T' + toks[1], '%Y/%m/%dT%H:%M:%S.%f') ts = datetime.datetime.strptime(evdate + 'T' + toks[2], '%Y/%m/%dT%H:%M:%S.%f') tsp = (ts - tp).total_seconds() evtsp[evid][sta] = [tp, ts, tsp] references = num.array(references) return references, refevid, evtsp, refor, events
def catalogue_creation(self, event, lat0, lon0, ntrial, refell=23): (zorig,eorig,norig)=LatLongUTMconversion.LLtoUTM(refell, lat0, lon0) #da adeguare in python 3 ev_file=self.output_path+'/'+event+'/'+event+'.loc' data=num.loadtxt(ev_file) if (ntrial>1): w=num.sum(data[:,4]) xb= ((num.dot(data[:,1],data[:,4])/w)*1000)+eorig yb= ((num.dot(data[:,2],data[:,4])/w)*1000)+norig late,lone=LatLongUTMconversion.UTMtoLL(refell, yb, xb, zorig) zb= num.dot(data[:,3],data[:,4])/w cb= num.mean(data[:,4]) cmax=num.max(data[:,4]) merr=num.vstack((data[:,1],data[:,2],data[:,3])) err=num.cov(merr) errmax= num.sqrt(num.max(num.linalg.eigvals(err))) else: late,lone=LatLongUTMconversion.UTMtoLL(refell, (data[2]*1000)+norig, (data[1]*1000)+eorig, zorig) zb= data[3]; errmax='NA'; cb=data[4]; cmax=data[4]; f=open(self.output_path+'/'+'catalogue','a') f.write(event+' '+str(late)+' '+str(lone)+' '+str(zb)+' '+str(errmax)+' '+str(cb)+' '+str(cmax)+'\n') f.close()
def read_references_2stations(ref_file): '''read the file containing the reference events, it is a text file with five columns as follow: origin_time lat lon depth(km) tP tS the format for origin_time, tP and tS is the following: yyyymmddThhmmss.ms the first row of the file contains information of the origin of reference system and it is denoted with the word ORIGIN, followed by latitute and longitude values EXAMPLE: ORIGIN 38.226782 -122.331413 20140824T102044.07 38.21517 -122.31233 11.12 20140824T102048.270000 20140824T102051.240000 20140824T102444.24 38.25983 -122.33733 10.34 20140824T102447.510000 20140824T102449.840000 20140824T102725.97 38.23917 -122.33783 6.77 20140824T102729.190000 20140824T102731.570000 ''' with open(ref_file, 'r') as f: refevs=[] reftsp=[] reflocs=[] z0,e0,n0=[0,0,0] reforig=[0,0,0] for line in f: toks=line.split() if toks[0]=='ORIGIN' or toks[0]=='origin': z0,e0,n0=LatLongUTMconversion.LLtoUTM(23, eval(toks[1]), eval(toks[2])) reforig=(e0,n0,z0) else: otime, lat, lon, depth=toks[0], eval(toks[1]), eval(toks[2]), eval(toks[3])*km, tp1=datetime.datetime.strptime(toks[4], '%Y%m%dT%H%M%S.%f') ts1=datetime.datetime.strptime(toks[5], '%Y%m%dT%H%M%S.%f') tsp1=(ts1-tp1).total_seconds() tp2=datetime.datetime.strptime(toks[6], '%Y%m%dT%H%M%S.%f') ts2=datetime.datetime.strptime(toks[7], '%Y%m%dT%H%M%S.%f') tsp2=(ts2-tp2).total_seconds() z,e,n=LatLongUTMconversion.LLtoUTM(23, lat, lon) reflocs.append([e-reforig[0],n-reforig[1],depth]) reftsp.append([tsp1,tsp2]) refevs.append([otime,lat,lon,e-reforig[0],n-reforig[1],depth]) refloc=num.array(reflocs) reftsp=num.array(reftsp) return refevs, refloc, reftsp, reforig
def TraiteData(data_float): """ Traitement de l'ensemble du fichier """ print " -> Conversion des données en UTM" coords = [] # Stockage des données UTM for line_data in data_float: # Conversion des données dmd en latitude,longitude latitude = dmd_to_dd(line_data[1]) longitude = dmd_to_dd(line_data[2]) # Conversion latitude,longitude -> UTM (est, nord) # on se trouve dans la zone 23 (port de Brest) (zone, est, nord) = LLUC.LLtoUTM(23, latitude, longitude) coords.append([line_data[0], est, nord, line_data[3]]) return coords
def getCoordinateList(conn, cur, sniv1_id, sosiUTM, sosiUnit, sosiFilename): sortOrder = "" if float(sniv1_id) < 0: sortOrder = "ASC" # Query to read the coordinates into a list. cur.execute("SELECT public.tbl_koordinat.x, public.tbl_koordinat.y , public.tbl_koordinat.z \ FROM public.tbl_rel_fil_sniv1 \ INNER JOIN public.tbl_sniv1 ON (public.tbl_rel_fil_sniv1.ref_sniv1=public.tbl_sniv1.id) \ INNER JOIN public.tbl_fil ON (public.tbl_rel_fil_sniv1.ref_fil=public.tbl_fil.id) \ INNER JOIN public.tbl_rel_geoobj_koordinat ON (public.tbl_rel_geoobj_koordinat.ref_geoobj=public.tbl_sniv1.id) \ INNER JOIN public.tbl_koordinat ON (public.tbl_rel_geoobj_koordinat.ref_koordinat=public.tbl_koordinat.id) \ WHERE ((public.tbl_sniv1.content = '%s') \ AND (public.tbl_fil.filnavn = '%s')) \ ORDER BY \ public.tbl_rel_geoobj_koordinat.rekkefnr %s " \ % (sniv1_id,sosiFilename,sortOrder)) rows = cur.fetchall() #initiate koordliste = [] for row in rows: # find integer value and establish unit y = int(row[0]) y = y * sosiUnit # find integer value and establish unit x = int(row[1]) x = x * sosiUnit # find integer value and establish unit if (row[2]): z = int(row[2]) z = z * sosiUnit else: z = 0 (lat, lon) = LatLongUTMconversion.UTMtoLL(23, int(y), int(x), sosiUTM) koordliste.append([lat, lon, z]) return koordliste
def __read_stafile(input_file, reforig): (e0, n0, z0, depth0) = reforig stations = {} with open(input_file, 'r') as f: for line in f: toks = line.split() sta = toks[0] z, e, n = LatLongUTMconversion.LLtoUTM(23, eval(toks[1]), eval(toks[2]), z0) #order lat lon elev = eval(toks[3]) * km if z == z0: stations[sta] = [e - e0, n - n0, elev] else: print('cluster and stations are in different UTM zones') sys.exit() return stations
def read_boxes(box_data): with open(box_data, "rb") as bd: reader = list(csv.reader(bd, delimiter=',')) reader.pop(0) seed_box = {} seed_id = [] for row in reader: if row[4] not in seed_id and row[4] != "Br": seed_id.append(row[4]) if row[3] not in seed_id and row[4] == "Br": seed_id.append(row[3]) for i in range(len(seed_id)): lat = [] longi = [] for row in reader: if row[4] == seed_id[i] or row[3] == seed_id[i]: coords = list(LatLongUTMconversion.LLtoUTM(23, float(row[0]), float(row[1])))[1:] lat.append(float(coords[0])) longi.append(float(coords[1])) lat_max = round(max(lat), 6) lat_min = round(min(lat), 6) longi_max = round(max(longi), 6) longi_min = round(min(longi), 6) lat_avg = (lat_max + lat_min) / 2. longi_avg = (longi_max + longi_min) / 2. if len(seed_id[i]) > 8: seed_id[i] = "Br_" + seed_id[i] seed_box[seed_id[i]] = [lat_avg, longi_avg] return seed_box, seed_id
def geo2utm(lon, lat, unit, ellipsoid=23): """conversion geocoodinates from geographical to utm usage: x,y=geo2utm(lon,lat,unit,ellipsoid=23) dafault ellipsoid is 23 = WGS-84, ellipsoid: 1, "Airy" 2, "Australian National" 3, "Bessel 1841" 4, "Bessel 1841 (Nambia] " 5, "Clarke 1866" 6, "Clarke 1880" 7, "Everest" 8, "Fischer 1960 (Mercury] " 9, "Fischer 1968" 10, "GRS 1967" 11, "GRS 1980" 12, "Helmert 1906" 13, "Hough" 14, "International" 15, "Krassovsky" 16, "Modified Airy" 17, "Modified Everest" 18, "Modified Fischer 1960" 19, "South American 1969" 20, "WGS 60" 21, "WGS 66" 22, "WGS-72" 23, "WGS-84" unit: 'geo' if the coordinates of the model (lon,lat) are geographical 'utm' if the coordinates of the model (lon,lat) are utm x,y: the function return the easting, northing utm coordinates """ import LatLongUTMconversion if unit == 'geo': (zone, x, y) = LatLongUTMconversion.LLtoUTM(ellipsoid, lat, lon) elif unit == 'utm': x = lon y = lat return x, y
def get_lat_lon(exif_data): """Returns the latitude and longitude if available, from the provided exif_data (obtained through get_exif_data above)""" lat = None lon = None if "GPSInfo" in exif_data: gps_info = exif_data["GPSInfo"] gps_latitude = _get_if_exist(gps_info, "GPSLatitude") gps_latitude_ref = _get_if_exist(gps_info, 'GPSLatitudeRef') gps_longitude = _get_if_exist(gps_info, 'GPSLongitude') gps_longitude_ref = _get_if_exist(gps_info, 'GPSLongitudeRef') if gps_latitude and gps_latitude_ref and gps_longitude and gps_longitude_ref: lat = _convert_to_degress(gps_latitude) if gps_latitude_ref != "N": lat = 0 - lat lon = _convert_to_degress(gps_longitude) if gps_longitude_ref != "E": lon = 0 - lon # Added to compensate for any false GPS data from the image. # Some images (Canon specifically) were causing # errors becuase the program incorrectly identified them as # having GPS information. This was causing the # program to abort when LatLongUTMconversion would be called with # lat/lon variables that didn't have numbers. # This required the if statement below to see if the lat/lon # variables were still set to their initialized values. if lat == None or lon == None: UTMrec = [0,0,0] else: UTMrec = LatLongUTMconversion.LLtoUTM(23, float(lat), float(lon)) # return lat, lon return UTMrec
def interpolation(points, xax, yax): xgrid, ygrid = num.meshgrid(xax, yax) zgrid = griddata(points[:,0:2],points[:,2],(xgrid, ygrid), method='nearest') #plt.imshow(zgrid) #plt.show() return zgrid, xgrid, ygrid filename='piton_topo' spacing=100. latmin=-21.35; latmax=-21.10; lonmin=55.60; lonmax=55.85; points,xax,yax=conversion(-21.35, -21.10, 55.60, 55.85, 0.1, 100, filename) topo, xgrid, ygrid=interpolation(points, xax, yax) topo=topo-100. zone,xmin,ymin=ll.LLtoUTM(23,latmin,lonmin) latsta=-21.33533333; lonsta=55.794 zone,xsta,ysta=ll.LLtoUTM(23,latsta,lonsta) ix=int((xsta-xmin)/spacing) iy=int((ysta-ymin)/spacing) #fig, ax = plt.subplots(subplot_kw=dict(projection='3d')) #ls = LightSource(270, 45) # To use a custom hillshading mode, override the built-in shading and pass
return lat, lon,alt ################ # Example ###### ################ if __name__ == "__main__": # load an image through PIL's Image object if len(sys.argv) < 2: print "Error! No image file specified!" print "Usage: %s <filename>" % sys.argv[0] sys.exit(1) inp=open(sys.argv[2],"w") p=getPhotosFromDirectory(sys.argv[1]) for path in p: #print(path) photopath=os.path.join(sys.argv[1],path) #print photopath photoHandle = Image.open(photopath) exif_data = get_exif_data(photoHandle) lat,lon,alt=get_lat_lon(exif_data) if lat==None or lon==None or alt==None: inp.write("none none none") inp.write('\n') else: (z, e, n) = con.LLtoUTM(23,lon,lat) inp.write(str(e)+'\t'+str(n)+'\t'+str(alt)+'\n')
import LatLongUTMconversion as LLUC file = open("GPS_data.txt", 'r') data = [] for i in file: try: line = file.readline() data_txt = line.split() data1 = [] for c in data_txt: data1.append(float(c)) #datal = [float(_) for _ in data_txt] data2 = [0, 0, 0, 0] dummy, data2[1], data2[2] = LLUC.LLtoUTM(23, data1[1], data1[2]) data2[0] = data1[0] data2[3] = data1[3] data.append(data2) except Exception as e: print(e) print(i) pass file.close() n_file = open("gps_extract", 'w', encoding='utf-8') data_strs = [] for i in range(len(data)): data1 = data[i] string = "" for j in range(len(data1)): string = string + " " + str(data1[j])
"green": ((0.0, 0.0, 0.0), (0.5, 1.0, 1.0), (1.0, 0.0, 0.0)), "blue": ((0.0, 0.0, 1.0), (0.5, 1.0, 1.0), (1.0, 0.0, 0.0)), } rtcmap3 = LinearSegmentedColormap("rtcmap3", rtcmapdict3, 256) # resistivity tensor map for calcluating apparent resistivity rtcmapdict3r = { "red": ((0.0, 1.0, 1.0), (0.5, 1.0, 1.0), (1.0, 0.0, 0.0)), "green": ((0.0, 0.0, 0.0), (0.5, 1.0, 1.0), (1.0, 0.0, 0.0)), "blue": ((0.0, 0.0, 0.0), (0.5, 1.0, 1.0), (1.0, 1.0, 1.0)), } rtcmap3r = LinearSegmentedColormap("rtcmap3r", rtcmapdict3r, 256) # borehole location bhll = (139.72851, -30.2128) bhz, bhe, bhn = utm2ll.LLtoUTM(refe, bhll[1], bhll[0]) ecmin = 0 # =============================================================================== # Initialize parameters # =============================================================================== if ctype == "data": # set edipaths # set edipaths if ttype == "pt": edipathi = r"c:\Users\jpeacock-pr\Documents\Paralana\Post\MedFilt_2" edipathb = r"c:\Users\jpeacock-pr\Documents\Paralana\Base\MedFilt_2" elif ttype == "rt":