Ejemplo n.º 1
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()
Ejemplo n.º 2
0
    ys = p(xs)
    rms = np.sqrt(np.sum((np.polyval(z, x) - y) ** 2) / len(x))
    return {'xs': xs, 'ys': ys, 'rms': rms}


datadir = '/Users/fisher/Desktop/work/2017/LLL/aia/'
mkmc = 1
if mkmc:
    from sunpy.physics.transforms.solar_rotation import mapcube_solar_derotate

    t1, t2 = Time('2014-11-09T10:00:00'), Time('2014-11-09T13:00:00')
    binwdth = 2
    dt_data = 1
    trange = [t1.jd, t2.jd]
    SDOdir = '/Volumes/NAOC-001/work/database/aiaBrowserData/Download/'
    sdofile = DButil.readsdofile(datadir=SDOdir, wavelength='171', jdtime=trange)
    # 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:
Ejemplo n.º 3
0
def DownloadData():
    [tst, ted] = gettime()
    if ted.mjd <= tst.mjd:
        Div_JSOC_info.text = '''Error: start time must occur earlier than end time. please re-enter start time and end time!!!'''
    elif len(Wavelngth_checkbox.active) == 0:
        Div_JSOC_info.text = '''Error: at least choose one wavelength!!!'''
    else:
        Div_JSOC_info.text = ''''''
        c = drms.Client(verbose=True)
        export_protocol = 'fits'
        if not Text_email.value:
            Div_JSOC_info.text = '''Error: provide your JSOC registered email address!!!'''
            raise RuntimeError('Email address is required.')
        else:
            if not c.check_email(Text_email.value):
                Div_JSOC_info.text = '''Error: <b>Email address</b> is not valid or not registered.!!!'''
                raise RuntimeError(
                    'Email address is not valid or not registered.')
            else:
                config_main['core']['JSOC_reg_email'] = Text_email.value
                DButil.updatejsonfile(suncasa_dir + 'DataBrowser/config.json',
                                      config_main)

        labelsactive = [
            Wavelngth_checkbox.labels[ll] for ll in Wavelngth_checkbox.active
        ]
        if 'goes' in labelsactive:
            global goes
            tr = TimeRange(tst.iso, ted.iso)
            goes = GOESLightCurve.create(tr)
            fout = database_dir + 'goes-' + Text_PlotID.value
            with open(fout, 'wb') as fp:
                pickle.dump(goes, fp)
            Div_JSOC_info.text = """<p>{} saved.</p>""".format(fout)
            MkPlot_args_dict['goesfile'] = os.path.basename(fout)
            labelsactive.pop(labelsactive.index('goes'))
        for series in ['hmi.M_45s', 'aia.lev1_uv_24s', 'aia.lev1_euv_12s']:
            waves = []
            for ll in labelsactive:
                if serieslist[ll] == series:
                    waves.append(ll)
            if len(waves) > 0:
                # try:
                tsel = tst.iso.replace(' ', 'T') + '_TAI-' + ted.iso.replace(
                    ' ', 'T') + '_TAI'
                wave = ','.join(waves)
                cadence = Text_Cadence.value
                if cadence[-1] == 's' and get_num(cadence) < 12:
                    cadence = '12s'
                    Text_Cadence.value = cadence
                if series == 'aia.lev1_uv_24s':
                    if cadence[-1] == 's' and get_num(cadence) < 24:
                        cadence = '24s'
                if series == 'hmi.M_45s':
                    wave = ''
                    if cadence[-1] == 's' and get_num(cadence) < 45:
                        cadence = '45s'
                segments = 'image'
                qstr = '%s[%s@%s][%s]{%s}' % (series, tsel, cadence, wave,
                                              segments)
                print qstr
                r = c.export(qstr,
                             method='url',
                             protocol=export_protocol,
                             email=Text_email.value)
                Div_JSOC_info.text = Div_JSOC_info.text + """<p>Submitting export request <b>{}</b>...</p>""".format(
                    qstr)
                Div_JSOC_info.text = Div_JSOC_info.text + """<p>Request URL: {}</p>""".format(
                    r.request_url)
                Div_JSOC_info.text = Div_JSOC_info.text + """<p>{:d} file(s) available for download.</p>""".format(
                    len(r.urls))
                idx2download = DButil.FileNotInList(
                    r.data['filename'],
                    DButil.readsdofile(datadir=SDOdir,
                                       wavelength=wave,
                                       jdtime=[tst.jd, ted.jd],
                                       isexists=True))
                if len(idx2download) > 0:
                    Div_JSOC_info.text = Div_JSOC_info.text + """<p><b>Downloading</b>....</p>"""
                    r.download(SDOdir, index=idx2download)
                else:
                    Div_JSOC_info.text = Div_JSOC_info.text + """<p>Target file(s) existed.</p>"""

                filename = glob.glob(SDOdir + '*.fits')
                if len(filename) > 0:
                    dirs = DButil.getsdodir(filename)
                    for ll, dd in enumerate(dirs['dir']):
                        if not os.path.exists(SDOdir + dd):
                            os.makedirs(SDOdir + dd)
                        os.system('mv {}/*{}*.fits {}{}'.format(
                            SDOdir, dirs['timstr'][ll], SDOdir, dd))

                Div_JSOC_info.text = Div_JSOC_info.text + """<p>Download <b>finished</b>.</p>"""
                Div_JSOC_info.text = Div_JSOC_info.text + """<p>file(s) downloaded to <b>{}</b></p>""".format(
                    os.path.abspath(SDOdir))
Ejemplo n.º 4
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()