Пример #1
0
    def __init__(self):
        self._view = QtWidgets.QWidget()
        self._ui = Ui_DataManager()
        self._ui.setupUi(self._view)

        self._ui.refresh_button.setIcon(self._view.style().standardIcon(
            QStyle.SP_BrowserReload))
        self._ui.remove_button.setIcon(self._view.style().standardIcon(
            QStyle.SP_DialogNoButton))
        self._ui.add_button.setIcon(self._view.style().standardIcon(
            QStyle.SP_DialogYesButton))

        self.dlg = DataManagerFilterDialog()

        db = QtSql.QSqlDatabase.addDatabase('QSQLITE')
        db.setDatabaseName(
            sunpy.config.get("database", "url").replace("sqlite:///", ""))

        model = QtSql.QSqlTableModel()
        model.setTable("data")
        model.setEditStrategy(QtSql.QSqlTableModel.OnFieldChange)
        model.select()
        self._ui.data_table.setModel(model)

        self.initTableHeader(model)

        self._ui.add_button.clicked.connect(lambda x: self.onAdd())
        self._ui.remove_button.clicked.connect(lambda x: self.onRemove())
        self._ui.open_button.clicked.connect(lambda x: self.onOpen())
        self._ui.refresh_button.clicked.connect(lambda x: self.model.select())
        self._ui.filter_button.clicked.connect(lambda x: self.onFilter())

        self.sunpy_db = Database()
        self.model = model
Пример #2
0
def test_config_url(monkeypatch):
    monkeypatch.setattr("sunpy.config", ConfigParser.SafeConfigParser())
    url = 'sqlite:///'
    sunpy.config.add_section('database')
    sunpy.config.set('database', 'url', url)
    database = Database()
    assert database.url == url
Пример #3
0
def test_fetch_separate_filenames():
    # Setup
    db = Database('sqlite:///')

    download_query = [
        vso.attrs.Time('2012-08-05', '2012-08-05 00:00:05'),
        vso.attrs.Instrument('AIA')
    ]

    tmp_test_dir = os.path.join(sunpy.config.get('downloads', 'download_dir'),
                                'tmp_test_dir/')

    if not os.path.isdir(tmp_test_dir):
        os.mkdir(tmp_test_dir)

    path = tmp_test_dir + '{file}'

    db.fetch(*download_query, path=path)

    # Test
    assert len(db) == 4

    dir_contents = os.listdir(tmp_test_dir)
    assert 'aia_lev1_335a_2012_08_05t00_00_02_62z_image_lev1.fits' in dir_contents
    assert 'aia_lev1_94a_2012_08_05t00_00_01_12z_image_lev1.fits' in dir_contents
    assert os.path.isfile(
        os.path.join(tmp_test_dir,
                     'aia_lev1_335a_2012_08_05t00_00_02_62z_image_lev1.fits'))
    assert os.path.isfile(
        os.path.join(tmp_test_dir,
                     'aia_lev1_94a_2012_08_05t00_00_01_12z_image_lev1.fits'))

    # Teardown
    shutil.rmtree(tmp_test_dir)
Пример #4
0
def filled_database():
    database = Database('sqlite:///:memory:')
    for i in xrange(1, 11):
        entry = DatabaseEntry()
        database.add(entry)
        # every fourth entry gets the tag 'foo'
        if i % 4 == 0:
            database.tag(entry, 'foo')
        # every fifth entry gets the tag 'bar'
        if i % 5 == 0:
            database.tag(entry, 'bar')
    database.commit()
    return database
Пример #5
0
    def connect_db(self, conn_string=''):
        '''
    		This function creates a database connection based on the parameters
    		specified in the GUI.
    		Parameters: conn_string (string of the connection for the object) Optional
    	'''

        def_wavelength = self.default_wavelength.get_widget().currentText()

        try:
            if conn_string == '':
                conn_string = sunpy.config.get('database', 'url')
            global database
            database = Database(conn_string, default_waveunit=def_wavelength)
        except:
            conn_string = self.get_conn_string()
            global database
            database = Database(conn_string, default_waveunit=def_wavelength)

        if self.set_default_box.get_state():
            self.set_default_db(conn_string)

        self.set_info("Database Connected at %s" % conn_string)
        return database
Пример #6
0
    def __init__(self):
        self._view = QtWidgets.QWidget()
        self._ui = Ui_DownloadResult()
        self._ui.setupUi(self._view)

        self._ui.tabs.clear()
        self._ui.tabs.tabCloseRequested.connect(self._onRemoveTab)

        self.database = Database()

        self.tabs = {}
        self.queries = {}
        self.query_id = 0
        self.loading = []
        self.loaded = {entry.fileid: entry.path for entry in list(self.database)}

        self._ui.download_button.clicked.connect(lambda evt: self._onDownloadSelected())
        self._ui.open_button.clicked.connect(lambda evt: self._onOpenSelected())
