Exemplo n.º 1
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()
Exemplo n.º 2
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
Exemplo n.º 3
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')
Exemplo n.º 4
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))
Exemplo n.º 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))
Exemplo n.º 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)
Exemplo n.º 7
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.0, 1.0, 1.0]

        # Setup UI
        self._load_data_sources()

        # Load initial data
        self._load_defaults()

        # Initialize event handlers
        self._initEvents()
Exemplo n.º 8
0
class TestHelioviewerClient:
    """Tests the Helioviewer.org API Client class"""
    def setup_class(self):
        self.client = HelioviewerClient()
        self.sources = self.client.get_data_sources()

    def teardown_class(self):
        self.client = None

    def test_get_datasources(self):
        """Makes sure datasource query returns a valid result and source id
        is casted to an integer"""
        assert type(
            self.sources['SDO']['AIA']['AIA']['171']['sourceId']) is int

    def test_get_closest_image(self):
        """Tests getClosestImage API method"""
        # check basic query
        im1 = self.client.get_closest_image('1994/01/01',
                                            observatory='SOHO',
                                            instrument='EIT',
                                            detector='EIT',
                                            measurement='195')
        assert im1['width'] == im1['height'] == 1024

        # result should be same when using source id to query
        source_id = self.sources['SOHO']['EIT']['EIT']['195']['sourceId']

        im2 = self.client.get_closest_image('1994/01/01', sourceId=source_id)

        assert im1 == im2

    def test_download_jp2(self):
        """Tests getJP2Image API method"""
        filepath = self.client.download_jp2('2020/01/01',
                                            observatory='SOHO',
                                            instrument='MDI',
                                            detector='MDI',
                                            measurement='continuum')
        try:
            map_ = sunpy.make_map(filepath)
        except sunpy.io.jp2.MissingOpenJPEGBinaryError:
            # We can't test JP2 decoding if binary is not available
            pass
        else:
            assert isinstance(map_, sunpy.Map)
Exemplo n.º 9
0
class TestHelioviewerClient:
    """Tests the Helioviewer.org API Client class"""
    def setup_class(self):
        self.client = HelioviewerClient()
        self.sources = self.client.get_data_sources()

    def teardown_class(self):
        self.client = None
        
    def test_get_datasources(self):
        """Makes sure datasource query returns a valid result and source id
        is casted to an integer"""
        assert type(self.sources['SDO']['AIA']['AIA']['171']['sourceId']) is int
        
    def test_get_closest_image(self):
        """Tests getClosestImage API method"""
        # check basic query
        im1 = self.client.get_closest_image('1994/01/01', 
                                              observatory='SOHO', 
                                              instrument='EIT', 
                                              detector='EIT', 
                                              measurement='195')
        assert im1['width'] == im1['height'] == 1024
        
        # result should be same when using source id to query
        source_id = self.sources['SOHO']['EIT']['EIT']['195']['sourceId']
        
        im2 = self.client.get_closest_image('1994/01/01', sourceId=source_id)
        
        assert im1 == im2
        
    def test_download_jp2(self):
        """Tests getJP2Image API method"""
        filepath = self.client.download_jp2('2020/01/01', observatory='SOHO', 
                                            instrument='MDI', detector='MDI',
                                            measurement='continuum')
        try:
            map_ = sunpy.make_map(filepath)
        except sunpy.io.jp2.MissingOpenJPEGBinaryError:
            # We can't test JP2 decoding if binary is not available
            pass
        else:
            assert isinstance(map_, sunpy.Map)
Exemplo n.º 10
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
Exemplo n.º 11
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')
Exemplo n.º 12
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 != ""
Exemplo n.º 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
Exemplo n.º 14
0
 def setup_class(self):
     self.client = HelioviewerClient()
     self.sources = self.client.get_data_sources()
Exemplo n.º 15
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 ) 
	
Exemplo n.º 16
0
 def setup_class(self):
     self.client = HelioviewerClient()
     self.sources = self.client.get_data_sources()
Exemplo n.º 17
0
from sunpy.net.helioviewer import HelioviewerClient
hv = HelioviewerClient()
hv.download_png("2099/01/01", 6,
                 "[SDO,AIA,AIA,304,1,100],[SDO,AIA,AIA,193,1,50],"+
                 "[SOHO,LASCO,C2,white-light,1,100]",
                 x0=0, y0=0, width=768, height=768)
