Question: in python code, compute the distance between cities. please use this code template. 7.15 LAB: Great-Circle Distances between cities on Earth The shortest distance between




7.15 LAB: Great-Circle Distances between cities on Earth The shortest distance between two points on a sphere is the distance traveled from one point to the other along the great circle containing those two points. The great circle is the single circle embedded in the surface of the sphere that shares a center with the sphere and passes through the two points. Here, you will write a program that will use the Great Circle formula (below) to compute distances bewteen pairs of cities enumerated in a CSV file that lists each city with its latitude and longitude Given the latitude and longitude (in radians) of two points expressed as (01.01) and (0,02), first define the difference in latitude as A0 - 82 - and then the Great Circle formula (after Vincenty) for finding the shortest distance between them don a sphere of radius ris (cos o, sin A0)2 + (cos sin 2-sino, cos cos 49) d = rarctan sin o sin dy + cos di cos y cos All In the program template given here, my_great_circle.py, you will find a function stub for great_circle_distance() that you must complete. The first two positional parameters are toples containing the latitude and longitude measurements for two locations Notice the comment in the function, it explains the parameters your function must include in the _main_block, the template includes statements that Grabs name of CSV input file from input. Reads the reference location name and coordinates from input, convert coordinates to floats and store in a tuple, and Reads the CSV file into a dictionary Your tasks in this assignment are 1 Complete the definition of the great_circle_distance function 2. Complete the defiwtion of the main() function so that the program loops over all cities read in the CSV file and compute the great circle distance in kombetween the your user entered city and each city in the file outputting each resultan User_city_lame->sv_city Mame: XX.XX km Do not edit the __main_block at allYour program must have a main() function Important Hints: Inside your definition of great_circle_distance(), remember to convert to radians before using math.cos() and math.sin() only if the optional keyword units is set as degrees' Use the math. atan2() function to take the arctangent, How do you loop over items in a dictionary? This demonstrates one way by example >>> a dict-keyl":"valuel, 'key'value2", "key":"value3 ) >>> for key, value in a dict.items(): print('The value for key', key,'1', value) The value for key keyl is value The value for key key2 is value2 The value for key keys is value The items() method is an example of a special set of methods called Views" which we will see more examples of later, Example: As an example, the file cities-testbench.csv looks like this: Oo, 36.2882-99.1328 Devils Lake, 48.1131,-98.075 Cabudare, 10.0331,-69.2633 Al Maroul, 35.0104.-3.0073 Brac, 37.0692,15.2675 Colon, 22.7235,-60.5063 Wilmington, 51.4309,0.1076 ye, 52.450,- 2.116 Want tincoin, 43.066.-75.5663 Makati City.14.55.121.0133 Running your program with this input file should produce this output Running your program with this input file should produce this output Enter name of CSV file: cities-testbench.csv Enter a city, its latitude (deg), and longitude (deg) separated by commas: Walla Walla, 46.065, -118.330278 generates the output Walla Walla, 46.065, -118.330278 Walla Walla->Owasso: 2513.24 km Walla Walla->Devils Lake: 2164.22 km Walla Walla->Cabudare: 5179.63 km Walla Walla->Al Aaroni: 12761.49 km Walla Walla->Siracusa: 14800.25 km Walla Walla->Colon: 4096.53 km Walla Walla->Wilmington: 13163.52 km Walla Walla-Lye: 12901.51 km Walla Walla->West Lincoln: 4309.12 km Walla Walla->Makati City: 13684.84 km One place to find decimal-form latitude and longitude measurements for municipalities on Earth is geohack toolforge.org 7040 11 from math import pi, sqrt, sin, cos, atan2 import csv det greit_alrcle_distance (locl, loc2, 8-6371.0, units-degrees') : computes the great_circle_distance using the Vincenty formula loci [0] is latitude of point 1 and loc1[1] is longitude of point 1 loc2[0] is latitude of point 2 and loc2[1] ia longitude of point 2 I is the radius of the sphere (default is Earth's radius in lon) units is 'degrees by default: radians assumed 1 this is any other value d-0.0 locl - return d defin() ** Grab name of csv input file from input cavinput-input (cities-testbench.csv) Read the reference location name and coordinates from input, convert coordinates to floats and store in a tuple my_city, my_lat_atring, my_long_atring - input(' ').split('.) my_loc - ToatTmy_lat_string). Float (my_long_string)) *** Read the csv file into a dictionary *** input_cities_dict - ( with open (cavinput) as cavfile: citiesreader - cav.reader (cavfile) For Tow in citiesreader: Input_cities_dict [row (01)-(float(row[1]). flokt (row [2])) ** Your code goes here *** Do not edit this block name main__': main() AutoSave Off cities-testbench File Home Insert Draw Page Layout Formulas Data Revie of Cut Calibri LECopy ~ 11 - A Paste & Format Painter BIU v a. Av EEEEEE Clipboard Font L2 Alignmer A12 X fx B C D E F . 1 cit 2 Devils Lake,48.1131,-98.875 3 Cabudare, 10.0331,-69.2633 4 Al Aaroui,35.0104,-3.0073 5 Siracusa 37.0692,15.2875 6 Colon,22.7225,-80.9067 7 Wilmington, 51.4309,0.1876 8 Lye,52.459,-2.116 9 West Lincoln,43.0667,-79.5667 10 Makati City, 14.55,121.0333 11 7.15 LAB: Great-Circle Distances between cities on Earth The shortest distance between two points on a sphere is the distance traveled from one point to the other along the great circle containing those two points. The great circle is the single circle embedded in the surface of the sphere that shares a center with the sphere and passes through the two points. Here, you will write a program that will use the Great Circle formula (below) to compute distances bewteen pairs of cities enumerated in a CSV file that lists each city with its latitude and longitude Given the latitude and longitude (in radians) of two points expressed as (01.01) and (0,02), first define the difference in latitude as A0 - 82 - and then the Great Circle formula (after Vincenty) for finding the shortest distance between them don a sphere of radius ris (cos o, sin A0)2 + (cos sin 2-sino, cos cos 49) d = rarctan sin o sin dy + cos di cos y cos All In the program template given here, my_great_circle.py, you will find a function stub for great_circle_distance() that you must complete. The first two positional parameters are toples containing the latitude and longitude measurements for two locations Notice the comment in the function, it explains the parameters your function must include in the _main_block, the template includes statements that Grabs name of CSV input file from input. Reads the reference location name and coordinates from input, convert coordinates to floats and store in a tuple, and Reads the CSV file into a dictionary Your tasks in this assignment are 1 Complete the definition of the great_circle_distance function 2. Complete the defiwtion of the main() function so that the program loops over all cities read in the CSV file and compute the great circle distance in kombetween the your user entered city and each city in the file outputting each resultan User_city_lame->sv_city Mame: XX.XX km Do not edit the __main_block at allYour program must have a main() function Important Hints: Inside your definition of great_circle_distance(), remember to convert to radians before using math.cos() and math.sin() only if the optional keyword units is set as degrees' Use the math. atan2() function to take the arctangent, How do you loop over items in a dictionary? This demonstrates one way by example >>> a dict-keyl":"valuel, 'key'value2", "key":"value3 ) >>> for key, value in a dict.items(): print('The value for key', key,'1', value) The value for key keyl is value The value for key key2 is value2 The value for key keys is value The items() method is an example of a special set of methods called Views" which we will see more examples of later, Example: As an example, the file cities-testbench.csv looks like this: Oo, 36.2882-99.1328 Devils Lake, 48.1131,-98.075 Cabudare, 10.0331,-69.2633 Al Maroul, 35.0104.-3.0073 Brac, 37.0692,15.2675 Colon, 22.7235,-60.5063 Wilmington, 51.4309,0.1076 ye, 52.450,- 2.116 Want tincoin, 43.066.-75.5663 Makati City.14.55.121.0133 Running your program with this input file should produce this output Running your program with this input file should produce this output Enter name of CSV file: cities-testbench.csv Enter a city, its latitude (deg), and longitude (deg) separated by commas: Walla Walla, 46.065, -118.330278 generates the output Walla Walla, 46.065, -118.330278 Walla Walla->Owasso: 2513.24 km Walla Walla->Devils Lake: 2164.22 km Walla Walla->Cabudare: 5179.63 km Walla Walla->Al Aaroni: 12761.49 km Walla Walla->Siracusa: 14800.25 km Walla Walla->Colon: 4096.53 km Walla Walla->Wilmington: 13163.52 km Walla Walla-Lye: 12901.51 km Walla Walla->West Lincoln: 4309.12 km Walla Walla->Makati City: 13684.84 km One place to find decimal-form latitude and longitude measurements for municipalities on Earth is geohack toolforge.org 7040 11 from math import pi, sqrt, sin, cos, atan2 import csv det greit_alrcle_distance (locl, loc2, 8-6371.0, units-degrees') : computes the great_circle_distance using the Vincenty formula loci [0] is latitude of point 1 and loc1[1] is longitude of point 1 loc2[0] is latitude of point 2 and loc2[1] ia longitude of point 2 I is the radius of the sphere (default is Earth's radius in lon) units is 'degrees by default: radians assumed 1 this is any other value d-0.0 locl - return d defin() ** Grab name of csv input file from input cavinput-input (cities-testbench.csv) Read the reference location name and coordinates from input, convert coordinates to floats and store in a tuple my_city, my_lat_atring, my_long_atring - input(' ').split('.) my_loc - ToatTmy_lat_string). Float (my_long_string)) *** Read the csv file into a dictionary *** input_cities_dict - ( with open (cavinput) as cavfile: citiesreader - cav.reader (cavfile) For Tow in citiesreader: Input_cities_dict [row (01)-(float(row[1]). flokt (row [2])) ** Your code goes here *** Do not edit this block name main__': main() AutoSave Off cities-testbench File Home Insert Draw Page Layout Formulas Data Revie of Cut Calibri LECopy ~ 11 - A Paste & Format Painter BIU v a. Av EEEEEE Clipboard Font L2 Alignmer A12 X fx B C D E F . 1 cit 2 Devils Lake,48.1131,-98.875 3 Cabudare, 10.0331,-69.2633 4 Al Aaroui,35.0104,-3.0073 5 Siracusa 37.0692,15.2875 6 Colon,22.7225,-80.9067 7 Wilmington, 51.4309,0.1876 8 Lye,52.459,-2.116 9 West Lincoln,43.0667,-79.5667 10 Makati City, 14.55,121.0333 11
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
