Beispiel #1
0
def main(locality_file):

	if args.l_shape:
		localities = ShapeLocalities(args, locality_file)
	if args.localities:
		localities = TextLocalities(args, locality_file)

	from lib.result import Result

	# This next part is probably redundant, sinch assigning the 'polygons' variable is now done in the main() function.
	if args.p_shape:
		polygons = ShapePolygons(args)
	if args.polygons:
		polygons = TextPolygons(args)
	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 or args.l_shape:
#		localities = TextLocalities(args, locality_file)
		numLoc = localities.getNrLocalities()
		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.
				# locality[0] = species name, locality[1] = latitude, locality[2] =  longitude
#				if pointInPolygon(polygon[1], locality[2], locality[1]) == True:
				if pointInPolygon(polygon[1], locality) == 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])
	
	if args.gbif:
		gbifData = GbifLocalities(args)
		result.setSpeciesNames(gbifData)
		numLoc = gbifData.getNrLocalities()

		# 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:
				if pointInPolygon(polygon[1], locality) == 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])

	# Clean up
	if args.np > 1:
		try:
			os.remove(locality_file)
		except:
			pass
	sys.stderr.write("\n")
	return result
Beispiel #2
0
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)
Beispiel #3
0
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)
def main(locality_file):

    if args.l_shape:
        localities = ShapeLocalities(args, locality_file)
    if args.localities:
        localities = TextLocalities(args, locality_file)

    from lib.result import Result

    # This next part is probably redundant, sinch assigning the 'polygons' variable is now done in the main() function.
    if args.p_shape:
        polygons = ShapePolygons(args)
    if args.polygons:
        polygons = TextPolygons(args)
    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 or args.l_shape:
        #		localities = TextLocalities(args, locality_file)
        numLoc = localities.getNrLocalities()
        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.
                # locality[0] = species name, locality[1] = latitude, locality[2] =  longitude
                #				if pointInPolygon(polygon[1], locality[2], locality[1]) == True:
                if pointInPolygon(polygon[1], locality) == 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])

    if args.gbif:
        gbifData = GbifLocalities(args)
        result.setSpeciesNames(gbifData)
        numLoc = gbifData.getNrLocalities()

        # 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:
                if pointInPolygon(polygon[1], locality) == 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])

    # Clean up
    if args.np > 1:
        try:
            os.remove(locality_file)
        except:
            pass
    sys.stderr.write("\n")
    return result