def processTracks(self, tracks): """ Given a collection of :class:`Track` objects and set of gate vertices, calculate if the tracks cross the gates in either an onshore or offshore direction. Returns the histograms for the gate counts. """ landfall = [] offshore = [] for t in tracks: for i in range(1, len(t.Longitude)): cross = Int.Crossings() start = Int.Point(t.Longitude[i - 1], t.Latitude[i - 1]) end = Int.Point(t.Longitude[i], t.Latitude[i]) startOnshore = Int.inLand(start, self.coast) endOnshore = Int.inLand(end, self.coast) if not startOnshore and endOnshore: # Landfall: cross = Int.Crossings() for j in range(1, len(self.gates) - 1): r = cross.LineLine(start, end, self.gates[j - 1], self.gates[j]) if r.status == "Intersection": landfall.append(j) elif startOnshore and not endOnshore: # Moving offshore: cross = Int.Crossings() for j in range(1, len(self.gates) - 1): r = cross.LineLine(start, end, self.gates[j - 1], self.gates[j]) if r.status == "Intersection": offshore.append(j) # Generate the histograms to be returned: lh, n = np.histogram(landfall, np.arange(len(self.gates)), density=True) oh, n = np.histogram(offshore, np.arange(len(self.gates)), density=True) return lh, oh
def findCrossings(self, tracks): """ Given a series of track points and a longitude, calculate if the tracks intersect that line of longitude. :param tracks: collection of :class:`Track` objects :return: h, ewh, weh, histograms for each line of longitude, recording the rate of crossings """ LOG.debug("Processing %d tracks" % (len(tracks))) h = np.zeros((len(self.gateLats) - 1, len(self.gateLons))) ewh = np.zeros((len(self.gateLats) - 1, len(self.gateLons))) weh = np.zeros((len(self.gateLats) - 1, len(self.gateLons))) for n, gLon in enumerate(self.gateLons): gStart = Int.Point(gLon, self.gateLats.max()) gEnd = Int.Point(gLon, self.gateLats.min()) lats = [] ewlats = [] welats = [] for t in tracks: for i in range(len(t.Longitude) - 1): cross = Int.Crossings() start = Int.Point(t.Longitude[i], t.Latitude[i]) end = Int.Point(t.Longitude[i + 1], t.Latitude[i + 1]) r = cross.LineLine(start, end, gStart, gEnd) if r.status == "Intersection": lats.append(r.points[0].y) startSide = Int._isLeft(gStart, gEnd, start) endSide = Int._isLeft(gStart, gEnd, end) if ((startSide < 0.) and (endSide >= 0.)) \ or ((startSide <= 0.) and (endSide > 0.)): welats.append(r.points[0].y) elif ((startSide > 0.) and (endSide <= 0.)) \ or ((startSide >= 0.) and (endSide < 0.)): ewlats.append(r.points[0].y) else: # Track segment doesn't cross that longitude continue # Generate the histograms to be returned: if len(lats) > 0: h[:, n], bins = np.histogram(lats, self.gateLats, density=True) if len(ewlats) > 0: ewh[:, n], bins = np.histogram(ewlats, self.gateLats, density=True) if len(welats) > 0: weh[:, n], bins = np.histogram(welats, self.gateLats, density=True) return h, ewh, weh
def setUp(self): """Set up the test environment""" xverts = [100., 100., 110., 110., 100.] yverts = [-20., -30., -30., -20., -20.] self.point1 = Intersections.Point(xverts[0],yverts[0]) self.point2 = Intersections.Point(xverts[1],yverts[1]) self.leftPoint = Intersections.Point( 105., -25. ) self.rightPoint = Intersections.Point( 95., -25. ) self.circleCentre = Intersections.Point( 105., -25. ) self.circleRadius0 = 0.0 self.circleRadius1 = 5.0 self.circleRadius2 = 7.5 self.circleRadius3 = 7.0 self.Crossings = Intersections.Crossings() self.vertices = Intersections.convert2vertex( xverts, yverts )