Exemplo n.º 1
0
    def movieRad(self,
                 cut=0.5,
                 levels=12,
                 cm='RdYlBu_r',
                 png=False,
                 step=1,
                 normed=False,
                 dpi=80,
                 bgcolor=None,
                 deminc=True,
                 removeMean=False,
                 precision='Float64',
                 contour=False,
                 mer=False):
        """
        Plotting function (it can also write the png files)

        .. warning:: the python bindings of `SHTns <https://bitbucket.org/bputigny/shtns-magic>`_ are mandatory to use this plotting function!

        :param levels: number of contour levels
        :type levels: int
        :param cm: name of the colormap
        :type cm: str
        :param cut: adjust the contour extrema to max(abs(data))*cut
        :type cut: float
        :param png: save the movie as a series of png files when
                    set to True
        :type png: bool
        :param dpi: dot per inch when saving PNGs
        :type dpi: int
        :param bgcolor: background color of the figure
        :type bgcolor: str
        :param normed: the colormap is rescaled every timestep when set to True,
                       otherwise it is calculated from the global extrema
        :type normed: bool
        :param step: the stepping between two timesteps
        :type step: int
        :param deminc: a logical to indicate if one wants do get rid of the
                       possible azimuthal symmetry
        :type deminc: bool
        :param precision: single or double precision
        :type precision: char
        :param contour: also display the solid contour levels when set to True
        :type contour: bool
        :param mer: display meridians and circles when set to True
        :type mer: bool
        :param removeMean: remove the time-averaged part when set to True
        :type removeMean: bool
        """

        if removeMean:
            dataCut = self.wlm - self.wlm.mean(axis=0)
        else:
            dataCut = self.wlm

        nlat = max(int(self.l_max_r * (3. / 2. / 2.) * 2.), 192)
        nphi = 2 * nlat / self.minc

        # Define spectral transform setup
        sh = SpectralTransforms(l_max=self.l_max_r,
                                minc=self.minc,
                                lm_max=self.lm_max_r,
                                n_theta_max=nlat)
        """
        # The python bindings of shtns are mandatory to use this function !!!
        import shtns

        # Define shtns setup
        sh = shtns.sht(int(self.l_max_r), int(self.m_max_r/self.minc),
                       mres=int(self.minc),
                       norm=shtns.sht_orthonormal | shtns.SHT_NO_CS_PHASE)
        """

        # Transform data on grid space
        data = np.zeros((self.nstep, nphi, nlat), precision)
        print('Spectral -> Spatial transform')
        for k in progressbar(range(self.nstep)):
            data[k, ...] = sh.spec_spat(dataCut[k, :] * self.ell *
                                        (self.ell + 1) / self.radius**2)
        print('Done')

        if png:
            plt.ioff()
            if not os.path.exists('movie'):
                os.mkdir('movie')
        else:
            plt.ion()

        if not normed:
            vmin = -max(abs(data.max()), abs(data.min()))
            vmin = cut * vmin
            vmax = -vmin
            cs = np.linspace(vmin, vmax, levels)

        th = np.linspace(np.pi / 2., -np.pi / 2., nlat)
        if deminc:
            phi = np.linspace(-np.pi, np.pi, self.minc * nphi + 1)
            xxout, yyout = hammer2cart(th, -np.pi)
            xxin, yyin = hammer2cart(th, np.pi)
        else:
            phi = np.linspace(-np.pi / self.minc, np.pi / self.minc, nphi)
            xxout, yyout = hammer2cart(th, -np.pi / self.minc)
            xxin, yyin = hammer2cart(th, np.pi / self.minc)
        ttheta, pphi = np.meshgrid(th, phi)
        xx, yy = hammer2cart(ttheta, pphi)
        if deminc:
            fig = plt.figure(figsize=(8, 4))
        else:
            fig = plt.figure(figsize=(8 / self.minc, 4))
        fig.subplots_adjust(top=0.99, right=0.99, bottom=0.01, left=0.01)
        ax = fig.add_subplot(111, frameon=False)

        if mer:
            theta = np.linspace(np.pi / 2, -np.pi / 2, nlat)
            meridians = np.r_[-120, -60, 0, 60, 120]
            circles = np.r_[60, 30, 0, -30, -60]

        for k in range(self.nstep):
            if k == 0:
                if normed:
                    vmin = -max(abs(data[k, ...].max()), abs(data[k,
                                                                  ...].min()))
                    vmin = cut * vmin
                    vmax = -vmin
                    cs = np.linspace(vmin, vmax, levels)
                if deminc:
                    dat = symmetrize(data[k, ...], self.minc)
                else:
                    dat = data[k, ...]
                im = ax.contourf(xx,
                                 yy,
                                 dat,
                                 cs,
                                 cmap=plt.get_cmap(cm),
                                 extend='both')
                if contour:
                    ax.contour(xx,
                               yy,
                               dat,
                               cs,
                               linestyles=['-', '-'],
                               colors=['k', 'k'],
                               linewidths=[0.7, 0.7])
                ax.plot(xxout, yyout, 'k-', lw=1.5)
                ax.plot(xxin, yyin, 'k-', lw=1.5)

                if mer:
                    for lat0 in circles:
                        x0, y0 = hammer2cart(lat0 * np.pi / 180., phi)
                        ax.plot(x0, y0, 'k:', linewidth=0.7)
                    for lon0 in meridians:
                        x0, y0 = hammer2cart(theta, lon0 * np.pi / 180.)
                        ax.plot(x0, y0, 'k:', linewidth=0.7)

                ax.axis('off')
                man = plt.get_current_fig_manager()
                man.canvas.draw()

                if png:
                    filename = 'movie/img%05d.png' % k
                    print('write %s' % filename)
                    #st = 'echo %i' % ivar + ' > movie/imgmax'
                    if bgcolor is not None:
                        fig.savefig(filename, facecolor=bgcolor, dpi=dpi)
                    else:
                        fig.savefig(filename, dpi=dpi)

            elif k != 0 and k % step == 0:
                if not png:
                    print(k)
                plt.cla()
                if normed:
                    vmin = -max(abs(data[k, ...].max()), abs(data[k,
                                                                  ...].min()))
                    vmin = cut * vmin
                    vmax = -vmin
                    cs = np.linspace(vmin, vmax, levels)
                if deminc:
                    dat = symmetrize(data[k, ...], self.minc)
                else:
                    dat = data[k, ...]
                im = ax.contourf(xx,
                                 yy,
                                 dat,
                                 cs,
                                 cmap=plt.get_cmap(cm),
                                 extend='both')
                if contour:
                    ax.contour(xx,
                               yy,
                               dat,
                               cs,
                               colors=['k'],
                               linestyles=['-', '-'],
                               linewidths=[0.7, 0.7])
                ax.plot(xxout, yyout, 'k-', lw=1.5)
                ax.plot(xxin, yyin, 'k-', lw=1.5)

                if mer:
                    for lat0 in circles:
                        x0, y0 = hammer2cart(lat0 * np.pi / 180., phi)
                        ax.plot(x0, y0, 'k:', linewidth=0.7)
                    for lon0 in meridians:
                        x0, y0 = hammer2cart(theta, lon0 * np.pi / 180.)
                        ax.plot(x0, y0, 'k:', linewidth=0.7)

                ax.axis('off')
                man.canvas.draw()
                if png:
                    filename = 'movie/img%05d.png' % k
                    print('write %s' % filename)
                    #st = 'echo %i' % ivar + ' > movie/imgmax'
                    if bgcolor is not None:
                        fig.savefig(filename, facecolor=bgcolor, dpi=dpi)
                    else:
                        fig.savefig(filename, dpi=dpi)
