How to use timezonefinder - 10 common examples

To help you get started, we’ve selected a few timezonefinder examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MrMinimal64 / timezonefinder / test / test_it.py View on Github external
def setUpClass(cls):
        # preparations which have to be made only once
        print("\nSTARTING PACKAGE TESTS\n\n")
        cls.print_tf_class_props(cls)

        global in_memory_mode
        in_memory_mode = cls.in_memory_mode
        t = timeit.timeit("TimezoneFinder(in_memory=in_memory_mode)", globals=globals(), number=1)
        print('startup time:', time_preprocess(t), '\n')

        cls.timezone_finder = TimezoneFinder(bin_file_location=cls.bin_file_dir, in_memory=cls.in_memory_mode)

        # create an array of points where timezone_finder finds something (realistic queries)
        print('collecting and storing', N, 'realistic points for the tests...')
        cls.realistic_points = []
        ps_for_10percent = int(N / 10)
        percent_done = 0

        i = 0
        while i < N:
            lng, lat = random_point()
            # a realistic point is a point where certain_timezone_at() finds something
            if cls.timezone_finder.certain_timezone_at(lng=lng, lat=lat):
                i += 1
                cls.realistic_points.append((lng, lat))
                if i % ps_for_10percent == 0:
                    percent_done += 10
github MrMinimal64 / timezonefinder / test / test_it.py View on Github external
print('')
            print('\nTIMES for ', N, type_of_points)
            print('tzwhere:', his_time)
            print('timezonefinder:', my_time)
            try:
                print(round(his_time / my_time, 2), 'times faster')
            except TypeError:
                pass
                # assert his_time > my_time

        print('\n\n')
        if SHAPELY:
            print('shapely: ON (tzwhere)')
        else:
            print('shapely: OFF (tzwhere)')
        if TimezoneFinder.using_numba():
            print('Numba: ON (timezonefinder)')
        else:
            print('Numba: OFF (timezonefinder)')
        print_speed_test('realistic points', self.realistic_points)
        print_speed_test('random points', list_of_random_points(length=N))
