def ylim(self): '''Return the ylim of the map''' lat1 = self.lat(-0.5 * self.size[1]) lat2 = self.lat(+0.5 * self.size[1]) x, y1 = wgs2rd(self.center[1], lat1) x, y2 = wgs2rd(self.center[1], lat2) return y1, y2
def xlim(self): '''Return the xlim of the map.''' lon1 = self.lon(-0.5 * self.size[0]) lon2 = self.lon(+0.5 * self.size[0]) x1, y = wgs2rd(lon1, self.center[0]) x2, y = wgs2rd(lon2, self.center[0]) return x1, x2
def __init__(self, stationsFileName): # scan the file self.data = {} try: with open(stationsFileName) as f: s = f.readline() while not s.startswith('==='): s = f.readline() while True: try: name = f.readline().split(' ')[0] ln = f.readline().split('coordinates:')[-1] ln = [s[:-1].replace(' ', '') for s in ln.split(',')][:3] N, E, elev = [float(s) for s in ln] x, y = wgs2rd(E, N) #print(N, E, elev) ln = f.readline().split(' ')[2:4] code = int(ln[0]) #print(code) ln = f.readline().split(' ') #print(ln) nyears = int(ln[-6]) years = [int(y) for y in ln[-1].split('-')] yr_start, yr_end = years self.data[name] = { 'nr': code, 'N': N, 'E': E, 'elev': elev, 'x': np.round(x), 'y': np.round(y), 'nyears': nyears, 'start': yr_start, 'endyr': yr_end } next(f) except: print('Number of stations: ', len(self.data)) break except: raise FileNotFoundError(stationsFileName)
def __init__(self, name, EN=None, RD=None): self.name = name if EN is None and RD is None: raise ValueError('EN and RD cannot both be None') if EN is None: self.rd = RD x, y = RD[:, 0], RD[:, 1] E, N = rd2wgs(x, y) self.EN = np.vstack((E, N)).T if RD is None: self.EN = EN e, n = EN[:, 0], EN[:, 1] x, y = wgs2rd(e, n) self.rd = np.vstack((x, y)).T self.Em = np.mean(self.EN[:, 0]) self.Nm = np.mean(self.EN[:, 1]) self.xm = np.mean(self.rd[:, 0]) self.ym = np.mean(self.rd[:, 1]) self.xlim = (np.min(self.rd[:, 0]), np.max(self.rd[:, 0])) self.ylim = (np.min(self.rd[:, 1]), np.max(self.rd[:, 1]))
def getWstations(loc="http://climexp.knmi.nl/KNMIData/list_dx.txt"): """return dict with meta data of KNMI stations. The URL was valid in March 2017. """ r = requests.get(loc) #data = r.content.decode('utf-8').split('\n') data = r.text.split('\n') stations=dict() for i, line in enumerate(data[1:]): j = i%5 if j==0: pass # '====' if j==1: # name and country we'll get it from station code pass elif j==2: # coordinates coords, meta = line.split(' <a href=') _, coords = coords.split(':') coords = coords.strip().replace(',','').replace(' ',' ')\ .replace(' ',' ').replace(' ',' ').split(' ') meta = meta.split(' ')[0].replace('"', '') WGS = [float(c[:-1]) for c in coords] RD = WGS[:] RD[0], RD[1] = wgs2rd(WGS[1], WGS[0]) elif j==3: code, name = line.split(':')[1].strip().split(' ') elif j==4: period = line.split(' ')[-1] stations[name] = {'code': code, 'lat': WGS[0], 'lon': WGS[1], 'x': RD[0], 'y': RD[1], 'z': RD[2], 'period': period, 'meta': meta} return stations
def xcyc(self): return wgs2rd(self.center[1], self.center[0])
def pgbb_rd(self): xy = self.pgon_bb return wgs2rd(*xy.T)
def URrd(self): return wgs2rd(*self.UR)
def LRrd(self): return wgs2rd(*self.LR)
def LLrd(self): return wgs2rd(*self.LL)
def ULrd(self): return wgs2rd(*self.UL)
def xy(self, px, py): lat, lon = self.lonlat(px, py) return wgs2rd(lon, lat)