Exemplo n.º 2
0
    def timeLongitude(self,
                      removeMean=True,
                      lat0=0.,
                      levels=12,
                      cm='RdYlBu_r',
                      deminc=True,
                      shtns_lib='shtns'):
        """
        Plot the time-longitude diagram of Br (input latitude can be chosen)

        .. warning:: the python bindings of `SHTns <https://bitbucket.org/bputigny/shtns-magic>`_ are mandatory to use this plotting function!

        :param lat0: value of the latitude
        :type lat0: float
        :param levels: number of contour levels
        :type levels: int
        :param cm: name of the colormap
        :type cm: str
        :param deminc: a logical to indicate if one wants do get rid of the
                       possible azimuthal symmetry
        :type deminc: bool
        :param shtns_lib: version of shtns library used: can be either 'shtns'
                          or 'shtns-magic'
        :type shtns_lib: char
        :param removeMean: remove the time-averaged part when set to True
        :type removeMean: bool
        """
        # The python bindings of shtns are mandatory to use this function !!!
        import shtns

        if removeMean:
            blmCut = self.blm - self.blm.mean(axis=0)
        else:
            blmCut = self.blm

        # Define shtns setup
        sh = shtns.sht(int(self.l_max_cmb),
                       int(self.m_max_cmb / self.minc),
                       mres=int(self.minc),
                       norm=shtns.sht_orthonormal | shtns.SHT_NO_CS_PHASE)

        polar_opt_threshold = 1e-10
        nlat = max(int(self.l_max_cmb * (3. / 2. / 2.) * 2.), 192)
        nphi = 2 * nlat / self.minc
        nlat, nphi = sh.set_grid(nlat, nphi, polar_opt=polar_opt_threshold)

        th = np.linspace(np.pi / 2., -np.pi / 2., nlat)
        lat0 *= np.pi / 180.
        mask = np.where(abs(th - lat0) == abs(th - lat0).min(), 1, 0)
        idx = np.nonzero(mask)[0][0]

        # Transform data on grid space
        BrCMB = np.zeros((self.nstep, nphi, nlat), 'Float64')
        if deminc:
            dat = np.zeros((self.nstep, self.minc * nphi + 1), 'Float64')
        else:
            dat = np.zeros((self.nstep, nphi), 'Float64')
        for k in range(self.nstep):
            tmp = sh.synth(blmCut[k, :] * sh.l * (sh.l + 1) / self.rcmb**2)
            tmp = tmp.T  # Longitude, Latitude

            if shtns_lib == 'shtns-magic':
                BrCMB[k, ...] = rearangeLat(tmp)
            else:
                BrCMB[k, ...] = tmp

            if deminc:
                dat[k, :] = symmetrize(BrCMB[k, :, idx], self.minc)
            else:
                dat[k, :] = BrCMB[k, :, idx]

        th = np.linspace(np.pi / 2., -np.pi / 2., nlat)
        if deminc:
            phi = np.linspace(-np.pi, np.pi, self.minc * nphi + 1)
        else:
            phi = np.linspace(-np.pi / self.minc, np.pi / self.minc, nphi)

        fig = plt.figure()
        ax = fig.add_subplot(111)
        vmin = -max(abs(dat.max()), abs(dat.min()))
        vmax = -vmin
        cs = np.linspace(vmin, vmax, levels)
        ax.contourf(phi, self.time, dat, cs, cmap=plt.get_cmap(cm))

        ax.set_xlabel('Longitude')
        ax.set_ylabel('Time')

        w2 = np.fft.fft2(dat)
        w2 = abs(w2[1:self.nstep / 2 + 1, 0:self.m_max_cmb + 1])

        dw = 2. * np.pi / (self.time[-1] - self.time[0])
        omega = dw * np.arange(self.nstep)
        omega = omega[1:self.nstep / 2 + 1]
        ms = np.arange(self.m_max_cmb + 1)

        fig1 = plt.figure()
        ax1 = fig1.add_subplot(111)
        ax1.contourf(ms, omega, w2, 17, cmap=plt.get_cmap('jet'))
        ax1.set_yscale('log')
        ax1.set_xlim(0, 13)
        ax1.set_xlabel(r'Azimuthal wavenumber')
        ax1.set_ylabel(r'Frequency')