github MrMinimal64 / timezonefinder / test / test_helpers.py View on Github external
class HelperTestNumba(HelperTest):
    # all Numba compiled functions have to receive their arguments in the proper data type (and numpy array shape)
    try:
        import timezonefinder.helpers_numba as helpers
        fct_dict = {
            "all_the_same": helpers.all_the_same,
            "coord2int": helpers.coord2int,
            "int2coord": helpers.int2coord,
            "distance_to_point_on_equator": helpers.distance_to_point_on_equator,
            "distance_to_polygon": helpers.distance_to_polygon,
            "distance_to_polygon_exact": helpers.distance_to_polygon_exact,
            "haversine": helpers.haversine,
            "inside_polygon": helpers.inside_polygon,
            "coord2shortcut": helpers.coord2shortcut,
            "rectify_coordinates": helpers.rectify_coordinates,
            'convert2coords': helpers.convert2coords,
            'convert2coord_pairs': helpers.convert2coord_pairs,
        }
        print('\nNumba installation found.\ntesting helpers_numba.py functions...')

    except ImportError:
        fct_dict = {
            "all_the_same": None,
            "coord2int": None,
            "int2coord": None,
            "distance_to_point_on_equator": None,
            "distance_to_polygon": None,
            "distance_to_polygon_exact": None,
            "haversine": None,
            "inside_polygon": None,
            "coord2shortcut": None,
            "rectify_coordinates": None,
github MrMinimal64 / timezonefinder / test / test_helpers.py View on Github external
assert km2deg(distance_exact) == 0.5
        # print('=====')
        distance = distance_to_polygon(x_rad, y_rad, len(x_coords), np.array(points, dtype=DTYPE_FORMAT_SIGNED_I_NUMPY))
        # print(km2deg(distance))
        assert abs(km2deg(distance) - sqrt(2) / 2) < 0.00001


class HelperTestNumba(HelperTest):
    # all Numba compiled functions have to receive their arguments in the proper data type (and numpy array shape)
    try:
        import timezonefinder.helpers_numba as helpers
        fct_dict = {
            "all_the_same": helpers.all_the_same,
            "coord2int": helpers.coord2int,
            "int2coord": helpers.int2coord,
            "distance_to_point_on_equator": helpers.distance_to_point_on_equator,
            "distance_to_polygon": helpers.distance_to_polygon,
            "distance_to_polygon_exact": helpers.distance_to_polygon_exact,
            "haversine": helpers.haversine,
            "inside_polygon": helpers.inside_polygon,
            "coord2shortcut": helpers.coord2shortcut,
            "rectify_coordinates": helpers.rectify_coordinates,
            'convert2coords': helpers.convert2coords,
            'convert2coord_pairs': helpers.convert2coord_pairs,
        }
        print('\nNumba installation found.\ntesting helpers_numba.py functions...')

    except ImportError:
        fct_dict = {
            "all_the_same": None,
            "coord2int": None,
            "int2coord": None,
github MrMinimal64 / timezonefinder / test / test_helpers.py View on Github external
# print(km2deg(distance))
        assert abs(km2deg(distance) - sqrt(2) / 2) < 0.00001


class HelperTestNumba(HelperTest):
    # all Numba compiled functions have to receive their arguments in the proper data type (and numpy array shape)
    try:
        import timezonefinder.helpers_numba as helpers
        fct_dict = {
            "all_the_same": helpers.all_the_same,
            "coord2int": helpers.coord2int,
            "int2coord": helpers.int2coord,
            "distance_to_point_on_equator": helpers.distance_to_point_on_equator,
            "distance_to_polygon": helpers.distance_to_polygon,
            "distance_to_polygon_exact": helpers.distance_to_polygon_exact,
            "haversine": helpers.haversine,
            "inside_polygon": helpers.inside_polygon,
            "coord2shortcut": helpers.coord2shortcut,
            "rectify_coordinates": helpers.rectify_coordinates,
            'convert2coords': helpers.convert2coords,
            'convert2coord_pairs': helpers.convert2coord_pairs,
        }
        print('\nNumba installation found.\ntesting helpers_numba.py functions...')

    except ImportError:
        fct_dict = {
            "all_the_same": None,
            "coord2int": None,
            "int2coord": None,
            "distance_to_point_on_equator": None,
            "distance_to_polygon": None,
            "distance_to_polygon_exact": None,
github MrMinimal64 / timezonefinder / test / test_helpers.py View on Github external
# print('=====')
        distance = distance_to_polygon(x_rad, y_rad, len(x_coords), np.array(points, dtype=DTYPE_FORMAT_SIGNED_I_NUMPY))
        # print(km2deg(distance))
        assert abs(km2deg(distance) - sqrt(2) / 2) < 0.00001


class HelperTestNumba(HelperTest):
    # all Numba compiled functions have to receive their arguments in the proper data type (and numpy array shape)
    try:
        import timezonefinder.helpers_numba as helpers
        fct_dict = {
            "all_the_same": helpers.all_the_same,
            "coord2int": helpers.coord2int,
            "int2coord": helpers.int2coord,
            "distance_to_point_on_equator": helpers.distance_to_point_on_equator,
            "distance_to_polygon": helpers.distance_to_polygon,
            "distance_to_polygon_exact": helpers.distance_to_polygon_exact,
            "haversine": helpers.haversine,
            "inside_polygon": helpers.inside_polygon,
            "coord2shortcut": helpers.coord2shortcut,
            "rectify_coordinates": helpers.rectify_coordinates,
            'convert2coords': helpers.convert2coords,
            'convert2coord_pairs': helpers.convert2coord_pairs,
        }
        print('\nNumba installation found.\ntesting helpers_numba.py functions...')

    except ImportError:
        fct_dict = {
            "all_the_same": None,
            "coord2int": None,
            "int2coord": None,
            "distance_to_point_on_equator": None,
github MrMinimal64 / timezonefinder / test / test_helpers.py View on Github external
distance = distance_to_polygon(x_rad, y_rad, len(x_coords), np.array(points, dtype=DTYPE_FORMAT_SIGNED_I_NUMPY))
        # print(km2deg(distance))
        assert abs(km2deg(distance) - sqrt(2) / 2) < 0.00001


class HelperTestNumba(HelperTest):
    # all Numba compiled functions have to receive their arguments in the proper data type (and numpy array shape)
    try:
        import timezonefinder.helpers_numba as helpers
        fct_dict = {
            "all_the_same": helpers.all_the_same,
            "coord2int": helpers.coord2int,
            "int2coord": helpers.int2coord,
            "distance_to_point_on_equator": helpers.distance_to_point_on_equator,
            "distance_to_polygon": helpers.distance_to_polygon,
            "distance_to_polygon_exact": helpers.distance_to_polygon_exact,
            "haversine": helpers.haversine,
            "inside_polygon": helpers.inside_polygon,
            "coord2shortcut": helpers.coord2shortcut,
            "rectify_coordinates": helpers.rectify_coordinates,
            'convert2coords': helpers.convert2coords,
            'convert2coord_pairs': helpers.convert2coord_pairs,
        }
        print('\nNumba installation found.\ntesting helpers_numba.py functions...')

    except ImportError:
        fct_dict = {
            "all_the_same": None,
            "coord2int": None,
            "int2coord": None,
            "distance_to_point_on_equator": None,
            "distance_to_polygon": None,
github MrMinimal64 / timezonefinder / test / test_helpers.py View on Github external
np.array(trans_points, dtype=DTYPE_FORMAT_F_NUMPY))
        # print(km2deg(distance_exact))
        assert km2deg(distance_exact) == 0.5
        # print('=====')
        distance = distance_to_polygon(x_rad, y_rad, len(x_coords), np.array(points, dtype=DTYPE_FORMAT_SIGNED_I_NUMPY))
        # print(km2deg(distance))
        assert abs(km2deg(distance) - sqrt(2) / 2) < 0.00001


class HelperTestNumba(HelperTest):
    # all Numba compiled functions have to receive their arguments in the proper data type (and numpy array shape)
    try:
        import timezonefinder.helpers_numba as helpers
        fct_dict = {
            "all_the_same": helpers.all_the_same,
            "coord2int": helpers.coord2int,
            "int2coord": helpers.int2coord,
            "distance_to_point_on_equator": helpers.distance_to_point_on_equator,
            "distance_to_polygon": helpers.distance_to_polygon,
            "distance_to_polygon_exact": helpers.distance_to_polygon_exact,
            "haversine": helpers.haversine,
            "inside_polygon": helpers.inside_polygon,
            "coord2shortcut": helpers.coord2shortcut,
            "rectify_coordinates": helpers.rectify_coordinates,
            'convert2coords': helpers.convert2coords,
            'convert2coord_pairs': helpers.convert2coord_pairs,
        }
        print('\nNumba installation found.\ntesting helpers_numba.py functions...')

    except ImportError:
        fct_dict = {
            "all_the_same": None,
github MrMinimal64 / timezonefinder / test / test_helpers.py View on Github external
np.array(points, dtype=DTYPE_FORMAT_SIGNED_I_NUMPY),
                                                   np.array(trans_points, dtype=DTYPE_FORMAT_F_NUMPY))
        # print(km2deg(distance_exact))
        assert km2deg(distance_exact) == 0.5
        # print('=====')
        distance = distance_to_polygon(x_rad, y_rad, len(x_coords), np.array(points, dtype=DTYPE_FORMAT_SIGNED_I_NUMPY))
        # print(km2deg(distance))
        assert abs(km2deg(distance) - sqrt(2) / 2) < 0.00001


class HelperTestNumba(HelperTest):
    # all Numba compiled functions have to receive their arguments in the proper data type (and numpy array shape)
    try:
        import timezonefinder.helpers_numba as helpers
        fct_dict = {
            "all_the_same": helpers.all_the_same,
            "coord2int": helpers.coord2int,
            "int2coord": helpers.int2coord,
            "distance_to_point_on_equator": helpers.distance_to_point_on_equator,
            "distance_to_polygon": helpers.distance_to_polygon,
            "distance_to_polygon_exact": helpers.distance_to_polygon_exact,
            "haversine": helpers.haversine,
            "inside_polygon": helpers.inside_polygon,
            "coord2shortcut": helpers.coord2shortcut,
            "rectify_coordinates": helpers.rectify_coordinates,
            'convert2coords': helpers.convert2coords,
            'convert2coord_pairs': helpers.convert2coord_pairs,
        }
        print('\nNumba installation found.\ntesting helpers_numba.py functions...')

    except ImportError:
        fct_dict = {
github MrMinimal64 / timezonefinder / test / test_helpers.py View on Github external
# print(km2deg(distance_exact))
        assert km2deg(distance_exact) == 0.5
        # print('=====')
        distance = distance_to_polygon(x_rad, y_rad, len(x_coords), np.array(points, dtype=DTYPE_FORMAT_SIGNED_I_NUMPY))
        # print(km2deg(distance))
        assert abs(km2deg(distance) - sqrt(2) / 2) < 0.00001


class HelperTestNumba(HelperTest):
    # all Numba compiled functions have to receive their arguments in the proper data type (and numpy array shape)
    try:
        import timezonefinder.helpers_numba as helpers
        fct_dict = {
            "all_the_same": helpers.all_the_same,
            "coord2int": helpers.coord2int,
            "int2coord": helpers.int2coord,
            "distance_to_point_on_equator": helpers.distance_to_point_on_equator,
            "distance_to_polygon": helpers.distance_to_polygon,
            "distance_to_polygon_exact": helpers.distance_to_polygon_exact,
            "haversine": helpers.haversine,
            "inside_polygon": helpers.inside_polygon,
            "coord2shortcut": helpers.coord2shortcut,
            "rectify_coordinates": helpers.rectify_coordinates,
            'convert2coords': helpers.convert2coords,
            'convert2coord_pairs': helpers.convert2coord_pairs,
        }
        print('\nNumba installation found.\ntesting helpers_numba.py functions...')

    except ImportError:
        fct_dict = {
            "all_the_same": None,
            "coord2int": None,