Пример #1
0
    def testLargeArrayConversion(self):
        """ Test that we don't get segmentation fault: 11 on large (1MM points) arrays using Ctypes """
        # UK bounding box
        N = 55.811741
        E = 1.768960
        S = 49.871159
        W = -6.379880

        num_coords = 1000000
        lon_ls = list(np.random.uniform(W, E, [num_coords]))
        lat_ls = list(np.random.uniform(S, N, [num_coords]))
        convert_bng(lon_ls, lat_ls)
Пример #2
0
    def testLargeArrayConversion(self):
        """ Test that we don't get segmentation fault: 11 on large (1MM points) arrays using Ctypes """
        # UK bounding box
        N = 55.811741
        E = 1.768960
        S = 49.871159
        W = -6.379880

        num_coords = 1000000
        lon_ls = list(np.random.uniform(W, E, [num_coords]))
        lat_ls = list(np.random.uniform(S, N, [num_coords]))
        convert_bng(lon_ls, lat_ls)
Пример #3
0
    def testNumpyConversion(self):
        """ Test lon, lat --> BNG conversion of numpy arrays """
        # UK bounding box
        N = 55.811741
        E = 1.768960
        S = 49.871159
        W = -6.379880

        num_coords = 1000
        lon_arr = np.random.uniform(W, E, [num_coords])
        lat_arr = np.random.uniform(S, N, [num_coords])
        convert_bng(lon_arr, lat_arr)
Пример #4
0
    def testNumpyConversion(self):
        """ Test lon, lat --> BNG conversion of numpy arrays """
        # UK bounding box
        N = 55.811741
        E = 1.768960
        S = 49.871159
        W = -6.379880

        num_coords = 1000
        lon_arr = np.random.uniform(W, E, [num_coords])
        lat_arr = np.random.uniform(S, N, [num_coords])
        convert_bng(lon_arr, lat_arr)
Пример #5
0
    def testConvertLonLat(self):
        """ Test multithreaded lon, lat --> BNG function """
        expected = ([516274.46, 398915.554], [173141.101, 521544.09])

        result = convert_bng([-0.32824866, -2.0183041005533306],
                             [51.44533267, 54.589097162646141])
        self.assertEqual(expected, result)
Пример #6
0
def get_nearest_in_area(X, Y, points, radius=10, n_points=10, latlon=True, json_output=True):
    # If input is in lat long (WGS84), convert to metre (BGS36)
    if latlon == True:
        result = convert_bng(X, Y)
        X, Y = [elem[0] for elem in result]
    
    # Limit search area. Not really 10 metre radius, but close. This makes the code
    # run faster as limit distance computations
    cond = (points['X'] < X + radius)\
             & (points['X'] > X - radius)\
             & (points['Y'] < Y + radius)\
             & (points['Y'] > Y - radius)
    
    # Compute distance from the requested points to all points in the search space
    in_radius = points[cond].copy()
    in_radius['distance'] = np.sqrt((in_radius['X'] - X)**2 + (in_radius['Y'] - Y)**2)
    
    # Get n closest points, order by distance, nearest first
    selected = in_radius.sort_values('distance').head(n_points)
    
    # select only relevant columns
    selected = selected[['ID', 'X', 'Y', 'distance', 'elevation', 'SewerUsage']]
#
    # Give json string to feed to other apps
    if json_output:
        selected = selected.to_json(orient='records')
        
    return selected
Пример #7
0
    def do_GET(self):
        split = parse.urlsplit(self.path)
        print('path = ', split.path)
        params = parse.parse_qs(split.query)

        if params.get('test') is not None:
            self.serve_test_page()
        elif (split.path == '/map' or split.path == '/map/') and params.get(
                'northing') is not None and params.get('easting') is not None:
            self.serve_map_page(params['easting'], params['northing'], True,
                                float(params['tempmin'][0]),
                                float(params['tempmax'][0]),
                                float(params['tempmean'][0]),
                                float(params['rainfall'][0]),
                                params['date'][0])
        elif (split.path == '/map' or split.path == '/map/'):
            if params.get('latitude') is not None and params.get(
                    'longitude') is not None:
                centre = convert_bng([float(params['longitude'][0])],
                                     [float(params['latitude'][0])])
                self.serve_map_page(centre[0], centre[1], True,
                                    float(params['tempmin'][0]),
                                    float(params['tempmax'][0]),
                                    float(params['tempmean'][0]),
                                    float(params['rainfall'][0]),
                                    params['date'][0])
            else:
                self.serve_map_page([888887], [777773], False, 0, 0, 0, 0, '')
        elif split.path == '/home' or split.path == '/home/':
            self.serve_home_page()
        else:
            self.serve_default_page(params)