Пример #7
0
def split_function_database():
    """
    Generates a custom database to test the split_database function
    """
    database = Database('sqlite:///:memory:')
    for i in range(1, 11):
        entry = DatabaseEntry()
        database.add(entry)
        # every fourth entry gets the instrument 'EIA'
        if i % 4 == 0:
            database.edit(entry, instrument='EIA')
        # every fifth entry gets the instrument 'AIA_3'
        elif i % 5 == 0:
            database.edit(entry, instrument='AIA_3')
        # every other entry gets instrument 'RHESSI'
        else:
            database.edit(entry, instrument='RHESSI')
        # all  entries have provider 'xyz'
        database.edit(entry, provider='xyz')
    database.commit()
    return database
Пример #8
0
def test_display_entries_empty_db():
    with pytest.raises(TypeError):
        display_entries(Database('sqlite:///'), ['id'])
Пример #9
0
def test_create_display_table_empty_db():
    with pytest.raises(TypeError):
        _create_display_table(Database('sqlite:///'), ['id'])
Пример #10
0
from sunpy.net import vso
from sunpy.database import Database
database = Database("sqlite:///")
database.download(vso.attrs.Time("2012-08-05", "2012-08-05 00:00:05"),
                  vso.attrs.Instrument('AIA'))
len(database)
from sunpy.database.tables import display_entries
print display_entries(database,
                      ["id", "observation_time_start", "wavemin", "wavemax"])
Пример #11
0
def database():
    return Database('sqlite:///:memory:')
Пример #12
0
def database_using_lfucache():
    return Database('sqlite:///:memory:', LFUCache, cache_size=3)
Пример #13
0
def test_config_url_none(monkeypatch):
    monkeypatch.setattr("sunpy.config", ConfigParser.SafeConfigParser())
    with pytest.raises(ConfigParser.NoSectionError):
        Database()
Пример #14
0
# This is how it would query sunpy the data mapped in 'gathering_data_information.txt'
# At this time the vso client seems unstable and sunpy integration could not be complete

from sunpy.database import Database
from sunpy.net import vso

#Sets the connection to database, in this case, it is in postgresql but it can be others too
database = Database('postgresql+psycopg2://user:password@host/dbname')


#downloads and add to database
def downloadData(q_provider, q_source, q_instrument, q_physobs):
    client = vso.VSOClient()
    qr = client.search(
        vso.attrs.Time('2016-05-07 00:00:00', '2016-05-08 00:00:00'))
    print(qr)
    database.add_from_vso_query_result(qr)
    database.commit()


#downloads MAgnetogram vector from vso client
def dl_MagnetogramVector():
    q_provider = 'JSOC'
    q_source = 'SDO'
    q_instrument = 'HMI'
    q_physobs = 'vector_magnetic_field'
    downloadData(q_provider, q_source, q_instrument, q_physobs)


#downloads XRay data from vso client
def dl_XRay():
Пример #15
0
def default_waveunit_database():
    unit_database = Database('sqlite:///:memory:',
                             default_waveunit=units.meter)
    str_database = Database('sqlite:///:memory:', default_waveunit="m")
    return unit_database, str_database
Пример #16
0
hmiC.plot(cmap=cmap, annotate=False)
plt.clim(0,300)
plt.show()

# Now compare your awesome image with the HMI Intensitygram on https://sdo.gsfc.nasa.gov/data/.
# Intensitygrams show how bright the sun is over it's surface. You'll also see a flattened version on the SDO website.
# The flattened image takes into account the fact that most of the light from the sides of the sun as we see it is not directed towards us. 
# This makes the sun look darker near the edges like in our image. This effect is called limb darkening.

## Multiwavelength Images

# We know that the sun emits many wavelengths of electromagnetic radiation lets get some images for the different parts of the EM spectrum.
# We've already seen a continuum or white light image of the sun that we colourised at the begining of the Notebook.
# To store our new data we are going to start a database which wil help us manage the observations we download:

db = Database('sqlite:///sunpydata.sqlite')
db.default_waveunit = 'angstrom' 

# You'll notice a file called sunpydata.sqlite has appeared in our directory.
# This is our database. Let's download something to fill it.
# Science ready data from spacecraft is not available instantly so we will have to get information from a while back.

result = Fido.search(a.Time('2019/05/06 12:00', '2019/05/06 12:01'),a.Instrument('aia'),a.vso.Sample(2*u.minute),a.Wavelength(94*u.angstrom)|a.Wavelength(131*u.angstrom)|a.Wavelength(171*u.angstrom)|a.Wavelength(193*u.angstrom)|a.Wavelength(211*u.angstrom)|a.Wavelength(304*u.angstrom)|a.Wavelength(335*u.angstrom)|a.Wavelength(1600*u.angstrom)|a.Wavelength(4500*u.angstrom))
print(result)

# You should see a load of tables with the results from our search.
# Each table is for a different wavelength we specified in Angstrom (10E-10 m).
# We searched images from the SDO instrument AIA, and set a.vso.Sample() greater than the time period we searched.
# This meant we only get one image for each wavelength in that time period (which is only 2 minutes to begin with!).
# We can now download the data.