def test_physical_coverage(self): meta = Metadata('xyfile1.csv', []) edges = meta.get_physical_coverage() self.assertEqual(edges, [8.975, -79.5915, 10, -79.5915])
def test_title(self): meta = Metadata('xyfile1.csv', []) self.assertEqual(meta.get_title(), 'Unittest XML')
def make_map(data_paths, run_name, whole_globe=False): ''' Makes a map of all sites in run. Parameter --------- data_paths : list Paths to data files (csv's). Data location will be extracted from corresponding xml metadata file. run_name : str Name of run, used as name of map file. whole_globe : bool If True, map is entire globe. If False, map is "zoomed in" on data locations. Returns ------- map_created : bool True if file was created, False if a file already existed and none was created. Notes ----- Map will be given the name of a run. If multiple runs have the same name, only the map associated with the first run of that name will be saved. The label for each site will be the data file base name (e.g., LBRI_2000.csv and LBRI.csv will be LBRI_2000 and LBRI respectively). ''' # Check if Basemap present - if not, log and return try: from mpl_toolkits.basemap import Basemap except: logging.debug('Basemap module is not available, no map of data ' + 'locations can be created') return False # Set map_name map_name = 'map_' + run_name + '.png' # TODO: Check if run_name is unique # Check if map with this run_name already exists if os.path.isfile(map_name): logging.debug('Map with this run name already exists. New map ' + 'overwriting old one.') # Get lat, long, and name of each data set lats = [] lons = [] names = [] for path in data_paths: temp = list(os.path.split(path)) temp[1] = temp[1].split('.')[0] + '.xml' x = os.path.join(temp[0], temp[1]) try: meta = Metadata(x, {}) bounds = meta.get_physical_coverage() lats.append(bounds[0]) lons.append(bounds[1]) fname, fext = os.path.splitext(os.path.split(path)[-1]) names.append(fname) # First 4 letters of data set name except: logging.info('No location data found in %s, no map point ' 'added.' % x) # If no valid location data, return without making a map if len(names) == 0: return False # Set up map logging.debug('Creating map for run %s' % run_name) if whole_globe: m = Basemap(projection='cyl', resolution='i') else: # 10 degree buffer around min and max lat/long m = Basemap(projection='cyl', lat_0=50, lon_0=-100, llcrnrlon=min(lons)-10, llcrnrlat=min(lats)-10, urcrnrlon=max(lons)+10, urcrnrlat=max(lats)+10, resolution='l') # Draw features m.bluemarble() m.drawcoastlines() m.drawcountries() m.drawmapboundary() # Add sites x, y = m(lons, lats) m.plot(x, y, 'yo') for n, xpt, ypt in zip(names,x,y): if n == 'BCIS': ypt += 1 # Manual Cleanup for crowded areas if n == 'SHER': ypt += 2 plt.text(xpt+.5,ypt+.5,n,color='yellow') plt.savefig(map_name) plt.close() return True