Exemplo n.º 18
0
#
# Download a set of jp2 files from helioviewer
#
import os
import datetime
import astropy.units as u
from sunpy.time import parse_time
from sunpy.net.helioviewer import HelioviewerClient

cadence = 28 * u.day
start_time = parse_time('2010/10/01')
end_time = parse_time('2017/02/01')

hv = HelioviewerClient()
observatory = 'SDO'
instrument = 'AIA'
detector = 'AIA'
measurements = ['94', '131', '171', '193', '211', '304', '335', '1600', '1700', '4500']
#measurements = ['193', '211', '335', '1600', '1700', '4500']

storage = os.path.expanduser('~/Data/hvp/aia_color_correction')
if not os.path.isdir(storage):
    os.makedirs(storage)


for measurement in measurements:
    # Make the storage directory
    storage_measurement = os.path.join(storage, measurement)
    if not os.path.isdir(storage_measurement):
        os.makedirs(storage_measurement)
Exemplo n.º 19
0
# conda install -c sunpy glymur
# pip install sunpy zeep drms sqlalchemy
import sunpy.map
from sunpy.database.tables import display_entries
from sunpy.net import Fido, attrs as a
from sunpy.database import Database
from sunpy.io.file_tools import read_file
from sunpy.timeseries import TimeSeries
from sunpy.data.sample import NOAAINDICES_TIMESERIES as noaa_ind
import sunpy.data.sample as sample_data

# We can use the Helioviewer to get a Jpeg of the Sun from today:

from sunpy.net.helioviewer import HelioviewerClient
hv = HelioviewerClient()  
sun = hv.download_jp2('2020/05/06', observatory="SDO", instrument="HMI", measurement="continuum") 
hmiC = sunpy.map.Map(sun)
hmiC.peek()

# Here we have specified the telescope, SDO, the instrument/camera, HMI, and the measurement to plot, continuum.
# To view the full list of options we can print the data sources available to us like this:

print(hv.data_sources)

# Let's clean up this plot and make it the orange/yellow colour we see visually.

fig = plt.figure(1)
ax = plt.subplot(111, projection=hmiC)
ax.set_axis_off()
cmap = plt.get_cmap('afmhot')
Exemplo n.º 20
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
Exemplo n.º 21
0
class RGBCompositeImageApp(QtGui.QMainWindow):
    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.0, 1.0, 1.0]

        # Setup UI
        self._load_data_sources()

        # Load initial data
        self._load_defaults()

        # Initialize event handlers
        self._initEvents()

    def _load_data_sources(self):
        """Downloads and displays latest images for default wavelengths"""
        self._datasources = self._hv.get_data_sources()["SDO"]["AIA"]["AIA"]
        sorted_datasources = sorted(self._datasources, key=int)

        for wl in sorted_datasources:
            self.ui.redWavelengthSelect.addItem(wl, self._datasources[wl])
            self.ui.greenWavelengthSelect.addItem(wl, self._datasources[wl])
            self.ui.blueWavelengthSelect.addItem(wl, self._datasources[wl])

        # Default wavelengths: 304, 193, 171
        self.ui.redWavelengthSelect.setCurrentIndex(5)
        self.ui.greenWavelengthSelect.setCurrentIndex(3)
        self.ui.blueWavelengthSelect.setCurrentIndex(2)

    def _load_defaults(self):
        """Load initial images"""
        now = datetime.datetime.utcnow()
        self.ui.dateTimeEdit.setDateTime(now)

        r = self._hv.download_jp2(now, sourceId=self._datasources["304"]["sourceId"])
        g = self._hv.download_jp2(now, sourceId=self._datasources["193"]["sourceId"])
        b = self._hv.download_jp2(now, sourceId=self._datasources["171"]["sourceId"])

        self.red = sunpy.map.Map(r)
        self.green = sunpy.map.Map(g)
        self.blue = sunpy.map.Map(b)

        self._updateRedPreview()
        self._updateGreenPreview()
        self._updateBluePreview()

        self._createCompositeImage()

    def _updateCompositeImage(self):
        """Updates the composite image"""
        # Remove old composite
        rgb = RGBCompositeMap(self.red, self.green, self.blue)
        self.ui.compositeContainer.removeWidget(self.ui.compositeImage)
        self.ui.compositeImage.close()

        # Plot new one
        self.ui.compositeImage = RGBCompositePlot(rgb, 512, 512)
        self.ui.compositeImage.set_rgb_weights(self._weights)
        self.ui.compositeContainer.addWidget(self.ui.compositeImage, 1)
        self.ui.compositeContainer.update()

    def _createCompositeImage(self):
        """Creates an initial composite image plot"""
        rgb = RGBCompositeMap(self.red, self.green, self.blue)
        self.ui.compositeContainer.removeWidget(self.ui.compositePlaceholder)
        self.ui.compositePlaceholder.close()
        self.ui.compositeImage = RGBCompositePlot(rgb, 512, 512)
        self.ui.compositeContainer.addWidget(self.ui.compositeImage, 1)
        self.ui.compositeContainer.update()

    def _updateRedPreview(self):
        """Updates the red preview image"""
        if hasattr(self.ui, "redPreviewImage"):
            self.ui.redPreview.removeWidget(self.ui.redPreviewImage)
            self.ui.redPreviewImage.close()
        else:
            self.ui.redPreview.removeWidget(self.ui.redPlaceholder)
            self.ui.redPlaceholder.close()

        self.ui.redPreviewImage = SunPyPlot(self.red, 256, 256)  # cmap=cm.Reds_r
        self.ui.redPreview.addWidget(self.ui.redPreviewImage, 1)
        self.ui.redPreview.update()

    def _updateGreenPreview(self):
        """Updates the green preview image"""
        if hasattr(self.ui, "greenPreviewImage"):
            self.ui.greenPreview.removeWidget(self.ui.greenPreviewImage)
            self.ui.greenPreviewImage.close()
        else:
            self.ui.greenPreview.removeWidget(self.ui.greenPlaceholder)
            self.ui.greenPlaceholder.close()

        self.ui.greenPreviewImage = SunPyPlot(self.green, 256, 256)  # cmap=cm.Greens_r
        self.ui.greenPreview.addWidget(self.ui.greenPreviewImage, 1)
        self.ui.greenPreview.update()

    def _updateBluePreview(self):
        """Updates the blue preview image"""
        if hasattr(self.ui, "bluePreviewImage"):
            self.ui.bluePreview.removeWidget(self.ui.bluePreviewImage)
            self.ui.bluePreviewImage.close()
        else:
            self.ui.bluePreview.removeWidget(self.ui.bluePlaceholder)
            self.ui.bluePlaceholder.close()

        self.ui.bluePreviewImage = SunPyPlot(self.blue, 256, 256)  # cmap=cm.Blues_r
        self.ui.bluePreview.addWidget(self.ui.bluePreviewImage, 1)
        self.ui.bluePreview.update()

    def _initEvents(self):
        """Initialize event handlers"""
        self.connect(self.ui.redWeightSlider, QtCore.SIGNAL("valueChanged(int)"), self.onRedWeightChange)
        self.connect(self.ui.greenWeightSlider, QtCore.SIGNAL("valueChanged(int)"), self.onGreenWeightChange)
        self.connect(self.ui.blueWeightSlider, QtCore.SIGNAL("valueChanged(int)"), self.onBlueWeightChange)
        self.connect(self.ui.dateTimeEdit, QtCore.SIGNAL("dateTimeChanged(QDateTime)"), self.onDateChange)
        self.connect(self.ui.dateTimeEdit, QtCore.SIGNAL("dateTimeChanged(QDateTime)"), self.onDateChange)
        self.connect(self.ui.actionSave, QtCore.SIGNAL("activated()"), self.onSaveClick)

    def onRedWeightChange(self, value):
        """Red channel weight changed"""
        self._weights[0] = value / 100.0
        self.ui.compositeImage.set_rgb_weights((self._weights))

    def onGreenWeightChange(self, value):
        """Green channel weight changed"""
        self._weights[1] = value / 100.0
        self.ui.compositeImage.set_rgb_weights((self._weights))

    def onBlueWeightChange(self, value):
        """Blue channel weight changed"""
        self._weights[2] = value / 100.0
        self.ui.compositeImage.set_rgb_weights((self._weights))

    def onDateChange(self, qdatetime):
        """Updates the images when the date is changed"""
        dt = qdatetime.toPyDateTime()

        r = self._hv.download_jp2(dt, sourceId=self._datasources["304"]["sourceId"])
        g = self._hv.download_jp2(dt, sourceId=self._datasources["193"]["sourceId"])
        b = self._hv.download_jp2(dt, sourceId=self._datasources["171"]["sourceId"])

        self.red = sunpy.map.Map(r)
        self.green = sunpy.map.Map(g)
        self.blue = sunpy.map.Map(b)

        self._updateRedPreview()
        self._updateGreenPreview()
        self._updateBluePreview()

        self._updateCompositeImage()

    def onSaveClick(self):
        """Save the composite image"""
        filename = QtGui.QFileDialog.getSaveFileName(self, "Save image", "composite.png")
        self.ui.compositeImage.figure.savefig(str(filename))
