Commit de8f2851 authored by bepinat's avatar bepinat

Merge branch 'dev_adhoc_to_fits'

Necessary to make PyQubeVis work with new options
parents 0ae6ceb6 adfbbf6f
Pipeline #1069 canceled with stages
......@@ -29,7 +29,8 @@ import astropy.io.fits as fits
import numpy as np
import gzip
#import pywcs
import ipdb
#import ipdb
import argparse
from PyQt5 import QtGui, QtCore, QtWidgets
from PyQt5.QtWidgets import QApplication, QMainWindow, QTextEdit, QPushButton, QMessageBox
......@@ -613,6 +614,108 @@ class MainWindow(QMainWindow, Ui_PyQubeVis):
print('Problem encountered when saving file')
def openfile_cl(self, fname):
'''Open from command line call to PyQubeVis'''
#Determination of extension
if fname == '':
return
namesplit = os.path.splitext(fname)
ext = namesplit[1].lower()
if ext == '.gz':
ext = os.path.splitext(namesplit[0])[1] + ext
#File reading depending on extension
if ext == '.fits':
hdu = fits.open(fname)
elif ext == '.fits.gz':
hdu = fits.open(gzip.open(fname))
elif ext == '.ad2':
dtu = pad.read_ad2(fname)
hdu = dtu.tohdu()
elif ext == '.ad2.gz':
dtu = pad.read_ad2(gzip.open(fname))
hdu = dtu.tohdu()
elif ext == '.ad3':
dtu = pad.read_ad3(fname)
hdu = dtu.tohdu()
elif ext == '.ad3.gz':
dtu = pad.read_ad3(gzip.open(fname))
hdu = dtu.tohdu()
else:
return
hdr = hdu[0].header
data = hdu[0].data
if self.numim == 0:
self.displayScrollAreaWidgetContents.setEnabled(True)
#Running path update
#(self.path, filen) = os.path.split(fname)
(self.path, filen) = os.path.split(fname)
#Update of data arguments
#self.argfiles['fullfilename'].append(fname)
#self.colorTableList = QtColorTable()
self.argfiles['fullfilename'].append(fname)
self.argfiles['filename'].append(filen)
self.argfiles['data'].append(np.array(data))
self.argfiles['sum'].append(None)
self.argfiles['sumhighthr'].append(None)
self.argfiles['sumlowthr'].append(None)
self.argfiles['issum'].append(0)
self.argfiles['profilenumber'].append(1)
self.argfiles['header'].append(hdr)
if np.size(np.shape(data)) == 1:
self.argfiles['sx'].append(np.shape(data)[0])
self.argfiles['sy'].append(0)
self.argfiles['sz'].append(0)
self.argfiles['numcube'].append(0)
if np.size(np.shape(data)) == 2:
self.argfiles['sx'].append(np.shape(data)[1])
self.argfiles['sy'].append(np.shape(data)[0])
self.argfiles['sz'].append(0)
self.argfiles['numcube'].append(0)
if np.size(np.shape(data)) == 3:
self.argfiles['sx'].append(np.shape(data)[2])
self.argfiles['sy'].append(np.shape(data)[1])
self.argfiles['sz'].append(np.shape(data)[0])
self.numberofcubes += 1
self.argfiles['numcube'].append(self.numberofcubes)
#A mettre a jour correctement ou enlever?
self.argfiles['pixmap'].append(None)
self.argfiles['zoompixmap'].append(None)
self.argfiles['actionimage'].append(None)
self.argfiles['actionprofile'].append(None)
self.argfiles['highthr'].append(np.nanmax(data))
self.argfiles['lowthr'].append(np.nanmin(data))
self.argfiles['ctinvert'].append(False)
self.argfiles['ctscale'].append('Lin')
self.argfiles['max'].append(np.nanmax(data))
self.argfiles['min'].append(np.nanmin(data))
self.argfiles['colortable'].append(self.createColorTable(self.defaultColorTable))
self.argfiles['zoom'].append(1.)
self.argfiles['flipx'].append(False)
self.argfiles['flipy'].append(False)
self.argfiles['mask'].append(None)
self.argfiles['highmask'].append(None)
self.argfiles['lowmask'].append(None)
value_range = np.nanmax (data) - np.nanmin (data)
if value_range == 0:
formatval = 0
else:
formatval = np.ceil(- np.log10(value_range) + 4)
self.argfiles['thresholdstep'].append(str(10 ** (-formatval + 3)))
if formatval < 0: formatval = 0
formatval = '%.' + '%if'%formatval
self.argfiles['formatval'].append(formatval)
self.numim = np.size(self.argfiles['filename'])
if np.size(np.shape(data)) == 3:
self.numcube = self.numim
self.firstDisplay()
def openfile(self):
'''Popup to select the file to open'''
#Il faudrait empecher de modifier le filtre
......@@ -903,12 +1006,18 @@ class MainWindow(QMainWindow, Ui_PyQubeVis):
platform.python_version(), PYQT_VERSION_STR, QT_VERSION_STR))
def main():
def main(argv):
app = QApplication(sys.argv)
#parser = argparse.ArgumentParser()
#parser.add_argument('filename', action="store", default='', help="name of the file to open")
#options = parser.parse_args(app.arguments()[1:])
#print(options.filename, len(options.filename))
frame = MainWindow()
for fname in sys.argv[1:]:
frame.openfile_cl(fname)
frame.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
main(sys.argv[1:])
......@@ -17,4 +17,7 @@ To be executable, PyQubeVis.py has to be in the PATH
## Usage
Files can be opened directly from the command line. The names must be indicated:
PyQubeVis.py file_1 file_2 ... file_n
**PyQubeVis** can be used to visualise cubes in the **adhocw** format. It can also be used to manually clean 2D maps. Using *control* or *shift* allows to clean/select regions.
......@@ -868,7 +868,9 @@ def ad3_to_fits(ad3_file, fits_file=None, overwrite=False, header_from=None):
if fits_file is None:
fits_file = ad3_file + '.fits'
tdu = read_ad3(ad3_file)
tdu = read_ad3(ad3_file) # XXX Could also be with other read_ad3 options...
# XXX We might use a function tdu_to_hdu to do the core of this function and just read and write here. Same for other format conversion (ad2_to_fits, fits_to_ad?)
assert tdu.data.ndim == 3
......@@ -1061,6 +1063,8 @@ def fits_to_adhoc(fits_filename, adhoc_filename, adhoc_trailer=None,
def fits_header_to_ad2trailer(header):
# Should use a default header first and then update what is important, same for other metadata transformations.
dt = np.dtype(TRAILER_AD2)
trailer = np.empty(1, dtype=dt)[0]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment