예제 #1
0
def get_helioviewer_client():
    hv = HelioviewerClient()
    if not _is_online(hv):
        # fall back to mirror server
        print("https://www.helioviewer.org/ seems to be offline,"
              "switching to mirror at https://helioviewer.ias.u-psud.fr/")
        hv = HelioviewerClient("https://helioviewer-api.ias.u-psud.fr/")
    return hv
예제 #2
0
    def __init__(self):
        QtGui.QMainWindow.__init__(self)
        self.ui = Ui_RGBComposite.Ui_RGBComposite()
        self.ui.setupUi(self)

        # Helioviewer client
        self._hv = HelioviewerClient()
        self._datasources = None

        # Loaded images
        self.red = None
        self.green = None
        self.blue = None

        # Color channel weights
        self._weights = [1., 1., 1.]

        # Setup UI
        self._load_data_sources()

        # Load initial data
        self._load_defaults()

        # Initialize event handlers
        self._initEvents()
예제 #3
0
 def test_progress_png(self, client, capsys):
     """
     Tests if progress bars are disabled when running `download_png()`.
     """
     msg = "\rFiles Downloaded:"
     client = HelioviewerClient()
     client.download_png('2012/07/16 10:08:00',
                         2.4,
                         "[SDO,AIA,AIA,171,1,100]",
                         x0=0,
                         y0=0,
                         width=1024,
                         height=1024,
                         progress=False)
     _, err = capsys.readouterr()
     assert msg not in err
     client.download_png('2012/07/16 10:08:00',
                         2.4,
                         "[SDO,AIA,AIA,171,1,100]",
                         x0=0,
                         y0=0,
                         width=1024,
                         height=1024)
     _, err = capsys.readouterr()
     assert msg in err
예제 #4
0
def fetch_image(date, obs, ins, det, meas):
	hv = HelioviewerClient()
	filepath = hv.download_jp2(date,observatory=obs, instrument=ins, detector=det, measurement=meas)
	print filepath
	hmi = sunpy.map.Map(filepath)
	hmi.meta['CROTA2'] = 0
	fig = plt.figure()
	hmi.plot()
	plt.colorbar()
	return mpld3.fig_to_html(fig, template_type='notebook')
예제 #5
0
def client():
    """
    Fixture to create a client and skip tests if not available
    """
    try:
        client = HelioviewerClient()
        client.sources = client.get_data_sources()
        return client
    except urllib.error.HTTPError as e:
        print("There's a HTTP problem {} {}".format(e.code, e.args))
        pytest.skip("HTTP error {}".format(e.code))
예제 #6
0
def hello():
	hv = HelioviewerClient()
	datasources = hv.get_data_sources()
	entries = []
	for observatory, instruments in datasources.items():
		for inst, detectors in instruments.items():
			for det, measurements in detectors.items():
				for meas, params in measurements.items():
					entry = OrderedDict()				
					entry['name'] = params['nickname']
					entry['obs'] = observatory
					entry['val'] = observatory + "," + inst + "," + det + "," + meas
					entries.append(entry)
	print entries
	return render_template('index.html',evs=event_types, entries=entries)
예제 #7
0
 def test_progress_jp2(self, client, capsys):
     """
     Tests if progress bars are disabled when running `download_jp2()`.
     """
     client = HelioviewerClient()
     client.download_jp2("2012/01/01",
                         observatory="SOHO",
                         instrument="MDI",
                         measurement="continuum",
                         progress=False)
     out, err = capsys.readouterr()
     assert err == ""
     client.download_jp2("2012/01/01",
                         observatory="SOHO",
                         instrument="MDI",
                         measurement="continuum")
     out, err = capsys.readouterr()
     assert err != ""
예제 #8
0
def get_images(path):
    #constantes
    for file in glob.glob('%s/*.dat' % (path)):
        df_solarflayers = pd.read_csv(
            file, sep='\t', header=None
        )  #, usecols=[0, 1, 2], names=['STARTT', 'MAXFlux', 'ENDT'])#, index=None)
        for index, event in df_solarflayers.iterrows():
            for c in range(2):
                year, month, day, hour, minute, second = event[c][:4], event[
                    c][5:7], event[c][8:10], event[c][11:13], event[c][
                        14:16], event[c][17:19]
                print('La imagen con fecha %s se esta descargando ...' %
                      (year + '/' + month + '/' + day + ':' + hour + ':' +
                       minute + ':' + second + '\n'))
                hv = HelioviewerClient()

                #                data_sources = hv.get_data_sources()
                filepath = hv.download_jp2(
                    '%s/%s/%s %s:%s:%s' %
                    (year, month, day, hour, minute, second),
                    observatory='SDO',
                    instrument='HMI',
                    measurement='magnetogram')
예제 #9
0
"""
Helioviewer Client tests
"""
from __future__ import absolute_import

#pylint: disable=C0103,R0904,W0201,W0212,W0232,E1103
import sunpy
import sunpy.map
import pytest
from sunpy.net.helioviewer import HelioviewerClient

from sunpy.tests.helpers import skip_glymur

# If server is not accessible, skip Helioviewer tests
client = HelioviewerClient()
if not client.is_online():
    __SKIP_TESTS__ = True
    print("Skipping Helioviewer.org tests (server inaccessible)")
else:
    __SKIP_TESTS__ = False


class TestHelioviewerClient:
    """Tests the Helioviewer.org API Client class"""
    def setup_class(self):
        self.client = client
        self.sources = self.client.get_data_sources()

    def teardown_class(self):
        self.client = None
예제 #10
0
def build_timelist(YEAR, MONTH, DAY):
	times = []

	for hours in range (0, 24):
		for minutes in xrange (0, 60, 12):
			times.append(datetime.datetime(YEAR, MONTH, DAY, hours, minutes, 00))
	return times


if __name__ == '__main__':
	
	year, month, day = get_date()

	timelist = build_timelist(year, month, day)
	hv = HelioviewerClient()  
	#file = hv.download_png('2015/01/01', 6, "[SDO,AIA,AIA,304,1,100],[SDO,AIA,AIA,193,1,50],[SOHO,LASCO,C2,white-light,1,100],[SOHO,LASCO,C3,white-light,1,100]", x0=0, y0=0, width=900, height=900)  
	minutes = []
	for minute in xrange(0, 60, 12):
		minutes.append(minute)

	for time in timelist:
		filenum = timelist.index(time) + 1
		total = len(timelist)
		print("DOWNLOADING: " + str(time) + " --- " + str(filenum) + "/" + str(total))
		file = hv.download_png(time, 6, 
		                       "[SDO,AIA,AIA,193,1,100],"\
		                       "[SOHO,LASCO,C2,white-light,1,100]",
		                       directory="./downloaded", 
		                       x0=0, y0=0, width=2000, height=2000, watermark=False ) 
	
예제 #11
0
 def setup_class(self):
     self.client = HelioviewerClient()
     self.sources = self.client.get_data_sources()
예제 #12
0
def download_images(c1, c2, craft, c1_hvr, c2_hvr, cme_root):
    """Download the COR1 and COR2 fits files for the frame nearest tm, to get
    coords and do distance calc. Download several pngs around the event.
    """
    # Open up a VSO client and a Helioviewer Client
    vsoclient = vso.VSOClient()
    hv = HelioviewerClient()
    # Loop over the events, make event directory, download closest fits file
    # and several pngs.
    for i in range(len(c1)):
        print 'length of c1'
        print len(c1)
        print i
        cme_dir = cme_root + r'\cme_' + '{0:02d}'.format(i + 1)
        if not os.path.exists(cme_dir):
            os.makedirs(cme_dir)
        #######################################################################
        # Search for COR1 data in +/- 30min window around event tm1
        dt = pd.Timedelta(30, 'm')
        tl = [(c1['tm'][i] - dt).isoformat(), (c1['tm'][i] + dt).isoformat()]
        # Query VSO to find what files available
        qr = vsoclient.query(vso.attrs.Time(tl[0], tl[1]),
                             vso.attrs.Instrument('cor1'),
                             vso.attrs.Source(craft))
        # Take out values that are not 0deg polarised
        q = 0
        while q <= len(qr) - 1:
            tpe = qr[q]['info'].split(';')[3].strip()
            if tpe == '0deg.':
                q = q + 1
            else:
                qr.pop(q)
        # Find closest mathced in time
        # Get datetimes of the query resutls
        times = np.array([pd.to_datetime(x['time']['start']) for x in qr])
        # Remove querys before the closest match
        q = 0
        while q < np.argmin(np.abs(times - c1['tm'][i])):
            qr.pop(0)
            q = q + 1
        # Remove querys after the closest match
        while len(qr) > 1:
            qr.pop(1)
        # Download best matched file
        vsoclient.get(qr, path=cme_dir + r"\{file}").wait()
        for t in times:
            hv.download_png(t.isoformat(),
                            7.5,
                            c1_hvr,
                            x0=0,
                            y0=0,
                            width=1024,
                            height=1024,
                            directory=cme_dir,
                            watermark=True)
        ###################################################################
        # Search for COR2 data around tm2
        dt = pd.Timedelta(90, 'm')
        tl = [(c2['tm'][i] - dt).isoformat(), (c2['tm'][i] + dt).isoformat()]
        qr = vsoclient.query(vso.attrs.Time(tl[0], tl[1]),
                             vso.attrs.Instrument('cor2'),
                             vso.attrs.Source(craft))
        # Take out values not 2048x2048 double exposures
        q = 0
        while q <= len(qr) - 1:
            tpe = qr[q]['info'].split(';')[2].strip()
            sze = qr[q]['info'].split(';')[-1].strip()
            if tpe == 'DOUBLE' and sze == '2048x2048':
                q = q + 1
            else:
                qr.pop(q)
        # Find closest mathced in time
        # Get datetimes of the query resutls
        times = np.array([pd.to_datetime(x['time']['start']) for x in qr])
        # Remove querys before the closest match
        q = 0
        while q < np.argmin(np.abs(times - c2['tm'][i])):
            qr.pop(0)
            q = q + 1
        # Remove querys after the closest match
        while len(qr) > 1:
            qr.pop(1)
        # Download best matched file
        vsoclient.get(qr, path=cme_dir + r"\{file}").wait()
        # Use the query times to download helioviewer PNGS
        for t in times:
            hv.download_png(t.isoformat(),
                            14.7,
                            c2_hvr,
                            x0=0,
                            y0=0,
                            width=2048,
                            height=2048,
                            directory=cme_dir,
                            watermark=True)
        ###################################################################
        # Now use the fits files to work out the mid point distance and
        # update the arrays
        c1_file = glob.glob(cme_dir + r'\*c1*.fts')
        rb, rm = calc_radial_distance(c1_file, cme_root)
        c1['rb'][i] = rb
        c1['rm'][i] = rm
        # Repeat for COR2
        c2_file = glob.glob(cme_dir + r'\*c2*.fts')
        rb, rm = calc_radial_distance(c2_file, cme_root)
        c2['rb'][i] = rb
        c2['rm'][i] = rm
    return c1, c2
