Exemple #1
0
    def run_plot_weights(self, rname):
        grid = rname[0]
        if (grid == 'A'):
            plotter = self.plotterA
        elif (grid == 'E'):
            plotter = self.plotterE
        elif (grid == 'I'):
            plotter = self.plotterI

        wB_C, BvA_C, wA_C = self.rm.matrix(rname, scale=True, correctA=True)()
        wB_c, BvA_c, wA_c = self.rm.matrix(rname, scale=True, correctA=False)()

        wBvA_C = np.squeeze(np.asarray(BvA_C.sum(axis=1)))  # sum rows
        wBvA_c = np.squeeze(np.asarray(BvA_c.sum(axis=1)))  # sum rows

        figure = matplotlib.pyplot.figure(figsize=(11, 17))

        ax = figure.add_subplot(221)
        basemap = giss.basemap.greenland_laea(ax=ax)
        giss.plot.plot_var(ax=ax,
                           basemap=basemap,
                           **deprecated_plot_params.plot_params(
                               'weight-%s (corrected)' % rname,
                               val=wB_C,
                               plotter=plotter))

        ax = figure.add_subplot(222)
        basemap = giss.basemap.greenland_laea(ax=ax)
        giss.plot.plot_var(ax=ax,
                           basemap=basemap,
                           **deprecated_plot_params.plot_params(
                               'computed weight-%s (corrected)' % rname,
                               val=wBvA_C,
                               plotter=plotter))

        ax = figure.add_subplot(223)
        basemap = giss.basemap.greenland_laea(ax=ax)
        giss.plot.plot_var(
            ax=ax,
            basemap=basemap,
            **deprecated_plot_params.plot_params(
                'weight-%s (ratio: corrected/uncorrected)' % rname,
                val=np.divide(wB_C, wB_c),
                plotter=plotter))

        ax = figure.add_subplot(224)
        basemap = giss.basemap.greenland_laea(ax=ax)
        giss.plot.plot_var(
            ax=ax,
            basemap=basemap,
            **deprecated_plot_params.plot_params(
                'computed weight-%s (ratio: corrected/uncorrected)' % rname,
                val=np.divide(wBvA_C, wBvA_c),
                plotter=plotter))

        figure.savefig('%s-weight' % rname, dpi=70, transparent=False)
Exemple #2
0
    def test_correctA(self):
        """Tests conservation of mass.  Checks that the amount of
        stuff (== value * weight) remains constant."""

        fname = 'test_correctA.png'
        figure = matplotlib.pyplot.figure(figsize=(22, 17))

        for i, (correctA, msg) in enumerate(
            ((False, 'should see constant=1'),
             (True, 'should see rainbow stripes'))):
            IvE, wIvE = self.rm.regrid('IvE', scale=True, correctA=correctA)
            nE = IvE.shape[1]

            valE = (np.zeros((nE, )) + 1).reshape(-1)

            # E <--> I
            valIE = icebin.coo_multiply(IvE, valE, fill=np.nan)

            # Plot it...
            ax = figure.add_subplot(1, 2, i + 1)
            basemap = giss.basemap.greenland_laea(ax=ax)
            giss.plot.plot_var(
                ax=ax,
                basemap=basemap,
                **deprecated_plot_params.plot_params('IE-{}\n({})'.format(
                    'corrected' if correctA else 'uncorrected', msg),
                                                     val=valIE,
                                                     plotter=self.plotterI))

        figure.savefig(fname, dpi=100, transparent=False)
Exemple #3
0
    def test_conserv(self):
        """Tests conservation of mass.  Checks that the amount of
        stuff (== value * weight) remains constant."""

        for fname, valI_fn in (('test_diagonal.png', self.diagonalI),
                               ('test_elevation.png', self.elevationI)):

            valI = valI_fn()

            # A <--> I
            valAI = icebin.coo_multiply(self.AvI, valI, fill=np.nan)
            self.assert_eq_weighted(valI, self.wIvA, valAI, self.wAvI)
            valIAI = icebin.coo_multiply(self.IvA, valAI, fill=np.nan)
            self.assert_eq_weighted(valIAI, self.wIvA, valAI, self.wAvI)

            # E <--> I
            valEI = icebin.coo_multiply(self.EvI, valI, fill=np.nan)
            self.assert_eq_weighted(valI, self.wIvE, valEI, self.wEvI)

            valIEI_rough = icebin.coo_multiply(self.IvE, valEI, fill=np.nan)
            self.assert_eq_weighted(valIEI_rough, self.wIvE, valEI, self.wEvI)

            valIEI_smooth = self.IvE_smooth_x.apply(valEI)
            self.assert_eq_weighted(valIEI_smooth, self.wIvE, valEI, self.wEvI)

            # A <--> E
            valE = valEI
            valAE = icebin.coo_multiply(self.AvE, valE, fill=np.nan)
            self.assert_eq_weighted(valE, self.wEvA, valAE, self.wAvE)
            valEAE = icebin.coo_multiply(self.EvA, valAE, fill=np.nan)
            self.assert_eq_weighted(valEAE, self.wEvA, valAE, self.wAvE)

            # Plot it...
            figure = matplotlib.pyplot.figure(figsize=(22, 17))

            ax = figure.add_subplot(231)
            basemap = giss.basemap.greenland_laea(ax=ax)
            giss.plot.plot_var(ax=ax,
                               basemap=basemap,
                               **deprecated_plot_params.plot_params(
                                   'I', val=valI, plotter=self.plotterI))

            ax = figure.add_subplot(232)
            basemap = giss.basemap.greenland_laea(ax=ax)
            giss.plot.plot_var(ax=ax,
                               basemap=basemap,
                               **deprecated_plot_params.plot_params(
                                   'AI', val=valAI, plotter=self.plotterA))

            ax = figure.add_subplot(233)
            basemap = giss.basemap.greenland_laea(ax=ax)
            giss.plot.plot_var(ax=ax,
                               basemap=basemap,
                               **deprecated_plot_params.plot_params(
                                   'IAI', val=valIAI, plotter=self.plotterI))

            ax = figure.add_subplot(234)
            basemap = giss.basemap.greenland_laea(ax=ax)
            giss.plot.plot_var(ax=ax,
                               basemap=basemap,
                               **deprecated_plot_params.plot_params(
                                   'IEI-rough',
                                   val=valIEI_rough,
                                   plotter=self.plotterI))

            ax = figure.add_subplot(235)
            basemap = giss.basemap.greenland_laea(ax=ax)
            giss.plot.plot_var(ax=ax,
                               basemap=basemap,
                               **deprecated_plot_params.plot_params(
                                   'IEI-smooth',
                                   val=valIEI_smooth,
                                   plotter=self.plotterI))

            valEAI = icebin.coo_multiply(self.EvA, valAI, fill=np.nan)
            valIEAI = icebin.coo_multiply(self.IvE, valEAI, fill=np.nan)
            ax = figure.add_subplot(236)
            basemap = giss.basemap.greenland_laea(ax=ax)
            giss.plot.plot_var(ax=ax,
                               basemap=basemap,
                               **deprecated_plot_params.plot_params(
                                   'IEAI', val=valIEAI, plotter=self.plotterI))

            figure.savefig(fname, dpi=100, transparent=False)