__license__ = "" __version__ = "0.1" __maintainer__ = "" __email__ = "" __date__ = "January 2015" __status__ = "Development" import sys sys.path = [ '.', '../..' ] + sys.path from utils import _init_log from events import * import dateutil.parser from datetime import * log = _init_log("example-2") file = open('../data/events/weather_data.txt', 'r') events = [] for line in file: fields = line.split(' ') properties = { 'number': fields[0][:-1], 'latitude': fields[3][:-1], 'longitude': fields[4], 'type': ' '.join(fields[5:len(fields)]) }
The classes are written in an object-oriented style. """ __author__ = "Werner Kuhn and Andrea Ballatore" __copyright__ = "Copyright 2014" __credits__ = ["Werner Kuhn", "Andrea Ballatore"] __license__ = "" __version__ = "0.1" __maintainer__ = "Andrea Ballatore" __email__ = "" __date__ = "August 2014" __status__ = "Development" from utils import _init_log log = _init_log("coreconcepts") class CcLocation(object): """ Class defining abstract location relations Note: Unused for the moment. """ def isAt(figure, ground): """ @return Bool """ raise NotImplementedError("isAt") def isIn(figure, ground): """
__author__ = "Michel Zimmer" __copyright__ = "Copyright 2014" __credits__ = ["Michel Zimmer", "Andrea Ballatore"] __license__ = "" __version__ = "0.1" __maintainer__ = "" __email__ = "" __date__ = "December 2014" __status__ = "Development" import networkx as nx from utils import _init_log from coreconcepts import CcNetwork log = _init_log("networks") class NetworkX(CcNetwork): """ NetworkX wrapper implementation for core concept 'network' """ def __init__(self): self._G = nx.Graph() def nodes(self, data=False): """ @return a copy of the graph nodes in a list """ return self._G.nodes(data=data) def edges(self, data=False): """ @return list of edges """
__license__ = "" __version__ = "0.1" __maintainer__ = "" __email__ = "" __date__ = "December 2014" __status__ = "Development" import sys import os import unittest sys.path = [ '.', '..' ] + sys.path from utils import _init_log from objects import * log = _init_log("objects_test") class TestArcShpObject(unittest.TestCase): def test_bounds( self ): #Get objects from shapefiles shapefile1 = os.path.join("..","..","data","objects","Rooftops.shp") shapefile2 = os.path.join("..","..","data","objects","ViablePVArea.shp") roofObj = ArcShpObject( shapefile1, 0 ) pvObj = ArcShpObject( shapefile2, 236 ) #test getBounds on roof object - Poultry Science building print "\nTest shapefile objects - getBounds for CalPoly roof" roofObj = ArcShpObject ( shapefile1, 0 ) roofBounds = roofObj.bounds() roofBounds = ( round( roofBounds[0],2 ),round( roofBounds[1],2 ),round( roofBounds[2],2 ),round( roofBounds[3],2 ) ) print "\nBounding box coordinates, UTM Zone 10N, in form (MinX, MaxX, MinY, MaxY):\n",roofBounds,"\n"
__copyright__ = "Copyright 2015" __credits__ = ["Eric Ahlgren"] __license__ = "" __version__ = "0.1" __maintainer__ = "" __email__ = "" __date__ = "March 2015" __status__ = "Development" import sys sys.path = [ '.', '../..' ] + sys.path from utils import _init_log from fields import * log = _init_log("slopeCalc") # Import system modules import arcpy from arcpy import env from arcpy.sa import * import os # Set environment settings env.workspace = os.path.join("..","..","..","data","fields") # Set local variables inRaster = "CalPolyDEM.tif" outMeasurement = "DEGREE" # Check out the ArcGIS Spatial Analyst extension license
The classes are written in an object-oriented style. """ __author__ = "Werner Kuhn and Andrea Ballatore" __copyright__ = "Copyright 2014" __credits__ = ["Werner Kuhn", "Andrea Ballatore"] __license__ = "" __version__ = "0.1" __maintainer__ = "Andrea Ballatore" __email__ = "" __date__ = "August 2014" __status__ = "Development" from utils import _init_log log = _init_log("coreconcepts") class CcLocation(object): """ Class defining abstract location relations Note: Unused for the moment. """ def isAt( figure, ground ): """ @return Bool """ raise NotImplementedError("isAt") def isIn( figure, ground ): """
__author__ = "Marc Tim Thiemann" __copyright__ = "Copyright 2014" __credits__ = ["Marc Tim Thiemann", "Andrea Ballatore"] __license__ = "" __version__ = "0.1" __maintainer__ = "" __email__ = "" __date__ = "December 2014" __status__ = "Development" from utils import _init_log from coreconcepts import CcEvent import datetime import inspect log = _init_log("events") class PyEvent(CcEvent): def __init__(self, period, properties): """ @param period a tuple of datetime objects @param properties a dictionary of key-value pairs """ if period[1] is not None: assert period[1] >= period[0] self.startTime = period[0] self.endTime = period[1]
__copyright__ = "Copyright 2015" __credits__ = ["Eric Ahlgren"] __license__ = "" __version__ = "0.1" __maintainer__ = "" __email__ = "" __date__ = "March 2015" __status__ = "Development" import sys sys.path = [ '.', '../..' ] + sys.path from utils import _init_log from fields import * log = _init_log("aspectCalc") # Import system modules import arcpy from arcpy import env from arcpy.sa import * import os # Set environment settings env.workspace = os.path.join("..","..","..","data","fields") # Set local variables inRaster = "CalPolyDEM.tif" outMeasurement = "DEGREE" # Check out the ArcGIS Spatial Analyst extension license
__license__ = "" __version__ = "0.1" __maintainer__ = "" __email__ = "" __date__ = "December 2014" __status__ = "Development" import sys import itertools import networkx as nx sys.path = [ '.', '../..' ] + sys.path from utils import _init_log from networks import * log = _init_log("karate") print "Analysis of the network of friendships between the 34 members of a karate club at a US university, as described by Wayne Zachary in 1977." N = NetworkX() N._G = nx.read_gml('../data/networks/karate.gml') print "\nPeople who don't maintain a friendship inside the karate club:" a = [] for b in N.nodes(): if N.degree(b) == 0: a.append(b) assert len(a) == 0 print " non"
__status__ = "Development" import types import numpy as np import numpy.ma as ma import gdal from gdalconst import * from utils import _init_log, _pixel_to_coords, _coords_to_pixel, _rasterize_layer from coreconcepts import CcField VALID_LOCAL_OPS = ('average', 'mean', 'median', 'min', 'minimum', 'max', 'maximum') VALID_DOMAIN_OPS = ('inside', 'outside') log = _init_log("fields") def local(fields, func, domain=None): """ Assign a new value to each pixel in gtiff based on func. Return a new GeoTiff at newGtiffPath. "Local operations A local operation acts upon one or more spatial fields to produce a new field. The distinguishing feature of a local operation is that the value is dependent only on the values of the input field functions at that location. Local operations may be unary (transforming a single field), binary (transforming two fields), or n-ary (transforming any number of fields). 1. For each location x, h(x) = f(x) dot g(x)" (Worboys & Duckham 148) @param fields - List of input fields (assuming all fields have same projection and transform)
__maintainer__ = "" __email__ = "" __date__ = "January 2015" __status__ = "Development" import sys sys.path = [ '.', '../..' ] + sys.path from utils import _init_log from events import * import dateutil.parser from datetime import * from random import randrange import csv log = _init_log("example-3") events = [] f = open('../data/events/course_data.csv') reader = csv.DictReader(f) def getWeekDayName(weekDayNumber): days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] return days[weekDayNumber] def getWeekDays(event): ''' @param event an event @return array of integers for the weekdays of this course (0-6 = Monday - Sunday) '''
__copyright__ = "Copyright 2015" __credits__ = ["Eric Ahlgren"] __license__ = "" __version__ = "0.1" __maintainer__ = "" __email__ = "" __date__ = "March 2015" __status__ = "Development" import sys sys.path = ['.', '../..'] + sys.path from utils import _init_log from fields import * log = _init_log("aspectCalc") # Import system modules import arcpy from arcpy import env from arcpy.sa import * import os # Set environment settings env.workspace = os.path.join("..", "..", "..", "data", "fields") # Set local variables inRaster = "CalPolyDEM.tif" outMeasurement = "DEGREE" # Check out the ArcGIS Spatial Analyst extension license
__version__ = "0.1" __maintainer__ = "" __email__ = "" __date__ = "December 2014" __status__ = "Development" import sys import itertools import networkx as nx import matplotlib.pyplot as plt sys.path = [ '.', '../..' ] + sys.path from utils import _init_log from networks import * log = _init_log("ucsb") print "\nShortest paths in the UCSB street network" N = NetworkX() node_ids = {} for edge in nx.read_shp('../data/networks/ucsb.shp').edges(data = True): sourceId = 0 sourceCoordinates = edge[0] if sourceCoordinates in node_ids: sourceId = node_ids[sourceCoordinates] else: sourceId = len(N.nodes()) + 1 N.addNode(sourceId, coordinates = sourceCoordinates) node_ids[sourceCoordinates] = sourceId targetId = 0
__author__ = "Michel Zimmer" __copyright__ = "Copyright 2014" __credits__ = ["Michel Zimmer", "Andrea Ballatore"] __license__ = "" __version__ = "0.1" __maintainer__ = "" __email__ = "" __date__ = "December 2014" __status__ = "Development" import networkx as nx from utils import _init_log from coreconcepts import CcNetwork log = _init_log("networks") class NetworkX(CcNetwork): """ NetworkX wrapper implementation for core concept 'network' """ def __init__( self ): self._G = nx.Graph() def nodes( self, data = False ): """ @return a copy of the graph nodes in a list """ return self._G.nodes(data = data) def edges( self, data = False ): """ @return list of edges """
__license__ = "" __version__ = "0.1" __maintainer__ = "" __email__ = "" __date__ = "December 2014" __status__ = "Development" import sys import unittest sys.path = [ '.', '..' ] + sys.path from utils import _init_log from events import * from datetime import datetime log = _init_log("events_test") class TestEvents(unittest.TestCase): def setUp(self): self.properties = {'building': 'Phelps Hall', 'room': '3512'} self.startTime = datetime(2015, 1, 7, 10, 48, 15) self.endTime = datetime(2015, 1, 7, 10, 48, 20) self.endTime2 = datetime(2015, 1, 7, 10, 48, 10) self.times = (self.startTime, self.endTime) # Events to test self.e = PyEvent(self.times, self.properties) self.f = PyEvent((datetime(2015, 1, 7, 11, 48, 15), None), self.properties)
__license__ = "" __version__ = "0.1" __maintainer__ = "" __email__ = "" __date__ = "December 2014" __status__ = "Development" import sys import unittest import networkx as nx sys.path = [ '.', '..' ] + sys.path from utils import _init_log from networks import * log = _init_log("networks_test") class TestNetworkXEmptyNetwork(unittest.TestCase): def setUp( self ): self.N = NetworkX() def test_nodes( self ): self.assertEqual(self.N.nodes(), []) def test_edges( self ): self.assertEqual(self.N.edges(), []) def test_addNode( self ): """ 1 2
__copyright__ = "Copyright 2015" __credits__ = ["Eric Ahlgren"] __license__ = "" __version__ = "0.1" __maintainer__ = "" __email__ = "" __date__ = "March 2015" __status__ = "Development" import sys sys.path = ['.', '../..'] + sys.path from utils import _init_log from fields import * log = _init_log("slopeCalc") # Import system modules import arcpy from arcpy import env from arcpy.sa import * import os # Set environment settings env.workspace = os.path.join("..", "..", "..", "data", "fields") # Set local variables inZoneData = "zonalRast.tif" zoneField = "Value" cellSize = 1
__license__ = "" __version__ = "0.1" __maintainer__ = "" __email__ = "" __date__ = "December 2014" __status__ = "Development" import sys import networkx as nx import matplotlib.pyplot as plt sys.path = [ '.', '../..' ] + sys.path from utils import _init_log from networks import * log = _init_log("synthetic_weighted_network") print "\nShortest paths in the synthetic weighted network" N = NetworkX() # horizontal N.addEdge(1, 2, length = 5) N.addEdge(3, 4, length = 5) N.addEdge(4, 5, length = 4) N.addEdge(6, 7, length = 9) # vertical N.addEdge(1, 3, length = 1) N.addEdge(1, 4, length = 3) N.addEdge(2, 4, length = 5) N.addEdge(2, 5, length = 2) N.addEdge(6, 3, length = 8)
__maintainer__ = "" __email__ = "" __date__ = "January 2015" __status__ = "Development" import sys sys.path = [".", "../.."] + sys.path from utils import _init_log from events import * import dateutil.parser from datetime import * from random import randrange import csv log = _init_log("example-3") events = [] f = open("../data/events/course_data.csv") reader = csv.DictReader(f) def getWeekDayName(weekDayNumber): days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] return days[weekDayNumber] def getWeekDays(event): """ @param event an event
__license__ = "" __version__ = "0.1" __maintainer__ = "" __email__ = "" __date__ = "December 2014" __status__ = "Development" import sys import itertools import networkx as nx sys.path = ['.', '../..'] + sys.path from utils import _init_log from networks import * log = _init_log("karate") print "Analysis of the network of friendships between the 34 members of a karate club at a US university, as described by Wayne Zachary in 1977." N = NetworkX() N._G = nx.read_gml('../data/networks/karate.gml') print "\nPeople who don't maintain a friendship inside the karate club:" a = [] for b in N.nodes(): if N.degree(b) == 0: a.append(b) assert len(a) == 0 print " non" print "\nHow many friendships are there?\n %d" % len(N.edges())
__version__ = "0.1" __maintainer__ = "" __email__ = "" __date__ = "January 2015" __status__ = "Development" import sys sys.path = ['.', '../..'] + sys.path from utils import _init_log from events import * import dateutil.parser from datetime import * import csv log = _init_log("example-1") f = open('../data/events/earthquake_data.csv') csv_f = csv.reader(f) events = [] for row in csv_f: properties = { 'latitude': row[1], 'longitude': row[2], 'depth': row[3], 'mag': row[4], 'magType': row[5], 'nst': row[6], 'gap': row[7],
__version__ = "0.1" __maintainer__ = "" __email__ = "" __date__ = "January 2015" __status__ = "Development" import sys sys.path = [ '.', '../..' ] + sys.path from utils import _init_log from events import * import dateutil.parser from datetime import * import csv log = _init_log("example-1") f = open('../data/events/earthquake_data.csv') csv_f = csv.reader(f) events = [] for row in csv_f: properties = { 'latitude': row[1], 'longitude': row[2], 'depth': row[3], 'mag': row[4], 'magType': row[5], 'nst': row[6], 'gap': row[7], 'dmin': row[8],
__maintainer__ = "" __email__ = "" __date__ = "December 2014" __status__ = "Development" import sys import os import unittest import numpy as np import random sys.path = ['.', '..'] + sys.path from utils import _init_log, float_eq from fields import * log = _init_log("fields_test") def getTestField(): testField = GeoTiffField( os.path.join("..", "..", "data", "fields", "testField.tif")) return testField def squareMean3(array, centerPixel): """ Kernel neighborhood function for focal map algebra. Reutrns mean of a 3x3 square array. @param array - array from which to retrieve the neighborhood kernel @param centerPixel - (i,j) corrdinates of center pixel of kernel in the array @return - mean of 3x3 square neighborhood around centerPixel """
import types import numpy as np import numpy.ma as ma import gdal from gdalconst import * from utils import _init_log, _pixel_to_coords, _coords_to_pixel, _rasterize_layer from coreconcepts import CcField VALID_LOCAL_OPS = ('average', 'mean', 'median', 'min', 'minimum', 'max', 'maximum') VALID_DOMAIN_OPS = ('inside', 'outside') log = _init_log("fields") def local(fields, func, domain=None): """ Assign a new value to each pixel in gtiff based on func. Return a new GeoTiff at newGtiffPath. "Local operations A local operation acts upon one or more spatial fields to produce a new field. The distinguishing feature of a local operation is that the value is dependent only on the values of the input field functions at that location. Local operations may be unary (transforming a single field), binary (transforming two fields), or n-ary (transforming any number of fields). 1. For each location x, h(x) = f(x) dot g(x)" (Worboys & Duckham 148)
__author__ = "Eric Ahlgren" __copyright__ = "Copyright 2014" __credits__ = ["Eric Ahlgren", "Andrea Ballatore"] __license__ = "" __version__ = "0.1" __maintainer__ = "" __email__ = "" __date__ = "December 2014" __status__ = "Development" import ogr from utils import _init_log from coreconcepts import CcObject, CcObjectSet log = _init_log("objects") VALID_RELATIONS = ('Intersects', 'Equals', 'Disjoint', 'Touches', 'Crosses', 'Within', 'Contains', 'Overlaps') def from_file(filepath): shp = ogr.Open(filepath) return OgrShpObjectSet(shp) class OgrShpObject(CcObject): """ Subclass of Abstract Object (CcObject) in the ArcMap Shapefile format """
__author__ = "Eric Ahlgren" __copyright__ = "Copyright 2014" __credits__ = ["Eric Ahlgren", "Andrea Ballatore"] __license__ = "" __version__ = "0.1" __maintainer__ = "" __email__ = "" __date__ = "December 2014" __status__ = "Development" import ogr from utils import _init_log from coreconcepts import CcObject, CcObjectSet log = _init_log("objects") VALID_RELATIONS = ('Intersects','Equals','Disjoint','Touches','Crosses','Within','Contains','Overlaps') def from_file(filepath): shp = ogr.Open(filepath) return OgrShpObjectSet(shp) class OgrShpObject(CcObject): """ Subclass of Abstract Object (CcObject) in the ArcMap Shapefile format """ def __init__( self, filepath, objIndex ): shpfile = ogr.Open(filepath)
__license__ = "" __version__ = "0.1" __maintainer__ = "" __email__ = "" __date__ = "December 2014" __status__ = "Development" import sys import networkx as nx import matplotlib.pyplot as plt sys.path = [".", "../.."] + sys.path from utils import _init_log from networks import * log = _init_log("synthetic_weighted_network") print "\nShortest paths in the synthetic weighted network" N = NetworkX() # horizontal N.addEdge(1, 2, length=5) N.addEdge(3, 4, length=5) N.addEdge(4, 5, length=4) N.addEdge(6, 7, length=9) # vertical N.addEdge(1, 3, length=1) N.addEdge(1, 4, length=3) N.addEdge(2, 4, length=5) N.addEdge(2, 5, length=2) N.addEdge(6, 3, length=8)
__maintainer__ = "" __email__ = "" __date__ = "December 2014" __status__ = "Development" import sys import os import unittest import numpy as np import random sys.path = [ '.', '..' ] + sys.path from utils import _init_log, float_eq from fields import * log = _init_log("fields_test") def getTestField(): testField = GeoTiffField( os.path.join("..","..","data","fields","testField.tif") ) return testField def squareMean3( array, centerPixel ): """ Kernel neighborhood function for focal map algebra. Reutrns mean of a 3x3 square array. @param array - array from which to retrieve the neighborhood kernel @param centerPixel - (i,j) corrdinates of center pixel of kernel in the array @return - mean of 3x3 square neighborhood around centerPixel """ rows = centerPixel[0] - 1 cols = centerPixel[1] - 1 neighArray = array[rows:rows + 3, cols:cols + 3]
""" __author__ = "Werner Kuhn and Andrea Ballatore" __copyright__ = "Copyright 2014" __credits__ = ["Werner Kuhn", "Andrea Ballatore"] __license__ = "" __version__ = "0.1" __maintainer__ = "" __email__ = "" __date__ = "August 2014" __status__ = "Development" from utils import _init_log from coreconcepts import CcLocation log = _init_log("location") class ExLoc(CcLocation): """ IGNORE THIS CLASS FOR THE MOMENT. A toy implementation of ALocate. """ def isAt( figure, ground ): # TODO: implementation with some geometric computation return True def isIn( figure, ground ): # TODO: implementation with some geometric computation return True