Пример #8
0
 def testGenerator(self):
     """ Test that the lon, lat -> BNG function can consume generators """
     expected = ([516274.46, 398915.554], [173141.101, 521544.09])
     inp = [[-0.32824866, -2.0183041005533306], [51.44533267, 54.589097162646141]]
     lon_generator = (n for n in inp[0])
     lat_generator = (n for n in inp[1])
     result = convert_bng(lon_generator, lat_generator)
     self.assertEqual(expected, result)
Пример #9
0
 def testGenerator(self):
     """ Test that the lon, lat -> BNG function can consume generators """
     expected = ([516274.46, 398915.554], [173141.101, 521544.09])
     inp = [[-0.32824866, -2.0183041005533306],
            [51.44533267, 54.589097162646141]]
     lon_generator = (n for n in inp[0])
     lat_generator = (n for n in inp[1])
     result = convert_bng(lon_generator, lat_generator)
     self.assertEqual(expected, result)
Пример #10
0
    def testCythonConsistency(self):
        """ Ensure Ctypes and Cython give same results """
        # London bounding box
        N = 51.691874116909894
        E = 0.3340155643740321
        S = 51.28676016315085
        W = -0.5103750689005356
        num_coords = 100

        rand = randrange(0, 100)
        lon_ls = np.random.uniform(W, E, [num_coords])
        lat_ls = np.random.uniform(S, N, [num_coords])
        # result is a list, so convert to an array. Ugh.
        res_ctypes = np.array(convert_bng(lon_ls, lat_ls)[0][rand])
        res_cython = cconvert_bng(lon_ls, lat_ls)[0][rand]

        self.assertEqual(res_ctypes, res_cython)
Пример #11
0
    def testCythonConsistency(self):
        """ Ensure Ctypes and Cython give same results """
        # London bounding box
        N = 51.691874116909894
        E = 0.3340155643740321
        S = 51.28676016315085
        W = -0.5103750689005356
        num_coords = 100

        rand = randrange(0, 100)
        lon_ls = np.random.uniform(W, E, [num_coords])
        lat_ls = np.random.uniform(S, N, [num_coords])
        # result is a list, so convert to an array. Ugh.
        res_ctypes = np.array(convert_bng(lon_ls, lat_ls)[0][rand])
        res_cython = cconvert_bng(lon_ls, lat_ls)[0][rand]

        self.assertEqual(res_ctypes, res_cython)
Пример #12
0
def lat_lon_to_north_east(lat, lon):
    """
    The Geo::Coordinates::OSGB description of ll_to_grid, which was used in the
    original implementation of this function:

        ll_to_grid translates a latitude and longitude pair into a grid easting
        and northing pair.

        The arguments should be supplied as real numbers representing decimal degrees.

        Following the normal mathematical convention, positive arguments mean North or East,
        negative South or West.

    Assumes that the lat/long are WGS84.

    :param lat: latitude in decimal degrees
    :param lon: longitude in decimal degrees
    :return: (n, e) grid easting and northing pair as a 2-tuple
    """
    # Convert from lat/lon into OSGB
    easts, norths = convert_bng(lon, lat)
    return norths[0], easts[0]
    def plot_maps(self,
                  number_of_systems=None,
                  _title="25,000 Systems",
                  version=0,
                  scale=500):
        """Plot map  of passiv systems"""

        if number_of_systems is None:
            _data = self.data
        else:
            _data = self.data.sample(number_of_systems)

        _data.sort_values(by="kwp", axis=0, inplace=True)

        res_list = convert_bng(_data.longitude.values.tolist(),
                               _data.latitude.values.tolist())

        fig, ax = plt.subplots(figsize=(6, 12))
        ax = plt.axes(projection=ccrs.OSGB())
        ax.set_extent([1393.0196, 671196.3657, 13494.9764, 1230275.0454],
                      crs=ccrs.OSGB())
        ax.coastlines(resolution='50m')
        ax.gridlines()
        ax.set_title(_title, fontsize=18)
        marker_scale = _data.kwp.values
        sc = ax.scatter(res_list[0],
                        res_list[1],
                        c=marker_scale,
                        s=10,
                        marker="o",
                        cmap="Spectral")
        clb = plt.colorbar(sc)
        clb.ax.set_title("kWp")
        fig_name = "../graphs/passiv_map_{}_{}.png".format(
            number_of_systems, version)
        fig.savefig(fig_name, bbbbox_inches="tight", dpi=600, transparent=True)
        plt.show()
        return fig
