Пример #1
0
    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
Пример #2
0
    def __init__(self, configFile):

        config = ConfigParser()
        config.read(configFile)
        self.configFile = configFile
        
        outputPath = config.get('Output', 'Path')
        self.trackPath = pjoin(outputPath, 'tracks')
        self.plotPath = pjoin(outputPath, 'plots', 'stats')
        self.dataPath = pjoin(outputPath, 'process')

        # Determine TCRM input directory
        tcrm_dir = pathLocator.getRootDirectory()
        self.inputPath = pjoin(tcrm_dir, 'input')

        self.synNumYears = config.getint('TrackGenerator',
                                         'yearspersimulation')

        try:
            gateFile = config.get('Input', 'CoastlineGates')
        except NoOptionError:
            log.exception(("No coastline gate file specified "
                          "in configuration file"))
            raise
        
        gateData = np.genfromtxt(gateFile, delimiter=',')
        nGates = len(gateData)
        self.gates = Int.convert2vertex(gateData[:, 1], gateData[:, 2])
        self.coast = list(self.gates)
        self.coast.append(self.gates[0])
Пример #3
0
    def __init__(self, configFile):

        config = ConfigParser()
        config.read(configFile)
        self.configFile = configFile

        outputPath = config.get('Output', 'Path')
        self.trackPath = pjoin(outputPath, 'tracks')
        self.plotPath = pjoin(outputPath, 'plots', 'stats')
        self.dataPath = pjoin(outputPath, 'process')

        # Determine TCRM input directory
        tcrm_dir = pathLocator.getRootDirectory()
        self.inputPath = pjoin(tcrm_dir, 'input')

        self.synNumYears = config.getint('TrackGenerator',
                                         'yearspersimulation')

        try:
            gateFile = config.get('Input', 'CoastlineGates')
        except NoOptionError:
            LOG.exception(("No coastline gate file specified "
                           "in configuration file"))
            raise

        gateData = np.genfromtxt(gateFile, delimiter=',')

        self.gates = Int.convert2vertex(gateData[:, 1], gateData[:, 2])
        self.coast = list(self.gates)
        self.coast.append(self.gates[0])
Пример #4
0
    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
Пример #5
0
    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
Пример #6
0
    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 )
Пример #7
0
    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
Пример #8
0
    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 )
Пример #9
0
 def test_inLand(self):
     """Test inLand() returns correct value for points in/outside vertices"""
     self.assertTrue( Intersections.inLand( self.leftPoint, self.vertices ) )
     self.assertFalse( Intersections.inLand( self.rightPoint, self.vertices ) )
Пример #10
0
 def test_isOnLine(self):
     """Test _isLeft() returns zero for a point lying on the line"""
     result = Intersections._isLeft(self.point1, self.point2, self.point2)
     self.assertTrue( result==0 )
Пример #11
0
 def test_isRight(self):
     """Test _isLeft() returns -ve value for a point to the right of the line"""
     result = Intersections._isLeft(self.point1, self.point2, self.rightPoint)
     self.assertTrue( result < 0 )
Пример #12
0
 def test_isLeft(self):
     """Test _isLeft() returns +ve value for a point to the left of the line"""
     result = Intersections._isLeft(self.point1, self.point2, self.leftPoint)
     self.assertTrue( result > 0 )
Пример #13
0
 def test_inLand(self):
     """Test inLand() returns correct value for points in/outside vertices"""
     self.assertTrue( Intersections.inLand( self.leftPoint, self.vertices ) )
     self.assertFalse( Intersections.inLand( self.rightPoint, self.vertices ) )
Пример #14
0
 def test_isOnLine(self):
     """Test _isLeft() returns zero for a point lying on the line"""
     result = Intersections._isLeft(self.point1, self.point2, self.point2)
     self.assertTrue( result==0 )
Пример #15
0
 def test_isRight(self):
     """Test _isLeft() returns -ve value for a point to the right of the line"""
     result = Intersections._isLeft(self.point1, self.point2, self.rightPoint)
     self.assertTrue( result < 0 )
Пример #16
0
 def test_isLeft(self):
     """Test _isLeft() returns +ve value for a point to the left of the line"""
     result = Intersections._isLeft(self.point1, self.point2, self.leftPoint)
     self.assertTrue( result > 0 )