treewide: move all modules into new submodule to fix relative imports

python, why are you like this?
This commit is contained in:
2024-03-05 13:06:44 +01:00
parent 2ef8664fd9
commit 3769a27a4f
15 changed files with 2 additions and 2 deletions
+52
View File
@@ -0,0 +1,52 @@
from PyQt5 import QtWidgets, uic
import os
from .db.StarsDB import StarDB
from .ui.NewStarDialog import NewStarDialog
DEFAULT_DB = "stars.db"
class AstrodataGUI(QtWidgets.QMainWindow):
def __init__(self):
super(AstrodataGUI, self).__init__()
classFileDir = os.path.dirname(os.path.abspath(__file__))
absUiFilePath = os.path.join(classFileDir, "astrodatagui.ui")
uic.loadUi(absUiFilePath, self)
self.actionExit.triggered.connect(self.actionExitTriggered)
self.btAddNew.clicked.connect(self.addNewClicked)
self.show()
self.loadDB()
def loadDB(self):
try:
self.starDB = StarDB.getInstance(DEFAULT_DB)
except Exception as e:
self.showErrorMessage("DB Connection failed",
f"Could not connect to local database file {DEFAULT_DB}\n\
{e}")
def showErrorMessage(self, title: str, msg: str):
print(title)
print(msg)
def closeEvent(self, event):
confirmation = QtWidgets.QMessageBox.question(self, "Confirmation", "Are you sure you want to close the application?",
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)
if confirmation == QtWidgets.QMessageBox.Yes:
event.accept() # Close the app
else:
event.ignore() # Don't close the app
def actionExitTriggered(self):
for starDB in StarDB.getAllInstances():
starDB.close()
self.close()
def addNewClicked(self):
diag = NewStarDialog()
diag.exec()
View File
+260
View File
@@ -0,0 +1,260 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AstroDataGUI</class>
<widget class="QMainWindow" name="AstroDataGUI">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1612</width>
<height>1043</height>
</rect>
</property>
<property name="windowTitle">
<string>AstroData</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>600</width>
<height>16777215</height>
</size>
</property>
<property name="title">
<string>Loaded Stars</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Search:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="leStarSearch">
<property name="maximumSize">
<size>
<width>200</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btAddNew">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QListWidget" name="listDownloaded">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>400</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>400</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btDelStar">
<property name="text">
<string>Delete Star Files</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Sequences/Quarters</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QListWidget" name="listSequences">
<property name="minimumSize">
<size>
<width>200</width>
<height>200</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>200</width>
<height>200</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QPushButton" name="btCombineSeq">
<property name="text">
<string>Combine</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btDeleteSeq">
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="FlaredetectorWidget" name="flaredetectorPreview" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1612</width>
<height>21</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
<property name="title">
<string>File</string>
</property>
<addaction name="actionOpen_Database"/>
<addaction name="separator"/>
<addaction name="actionExit"/>
</widget>
<addaction name="menuFile"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<action name="actionOpen_Database">
<property name="text">
<string>Open Database</string>
</property>
</action>
<action name="actionExit">
<property name="text">
<string>Exit</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
<class>FlaredetectorWidget</class>
<extends>QWidget</extends>
<header>main.astrodatagui.ui.FlaredetectorWidget</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
+86
View File
@@ -0,0 +1,86 @@
from enum import Enum
import sqlite3
class StarDBError(Enum):
NO_ERROR = 0
DB_CONNECTION_FAILED = 1
class StarDB():
__instances = list()
__dbNames = list()
@staticmethod
def getAllInstances():
return StarDB.__instances
@staticmethod
def getInstance(dbName: str):
if(dbName in StarDB.__dbNames):
return StarDB.__instances[StarDB.__dbNames.index(dbName)]
else:
instance = StarDB(dbName)
StarDB.__instances.append(instance)
StarDB.__dbNames.append(dbName)
def __init__(self, dbName: str):
if(dbName in StarDB.__dbNames):
raise Exception(f"StarDB {dbName} cannot be instantiated more than once!")
else:
self.dbName = dbName
StarDB.__dbNames.append(dbName)
StarDB.__instances.append(self)
self.error = StarDBError.NO_ERROR
try:
self.connection = sqlite3.connect(dbName)
self.dbCursor = self.connection.cursor()
except:
self.error = StarDBError.DB_CONNECTION_FAILED
if(self.error is not StarDBError.NO_ERROR):
raise Exception(f"StarDB cannot connect to the database: {self.error}")
else:
self.initializeDB()
def close(self):
StarDB.__instances.remove(self)
StarDB.__dbNames.remove(self.dbName)
self.connection.close()
def initializeDB(self):
print("Initializing database")
self.dbCursor.execute("""CREATE TABLE IF NOT EXISTS starnames
(
starID INTEGER NOT NULL,
name TEXT UNIQUE,
PRIMARY KEY (starID, name)
);""")
self.dbCursor.execute("""CREATE TABLE IF NOT EXISTS sequenceSourceNames
(
sequenceSourceNameID INTEGER NOT NULL,
name TEXT UNIQUE,
PRIMARY KEY (sequenceSourceNameID, name)
);""")
self.dbCursor.execute("""CREATE TABLE IF NOT EXISTS sequences
(
sequencesID INTEGER NOT NULL,
sequence INTEGER NOT NULL,
PRIMARY KEY (sequencesID, sequence)
);""")
self.dbCursor.execute("""CREATE TABLE IF NOT EXISTS stars
(
starID INTEGER NOT NULL,
sequenceSourceNameID INTEGER NOT NULL,
sequencesID INTEGER NOT NULL,
filename TEXT,
PRIMARY KEY (starID, sequenceSourceNameID, sequencesID),
FOREIGN KEY (starID) REFERENCES starnames(starID),
FOREIGN KEY (sequenceSourceNameID) REFERENCES sequenceSourceNames(sequenceSourceNameID)
FOREIGN KEY (sequencesID) REFERENCES sequences(sequencesID)
);""")
self.connection.commit()
View File
@@ -0,0 +1,19 @@
from PyQt5 import QtWidgets
from matplotlib.figure import Figure
from matplotlib.backends.backend_qtagg import (
FigureCanvas, NavigationToolbar2QT as NavigationToolbar)
class FlaredetectorWidget(QtWidgets.QWidget):
def __init__(self, name):
super(FlaredetectorWidget, self).__init__()
self.mainLayout = QtWidgets.QVBoxLayout()
self.setLayout(self.mainLayout)
self.figure = Figure()
self.figureAxis = self.figure.add_subplot()
fc = FigureCanvas(self.figure)
toolbar = NavigationToolbar(fc, self)
self.mainLayout.addWidget(toolbar)
self.mainLayout.addWidget(fc)
+57
View File
@@ -0,0 +1,57 @@
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QDialog, QListWidgetItem
from PyQt5 import uic
import os
from ...astrodatadownloader.astrodatadownloader import ObservationSource, getStarObservations
class NewStarDialog(QDialog):
def __init__(self):
super().__init__()
classFileDir = os.path.dirname(os.path.abspath(__file__))
absUiFilePath = os.path.join(classFileDir, "NewStarDialog.ui")
uic.loadUi(absUiFilePath, self)
self.btFetchData.clicked.connect(self.btFetchData_clicked)
self.btOk.clicked.connect(self.btOk_clicked)
self.btCancel.clicked.connect(self.btCancel_clicked)
def showErrorMessage(self, title: str, msg: str):
QtWidgets.QMessageBox.question(self, title, msg,
QtWidgets.QMessageBox.Ok)
def btFetchData_clicked(self):
star = self.leStarIdentifier.text()
if not star:
self.showErrorMessage("No star identifier",
"No star identifier given, please insert one before proceeding")
return
sources = []
if(self.gbTESS.isChecked()):
sources.append(ObservationSource.TESS)
if(self.gbKepler.isChecked()):
sources.append(ObservationSource.KEPLER)
if(self.gbK2.isChecked()):
sources.append(ObservationSource.K2)
if(len(sources) == 0):
self.showErrorMessage("No source",
"Please select atleast one source before proceeding")
return
obs = getStarObservations(star, sources)
if(len(obs) == 0):
self.showErrorMessage("No observations found",
"No observationnal data has been found with the current filters")
return
self.listPreview.clear()
for o in obs:
self.listPreview.addItem(QListWidgetItem(f"{o['target_name']} - {o['obs_collection']} - {o['sequence_number']}"))
def btOk_clicked(self):
return
def btCancel_clicked(self):
return
+539
View File
@@ -0,0 +1,539 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>549</width>
<height>615</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>549</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>549</width>
<height>16777215</height>
</size>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>100</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>100</height>
</size>
</property>
<property name="title">
<string>Star identifier</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLineEdit" name="leStarIdentifier">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>150</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gbTESS">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>100</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>100</height>
</size>
</property>
<property name="title">
<string>TESS Sequences</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="1">
<widget class="QLineEdit" name="leTESSMax">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>50</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>From:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="leTESSMin">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>50</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>To:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="cbTESSAll">
<property name="text">
<string>All</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gbKepler">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>100</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>100</height>
</size>
</property>
<property name="title">
<string>Kepler Quarters</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>From:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>To:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="leKeplerMax">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>50</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="leKeplerMin">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>50</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item row="2" column="1">
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="cbKeplerAll">
<property name="text">
<string>All</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gbK2">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>100</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>100</height>
</size>
</property>
<property name="title">
<string>K2 Quarters</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="1">
<widget class="QLineEdit" name="leK2Max">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>50</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>From:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="leK2Min">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>50</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>To:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<spacer name="verticalSpacer_5">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="cbK2All">
<property name="text">
<string>All</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btFetchData">
<property name="text">
<string>Fetch</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="groupBox_6">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Preview</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QListWidget" name="listPreview"/>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btOk">
<property name="text">
<string>Ok</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btCancel">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
View File