예제 #13
0
    def gather_files(self):
        """
        Downloads and/or concatenate into all files used for creating images 
        and producing the final movie
        """
        # use helioviewer if requested
        if self.usehv:
            from sunpy.net.helioviewer import HelioviewerClient
            import matplotlib.image as mpimg
            hv = HelioviewerClient()
            dayarray = glob.glob(self.sdir + '/raw/*jp2')
            forpool = np.arange(len(dayarray))
            #for i in forpool: format_img(i)
            pool2 = Pool(processes=nproc)
            outs = pool2.map(get_file, forpool)
            pool2.close()

        #video wall ratio
        self.rv = float(self.w0) / float(self.h0)

        #scale up the images with increasing dpi
        self.sc = self.dpi / 100

        self.span = (
            self.end -
            self.start).total_seconds()  #seconds to run the movie over

        #create a directory which will contain the raw png files
        #sdir = stard+eday.date().strftime('%Y%m%d')
        #creating a subdirectory to extra step is not need
        dirlist = [
            self.sdir, self.sdir + '/raw', self.sdir + '/working',
            self.sdir + '/working/symlinks', self.sdir + '/final',
            self.sdir + '/goes', self.sdir + '/ace'
        ]
        for i in dirlist:
            self.create_dir(i)

        #get all days in date time span
        if self.goes:
            ggxf.look_xrays(self.start,
                            self.end + dt(days=1),
                            self.sdir,
                            email=self.email)
            goesfil = glob.glob(self.sdir + '/goes/*txt')
            goesnames = [
                'YR', 'MO', 'DA', 'HHMM', 'JDay', 'Secs', 'Short', 'Long'
            ]
            self.goesdat = Table(names=goesnames)

            #loop over all day information and add to large array
            for m in goesfil:
                temp = ascii.read(m,
                                  guess=True,
                                  comment='#',
                                  data_start=2,
                                  names=goesnames)
                self.goesdat = vstack([self.goesdat, temp])

            #create datetime array
            self.goesdat['time_dt'] = [
                datetime(int(i['YR']), int(i['MO']), int(i['DA'])) +
                dt(seconds=i['Secs']) for i in self.goesdat
            ]

        if self.wind:
            aceb = glob.glob(self.sdir + '/ace/*mag*txt')
            acep = glob.glob(self.sdir + '/ace/*swe*txt')

            aceb_names = [
                'YR', 'MO', 'DA', 'HHMM', 'JDay', 'Secs', 'S', 'Bx', 'By',
                'Bz', 'Bt', 'Lat', 'Long'
            ]
            acep_names = [
                'YR', 'MO', 'DA', 'HHMM', 'JDay', 'Secs', 'S', 'Den', 'Speed',
                'Temp'
            ]

            acebdat = Table(names=aceb_names)
            acepdat = Table(names=acep_names)

            #put B field in large array
            for m in aceb:
                temp = ascii.read(m,
                                  guess=True,
                                  comment='#',
                                  data_start=2,
                                  names=aceb_names)
                acebdat = vstack([acebdat, temp])
        #put plasmag in large array
            for m in acep:
                temp = ascii.read(m,
                                  guess=True,
                                  comment='#',
                                  data_start=2,
                                  names=acep_names)
                acepdat = vstack([acepdat, temp])

            self.aceadat = join(acepdat,
                                acebdat,
                                keys=['YR', 'MO', 'DA', 'HHMM'])
            #create datetime array
            self.aceadat['time_dt'] = [
                datetime(int(i['YR']), int(i['MO']), int(i['DA'])) +
                dt(seconds=i['Secs_1']) for i in self.aceadat
            ]

        #download files locally
        if self.download:
            self.run_download()
        #use a local directory of files
        elif self.local:
            self.gather_local()
        else:
            self.scream()  # use SDO archive to search