Пример #1
0
def test_mapcube_solar_derotate(aia171_test_mapcube, aia171_test_submap):
    # Test that a mapcube is returned when the clipping is False
    tmc = mapcube_solar_derotate(aia171_test_mapcube, clip=False)
    assert (isinstance(tmc, map.MapCube))

    # Test that all entries have the same shape - nothing clipped
    for m in tmc:
        assert (m.data.shape == aia171_test_submap.data.shape)

    # Test that the returned reference pixels are correctly displaced.
    tmc = mapcube_solar_derotate(aia171_test_mapcube, clip=True)
    tshift = calculate_solar_rotate_shift(aia171_test_mapcube, layer_index=1)
    for im, m in enumerate(tmc):
        for i_s, s in enumerate(['x', 'y']):
            assert_allclose(m.reference_pixel[i_s],
                            aia171_test_submap.reference_pixel[i_s] +
                            tshift[s][im] / m.scale[i_s] -
                            tshift[s][0] / m.scale[i_s],
                            rtol=5e-2,
                            atol=0)

    # Test that a mapcube is returned on default clipping (clipping is True)
    tmc = mapcube_solar_derotate(aia171_test_mapcube)
    assert (isinstance(tmc, map.MapCube))

    # Test that the shape of data is correct when clipped
    clipped_shape = (25, 19)
    for m in tmc:
        assert (m.data.shape == clipped_shape)
Пример #2
0
def test_mapcube_solar_derotate(aia171_test_mapcube, aia171_test_submap):
    # Test that a mapcube is returned when the clipping is False
    tmc = mapcube_solar_derotate(aia171_test_mapcube, clip=False)
    assert(isinstance(tmc, map.MapCube))

    # Test that all entries have the same shape - nothing clipped
    for m in tmc:
        assert(m.data.shape == aia171_test_submap.data.shape)

    # Test that the returned reference pixels are correctly displaced.
    tmc = mapcube_solar_derotate(aia171_test_mapcube, clip=True)
    tshift = calculate_solar_rotate_shift(aia171_test_mapcube, layer_index=1)
    for im, m in enumerate(tmc):
        for i_s, s in enumerate(['x', 'y']):
            assert_allclose(m.reference_pixel[i_s],
                            aia171_test_submap.reference_pixel[i_s] +
                            tshift[s][im] / m.scale[i_s] -
                            tshift[s][0] / m.scale[i_s],
                            rtol=5e-2, atol=0)

    # Test that a mapcube is returned on default clipping (clipping is True)
    tmc = mapcube_solar_derotate(aia171_test_mapcube)
    assert(isinstance(tmc, map.MapCube))

    # Test that the shape of data is correct when clipped
    clipped_shape = (24, 20)
    for m in tmc:
        assert(m.data.shape == clipped_shape)
Пример #3
0
def test_mapcube_solar_derotate(aia171_test_mapcube, aia171_test_submap):
    # Test that a mapcube is returned when the clipping is False
    tmc = mapcube_solar_derotate(aia171_test_mapcube, clip=False)
    assert (isinstance(tmc, map.MapCube))

    # Test that all entries have the same shape - nothing clipped
    for m in tmc:
        assert (m.data.shape == aia171_test_submap.data.shape)

    # Test that the returned centers are correctly displaced.
    tshift = calculate_solar_rotate_shift(aia171_test_mapcube)
    for im, m in enumerate(tmc):
        for s in ['x', 'y']:
            assert_allclose(m.center[s],
                            aia171_test_submap.center[s] -
                            tshift[s][im].to('arcsec').value,
                            rtol=5e-2,
                            atol=0)

    # Test that a mapcube is returned on default clipping (clipping is True)
    tmc = mapcube_solar_derotate(aia171_test_mapcube)
    assert (isinstance(tmc, map.MapCube))

    # Test that the shape of data is correct when clipped
    clipped_shape = (24, 20)
    for m in tmc:
        assert (m.data.shape == clipped_shape)
Пример #4
0
    def make_mapcube(self, trange, outfile=None, fov=None, wavelength='171', binpix=1, dt_data=1, derotate=False, tosave=True, superpixel=False):
        if isinstance(trange, list):
            if isinstance(trange[0], Time):
                trange = Time([trange[0], trange[-1]])
                fitsfile = DButil.readsdofile(datadir=self.fitsdir, wavelength=wavelength, jdtime=trange.jd)
            else:
                fitsfile = trange
        elif isinstance(trange, Time):
            fitsfile = DButil.readsdofile(datadir=self.fitsdir, wavelength=wavelength, jdtime=trange.jd)
        else:
            print('Input trange format not recognized. trange can either be a file list or a timerange of astropy Time object')

        maplist = []
        print 'Loading fits files....'
        for ll in tqdm(fitsfile[::dt_data]):
            maptmp = sunpy.map.Map(ll)
            if fov:
                x0, x1, y0, y1 = fov
                try:
                    submaptmp = maptmp.submap(u.Quantity([x0 * u.arcsec, x1 * u.arcsec]), u.Quantity([y0 * u.arcsec, y1 * u.arcsec]))
                except:
                    from astropy.coordinates import SkyCoord
                    bl = SkyCoord(x0 * u.arcsec, y0 * u.arcsec, frame=maptmp.coordinate_frame)
                    tr = SkyCoord(x1 * u.arcsec, y1 * u.arcsec, frame=maptmp.coordinate_frame)
                    submaptmp = maptmp.submap(bl, tr)
            else:
                submaptmp = maptmp
            if superpixel:
                submaptmp = submaptmp.superpixel(u.Quantity([binpix * u.pix] * 2))/(np.float(binpix)**2)
            else:
                submaptmp = submaptmp.resample(u.Quantity(submaptmp.dimensions) / binpix)
            if submaptmp.detector == 'HMI':
                pass
            else:
                try:
                    submaptmp = DButil.normalize_aiamap(submaptmp)
                except:
                    pass
            maplist.append(submaptmp)
        if derotate:
            mapcube = mapcube_solar_derotate(sunpy.map.Map(maplist, cube=True))
        else:
            mapcube = sunpy.map.Map(maplist, cube=True)
        trange = Time([mapcube[0].date, mapcube[-1].date])
        self.fitsfile = fitsfile
        self.dt_data = dt_data
        self.mapcube = mapcube
        self.mapcube_info()

        if tosave:
            if not outfile:
                outfile = 'mapcube_{0}_bin{3}_dtdata{4}_{1}_{2}'.format(mapcube[0].meta['wavelnth'], trange[0].isot[:-4].replace(':', ''),
                                                                        trange[1].isot[:-4].replace(':', ''), binpix, dt_data)
            for ll in xrange(42):
                if os.path.exists(outfile):
                    if not os.path.exists(outfile + '_{}'.format(ll)):
                        outfile = outfile + '_{}'.format(ll)
            self.mapcube_tofile(outfile)
        gc.collect()
Пример #5
0
 def LoadSubChunk(self, mapdict, x0, x1, y0, y1):
     from sunpy.physics.transforms.solar_rotation import mapcube_solar_derotate
     submaplist = []
     for sidx, spmap in enumerate(mapdict['mc'].maps):
         submaptmp = spmap.submap(u.Quantity([x0 * u.arcsec, x1 * u.arcsec]),
                                  u.Quantity([y0 * u.arcsec, y1 * u.arcsec]))
         submaplist.append(submaptmp)
     try:
         submc = mapcube_solar_derotate(smap.Map(submaplist, cube=True))
     except:
         submc = smap.Map(submaplist, cube=True)
     return submc
Пример #6
0
def test_mapcube_solar_derotate(aia171_test_mapcube, aia171_test_submap):
    # Test that a mapcube is returned when the clipping is False
    tmc = mapcube_solar_derotate(aia171_test_mapcube, clip=False)
    assert isinstance(tmc, map.MapCube)

    # Test that all entries have the same shape - nothing clipped
    for m in tmc:
        assert m.data.shape == aia171_test_submap.data.shape

    # Test that the returned centers are correctly displaced.
    tshift = calculate_solar_rotate_shift(aia171_test_mapcube)
    for im, m in enumerate(tmc):
        for i_s, s in enumerate(["x", "y"]):
            assert_allclose(m.center[i_s], aia171_test_submap.center[i_s] - tshift[s][im], rtol=5e-2, atol=0)

    # Test that a mapcube is returned on default clipping (clipping is True)
    tmc = mapcube_solar_derotate(aia171_test_mapcube)
    assert isinstance(tmc, map.MapCube)

    # Test that the shape of data is correct when clipped
    clipped_shape = (24, 20)
    for m in tmc:
        assert m.data.shape == clipped_shape
