Пример #1
0
 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
Пример #2
0
 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
Пример #3
0
    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)
Пример #4
0
    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]))
Пример #5
0
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
Пример #6
0
 def xcyc(self):
     return wgs2rd(self.center[1], self.center[0])
Пример #7
0
 def pgbb_rd(self):
     xy = self.pgon_bb
     return wgs2rd(*xy.T)
Пример #8
0
 def URrd(self):
     return wgs2rd(*self.UR)
Пример #9
0
 def LRrd(self):
     return wgs2rd(*self.LR)
Пример #10
0
 def LLrd(self):
     return wgs2rd(*self.LL)
Пример #11
0
 def ULrd(self):
     return wgs2rd(*self.UL)
Пример #12
0
 def xy(self, px, py):
     lat, lon = self.lonlat(px, py)
     return wgs2rd(lon, lat)