Exemplo n.º 22
0
#!/usr/bin/env python3

#129L Final Project Part 3 -- user customizable program to plot locations of CMEs and sunspots on corresponding images

#import sunpy.map
from sunpy.net.helioviewer import HelioviewerClient
from matplotlib.image import imread
import matplotlib.pyplot as plt
from matplotlib import patches

hv = HelioviewerClient()

DAT = input('Date yyyy/m/d: ')
#IMRES = input('Image Resolution in arcseconds/pixel: ')
SRCID = input('Data Source ID: ')
#VIS = input('Visibility: ')
#OP = input('Opacity: ')
XFOC = input('Specify x-coord: ')
YFOC = input('Specify y-coord: ')

##include image size in a function, make dict for source ids, make optional args for composite images

IN = [SRCID, XFOC, YFOC]
FLIN = list(map(float, IN))

imgfile = hv.download_png(DAT,
                          6.0, [FLIN[0], 1.0, 100.0],
                          x0=FLIN[1],
                          y0=FLIN[2],
                          width=512,
                          height=512)
Exemplo n.º 23
0
#
# Code to download JP2 files
#
from sunpy.net.helioviewer import HelioviewerClient
from sunpy.map import Map
import os

hv = HelioviewerClient()
datasources = hv.get_data_sources()
get_files = False
directory = '/home/ireland/hv/sunpy_hv_test_images/'
#directory = '/home/ireland/hv/TRACE_test_images/'
# print a list of datasources and their associated ids
files = [] 
if get_files:

   for observatory, instruments in datasources.items():
        for inst, detectors in instruments.items():
            for det, measurements in detectors.items():
                for meas, params in measurements.items():
                    print("%s %s: %d" % (observatory, params['nickname'], params['sourceId']))
                    filepath = hv.download_jp2('2013/06/24 17:31:30',
                                               observatory=observatory,
                                               instrument=inst,
                                               detector=det,
                                               measurement=meas,
                                               directory=directory)
                    files.append(filepath)
else:
    flist = os.listdir(directory)
    for fl in flist:
Exemplo n.º 24
0
    try:
        t = time[0]
    except IndexError:
        print('Your search returned 0 results, please select another event')
    else:
        break

print('Time span of event closest to start of selected interval: ', time[0])

##Section2 -- setting up server request to Helioviewer.org that returns image of the sun nearest to requested event start time. User chooses which data source (instrument/detector) to obtain image from using the source ID. Each source has a unique imaging wavelength.

timex = time[0][0]
searchtime = timex[:timex.find('T')]
date = searchtime.replace('-', '/')

hv = HelioviewerClient()

