Skip to content

Instantly share code, notes, and snippets.

@PennyQ
Created December 22, 2020 10:30
Show Gist options
  • Save PennyQ/7d335a3df5e080d06d8283a21bef6039 to your computer and use it in GitHub Desktop.
Save PennyQ/7d335a3df5e080d06d8283a21bef6039 to your computer and use it in GitHub Desktop.
from glue.config import importer, settings
from glue.core import Data
from glue.core import DataCollection
from qtpy import QtGui
from qtpy.QtWidgets import QWidget, QInputDialog, QLineEdit
import numpy as np
# TODO: write a test code
class LoadDatabase(QWidget):
def __init__(self):
super(LoadDatabase, self).__init__()
self.title = 'Load data from database'
self.left = 10
self.top = 10
self.width = 640
self.height = 480
self.initUI()
def initUI(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
# self.getDouble()
# self.getChoice()
def getDouble(self):
ra, okPressed = QInputDialog.getDouble(self, "Get RA and DEC","RA:", 10.50, 0, 100, 10)
dec, okPressed = QInputDialog.getDouble(self, "Get RA and DEC","DEC:", 10.50, 0, 100, 10)
if okPressed:
print( ra, dec)
def getChoice(self):
items = ("Red","Blue","Green")
item, okPressed = QInputDialog.getItem(self, "Get item","Color:", items, 0, False)
if ok and item:
print(item)
def getText(self):
text, okPressed = QInputDialog.getText(self, "Input pixel range","x0, x1, y0, y1 (seperated by comma)", QLineEdit.Normal, "")
if okPressed and text != '':
pix_x0 = int(text.split(',')[0])
pix_x1 = int(text.split(',')[1])
pix_y0 = int(text.split(',')[2])
pix_y1 = int(text.split(',')[3])
return [pix_x0, pix_x1, pix_y0, pix_y1]
# print('ra and dec is ', ra, dec)
@importer("Import from local database")
def my_importer():
# pop up a dialog for input position
w = LoadDatabase()
mask = w.getText()
# make a fake numpy 3D array
cube = np.random.rand(50, 40, 30)
# sel_cube = cube[w.result[0]:w.result[1], w.result[2]:w.result[3], :]
sel_cube = cube[mask[0]:mask[1], mask[2]:mask[3], :]
print('sel_cube', sel_cube.shape)
data = Data(PRIMARY=sel_cube, label="Cube")
return [data]
# return [Data(...), Data(...)] returns a list of Data objects
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment