def plottResult(result): # polygons = TextPolygons(args) # if args.np > 1: # # Combine the results if multiprocessing has been used. # finalResult = Result(polygons, args) # joinResults(finalResult, result_objects) ########################################### # Print the output if args.tab == True: result.printTab(args) else: result.printNexus(args) if args.localities_in_polygon_tab: # Print the localities found in a polygon to a tab-separated file localities_in_polygon_tab = open(args.localities_in_polygon_tab, "w") localities_in_polygon_tab.write(result.localitiesInPolygons()) localities_in_polygon_tab.close() if args.localities_in_polygon_shape: import shapefile w = shapefile.Writer(shapefile.POINT) # shape_outfile = args.localities_in_polygon_shape # print shape_outfile w.autoBalance = 1 w.field('LATITUDE') w.field('LONGITUDE') w.field('SPECIES', 'C', '100') # for locality in result.localitiesInPolygons(): for locality in result.sampletable: w.point(float(locality[2]), float(locality[3])) # Set the field names # Set record name and type w.record(SPECIES=str(locality[0]), LATITUDE=float(locality[3]), LONGITUDE=float(locality[2])) # w.record('First', 'Point') w.save(args.localities_in_polygon_shape) # w.save(shape_outfile) if args.plot == True: # Generate various plots using R import os from lib.plot import prepare_plots prepare_plots(result, polygons) #__ GUI STUFF dir_output = args.dir_output # Working directory path_script = args.path_script cmd="Rscript %s/R/graphical_output.R %s %s %s %s %s %s" \ % (path_script,path_script, "coordinates.sgc.txt", "polygons.sgc.txt", "sampletable.sgc.txt", "speciestable.sgc.txt",dir_output) os.system(cmd) if args.stochastic_mapping == True: # Run teh stochastic mapping analysis import os import lib.stochasticMapping as stochasticMapping # Run the stochastic mapping analysis stochasticMapping.main(args, result) # Take uncertainty into account if args.uncertainty == True: print "\n" result.sensitivityTest()
def main(): from lib.result import Result # Create list to store the geotif objects in. polygons = Polygons() result = Result(polygons, args) done = 0 # Index the geotiff files if available. if args.tif: from lib.readGeoTiff import indexTiffs try: index = indexTiffs(args.tif) except AttributeError: sys.exit("[ Error ] No such file \'%s\'" % args.tif[0]) # Read the locality data and test if the coordinates # are located in any of the polygons. # For each locality record ... if args.localities: localities = MyLocalities() numLoc = localities.getQuant() result.setSpeciesNames(localities) for locality in localities.getLocalities(): done = print_progress(done, numLoc) # ... and for each polygon ... for polygon in polygons.getPolygons(): # ... test if the locality record is found in the polygon. if localities.getCoOrder() == "lat-long": # locality[0] = species name, locality[1] = latitude, locality[2] = longitude if pointInPolygon(polygon[1], locality[2], locality[1]) == True: # Test if elevation files are available. if args.tif: if elevationTest(locality[1], locality[2], polygon, index) == True: # Store the result result.setResult(locality, polygon[0]) else: # Store the result result.setResult(locality, polygon[0]) else: # locality[0] = species name, locality[1] = longitude, locality[2] = latitude if pointInPolygon(polygon[1], locality[1], locality[2]) == True: if args.tif: if elevationTest(locality[2], locality[1], polygon, index) == True: result.setResult(locality[0], polygon[0]) if args.gbif: gbifData = GbifLocalities() result.setSpeciesNames(gbifData) numLoc = gbifData.getQuant() # For each GBIF locality record ... for locality in gbifData.getLocalities(): done = print_progress(done, numLoc) # ... and for each polygon ... for polygon in polygons.getPolygons(): # ... test if the locality record is found in the polygon. if pointInPolygon(polygon[1], locality[2], locality[1]) == True: result.setResult(locality, polygon[0]) # Test if elevation files are available. if args.tif: if elevationTest(locality[1], locality[2], polygon, index) == True: # Store the result result.setResult(locality, polygon[0]) else: # Store the result result.setResult(locality, polygon[0]) sys.stderr.write("\n") result.printNexus(args.out) if args.plot == True: import os from lib.plot import prepare_plots prepare_plots(result, polygons) #__ GUI STUFF dir_output = args.dir_output # Working directory path_script = args.path_script cmd="Rscript %s/R/graphical_output.R %s %s %s %s %s %s" \ % (path_script,path_script, "coordinates.sgc.txt", "polygons.sgc.txt", "sampletable.sgc.txt", "speciestable.sgc.txt",dir_output) os.system(cmd) if args.stochastic_mapping == True: import os import lib.stochasticMapping as stochasticMapping # Run the stochastic mapping analysis stochasticMapping.main(args, result)