def test_calculate_distance_with_correct_parameters(self):
     self.assertEqual(
         41.68,
         calculate_distance(53.3381985, -6.2592576, 52.986375, -6.043701))
     self.assertEqual(
         313.1,
         calculate_distance(53.3381985, -6.2592576, 51.92893, -10.27699))
     self.assertEqual(
         324.22,
         calculate_distance(53.3381985, -6.2592576, 51.8856167,
                            -10.4240951))
def get_customers_in_a_range_of_100km(customers):
    """
    This function takes a dictionary of customers that contains a
    latitude and a longitude properties for each customer and return the
    customers in a range of 100Km of distance from Intercom office

    It raise a ValueError Exception in case a customer element of dictionary
    do not have a user_id, name, latitude or longitude keys
    """
    office_latitude = 53.3381985
    office_longitude = -6.2592576
    close_customers = []

    for customer in customers:
        if not customer.has_key("latitude") or not customer.has_key("longitude"):
            raise ValueError(
                "The customer dictionary needs to have a user_id, name, latitude and longitude keys.")
        distance_from_office = calculate_distance(office_latitude,
                                                  office_longitude,
                                                  float(customer["latitude"]),
                                                  float(customer["longitude"]))
        
        if distance_from_office <= 100.0:
            close_customers.append([customer["user_id"], customer["name"]])

    return sorted(close_customers)
Exemple #3
0
def get_customers_in_a_range_of_100km(customers):
    """
    This function takes a dictionary of customers that contains a
    latitude and a longitude properties for each customer and return the
    customers in a range of 100Km of distance from Intercom office

    It raise a ValueError Exception in case a customer element of dictionary
    do not have a user_id, name, latitude or longitude keys
    """
    office_latitude = 53.3381985
    office_longitude = -6.2592576
    close_customers = []

    for customer in customers:
        if not customer.has_key("latitude") or not customer.has_key(
                "longitude"):
            raise ValueError(
                "The customer dictionary needs to have a user_id, name, latitude and longitude keys."
            )
        distance_from_office = calculate_distance(office_latitude,
                                                  office_longitude,
                                                  float(customer["latitude"]),
                                                  float(customer["longitude"]))

        if distance_from_office <= 100.0:
            close_customers.append([customer["user_id"], customer["name"]])

    return sorted(close_customers)
    # print section heading
    print("Distance calculation\n____________________")
    # open file safely and put the information into a list
    with open(input_file) as pdb:
        content = pdb.readlines()
    # loop through arguments
    for atom in args.atoms:
        print("\nCalculating distance between:")
        # for each argument, unpack it into the separate atoms, then return the line number for the two atoms within the file
        startpos, endpos = parse_arguments(atom, content)

        # if the function completed correctly
        if not startpos == -1 and not endpos == -1:
            # calculate the distance between the atoms, and print it
            print("Distance between atoms: ",
                  calculate_distance(content, startpos, endpos))
        else:
            # if there was an error, inform the user
            print("Calculation not performed")

    print("\n")
#---------------------------------------------------------------------------------------------------------------------
# Draw the molecule using pymol, highlighting the secondary structural elements.  Export pngs of cartoon and line representations.

if 2 in args.perform:
    # print section heading
    print("Drawing molecule\n________________\n")
    # set the output filename based on the argument provided, or the input filename if no argument was provided
    if args.outputpng:
        output_fname = args.outputpng[0]
    else:
Exemple #5
0
def set_domain(lons, lats):
    """ Reads user selected lats and lons and configures the
    WPS and WRF Namelists"""

    WPS_GEOG_Path = '../../WRF_System/lib/WPS_GEOG'
    x_center = (lons[0] + lons[1]) / 2
    y_center = (lats[0] + lats[1]) / 2
    gridcells_x = round(
        round(
            calculate_distance(min(lons), max(lons), min(lats), min(lats)) /
            (resolution - 1)))
    #resolition -1 to cover edges of boundary
    gridcells_y = round(
        round(
            calculate_distance(min(lons), min(lons), min(lats), max(lats)) /
            (resolution - 1)))

    subprocess.call("sed -i /e_we/c\\e_we='{}' "
                    "/pi-wrf/WRF_System/WPS/namelist.wps".format(gridcells_x),
                    shell=True)
    subprocess.call(
        "sed -i /e_we/c\\e_we='{}' "
        "/pi-wrf/WRF_System/WRFV3/run/namelist.input".format(gridcells_x),
        shell=True)
    subprocess.call("sed -i /e_sn/c\\e_sn='{}' "
                    "/pi-wrf/WRF_System/WPS/namelist.wps".format(gridcells_y),
                    shell=True)
    subprocess.call(
        "sed -i /e_sn/c\\e_sn='{}' "
        "/pi-wrf/WRF_System/WRFV3/run/namelist.input".format(gridcells_y),
        shell=True)
    subprocess.call("sed -i /ref_lat/c\\ref_lat='{}' "
                    "/pi-wrf/WRF_System/WPS/namelist.wps".format(y_center),
                    shell=True)
    subprocess.call("sed -i /ref_lon/c\\ref_lon='{}' "
                    "/pi-wrf/WRF_System/WPS/namelist.wps".format(x_center),
                    shell=True)

    subprocess.call("sed -i /truelat1/c\\truelat1='{}' "
                    "/pi-wrf/WRF_System/WPS/namelist.wps".format(lats[0]),
                    shell=True)
    subprocess.call("sed -i /truelat2/c\\truelat2='{}' "
                    "/pi-wrf/WRF_System/WPS/namelist.wps".format(lats[1]),
                    shell=True)

    subprocess.call(
        "sed -i /pole_lat/c\\pole_lat='{}' "
        "/pi-wrf/WRF_System/WPS/namelist.wps".format(90 - abs(y_center)),
        shell=True)

    subprocess.call("sed -i /stand_lon/c\\stand_lon='{}' "
                    "/pi-wrf/WRF_System/WPS/namelist.wps".format(x_center),
                    shell=True)
    subprocess.call("sed -i /stand_lon/c\\stand_lon='{}' "
                    "/pi-wrf/WRF_System/WPS/namelist.wps".format(x_center),
                    shell=True)
    subprocess.call(
        "sed -i /geog_data_path/c\geog_data_path='{}' "
        "/pi-wrf/WRF_System/WPS/namelist.wps".format(WPS_GEOG_Path),
        shell=True)

    if (min(abs(lats[0]), abs(lats[1])) < 17) or (max(abs(lats[0]), abs(
            lats[1])) > 70):
        subprocess.call(
            "sed -i /time_step/c\\time_step=60 "
            "/pi-wrf/WRF_System/WRFV3/run/namelist.input",
            shell=True)
    elif max(lats) > 17 and min(lats) < -17:
        subprocess.call(
            "sed -i /time_step/c\\time_step=60 "
            "/pi-wrf/WRF_System/WRFV3/run/namelist.input",
            shell=True)
    else:
        subprocess.call(
            "sed -i /time_step/c\\time_step=180 "
            "/pi-wrf/WRF_System/WRFV3/run/namelist.input",
            shell=True)
 def test_calculate_distance_with_correct_parameters(self):
     self.assertEqual(41.68, calculate_distance(53.3381985, -6.2592576, 52.986375, -6.043701))
     self.assertEqual(313.1, calculate_distance(53.3381985, -6.2592576, 51.92893, -10.27699))
     self.assertEqual(324.22, calculate_distance(53.3381985, -6.2592576, 51.8856167, -10.4240951))
 def test_calculate_distance_with_wrong_parameters(self):
     self.assertRaises(ValueError, lambda: calculate_distance("wrong_value", 1, 2, 3))
Exemple #8
0
#
# with open('tools/stations_distances_matrix.json', 'w') as fp:
#     json.dump(stations_array, fp)

with open('tools/stations_distances_matrix.json') as fff:
    stations_array = json.load(fff)

with open('tools/stations_routes_matrix.json') as fff:
    routes_array = json.load(fff)

for i in range(150, 403):
    print(i)
    for j in range(i, len(keys)):
        try:

            x = calculate_distance(
                [stations[keys[i]]['lat'], stations[keys[i]]['lng']],
                [stations[keys[j]]['lat'], stations[keys[j]]['lng']])
            stations_array['matrix'][i][j] = x[0]

            routes_array['matrix'][i][j] = x[1]

        except TimeoutError:
            print('directions err')

    with open('tools/stations_distances_matrix.json', 'w') as fp:
        json.dump(stations_array, fp)

    with open('tools/stations_routes_matrix.json', 'w') as file:
        json.dump(routes_array, file)
 def test_calculate_distance_with_wrong_parameters(self):
     self.assertRaises(ValueError,
                       lambda: calculate_distance("wrong_value", 1, 2, 3))