print(
    'List of Observatories: [sourceID]:\n SDO HMI Mag: 19 \n SDO HMI Int: 18 \n SDO AIA 4500: 17 \n SDO AIA 94: 8 \n SDO AIA 131: 9 \n SDO AIA 335: 14 \n SDO AIA 171: 10 \n SDO AIA 304: 13 \n SDO AIA 1600: 15 \n SDO AIA 211: 12 \n SDO AIA 1700: 16 \n SDO AIA 193: 11 \n STEREO_B COR2-B: 31 \n STEREO_B EUVI-B 304: 27 \n STEREO_B EUVI-B 284: 26 \n STEREO_B EUVI-B 195: 25 \n STEREO_B EUVI-B 171: 24 \n STEREO_B COR1-B: 30 \n Yohkoh SXT white-light: 35 \n Yohkoh SXT thin-Al: 34 \n Yohkoh SXT AlMgMn: 33 \n SOHO MDI Mag: 6 \n SOHO MDI Int: 7 \n SOHO LASCO C3: 5 \n SOHO LASCO C2: 4 \n SOHO EIT 304: 3 \n SOHO EIT 284: 2 \n SOHO EIT 195: 1 \n SOHO EIT 171: 0 \n PROBA2 SWAP 174: 32 \n STEREO_A COR2-A: 29 \n STEREO_A EUVI-A 304: 23 \n STEREO_A EUVI-A 284: 22 \n STEREO_A EUVI-A 195: 21 \n STEREO_A EUVI-A 171: 20 \n STEREO_A COR1-A: 28'
)

id_list = [
    '19', '18', '17', '8', '9', '14', '10', '13', '15', '12', '16', '11', '31',
    '27', '26', '25', '24', '30', '35', '34', '33', '6', '7', '5', '4', '3',
    '2', '1', '0', '32', '29', '23', '22', '21', '20', '28'
]

source = None
while source not in id_list:
    source = input('Please input an available numerical data source ID: ')
Exemplo n.º 25
0
def _is_online(hv: HelioviewerClient):
    try:
        return hv.is_online()
    except:
        return False
Exemplo n.º 26
0
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 21 11:05:34 2020

@author: ventas

from sunpy.net.helioviewer import HelioviewerClient
from sunpy.map import Map

import matplotlib.pyplot as plt

hv = HelioviewerClient()
file = hv.download_jp2('2012/01/01', observatory="SDO", instrument="HMI",
                       measurement="304", Source_id=19) 
#('SDO', 'HMI', None, 'magnetogram'): 19

aia = Map(file)  
aia.peek() 
"""

from sunpy.net.helioviewer import HelioviewerClient
#from astropy.units import Quantity
#from sunpy.map import Map
hv = HelioviewerClient()  
data_sources = hv.get_data_sources()  
filepath = hv.download_jp2('2012/07/05 00:30:00', observatory='SDO',
                           instrument='HMI', measurement='magnetogram')  
#hmi = Map(filepath)  
#xrange = Quantity([200, 550], 'arcsec')  
#yrange = Quantity([-400, 200], 'arcsec')  
#hmi.submap(xrange, yrange).peek()  
Exemplo n.º 27
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

# 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
    
    @pytest.mark.skipif("__SKIP_TESTS__ is True")
    def test_get_datasources(self):
        """Makes sure datasource query returns a valid result and source id
Exemplo n.º 28
0
#
# Download a set of jp2 files from helioviewer
#
import os
import datetime
import astropy.units as u
from sunpy.time import parse_time
from sunpy.net.helioviewer import HelioviewerClient

cadence = 28 * u.day
start_time = parse_time('2010/10/01')
end_time = parse_time('2017/02/01')

hv = HelioviewerClient()
observatory = 'SDO'
instrument = 'AIA'
detector = 'AIA'
measurements = [
    '94', '131', '171', '193', '211', '304', '335', '1600', '1700', '4500'
]
#measurements = ['193', '211', '335', '1600', '1700', '4500']

storage = os.path.expanduser('~/Data/hvp/aia_color_correction')
if not os.path.isdir(storage):
    os.makedirs(storage)

for measurement in measurements:
    # Make the storage directory
    storage_measurement = os.path.join(storage, measurement)
    if not os.path.isdir(storage_measurement):
        os.makedirs(storage_measurement)
