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:
objectAn 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.QImageorNone the thumbnail to display; set it to
Noneif 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.BaseItemItems 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.BaseItemItems used when showing the distortion.
fits_namesis 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.QLabelBase 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
Custom signals¶ Name Signature Description sig_ifuToggledstr, 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 Custom slot¶ Name Signature Description ifuSelected()str, bool selects (second argument True)/deselects (second argumentFalse) the IFU, if itsSLOTIDis 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 :
QWidgetor derived instance, optional the parent of the current widget
Attributes: hw_sizeReturn the smaller between width and height of the widget
selectedWhether 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
emptyattribute.
-
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
selectedattribute 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_imgintocurrent_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.BaseIFUWidgetBase 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_itemClass representing one of the items to display in the IFU.
rect_thumbnailRectangle 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_colsandn_rowsand fill thethumb_itemslist.The method uses directly the following keys of the
tab_dictargument: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_colsandn_rowsattributes are set to the number of elements in the two variables.
Each element of the
thumb_itemslist is an instance ofth_itemwith:n_rowandn_colset to the position of the item;row_nameandcol_nameset to the names of the row and column (from the configuration as described above) associated to the element;imageis the image of the item to show in the quadrant and is initialized toNone;format_dictis 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 thecolsandrowsconfiguration 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_colsandn_rowsset 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_colscolumns andn_rowsrows.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.imagetoNone. Otherwise create aPyQt5.QtGui.QImageand assign it.This implementation returns the input
itemunmodified.Parameters: - item :
BaseItemor child item representing one file to display
Returns: - item :
BaseItemor 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.imageisNone. If nothing remains, do nothing, otherwise add the images in the IFU and replace the empty image. The size of the displayed image isrect_thumbnailand 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.IFUSplitWidgetA custom class designed to contain one or more fits files for the IFU.
Parameters: - all
same as
IFUSplitWidget
Attributes: - all
same as
IFUSplitWidgetzmin_ifuReturns the minimum zmin for the fits files shown in the widget,
zmax_ifuReturns 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 toNonefiles_for_windowReturn the name of the files to pass to the fits viewer window.
titles_for_windowReturn the tab titles for the files passes to the fits viewer window.
tooltips_for_windowReturn 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.fnameattributes 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_dictargument: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_DIRintarget_dirParameters: - 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.dataand its min/max intoitem.zminanditem.zmax.Steps:
get_thumb(): if possible creates the thumbnail and returns its name; if not possible, return None and set the above elements ofitemare set toNone;- if the file name is returned and the file is newer than the stored
version, reloads the thumbnail and recompute
zminandzmax; - if there is a thumbnail, create a
PyQt5.QtGui.QImagewith 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,zminandzmaxattributes 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(). Iffnamedoes not exist, it makes sure that there is also no thumbnail file, to make sure that files are not shown after being removed. Iffnameexists 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_PREFIXto 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.FitsViewerWindowwith 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_windowandtooltips_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_itemsand 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
Noneor 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
Noneor 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.IFUFitsWidgetCreate 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 notbasenamesList of strings used as basenames.
-
basenames¶ List of strings used as basenames. If the property is present, setup will loop through
cols,rowsandbasenamesand 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. Thefnameattribute fromIFUFitsWidget.th_itemis used to store a list of file names needed for the reconstruction.The method uses the keys in
tab_dictand provide the formatting entries as described inIFUFitsWidget.setup(). It overrides thebasenameformatting entry as described inIFUQuickReconWidget.basenames.n_colsandn_rowsattributes 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.IFUFitsWidgetDisplay thumbnails from data cubes instead of from 2D fits files.
This widget is very similar to the
IFUFitsWidgetUnless 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_dictkeys asIFUFitsWidgetand the same formatting entries. It also accept the following key of thetab_dictargument:z_indx(optional): before creating the thumbnail for the data cubes, the image is compressed along the z-dimension using the median; ifz_indxis 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_PREFIXto the file name. Ifz_indxis 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.IFUFitsWidgetDisplay thumbnails from one of the extensions of a multi-extension fits file
This widget is very similar to the
IFUFitsWidgetUnless 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_dictkeys asIFUFitsWidgetand the same formatting entries. It also accept the following key of thetab_dictargument: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_PREFIXto the file name. Ifz_indxis 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.BaseIFUWidgetWidget 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_dictargument: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.IFUSplitWidgetWidget showing the distortion file and the corresponding region file created with
$CUREBIN/distviewParameters: - 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_namesattributes usingth_item.format_dict.Besides what the parent method needs, this method uses directly the following keys of the
tab_dictargument: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
imageattribute 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/distviewto 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 :
Inheritance diagram¶