Пример #7
0
    maplist = []
    print 'Loading fits files....'
    for ll in tqdm(sdofile[::dt_data]):
        maptmp = sunpy.map.Map(ll)
        submaptmp = maptmp.submap(u.Quantity([x0 * u.arcsec, x1 * u.arcsec]),
                                  u.Quantity([y0 * u.arcsec, y1 * u.arcsec]))
        submaptmp = submaptmp.resample(u.Quantity(submaptmp.dimensions) / binwdth)
        if submaptmp.detector == 'HMI':
            pass
        else:
            submaptmp = DButil.normalize_aiamap(submaptmp)
        maplist.append(submaptmp)
        # print '{}/{} loaded.'.format(idx + 1, len(sdofile))
    doderotate = False
    if doderotate:
        mapcube = mapcube_solar_derotate(sunpy.map.Map(maplist, cube=True))
    else:
        mapcube = sunpy.map.Map(maplist, cube=True)
    outfile = '{0}/mapcube_{1}_bin{4}_dtdata{5}_{2}_{3}'.format(datadir, mapcube[0].meta['wavelnth'],
                                                                t1.isot[:-4].replace(':', ''),
                                                                t2.isot[:-4].replace(':', ''), binwdth, dt_data)
    with open(outfile, 'wb') as sf:
        print 'Saving mapcube....'
        pickle.dump(mapcube, sf)
    gc.collect()
else:
    with open('{}/mapcube_{}'.format(datadir, 304), 'rb') as sf:
        print 'Loading mapcube....'
        mapcube = pickle.load(sf)
        # submaplist = []
        # for sidx, smap in enumerate(mapcube0):
Пример #8
0
 def mapcube_drot(self):
     self.mapcube = mapcube_solar_derotate(self.mapcube)
     return self.mapcube
Пример #9
0
 def mapcube_drot(self):
     return mapcube_solar_derotate(self.mapcube)
Пример #10
0
    def make_mapcube(self,
                     trange,
                     outfile=None,
                     fov=None,
                     binpix=1,
                     dt_data=1,
                     derotate=False,
                     tosave=True):
        if isinstance(trange, list):
            if isinstance(trange[0], Time):
                trange = Time([trange[0], trange[-1]])
                fitsfile = DButil.readsdofile(datadir=self.fitsdir,
                                              wavelength='171',
                                              jdtime=trange.jd)
            else:
                fitsfile = trange
        elif isinstance(trange, Time):
            fitsfile = DButil.readsdofile(datadir=self.fitsdir,
                                          wavelength='171',
                                          jdtime=trange.jd)
        else:
            print(
                'Input trange format not recognized. trange can either be a file list or a timerange of astropy Time object'
            )

        maplist = []
        print 'Loading fits files....'
        for ll in tqdm(fitsfile[::dt_data]):
            maptmp = sunpy.map.Map(ll)
            if fov:
                x0, x1, y0, y1 = fov
                submaptmp = maptmp.submap(
                    u.Quantity([x0 * u.arcsec, x1 * u.arcsec]),
                    u.Quantity([y0 * u.arcsec, y1 * u.arcsec]))
            else:
                submaptmp = maptmp
            submaptmp = submaptmp.resample(
                u.Quantity(submaptmp.dimensions) / binpix)
            if submaptmp.detector == 'HMI':
                pass
            else:
                submaptmp = DButil.normalize_aiamap(submaptmp)
            maplist.append(submaptmp)
        if derotate:
            mapcube = mapcube_solar_derotate(sunpy.map.Map(maplist, cube=True))
        else:
            mapcube = sunpy.map.Map(maplist, cube=True)
        trange = Time([mapcube[0].date, mapcube[-1].date])
        self.fitsfile = fitsfile
        self.dt_data = dt_data
        self.mapcube = mapcube
        self.mapcube_info()

        if tosave:
            if not outfile:
                outfile = 'mapcube_{0}_bin{3}_dtdata{4}_{1}_{2}'.format(
                    mapcube[0].meta['wavelnth'],
                    trange[0].isot[:-4].replace(':', ''),
                    trange[1].isot[:-4].replace(':', ''), binpix, dt_data)
            self.mapcube_tofile(outfile)
        gc.collect()