I am learning about the class and methods in Python.
The class Accuracy is a class of several (13 in total) statistic values between a reference polygon and one or more segmented polygons based on shapely module.
from numpy import average
#some stat
def ra_or(ref, seg):
return average([(ref.intersection(s).area/ref.area) for s in seg])
def ra_os(ref, seg):
return average([(ref.intersection(s).area/s.area) for s in seg])
def sim_size(ref, seg):
return average([(min(ref.area, s.area)/max(ref.area,s.area)) for s in seg])
def AFI(ref,seg):
return (ref.area - max([s.area for s in seg]))/ref.area
where ref.intersection(s).area
is the area of intersection between reference
and segmented polygon-i
my class design (really basic and probably to improve) is:
class Accuracy(object):
def __init__ (self,ref,seg = None, noData = -9999):
if seg == None:
self.area = ref.area
self.perimeter = ref.length
self.centroidX = ref.centroid.x
self.centroidY = ref.centroid.y
self.data = [self.centroidX,
self.centroidY,
self.area,
self.perimeter,
noData,
noData,
noData,
noData,
noData]
else:
self.area = ref.area
self.perimeter = ref.length
self.centroidX = ref.centroid.x
self.centroidY = ref.centroid.y
self.segments = len(seg)
self.RAor = ra_or(ref,seg)
self.RAos = ra_os(ref,seg)
self.SimSize = sim_size(ref,seg)
self.AFI = AFI(ref,seg)
self.data = [self.centroidX,
self.centroidY,
self.area,
self.perimeter,
self.segments,
self.RAor,
self.RAos,
self.SimSize,
self.AFI]
from shapely.geometry import Polygon
p1 = Polygon([(2, 4), (4, 4), (4, 2), (2, 2), (2, 4)])
p2 = Polygon([(0, 3), (3, 3), (3, 0), (0, 0), (0, 3)])
accp1 = Accuracy(p1,[p2])
accp1.data
[3.0, 3.0, 4.0, 8.0, 1, 0.25, 0.1111111111111111, 0.44444444444444442, -1.25]
accp1 = Accuracy(p1)
accp1.data
[3.0, 3.0, 4.0, 8.0, -9999, -9999, -9999, -9999, -9999]
ra_or
,ra_os
, etc. outside ofAccuracy
? \$\endgroup\$