Пример #1
0
    def plotGenesisDensityPercentiles(self):
        """
        Plot upper and lower percentiles of genesis density derived from
        synthetic event sets

        """

        datarange = (0, self.hist.max())
        figure = FilledContourMapFigure()
        lvls, exponent = levels(self.hist.max())

        map_kwargs = dict(llcrnrlon=self.lon_range.min(),
                          llcrnrlat=self.lat_range.min(),
                          urcrnrlon=self.lon_range.max(),
                          urcrnrlat=self.lat_range.max(),
                          projection='merc',
                          resolution='i')
        cbarlab = "TCs/yr"
        xgrid, ygrid = np.meshgrid(self.lon_range, self.lat_range)

        figure.add(self.synHistUpper.T * (10.**-exponent), xgrid, ygrid,
                   "Upper percentile", lvls * (10.**-exponent), cbarlab,
                   map_kwargs)
        figure.add(self.synHistLower.T * (10.**-exponent), xgrid, ygrid,
                   "Lower percentile", lvls * (10.**-exponent), cbarlab,
                   map_kwargs)
        figure.plot()
        outputFile = pjoin(self.plotPath, 'genesis_density_percentiles.png')
        saveFigure(figure, outputFile)
Пример #2
0
    def plotGenesisDensity(self):
        """Plot genesis density information"""

        datarange = (0, self.hist.max())
        figure = FilledContourMapFigure()
        lvls, exponent = levels(self.hist.max())
        map_kwargs = dict(llcrnrlon=self.lon_range.min(),
                          llcrnrlat=self.lat_range.min(),
                          urcrnrlon=self.lon_range.max(),
                          urcrnrlat=self.lat_range.max(),
                          projection='merc',
                          resolution='i')
        cbarlab = "TCs/yr"
        xgrid, ygrid = np.meshgrid(self.lon_range, self.lat_range)
        figure.add(self.hist.T * (10.**-exponent), self.X, self.Y, "Historic",
                   lvls * (10.**-exponent), cbarlab, map_kwargs)
        figure.add(self.synHistMean.T * (10.**-exponent), xgrid, ygrid,
                   "Synthetic", lvls * (10.**-exponent), cbarlab, map_kwargs)
        figure.plot()
        outputFile = pjoin(self.plotPath, 'genesis_density.png')
        saveFigure(figure, outputFile)

        figure2 = FilledContourMapFigure()
        figure2.add(self.hist.T * (10.**-exponent), xgrid, ygrid, "Historic",
                    lvls * (10.**-exponent), cbarlab, map_kwargs)
        figure2.add(self.synHist[0, :, :].T * (10.**-exponent), xgrid, ygrid,
                    "Synthetic", lvls * (10.**-exponent), cbarlab, map_kwargs)
        figure2.add(self.synHist[1, :, :].T * (10.**-exponent), xgrid, ygrid,
                    "Synthetic", lvls * (10.**-exponent), cbarlab, map_kwargs)
        figure2.add(self.synHist[2, :, :].T * (10.**-exponent), xgrid, ygrid,
                    "Synthetic", lvls * (10.**-exponent), cbarlab, map_kwargs)

        figure2.plot()
        outputFile = pjoin(self.plotPath, 'genesis_density_samples.png')
        saveFigure(figure2, outputFile)
Пример #3
0
    def test_MinGTMax(self):
        """Minimum greater than maximum automatically swaps values"""
        lvls = np.array([0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9])
        expo = 0

        rlevs, rexpo = maps.levels(0, minval=1)
        self.numpyAssertAlmostEqual(lvls, rlevs)
        self.assertEqual(expo, rexpo)
Пример #4
0
 def test_bigLevelValues(self):
     """Test level determination for big input values"""
     lvs = np.array([
         1000000., 2000000., 3000000., 4000000., 5000000., 6000000.,
         7000000., 8000000., 9000000.
     ])
     expo = 7
     rlevs, rexpo = maps.levels(10**7, 10**6)
     self.numpyAssertAlmostEqual(lvs, rlevs)
     self.assertEqual(expo, rexpo)
Пример #5
0
 def test_smallLevelValues(self):
     """Test level determination for small input values"""
     lvs = np.array([
         0.0000e+00, 1.0000e-06, 2.0000e-06, 3.0000e-06, 4.0000e-06,
         5.0000e-06, 6.0000e-06, 7.0000e-06, 8.0000e-06, 9.0000e-06
     ])
     expo = -5
     rlevs, rexpo = maps.levels(0, 10**-5)
     self.numpyAssertAlmostEqual(lvs, rlevs)
     self.assertEqual(expo, rexpo)
Пример #6
0
    def generateKDE(self, save=False, plot=False):
        """
        Generate the PDF for cyclone origins using kernel density
        estimation technique then save it to a file path provided by
        user.

        :param float bw: Optional, bandwidth to use for generating the PDF.
                         If not specified, use the :attr:`bw` attribute.
        :param boolean save: If ``True``, save the resulting PDF to a
                             netCDF file called 'originPDF.nc'.
        :param boolean plot: If ``True``, plot the resulting PDF.

        :returns: ``x`` and ``y`` grid and the PDF values.

        """

        self.kde = KDEMultivariate(self.lonLat, bw=self.bw, var_type='cc')
        xx, yy = np.meshgrid(self.x, self.y)
        xy = np.vstack([xx.ravel(), yy.ravel()])
        pdf = self.kde.pdf(data_predict=xy)
        pdf = pdf.reshape(xx.shape)

        self.pdf = pdf.transpose()

        if save:
            dimensions = {
                0: {
                    'name': 'lat',
                    'values': self.y,
                    'dtype': 'f',
                    'atts': {
                        'long_name': ' Latitude',
                        'units': 'degrees_north'
                    }
                },
                1: {
                    'name': 'lon',
                    'values': self.x,
                    'dtype': 'f',
                    'atts': {
                        'long_name': 'Longitude',
                        'units': 'degrees_east'
                    }
                }
            }

            variables = {
                0: {
                    'name': 'gpdf',
                    'dims': ('lat', 'lon'),
                    'values': np.array(pdf),
                    'dtype': 'f',
                    'atts': {
                        'long_name': 'TC Genesis probability distribution',
                        'units': ''
                    }
                }
            }

            ncSaveGrid(pjoin(self.processPath, 'originPDF.nc'), dimensions,
                       variables)

        if plot:
            from PlotInterface.maps import FilledContourMapFigure, \
                saveFigure, levels

            lvls, exponent = levels(pdf.max())

            [gx, gy] = np.meshgrid(self.x, self.y)

            map_kwargs = dict(llcrnrlon=self.x.min(),
                              llcrnrlat=self.y.min(),
                              urcrnrlon=self.x.max(),
                              urcrnrlat=self.y.max(),
                              projection='merc',
                              resolution='i')

            cbarlabel = r'Genesis probability ($\times 10^{' + \
                        str(exponent) + '}$)'
            figure = FilledContourMapFigure()
            figure.add(pdf * (10**-exponent), gx, gy, 'TC Genesis probability',
                       lvls * (10**-exponent), cbarlabel, map_kwargs)
            figure.plot()

            outputFile = pjoin(self.outputPath, 'plots', 'stats',
                               'originPDF.png')
            saveFigure(figure, outputFile)

        return self.x, self.y, self.pdf