Пример #14
0
def getEastingNorthing(lat, long):
    return convert_bng(long, lat)
Пример #15
0
 def testConvertArray(self):
     """ Test lon, lat --> BNG conversion of array.array """
     expected = ([651409.804], [313177.45])
     result = convert_bng(array.array("d", [1.716073973]), array.array("d", [52.658007833]))
     self.assertEqual(expected, result)
Пример #16
0
 def testConvertIterable(self):
     """ Test lon, lat --> BNG conversion of tuples """
     expected = ([651409.804], [313177.45])
     result = convert_bng(iter([1.7160739736]), iter([52.658007833]))
     self.assertEqual(expected, result)
Пример #17
0
 def testConvertString(self):
     """ Test that an error is thrown for incorrect types """
     with self.assertRaises(ArgumentError) as result:
         convert_bng(["Foo"], ["Bar"])
Пример #18
0
 def testConvertTuple(self):
     """ Test lon, lat --> BNG conversion of tuples """
     expected = ([651409.804], [313177.45])
     result = convert_bng((1.716073973,), (52.658007833,))
     self.assertEqual(expected, result)
Пример #19
0
 def testConvertLonLatSingle(self):
     """ Test lon, lat --> BNG conversion of single values """
     expected = ([651409.804], [313177.45])
     result = convert_bng(1.716073973, 52.658007833)
     self.assertEqual(expected, result)
Пример #20
0
 def testConvertString(self):
     """ Test that an error is thrown for incorrect types """
     with self.assertRaises(ArgumentError) as result:
         convert_bng(['Foo'], ['Bar'])
Пример #21
0
def lola2en(lon: list, lat: list):
    lon = np.array(lon)
    lat = np.array(lat)
    return convert_bng(lon, lat)
Пример #22
0
 def testConvertLonLatSingle(self):
     """ Test lon, lat --> BNG conversion of single values """
     expected = ([651409.804], [313177.45])
     result = convert_bng(1.716073973, 52.658007833)
     self.assertEqual(expected, result)
Пример #23
0
 def testConvertArray(self):
     """ Test lon, lat --> BNG conversion of array.array """
     expected = ([651409.804], [313177.45])
     result = convert_bng(array.array('d', [1.716073973]),
                          array.array('d', [52.658007833]))
     self.assertEqual(expected, result)
Пример #24
0
 def testConvertIterable(self):
     """ Test lon, lat --> BNG conversion of tuples """
     expected = ([651409.804], [313177.45])
     result = convert_bng(iter([1.7160739736]), iter([52.658007833]))
     self.assertEqual(expected, result)
Пример #25
0
import numpy as np
from convertbng.util import convert_bng

# London bounding box
N = 51.691874116909894
E = 0.3340155643740321
S = 51.28676016315085
W = -0.5103750689005356

num_coords = 1000000
lon_ls = np.random.uniform(W, E, [num_coords])
lat_ls = np.random.uniform(S, N, [num_coords])

if __name__ == "__main__":
    for x in xrange(50):
        convert_bng(lon_ls, lat_ls)
Пример #26
0
    def testConvertLonLat(self):
        """ Test multithreaded lon, lat --> BNG function """
        expected = ([516274.46, 398915.554], [173141.101, 521544.09])

        result = convert_bng([-0.32824866, -2.0183041005533306], [51.44533267, 54.589097162646141])
        self.assertEqual(expected, result)
Пример #27
0
 def testConvertTuple(self):
     """ Test lon, lat --> BNG conversion of tuples """
     expected = ([651409.804], [313177.45])
     result = convert_bng((1.716073973, ), (52.658007833, ))
     self.assertEqual(expected, result)