vdat.gui.tabs.ifu_widget
– The widget representing one IFU¶
Widgets showing the IFU in the focal plane
-
vdat.gui.tabs.ifu_widget.
update_painter_font_size
(painter, rect, string)[source]¶ If the string is too large, reduce the font. The code is taken from https://stackoverflow.com/questions/2202717/for-qt-4-6-x-how-to-auto-size-text-to-fit-in-a-specified-width
Parameters: - painter :
PyQt5.QtGui.QPainter
painter object
- rect :
PyQt5.QtCore.QRectF
rectangle in which the string is embedded
- string : string
string to paint
Returns: - painter :
PyQt5.QtGui.QPainter
updated painter
- painter :
-
class
vdat.gui.tabs.ifu_widget.
BaseItem
(**kwargs)[source]¶ Bases:
object
An editable version of
collections.namedtuple
. The name and number of attributes is fixed and the values are set to None by default.Derived classes must only define
__slots__
which should only contain names of any additional slots. For more information see the documenatationAttributes: - n_col, n_row : int
index of the column and of the row of the item
- col_name, row_name : string
name associated to the column and row
- format_dict : dict
dictionary with the fields and values that can be replaced in file names
- image :
PyQt5.QtGui.QImage
orNone
the thumbnail to display; set it to
None
if there is nothing to display
-
col_name
¶
-
format_dict
¶
-
image
¶
-
n_col
¶
-
n_row
¶
-
row_name
¶
-
class
vdat.gui.tabs.ifu_widget.
FitsItem
(**kwargs)[source]¶ Bases:
vdat.gui.tabs.ifu_widget.BaseItem
Items used in the widgets showing fits file
Attributes: - fname : str
full file name of the file to show
- data : nd.array
array representing the image
- zmin, zmax : float
minimum and maximum value of data after applying zscaling
- ctime : float
time of creation of the thumbnail stored in
image
-
ctime
¶
-
data
¶
-
fname
¶
-
zmax
¶
-
zmin
¶
-
class
vdat.gui.tabs.ifu_widget.
DistItem
(**kwargs)[source]¶ Bases:
vdat.gui.tabs.ifu_widget.BaseItem
Items used when showing the distortion.
fits_names
is initialized to an empty list.Attributes: - fname : str
full file name of the distortion file
- reg_fname : str
full name of the region file
- fits_names : list strings
name of the fits files to load into DS9 to use as base to display the regions
-
fits_names
¶
-
fname
¶
-
reg_fname
¶
-
class
vdat.gui.tabs.ifu_widget.
BaseIFUWidget
(ifuslot, x, y, specid, specslot, ifuid, ifurot, platescl, parent=None)[source]¶ Bases:
pyhetdex.het.fplane.IFU
,PyQt5.QtWidgets.QLabel
Base class representing one IFU in the focal plane.
This implement the basic functionalities that other IFU widgets have and all the hooks needed to make this work together with
BaseFplanePanel
.Upon initialization it:
- creates tooltip and whatsThis
- sets the default style
- customizes single and double click behaviour
¶ Name Signature Description sig_ifuToggled
str, bool emitted when a user selects/deselects the current IFU; the parameters are the SLOTID of the IFU and whether the IFU has been selected ¶ Name Signature Description ifuSelected()
str, bool selects (second argument True
)/deselects (second argumentFalse
) the IFU, if itsSLOTID
is the one given in the first argument.Parameters: - ifuslot : string
id of the slot in the focal plane
- x, y : string or float
x and y position of the ifuslot in the focal plane
- specid, specslot: int
id of the spectrograph where the ifu is plugged into and of the slot of the spectrograph
- ifuid : string
id of the ifu
- platescl : float
focal plane plate scale at the position in the IHMP
- parent :
QWidget
or derived instance, optional the parent of the current widget
Attributes: hw_size
Return the smaller between width and height of the widget
selected
Whether the IFU is selected or not.
- empty_img :
PyQt5.QtGui.QImage
empty image, black with a white cross
- current_img :
PyQt5.QtGui.QImage
image to show in the gui. The desired image should be assigned to this variable in
prepare_image()
and shown inshow_image()
.- default style attibutes
-
sig_ifuToggled
¶
-
_default_aspect
()[source]¶ Set the default aspect of the Widget.
Attributes: - border_style_selected, border_style_unselected : int
- defaultsize : int
default to 42
-
_create_empty_image
()[source]¶ Create an empty image, a white cross on black, and save it into the
empty
attribute.
-
hw_size
¶ Return the smaller between width and height of the widget
-
mouseDoubleClickEvent
(event)[source]¶ Make sure that a double click is not interpreted as a two single clicks. Beside this doesn’t do anything else.
Qt don’t deal with single and double click, so we do it here. If you overrides either of
mouseReleaseEvent()
ormouseDoubleClickEvent()
, make sure to execute the parent class implementation as first thing to avoid unexpected results.Parameters: - event :
PyQt5.QtGui.QMouseEvent
- event :
-
mouseReleaseEvent
(event)[source]¶ On a user clicking on the button, swap the logical value of the
selected
attribute and change the look of the button to reflect this.Qt don’t deal with single and double click, so we do it here. If you overrides either of
mouseReleaseEvent()
ormouseDoubleClickEvent()
, make sure to execute the parent class implementation as first thing to avoid unexpected results.Parameters: - event :
PyQt5.QtGui.QMouseEvent
- event :
-
selected
¶ Whether the IFU is selected or not.
-
prepare_image
()[source]¶ Prepare the image to show in the gui saving it into the
current_img
. The base implementation saves the empty imageempty_img
intocurrent_img
.Subclasses can override this method and should call it to make sure that sensible defaults are set
-
class
vdat.gui.tabs.ifu_widget.
IFUSplitWidget
(*args, **kwargs)[source]¶ Bases:
vdat.gui.tabs.ifu_widget.BaseIFUWidget
Base IFU widget for all the cases in which the image displayed is composed of multiple elements.
This class implements boilerplate code to setup a list of items to show, with their position, and to display them.
Parameters: - all
same as
BaseIFUWidget
Attributes: - all
same as
BaseIFUWidget
- thumb_items : list
- target_dir : string
the selected directory
- tab_dict : dictionary
dictionary with the specifications to use to build the tabs
- n_rows, n_cols : int
number of rows and columns to show in the IFU
th_item
Class representing one of the items to display in the IFU.
rect_thumbnail
Rectangle used to add the thumbnails to the IFU.
-
th_item
¶ Class representing one of the items to display in the IFU.
Returns: - :class:`BaseItem`
thumbnail item
-
setup
(target_dir, tab_dict, format_dict)[source]¶ Set
target_dir
,tab_dict
,n_cols
andn_rows
and fill thethumb_items
list.The method uses directly the following keys of the
tab_dict
argument:cols
,rows
(optional): list of objects, typically strings. The thumbnail gets divided into len(cols)*len(rows) quadrants and each one shows one file. If not given they default to a list with one empty string.n_cols
andn_rows
attributes are set to the number of elements in the two variables.
Each element of the
thumb_items
list is an instance ofth_item
with:n_row
andn_col
set to the position of the item;row_name
andcol_name
set to the names of the row and column (from the configuration as described above) associated to the element;image
is the image of the item to show in the quadrant and is initialized toNone
;format_dict
is a dictionary containing the following entries:- all the elements in the input parameter
format_dict
ifuslot
,ifuid
,specid
: ID of the slot, of the IFU bundle and of the spectrograph it is connected to.col
,row
: replaced with each of the elements in thecols
androws
configuration options.
- all the elements in the input parameter
Parameters: - target_dir : string
directory selected by the user
- tab_dict : dictionary
dictionary with the specifications to use to build the tabs
- format_dict : dictionary
dictionary with extra fields and values that can be used to e.g. format file names
-
rect_thumbnail
¶ Rectangle used to add the thumbnails to the IFU. It uses the values of
n_cols
andn_rows
set insetup()
to divide the widget in equal areas.
-
upper_left_qpoint
(i, j)[source]¶ Return the upper left point to use to add thumbnails to the IFU widget given
n_cols
columns andn_rows
rows.Parameters: - i, j : int
column/row index of the image to add
Returns: - :class:`PyQt5.QtCore.QPointF`
position of the upper left corner of the rectangle
-
load_thumbnail
(item)[source]¶ Create the thumbnail to be displayed in the IFU. If no image can be created, set
item.image
toNone
. Otherwise create aPyQt5.QtGui.QImage
and assign it.This implementation returns the input
item
unmodified.Parameters: - item :
BaseItem
or child item representing one file to display
Returns: - item :
BaseItem
or child updated item with the
image
- item :
-
prepare_image
()[source]¶ Create the images to show in the GUI.
Invoke the parent class method, to create empty images, then loop through the elements of
thumb_items
, for each callsload_thumbnail()
. Then filter the items for which theth_item.image
isNone
. If nothing remains, do nothing, otherwise add the images in the IFU and replace the empty image. The size of the displayed image isrect_thumbnail
and the position is given byupper_left_qpoint()
. If some image is missing the corresponding quadrant it is left black.Derived classes probably don’t need to override this method, but the ones called from here, notably
load_thumbnail()
.
-
class
vdat.gui.tabs.ifu_widget.
IFUFitsWidget
(*args, **kwargs)[source]¶ Bases:
vdat.gui.tabs.ifu_widget.IFUSplitWidget
A custom class designed to contain one or more fits files for the IFU.
Parameters: - all
same as
IFUSplitWidget
Attributes: - all
same as
IFUSplitWidget
zmin_ifu
Returns the minimum zmin for the fits files shown in the widget,
zmax_ifu
Returns the maximum zmax for the fits files shown in the widget,
- zmin_global, zmax_global : float
global zmin and zmax. If they are both not
None
, they are used instead of the individual zscale values. On cleanup they are reset toNone
files_for_window
Return the name of the files to pass to the fits viewer window.
titles_for_window
Return the tab titles for the files passes to the fits viewer window.
tooltips_for_window
Return the tab tool tips for the files passes to the fits viewer window.
-
th_item
¶ Item to display in the IFU.
Returns: - :class:`FitsItem`
thumbnail item
-
setup
(target_dir, tab_dict, format_dict)[source]¶ Informations needed to create the images to show.
After executing the corresponding method of the base class, fills the
th_item.fname
attributes usingth_item.format_dict
. It also ensures that the thumbnail directory gets created (withensure_thumb_dir()
)Besides what the parent method needs, this method uses directly the following keys of the
tab_dict
argument:file_name
(mandatory): name of the file(s) to show. It is possible to format the file name using the python formatting syntax.
Parameters: - target_dir : string
directory selected by the user
- tab_dict : dictionary
dictionary with the specifications to use to build the tabs
- format_dict : string
dictionary with the fields and values that can be replaced in file names
-
ensure_thumb_dir
(target_dir)[source]¶ If necessary creates the thumbnail directory
THUMB_DIR
intarget_dir
Parameters: - target_dir : string
directory selected by the user
-
load_thumbnail
(item)[source]¶ Create, if necessary, and load the thumbnail. To avoid reloading it multiple times, store the data into
item.data
and its min/max intoitem.zmin
anditem.zmax
.Steps:
get_thumb()
: if possible creates the thumbnail and returns its name; if not possible, return None and set the above elements ofitem
are set toNone
;- if the file name is returned and the file is newer than the stored
version, reloads the thumbnail and recompute
zmin
andzmax
; - if there is a thumbnail, create a
PyQt5.QtGui.QImage
with the data, using either the image or the globalzmin
/zmax
, and store it intoitem.image
Derived classes probably don’t need to override this method, but the ones called from here, notably
get_thumb()
andfile_ctime()
.Parameters: - item :
th_item
item representing one file to display
Returns: - item :
th_item
updated item with the
data
,image
,zmin
andzmax
attributes filled
-
get_thumb
(fname)[source]¶ Create the thumbnail from the file name.
It gets the name of the thumbnail file using
thumb_name()
and the creation times of the input file and the thumbnail usingfile_ctime()
. Iffname
does not exist, it makes sure that there is also no thumbnail file, to make sure that files are not shown after being removed. Iffname
exists and/or is newer than the thumbnail (re)create it usingcreate_thumb()
Parameters: - fname : string
name of the file for which the thumbnail is to be created
Returns: - thumb_name : string
name of the thumbnail file, or None if no thumbnail is created
-
create_thumb
(fname, thumb_name)[source]¶ Create the thumbnail from
fname
.Parameters: - fname : string
name of the file for which the thumbnail is to be created
- thumb_name : string
name of the file where to save the thumbnail
-
thumb_name
(fname)[source]¶ Create the name to use for the thumbnail, prepending
THUMB_DIR
/THUMB_PREFIX
to the file nameParameters: - fname : string
name of the file for which the thumbnail is to be created
Returns: - string
name of the thumbnail file
-
file_ctime
(fname)[source]¶ Get the ctime from the file.
Parameters: - fname : string
name of the file for which the thumbnail is to be created
Returns: - float
time of creation of a file or None if the file does not exist
-
zmin_ifu
¶ Returns the minimum zmin for the fits files shown in the widget, or None if no file is shown
-
zmax_ifu
¶ Returns the maximum zmax for the fits files shown in the widget, or None if no file is shown
-
mouseDoubleClickEvent
(event)[source]¶ On double click open a popup window of type
ifu_viewer.FitsViewerWindow
with details on the selected IFU.The list of files passed to the window is taken from
files_for_window
. If the list is empty no window will be shown. The new window tab titles and tooltips are taken fromtitles_for_window
andtooltips_for_window
. Derived classes can overrides these three properties to give the appropriate file and tabs names and tooltips.Parameters: - event :
PyQt5.QtGui.QMouseEvent
- event :
-
files_for_window
¶ Return the name of the files to pass to the fits viewer window. The file names are created in
setup()
, stored inthumb_items
and returned only if they exist.Returns: - flist : list of string
file names to plug display in the fits viewer window
-
titles_for_window
¶ Return the tab titles for the files passes to the fits viewer window.
It must return either
None
or a list of strings with the same length offiles_for_window
.Returns: - ``None``
-
tooltips_for_window
¶ Return the tab tool tips for the files passes to the fits viewer window.
It should return either
None
or a list of strings with the same length offiles_for_window
.Returns: - ``None``
-
class
vdat.gui.tabs.ifu_widget.
IFUQuickReconWidget
(*args, **kwargs)[source]¶ Bases:
vdat.gui.tabs.ifu_widget.IFUFitsWidget
Create IFU reconstructed images
Parameters: - all
same as
IFUFitsWidget
Attributes: - all
same as
IFUFitsWidget
- enabled : bool
whether the reconstruction is disabled or not, i.e. if the reconstructed object returned by
vdat.gui.utils.get_reconstructed()
returns None or notbasenames
List of strings used as basenames.
-
basenames
¶ List of strings used as basenames. If the property is present, setup will loop through
cols
,rows
andbasenames
and replace the{basename}
placeholder in the file names by each of the elements in this property, shadowing the placeholder insetup()
’sformat_dict
, if present. If the property is not set, the loop over the basenames is not done insetup()
.
-
setup
(target_dir, tab_dict, format_dict)[source]¶ Informations needed to create the reconstructed image to show.
The information needed to build the ifu reconstructed image are stored into the
thumb_items
. Thefname
attribute fromIFUFitsWidget.th_item
is used to store a list of file names needed for the reconstruction.The method uses the keys in
tab_dict
and provide the formatting entries as described inIFUFitsWidget.setup()
. It overrides thebasename
formatting entry as described inIFUQuickReconWidget.basenames
.n_cols
andn_rows
attributes are set to one.It also ensures that the thumbnail directory is created.
Parameters: - all :
as in
IFUFitsWidget.setup()
-
get_thumb
(fname)[source]¶ Create the reconstructed image from the file names.
This method is almost identical to
IFUFitsWidget.get_thumb()
except that it doesn’t attempt to create thumbnails if the quick reconstruction object is not present. However permits to show it if available.Todo
Replicating code is in general a bad idea, but I haven’t found yet a better solutions. This method implementation needs some re-thinking.
Parameters: - fname : list of string
names of the file for which the reconstructed image is to be created
Returns: - thumb_name : string
name of the thumbnail file, or None if no thumbnail is created
-
create_thumb
(fnames, thumb_name)[source]¶ Create the reconstructed image from the names and save it
Parameters: - fnames : list of string
names of the file for which the reconstructed image is to be created
- thumb_name : string
name of the file where to save the thumbnail
-
thumb_name
(fnames)[source]¶ Alias of
reconstructed_name()
-
reconstructed_name
(file_names)[source]¶ Creates the name to use to store the reconstructed image, as a md5 hash of the
file_names
. This way we can get a unique name for every combination of files.Parameters: - file_names : list of strings
name of the files to use to create the thumbnail
Returns: - string
name of the reconstructed file
-
file_ctime
(fname)[source]¶ Get the ctime from the file. If fname is a list, get the newest time.
Parameters: - fname : string or list of strings
name of the file for which the thumbnail is to be created
Returns: - float
newest time of creation (ctime) of a file or None if the file does not exist
-
files_for_window
¶ Return the name of the reconstructed file that should go into the fits viewer window.
If the file does not exist, try to create it. If it fails, return an empty list.
Returns: - flist : list of string
file name to plug display in the fits viewer window
-
titles_for_window
¶ The title of the reconstructed tab in the fits window is just “Reconstructed”
-
tooltips_for_window
¶ The tooltip show all the files making up the reconstructed image
-
cleanup
()[source]¶ Cleanup the widget as in
IFUFitsWidget()
, plus delete the basenames
-
class
vdat.gui.tabs.ifu_widget.
IFUCubeWidget
(*args, **kwargs)[source]¶ Bases:
vdat.gui.tabs.ifu_widget.IFUFitsWidget
Display thumbnails from data cubes instead of from 2D fits files.
This widget is very similar to the
IFUFitsWidget
Unless documented below, the class inherits signals, slots and connection from
IFUFitsWidget
.Parameters: - all :
see
IFUFitsWidget
Attributes: - all :
see
IFUFitsWidget
-
setup
(target_dir, tab_dict, format_dict)[source]¶ Informations needed to create the images to show.
The widget uses the same
tab_dict
keys asIFUFitsWidget
and the same formatting entries. It also accept the following key of thetab_dict
argument:z_indx
(optional): before creating the thumbnail for the data cubes, the image is compressed along the z-dimension using the median; ifz_indx
is not given, it uses the whole range, otherwise it uses only the part of the cube in the range [z_indx[0], z_indx[1])
Parameters: - all :
same as
IFUFitsWidget.setup()
-
create_thumb
(fname, thumb_name)[source]¶ Create the thumbnail from
fname
.Parameters: - fname : string
name of the file for which the thumbnail is to be created
- thumb_name : string
name of the file where to save the thumbnail
-
thumb_name
(fname)[source]¶ Create the name to use for the thumbnail, prepending
THUMB_DIR
/THUMB_PREFIX
to the file name. Ifz_indx
is given, add it to the thumbnail nameParameters: - fname : string
name of the file for which the thumbnail is to be created
Returns: - string
name of the thumbnail file
-
class
vdat.gui.tabs.ifu_widget.
IFUMultiExtWidget
(*args, **kwargs)[source]¶ Bases:
vdat.gui.tabs.ifu_widget.IFUFitsWidget
Display thumbnails from one of the extensions of a multi-extension fits file
This widget is very similar to the
IFUFitsWidget
Unless documented below, the class inherits signals, slots and connection from
IFUFitsWidget
.Parameters: - all :
see
IFUFitsWidget
Attributes: - all :
see
IFUFitsWidget
-
setup
(target_dir, tab_dict, format_dict)[source]¶ Informations needed to create the images to show.
The widget uses the same
tab_dict
keys asIFUFitsWidget
and the same formatting entries. It also accept the following key of thetab_dict
argument:ext
(int or string): index or number of the extension to display in IFU
Parameters: - all :
same as
IFUFitsWidget.setup()
-
create_thumb
(fname, thumb_name)[source]¶ Create the thumbnail from
fname
.Parameters: - fname : string
name of the file for which the thumbnail is to be created
- thumb_name : string
name of the file where to save the thumbnail
-
thumb_name
(fname)[source]¶ Create the name to use for the thumbnail, prepending
THUMB_DIR
/THUMB_PREFIX
to the file name. Ifz_indx
is given, add it to the thumbnail nameParameters: - fname : string
name of the file for which the thumbnail is to be created
Returns: - string
name of the thumbnail file
-
class
vdat.gui.tabs.ifu_widget.
TextFileWidget
(ifuslot, x, y, specid, specslot, ifuid, ifurot, platescl, parent=None)[source]¶ Bases:
vdat.gui.tabs.ifu_widget.BaseIFUWidget
Widget that paints the number of lines in the widget. On double click open a window to show the file content.
Parameters: - all
same as
BaseIFUWidget
-
rect_thumbnail
¶ Rectangle with the size of the thumbnails of the IFU. Use default values
-
setup
(target_dir, tab_dict, format_dict)[source]¶ Informations needed to create the images to show.
The method uses directly the following keys of the
tab_dict
argument:file_name
(mandatory): name of the file(s) to show. It is possible to format the file name using the python formatting syntax.
The following formatting entries are explicitly used in this method:
ifuslot
,ifuid
,specid
: ID of the slot, of the IFU bundle and of the spectrograph it is connected to.
Parameters: - target_dir : string
directory selected by the user
- tab_dict : dictionary
dictionary with the specifications to use to build the tabs
- format_dict : string
dictionary with the fields and values that can be replaced in file names
-
prepare_image
()[source]¶ Create the image to show in the GUI.
If the text file, whose name is created in
setup()
, exists, paint the number of lines of the file.
-
mouseDoubleClickEvent
(event)[source]¶ On double click, if the text file exists, open a window of type
ifu_viewer.FileEditorWindow
.Parameters: - event :
PyQt5.QtGui.QMouseEvent
- event :
-
class
vdat.gui.tabs.ifu_widget.
DistWidget
(*args, **kwargs)[source]¶ Bases:
vdat.gui.tabs.ifu_widget.IFUSplitWidget
Widget showing the distortion file and the corresponding region file created with
$CUREBIN/distview
Parameters: - all
same as
IFUSplitWidget
Attributes: - all
same as
IFUSplitWidget
-
th_item
¶ Item to display in the IFU.
Returns: - :class:`DistItem`
thumbnail item
-
setup
(target_dir, tab_dict, format_dict)[source]¶ Informations needed to create the images to show.
After executing the corresponding method of the base class, fills the
th_item.fname
,th_item.reg_fname' and :attr:`th_item.fits_names
attributes usingth_item.format_dict
.Besides what the parent method needs, this method uses directly the following keys of the
tab_dict
argument:file_name
(mandatory): name of the file(s) to show. It is possible to format the file name using the python formatting syntax.fits_names
(mandatory): list of names of the fits files to use then displaying the distortion in DS9. If the list is empty, it is not possible to display the data on DS9. Use the same formatting asfile_name
``
Parameters: - target_dir : string
directory selected by the user
- tab_dict : dictionary
dictionary with the specifications to use to build the tabs
- format_dict : string
dictionary with the fields and values that can be replaced in file names
-
load_thumbnail
(item)[source]¶ Create, if necessary, the region file and create the thumbnail to display.
Steps:
get_region()
: if possible creates the region file and returns whether it exists or not;- if the distortion and/or the region file exists, create an image with
the number or lines in either file and save it into
item.image
Parameters: - item :
th_item
item representing one file to display
Returns: - item :
th_item
updated item with the
image
attribute filled
-
get_region
(item)[source]¶ Create the region file using
$CUREBIN/distview
.Steps:
- if the distortion exists, but not the region file, create the latter;
- if the distortion exists and is newer than the region file, recreate the latter;
- if the distortion file does not exist but the region file does not, remove the region file;
- if none exists, do nothing.
Parameters: - item :
th_item
item representing one file to display
Returns: - dist_exists, reg_exists : bool
whether the distortion and the region file exist
-
_run_distview
(fname, reg_fname)[source]¶ Run
$CUREBIN/distview
to create the region fileParameters: - fname, reg_fname : string
name of the distortion and the region files
Returns: - success : bool
whether the operation is successful
-
mouseDoubleClickEvent
(event)[source]¶ On double click, if the distortion files exist, open a window of type
ifu_viewer.DistWindow
.Parameters: - event :
PyQt5.QtGui.QMouseEvent
- event :