Exemplo n.º 29
0
class RGBCompositeImageApp(QtGui.QMainWindow):
    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()

    def _load_data_sources(self):
        """Downloads and displays latest images for default wavelengths"""
        self._datasources = self._hv.get_data_sources()['SDO']['AIA']['AIA']
        sorted_datasources = sorted(self._datasources, key=int)

        for wl in sorted_datasources:
            self.ui.redWavelengthSelect.addItem(wl, self._datasources[wl])
            self.ui.greenWavelengthSelect.addItem(wl, self._datasources[wl])
            self.ui.blueWavelengthSelect.addItem(wl, self._datasources[wl])

        # Default wavelengths: 304, 193, 171
        self.ui.redWavelengthSelect.setCurrentIndex(5)
        self.ui.greenWavelengthSelect.setCurrentIndex(3)
        self.ui.blueWavelengthSelect.setCurrentIndex(2)

    def _load_defaults(self):
        """Load initial images"""
        now = datetime.datetime.utcnow()
        self.ui.dateTimeEdit.setDateTime(now)

        r = self._hv.download_jp2(
            now, sourceId=self._datasources['304']['sourceId'])
        g = self._hv.download_jp2(
            now, sourceId=self._datasources['193']['sourceId'])
        b = self._hv.download_jp2(
            now, sourceId=self._datasources['171']['sourceId'])

        self.red = sunpy.map.Map(r)
        self.green = sunpy.map.Map(g)
        self.blue = sunpy.map.Map(b)

        self._updateRedPreview()
        self._updateGreenPreview()
        self._updateBluePreview()

        self._createCompositeImage()

    def _updateCompositeImage(self):
        """Updates the composite image"""
        # Remove old composite
        rgb = RGBCompositeMap(self.red, self.green, self.blue)
        self.ui.compositeContainer.removeWidget(self.ui.compositeImage)
        self.ui.compositeImage.close()

        # Plot new one
        self.ui.compositeImage = RGBCompositePlot(rgb, 512, 512)
        self.ui.compositeImage.set_rgb_weights(self._weights)
        self.ui.compositeContainer.addWidget(self.ui.compositeImage, 1)
        self.ui.compositeContainer.update()

    def _createCompositeImage(self):
        """Creates an initial composite image plot"""
        rgb = RGBCompositeMap(self.red, self.green, self.blue)
        self.ui.compositeContainer.removeWidget(self.ui.compositePlaceholder)
        self.ui.compositePlaceholder.close()
        self.ui.compositeImage = RGBCompositePlot(rgb, 512, 512)
        self.ui.compositeContainer.addWidget(self.ui.compositeImage, 1)
        self.ui.compositeContainer.update()

    def _updateRedPreview(self):
        """Updates the red preview image"""
        if hasattr(self.ui, "redPreviewImage"):
            self.ui.redPreview.removeWidget(self.ui.redPreviewImage)
            self.ui.redPreviewImage.close()
        else:
            self.ui.redPreview.removeWidget(self.ui.redPlaceholder)
            self.ui.redPlaceholder.close()

        self.ui.redPreviewImage = SunPyPlot(self.red, 256,
                                            256)  #cmap=cm.Reds_r
        self.ui.redPreview.addWidget(self.ui.redPreviewImage, 1)
        self.ui.redPreview.update()

    def _updateGreenPreview(self):
        """Updates the green preview image"""
        if hasattr(self.ui, "greenPreviewImage"):
            self.ui.greenPreview.removeWidget(self.ui.greenPreviewImage)
            self.ui.greenPreviewImage.close()
        else:
            self.ui.greenPreview.removeWidget(self.ui.greenPlaceholder)
            self.ui.greenPlaceholder.close()

        self.ui.greenPreviewImage = SunPyPlot(self.green, 256,
                                              256)  #cmap=cm.Greens_r
        self.ui.greenPreview.addWidget(self.ui.greenPreviewImage, 1)
        self.ui.greenPreview.update()

    def _updateBluePreview(self):
        """Updates the blue preview image"""
        if hasattr(self.ui, "bluePreviewImage"):
            self.ui.bluePreview.removeWidget(self.ui.bluePreviewImage)
            self.ui.bluePreviewImage.close()
        else:
            self.ui.bluePreview.removeWidget(self.ui.bluePlaceholder)
            self.ui.bluePlaceholder.close()

        self.ui.bluePreviewImage = SunPyPlot(self.blue, 256,
                                             256)  #cmap=cm.Blues_r
        self.ui.bluePreview.addWidget(self.ui.bluePreviewImage, 1)
        self.ui.bluePreview.update()

    def _initEvents(self):
        """Initialize event handlers"""
        self.connect(self.ui.redWeightSlider,
                     QtCore.SIGNAL('valueChanged(int)'),
                     self.onRedWeightChange)
        self.connect(self.ui.greenWeightSlider,
                     QtCore.SIGNAL('valueChanged(int)'),
                     self.onGreenWeightChange)
        self.connect(self.ui.blueWeightSlider,
                     QtCore.SIGNAL('valueChanged(int)'),
                     self.onBlueWeightChange)
        self.connect(self.ui.dateTimeEdit,
                     QtCore.SIGNAL('dateTimeChanged(QDateTime)'),
                     self.onDateChange)
        self.connect(self.ui.dateTimeEdit,
                     QtCore.SIGNAL('dateTimeChanged(QDateTime)'),
                     self.onDateChange)
        self.connect(self.ui.actionSave, QtCore.SIGNAL('activated()'),
                     self.onSaveClick)

    def onRedWeightChange(self, value):
        """Red channel weight changed"""
        self._weights[0] = value / 100.
        self.ui.compositeImage.set_rgb_weights((self._weights))

    def onGreenWeightChange(self, value):
        """Green channel weight changed"""
        self._weights[1] = value / 100.
        self.ui.compositeImage.set_rgb_weights((self._weights))

    def onBlueWeightChange(self, value):
        """Blue channel weight changed"""
        self._weights[2] = value / 100.
        self.ui.compositeImage.set_rgb_weights((self._weights))

    def onDateChange(self, qdatetime):
        """Updates the images when the date is changed"""
        dt = qdatetime.toPyDateTime()

        r = self._hv.download_jp2(
            dt, sourceId=self._datasources['304']['sourceId'])
        g = self._hv.download_jp2(
            dt, sourceId=self._datasources['193']['sourceId'])
        b = self._hv.download_jp2(
            dt, sourceId=self._datasources['171']['sourceId'])

        self.red = sunpy.map.Map(r)
        self.green = sunpy.map.Map(g)
        self.blue = sunpy.map.Map(b)

        self._updateRedPreview()
        self._updateGreenPreview()
        self._updateBluePreview()

        self._updateCompositeImage()

    def onSaveClick(self):
        """Save the composite image"""
        filename = QtGui.QFileDialog.getSaveFileName(self, "Save image",
                                                     "composite.png")
        self.ui.compositeImage.figure.savefig(str(filename))
