Example #1
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 != ""
Example #2
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')
Example #3
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)
Example #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)
Example #5
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')
Example #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))
Example #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))
Example #8
0
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)

    today = start_time
    while today <= end_time:
        # Get the next file
        filepath = hv.download_jp2(today, observatory=observatory,
                                   instrument=instrument, detector=detector,
                                   measurement=measurement)

        # Move the file to the storage location
        _dummy, filename = os.path.split(filepath)
        os.rename(filepath, os.path.join(storage_measurement, filename))
        today += datetime.timedelta(seconds=cadence.to(u.s).value)
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)

    today = start_time
    while today <= end_time:
        # Get the next file
        filepath = hv.download_jp2(today,
                                   observatory=observatory,
                                   instrument=instrument,
                                   detector=detector,
                                   measurement=measurement)

        # Move the file to the storage location
        _dummy, filename = os.path.split(filepath)
        os.rename(filepath, os.path.join(storage_measurement, filename))
        today += datetime.timedelta(seconds=cadence.to(u.s).value)
Example #10
0
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:
        files.append(os.path.join(directory, fl))

files = sorted(files)

n = len(files)


for f in files:
    print f
Example #11
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')
hmiC.plot(cmap=cmap, annotate=False)
Example #12
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()