from datatool import datatool import numpy as np import math dt = datatool() dt.load_csv('bluefin_whale_data.csv') dt.tilemap_attach_col_lat_long('location-lat', 'location-long', 'individual-local-identifier') # First, the min and max in each direction. Lat is at index 3, long is 4, id is 11 D = dt.get_data_as_array() min_lat = D[0,4] max_lat = D[0,4] min_long = D[0,3] max_long = D[0,3] for i in range(D.shape[0]): # COPY YOUR CODE FROM the previous exercise here print('min-lat=', min_lat, 'max-lat=', max_lat) print('min-long=', min_long, 'max-long=', max_long) # COPY YOUR CODE FROM the previous exercise here. # Round min down, round max up print('min-lat=', min_lat, 'max-lat=', max_lat) print('min-long=', min_long, 'max-long=', max_long) # WRITE CODE in this function to determine whether the point # specified by lat,lon is inside the half-box whose bottom # left corner is box_lat, box_lon. Return True or False accordingly. def within(box_lat, box_lon, lat, lon): # Copy your code from the previous exercise here # WRITE CODE in this function to count the number of data points # from the 2D array D whose lat-lon's are inside the half-box # whose bottom left corner is box_lat, box_lon. def count_occurences(box_lat, box_lon): # Copy your code from the previous exercise here # Next, run through the boxes num_boxes = 0 max_count = 0 best_lat = 0 best_lon = 0 lat = min_lat while lat < max_lat: lon = min_long while lon < max_long: # Count occurrences within lat to lat+0.5, lon to lon+0.5 num_boxes += 1 count = count_occurences(lat, lon) if (count > max_count): max_count = count best_lat = lat best_lon = lon lon += 0.5 lat += 0.5 print('After searching', num_boxes, 'boxes: ') print(' => best box: lat', best_lat, ':', best_lat+0.5, ' lon', best_lon, ':', best_lon+0.5, ' count =', max_count) dt.tilemap_add_line(best_lat, best_lon, best_lat+0.5, best_lon) dt.tilemap_add_line(best_lat, best_lon, best_lat, best_lon+0.5) dt.tilemap_add_line(best_lat, best_lon+0.5, best_lat+0.5, best_lon+0.5) dt.tilemap_add_line(best_lat+0.5, best_lon, best_lat+0.5, best_lon+0.5) center = dict(lat = 35, lon =-119) dt.tilemap_czt(center, zoom=5, title='Best spotting area') # A bit west of Long Beach, CA, and northwest of Catalina Island dt.display()