Exemplo n.º 30
0
    img = sunpy.map.Map(filep)
    #Level0 quality flag equals 0 (0 means no issues)
    lev0 = img.meta['quallev0'] == 0
    #check level1 bitwise keywords (http://jsoc.stanford.edu/doc/keywords/AIA/AIA02840_K_AIA-SDO_FITS_Keyword_Document.pdf)
    lev1 = np.binary_repr(
        img.meta['quality']) == '1000000000000000000000000000000'
    #check to see if it is a calibration image
    #This keyword changed after AIA failure
    #    calb = np.binary_repr(img.meta['aiftsid']) == '1010000000000000'
    #check that both levels pass and it is not a calibration file
    check = ((lev0) & (lev1))  # & (calb))

    return check, img


hv = HelioviewerClient()
#datasources = hv.get_data_sources()

#Only thing to edit if someone else takes over weekly weather
#running in subdirectory so this step is not need (Prchlik J. 2017/03/03)
#stard = '/Volumes/Pegasus/jprchlik/weekly_weather/'

now = datetime.utcnow()

#day of weekly weather (currently Tuesday)
wday = 1

#dimensions of the image
w0 = 1900
h0 = 1144
#video wall ratio
Exemplo n.º 31
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
Exemplo n.º 32
0
from sunpy.net.helioviewer import HelioviewerClient
hv = HelioviewerClient()
hv.download_png("2099/01/01",
                6,
                "[SDO,AIA,AIA,304,1,100],[SDO,AIA,AIA,193,1,50]," +
                "[SOHO,LASCO,C2,white-light,1,100]",
                x0=0,
                y0=0,
                width=768,
                height=768)