def __init__(self, sunmap, aia=False): if aia: try: sunmap = DButil.normalize_aiamap(sunmap) except: pass data = sunmap.data data[data < 1.0] = 1.0 self.sunmap = smap.Map(data, sunmap.meta) else: self.sunmap = sunmap try: top_right_coord = self.sunmap.top_right_coord bottom_left_coord = self.sunmap.bottom_left_coord self.xrange = np.array([ bottom_left_coord.Tx.to(u.arcsec).value, top_right_coord.Tx.to(u.arcsec).value ]) * u.arcsec self.yrange = np.array([ bottom_left_coord.Ty.to(u.arcsec).value, top_right_coord.Ty.to(u.arcsec).value ]) * u.arcsec except: self.xrange = self.sunmap.xrange self.yrange = self.sunmap.yrange
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()
def __init__(self, sunmap, aia=False): if aia: try: sunmap = DButil.normalize_aiamap(sunmap) except: pass data = sunmap.data data[data < 1.0] = 1.0 self.sunmap = smap.Map(data, sunmap.meta) else: self.sunmap = sunmap
# SDOdir = '/Volumes/NAOC-001/work/2015/20141111/data/prep/0171/' # sdofile = glob.glob(SDOdir + 'AIA20141109_*_0171.fits') # sdofile = sorted(sdofile) # x0, x1, y0, y1 = -660., -575., -200., -115. x0, x1, y0, y1 = -850, -500., 730., 1200. # large 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:
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()