Exemplo n.º 3
0
    def timeLongitude(self, removeMean=True, lat0=0., levels=12, cm='RdYlBu_r',
                      deminc=True, shtns_lib='shtns'):
        """
        Plot the time-longitude diagram of Br (input latitude can be chosen)

        .. warning:: the python bindings of `SHTns <https://bitbucket.org/bputigny/shtns-magic>`_ are mandatory to use this plotting function!

        :param lat0: value of the latitude
        :type lat0: float
        :param levels: number of contour levels
        :type levels: int
        :param cm: name of the colormap
        :type cm: str
        :param deminc: a logical to indicate if one wants do get rid of the
                       possible azimuthal symmetry
        :type deminc: bool
        :param shtns_lib: version of shtns library used: can be either 'shtns'
                          or 'shtns-magic'
        :type shtns_lib: char
        :param removeMean: remove the time-averaged part when set to True
        :type removeMean: bool
        """
        # The python bindings of shtns are mandatory to use this function !!!
        import shtns

        if removeMean:
            blmCut = self.blm-self.blm.mean(axis=0)
        else:
            blmCut = self.blm

        # Define shtns setup
        sh = shtns.sht(int(self.l_max_cmb), int(self.m_max_cmb/self.minc), 
                       mres=int(self.minc), 
                       norm=shtns.sht_orthonormal | shtns.SHT_NO_CS_PHASE)

        polar_opt_threshold = 1e-10
        nlat = max((self.l_max_cmb*(3/2/2)*2),192)
        nphi = 2*nlat/self.minc
        nlat, nphi = sh.set_grid(nlat, nphi, polar_opt=polar_opt_threshold)

        th = np.linspace(np.pi/2., -np.pi/2., nlat)
        lat0 *= np.pi/180.
        mask = np.where(abs(th-lat0) == abs(th-lat0).min(), 1, 0)
        idx = np.nonzero(mask)[0][0]

        # Transform data on grid space
        BrCMB = np.zeros((self.nstep, nphi, nlat), 'Float64')
        if deminc:
            dat = np.zeros((self.nstep, self.minc*nphi+1), 'Float64')
        else:
            dat = np.zeros((self.nstep, nphi), 'Float64')
        for k in range(self.nstep):
            tmp = sh.synth(blmCut[k, :]*sh.l*(sh.l+1)/self.rcmb**2)
            tmp = tmp.T # Longitude, Latitude

            if shtns_lib == 'shtns-magic':
                BrCMB[k, ...] = rearangeLat(tmp)
            else:
                BrCMB[k, ...] = tmp

            if deminc:
                dat[k, :] = symmetrize(BrCMB[k, :, idx], self.minc)
            else:
                dat[k, :] = BrCMB[k, :, idx]


        th = np.linspace(np.pi/2., -np.pi/2., nlat)
        if deminc:
            phi = np.linspace(-np.pi, np.pi, self.minc*nphi+1)
        else:
            phi = np.linspace(-np.pi/self.minc, np.pi/self.minc, nphi)

        fig = plt.figure()
        ax = fig.add_subplot(111)
        vmin = -max(abs(dat.max()), abs(dat.min()))
        vmax = -vmin
        cs = np.linspace(vmin, vmax, levels)
        ax.contourf(phi, self.time, dat, cs, cmap=plt.get_cmap(cm))

        ax.set_xlabel('Longitude')
        ax.set_ylabel('Time')

        w2 = np.fft.fft2(dat)
        w2 = abs(w2[1:self.nstep/2+1, 0:self.m_max_cmb+1])

        dw = 2.*np.pi/(self.time[-1]-self.time[0])
        omega = dw*np.arange(self.nstep)
        omega = omega[1:self.nstep/2+1]
        ms = np.arange(self.m_max_cmb+1)

        fig1 = plt.figure()
        ax1 = fig1.add_subplot(111)
        ax1.contourf(ms, omega, w2, 17, cmap=plt.get_cmap('jet'))
        ax1.set_yscale('log')
        ax1.set_xlim(0,13)
        ax1.set_xlabel(r'Azimuthal wavenumber')
        ax1.set_ylabel(r'Frequency')
Exemplo n.º 4
0
    def movieRad(self, cut=0.5, levels=12, cm='RdYlBu_r', png=False, step=1,
                 normed=False, dpi=80, bgcolor=None, deminc=True, removeMean=False,
                 precision='Float64', shtns_lib='shtns', contour=False, mer=False):
        """
        Plotting function (it can also write the png files)

        .. warning:: the python bindings of `SHTns <https://bitbucket.org/bputigny/shtns-magic>`_ are mandatory to use this plotting function!

        :param levels: number of contour levels
        :type levels: int
        :param cm: name of the colormap
        :type cm: str
        :param cut: adjust the contour extrema to max(abs(data))*cut
        :type cut: float
        :param png: save the movie as a series of png files when
                    set to True
        :type png: bool
        :param dpi: dot per inch when saving PNGs
        :type dpi: int
        :param bgcolor: background color of the figure
        :type bgcolor: str
        :param normed: the colormap is rescaled every timestep when set to True,
                       otherwise it is calculated from the global extrema
        :type normed: bool
        :param step: the stepping between two timesteps
        :type step: int
        :param deminc: a logical to indicate if one wants do get rid of the
                       possible azimuthal symmetry
        :type deminc: bool
        :param precision: single or double precision
        :type precision: char
        :param shtns_lib: version of shtns library used: can be either 'shtns'
                          or 'shtns-magic'
        :type shtns_lib: char
        :param contour: also display the solid contour levels when set to True
        :type contour: bool
        :param mer: display meridians and circles when set to True
        :type mer: bool
        :param removeMean: remove the time-averaged part when set to True
        :type removeMean: bool
        """

        # The python bindings of shtns are mandatory to use this function !!!
        import shtns

        if removeMean:
            dataCut = self.wlm-self.wlm.mean(axis=0)
        else:
            dataCut = self.wlm

        # Define shtns setup
        sh = shtns.sht(int(self.l_max_r), int(self.m_max_r/self.minc), 
                       mres=int(self.minc), 
                       norm=shtns.sht_orthonormal | shtns.SHT_NO_CS_PHASE)

        polar_opt_threshold = 1e-10
        nlat = max((self.l_max_r*(3/2/2)*2),192)
        nphi = 2*nlat/self.minc
        nlat, nphi = sh.set_grid(nlat, nphi, polar_opt=polar_opt_threshold)

        # Transform data on grid space
        data = np.zeros((self.nstep, nphi, nlat), precision)
        for k in range(self.nstep):
            tmp = sh.synth(dataCut[k, :]*sh.l*(sh.l+1)/self.radius**2)
            tmp = tmp.T # Longitude, Latitude

            if shtns_lib == 'shtns-magic':
                data[k, ...] = rearangeLat(tmp)
            else:
                data[k, ...] = tmp

        if png:
            plt.ioff()
            if not os.path.exists('movie'):
                os.mkdir('movie')
        else:
            plt.ion()

        if not normed:
            vmin = - max(abs(data.max()), abs(data.min()))
            vmin = cut * vmin
            vmax = -vmin
            cs = np.linspace(vmin, vmax, levels)

        th = np.linspace(np.pi/2., -np.pi/2., nlat)
        if deminc:
            phi = np.linspace(-np.pi, np.pi, self.minc*nphi+1)
            xxout, yyout = hammer2cart(th, -np.pi)
            xxin, yyin = hammer2cart(th, np.pi)
        else:
            phi = np.linspace(-np.pi/self.minc, np.pi/self.minc, nphi)
            xxout, yyout = hammer2cart(th, -np.pi/self.minc)
            xxin, yyin = hammer2cart(th, np.pi/self.minc)
        ttheta, pphi = np.meshgrid(th, phi)
        xx, yy = hammer2cart(ttheta, pphi)
        if deminc:
            fig = plt.figure(figsize=(8, 4))
        else:
            fig = plt.figure(figsize=(8/self.minc, 4))
        fig.subplots_adjust(top=0.99, right=0.99, bottom=0.01, left=0.01)
        ax = fig.add_subplot(111, frameon=False)

        if mer:
            theta = np.linspace(np.pi/2, -np.pi/2, nlat)
            meridians = np.r_[-120, -60, 0, 60, 120]
            circles = np.r_[ 60, 30, 0, -30, -60]

        for k in range(self.nstep):
            if k == 0:
                if normed:
                    vmin = - max(abs(data[k, ...].max()), abs(data[k, ...].min()))
                    vmin = cut * vmin
                    vmax = -vmin
                    cs = np.linspace(vmin, vmax, levels)
                if deminc:
                    dat = symmetrize(data[k, ...], self.minc)
                else:
                    dat = data[k, ...]
                im = ax.contourf(xx, yy, dat, cs, cmap=plt.get_cmap(cm), extend='both')
                if contour:
                    ax.contour(xx, yy, dat, cs, linestyles=['-', '-'],
                               colors=['k', 'k'], linewidths=[0.7, 0.7])
                ax.plot(xxout, yyout, 'k-', lw=1.5)
                ax.plot(xxin, yyin, 'k-', lw=1.5)

                if mer:
                    for lat0 in circles:
                        x0, y0 = hammer2cart(lat0*np.pi/180., phi)
                        ax.plot(x0, y0, 'k:', linewidth=0.7)
                    for lon0 in meridians:
                        x0, y0 = hammer2cart(theta, lon0*np.pi/180.)
                        ax.plot(x0, y0, 'k:', linewidth=0.7)

                ax.axis('off')
                man = plt.get_current_fig_manager()
                man.canvas.draw()

                if png:
                    filename = 'movie/img%05d.png' % k
                    print('write %s' % filename)
                    #st = 'echo %i' % ivar + ' > movie/imgmax'
                    if bgcolor is not None:
                        fig.savefig(filename, facecolor=bgcolor, dpi=dpi)
                    else:
                        fig.savefig(filename, dpi=dpi)

            elif k != 0 and k % step == 0:
                if not png:
                    print(k)
                plt.cla()
                if normed:
                    vmin = - max(abs(data[k, ...].max()), abs(data[k, ...].min()))
                    vmin = cut * vmin
                    vmax = -vmin
                    cs = np.linspace(vmin, vmax, levels)
                if deminc:
                    dat = symmetrize(data[k, ...], self.minc)
                else:
                    dat = data[k, ...]
                im = ax.contourf(xx, yy, dat, cs, cmap=plt.get_cmap(cm), extend='both')
                if contour:
                    ax.contour(xx, yy, dat, cs, colors=['k'],
                               linestyles=['-', '-'], linewidths=[0.7, 0.7])
                ax.plot(xxout, yyout, 'k-', lw=1.5)
                ax.plot(xxin, yyin, 'k-', lw=1.5)

                if mer:
                    for lat0 in circles:
                        x0, y0 = hammer2cart(lat0*np.pi/180., phi)
                        ax.plot(x0, y0, 'k:', linewidth=0.7)
                    for lon0 in meridians:
                        x0, y0 = hammer2cart(theta, lon0*np.pi/180.)
                        ax.plot(x0, y0, 'k:', linewidth=0.7)

                ax.axis('off')
                man.canvas.draw()
                if png:
                    filename = 'movie/img%05d.png' % k
                    print('write %s' % filename)
                    #st = 'echo %i' % ivar + ' > movie/imgmax'
                    if bgcolor is not None:
                        fig.savefig(filename, facecolor=bgcolor, dpi=dpi)
                    else:
                        fig.savefig(filename, dpi=dpi)
Exemplo n.º 5
0
    def movieCmb(self,
                 cut=0.5,
                 levels=12,
                 cm='RdYlBu_r',
                 png=False,
                 step=1,
                 normed=False,
                 dpi=80,
                 bgcolor=None,
                 deminc=True,
                 removeMean=False,
                 precision=np.float64,
                 contour=False,
                 mer=False):
        """
        Plotting function (it can also write the png files)

        :param levels: number of contour levels
        :type levels: int
        :param cm: name of the colormap
        :type cm: str
        :param cut: adjust the contour extrema to max(abs(data))*cut
        :type cut: float
        :param png: save the movie as a series of png files when
                    set to True
        :type png: bool
        :param dpi: dot per inch when saving PNGs
        :type dpi: int
        :param bgcolor: background color of the figure
        :type bgcolor: str
        :param normed: the colormap is rescaled every timestep when set to True,
                       otherwise it is calculated from the global extrema
        :type normed: bool
        :param step: the stepping between two timesteps
        :type step: int
        :param deminc: a logical to indicate if one wants do get rid of the
                       possible azimuthal symmetry
        :type deminc: bool
        :param precision: single or double precision
        :type precision: char
        :param contour: also display the solid contour levels when set to True
        :type contour: bool
        :param mer: display meridians and circles when set to True
        :type mer: bool
        :param removeMean: remove the time-averaged part when set to True
        :type removeMean: bool
        """

        if removeMean:
            blmCut = self.blm - self.blm.mean(axis=0)
        else:
            blmCut = self.blm

        nlat = int(max(int(self.l_max_cmb * (3. / 2. / 2.) * 2.), 192))
        if np.mod(nlat, 2) == 1:
            nlat += 1
        nphi = int(2 * nlat / self.minc)

        # Define spectral transform setup
        sh = SpectralTransforms(l_max=self.l_max_cmb,
                                minc=self.minc,
                                lm_max=self.lm_max_cmb,
                                n_theta_max=nlat)

        # Transform data on grid space
        BrCMB = np.zeros((self.nstep, nphi, nlat), precision)
        print('Spectral -> Spatial transform')
        for k in progressbar(range(self.nstep)):
            BrCMB[k, ...] = sh.spec_spat(blmCut[k, :] * self.ell *
                                         (sh.ell + 1) / self.rcmb**2)
        print('Done')

        if png:
            plt.ioff()
            if not os.path.exists('movie'):
                os.mkdir('movie')
        else:
            plt.ion()

        if not normed:
            vmin = -max(abs(BrCMB.max()), abs(BrCMB.min()))
            vmin = cut * vmin
            vmax = -vmin
            cs = np.linspace(vmin, vmax, levels)

        th = np.linspace(np.pi / 2., -np.pi / 2., nlat)
        if deminc:
            phi = np.linspace(-np.pi, np.pi, self.minc * nphi + 1)
            xxout, yyout = hammer2cart(th, -np.pi)
            xxin, yyin = hammer2cart(th, np.pi)
        else:
            phi = np.linspace(-np.pi / self.minc, np.pi / self.minc, nphi)
            xxout, yyout = hammer2cart(th, -np.pi / self.minc)
            xxin, yyin = hammer2cart(th, np.pi / self.minc)
        ttheta, pphi = np.meshgrid(th, phi)
        xx, yy = hammer2cart(ttheta, pphi)
        if deminc:
            fig = plt.figure(figsize=(8, 4))
        else:
            fig = plt.figure(figsize=(8 / self.minc, 4))
        fig.subplots_adjust(top=0.99, right=0.99, bottom=0.01, left=0.01)
        ax = fig.add_subplot(111, frameon=False)

        if mer:
            theta = np.linspace(np.pi / 2, -np.pi / 2, nlat)
            meridians = np.r_[-120, -60, 0, 60, 120]
            circles = np.r_[60, 30, 0, -30, -60]

        for k in range(self.nstep):
            if k == 0:
                if normed:
                    vmin = -max(abs(BrCMB[k, ...].max()),
                                abs(BrCMB[k, ...].min()))
                    vmin = cut * vmin
                    vmax = -vmin
                    cs = np.linspace(vmin, vmax, levels)
                if deminc:
                    dat = symmetrize(BrCMB[k, ...], self.minc)
                else:
                    dat = BrCMB[k, ...]
                im = ax.contourf(xx,
                                 yy,
                                 dat,
                                 cs,
                                 cmap=plt.get_cmap(cm),
                                 extend='both')
                if contour:
                    ax.contour(xx,
                               yy,
                               dat,
                               cs,
                               linestyles=['-', '-'],
                               colors=['k', 'k'],
                               linewidths=[0.7, 0.7])
                ax.plot(xxout, yyout, 'k-', lw=1.5)
                ax.plot(xxin, yyin, 'k-', lw=1.5)
                #ax.text(0.12, 0.9, 't={:.6f}'.format(self.time[0]), fontsize=16,
                #horizontalalignment='right',
                #verticalalignment='center', transform = ax.transAxes)

                if mer:
                    for lat0 in circles:
                        x0, y0 = hammer2cart(lat0 * np.pi / 180., phi)
                        ax.plot(x0, y0, 'k:', linewidth=0.7)
                    for lon0 in meridians:
                        x0, y0 = hammer2cart(theta, lon0 * np.pi / 180.)
                        ax.plot(x0, y0, 'k:', linewidth=0.7)

                ax.axis('off')
                man = plt.get_current_fig_manager()
                man.canvas.draw()
            if k != 0 and k % step == 0:
                if not png:
                    print(k)
                plt.cla()
                if normed:
                    vmin = -max(abs(BrCMB[k, ...].max()),
                                abs(BrCMB[k, ...].min()))
                    vmin = cut * vmin
                    vmax = -vmin
                    cs = np.linspace(vmin, vmax, levels)
                if deminc:
                    dat = symmetrize(BrCMB[k, ...], self.minc)
                else:
                    dat = BrCMB[k, ...]
                im = ax.contourf(xx,
                                 yy,
                                 dat,
                                 cs,
                                 cmap=plt.get_cmap(cm),
                                 extend='both')
                if contour:
                    ax.contour(xx,
                               yy,
                               dat,
                               cs,
                               colors=['k'],
                               linestyles=['-', '-'],
                               linewidths=[0.7, 0.7])
                ax.plot(xxout, yyout, 'k-', lw=1.5)
                ax.plot(xxin, yyin, 'k-', lw=1.5)
                #ax.text(0.12, 0.9, 't={:.6f}'.format(self.time[k]), fontsize=16,
                #horizontalalignment='right',
                #verticalalignment='center', transform = ax.transAxes)

                if mer:
                    for lat0 in circles:
                        x0, y0 = hammer2cart(lat0 * np.pi / 180., phi)
                        ax.plot(x0, y0, 'k:', linewidth=0.7)
                    for lon0 in meridians:
                        x0, y0 = hammer2cart(theta, lon0 * np.pi / 180.)
                        ax.plot(x0, y0, 'k:', linewidth=0.7)

                ax.axis('off')
                man.canvas.draw()
            if png:
                filename = 'movie/img{:05d}.png'.format(k)
                print('write {}'.format(filename))
                #st = 'echo {}'.format(ivar) + ' > movie/imgmax'
                if bgcolor is not None:
                    fig.savefig(filename, facecolor=bgcolor, dpi=dpi)
                else:
                    fig.savefig(filename, dpi=dpi)