예제 #1
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))
예제 #2
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))
예제 #3
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)
예제 #4
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)
예제 #5
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)
예제 #6
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))
예제 #7
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))
예제 #8
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:
예제 #9
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()