Commit 4fad4195 authored by skamann's avatar skamann
Browse files

Revised interaction code for PampelMuse GUI.

parent 8436dbc9
......@@ -176,16 +176,16 @@ if __name__ == "__main__":
The prefix common to all FITS-files required by PampelMuse. The naming of the
files should be according to one of the following schemes:\n
(1) Data, uncertainties, and mask are included in a single FITS file. In that
(1) Data, uncertainties, and spectrumMask are included in a single FITS file. In that
case, a file named PREFIX.fits should be available, containing at least an
HDU named DATA and one named either ERROR (uncertainties) or STAT (variances).
The mask may be included in an additional HDU named MASK.
The spectrumMask may be included in an additional HDU named MASK.
(2) Different FITS files are used for data, uncertainties and mask. In that
(2) Different FITS files are used for data, uncertainties and spectrumMask. In that
case, the following files should be present:
(i) PREFIX.dat.fits - the IFS data
(ii) PREFIX.err.fits - the uncertainties of the IFS data
(iii) PREFIX.msk.fits - optional! - a bad-pixel mask
(iii) PREFIX.msk.fits - optional! - a bad-pixel spectrumMask
All routines except for INITFIT also require the PampelMuse PRM file, named
PREFIX.prm.fits. This file is created by the routine INITFIT.""")
......
......@@ -190,7 +190,7 @@ def run_ap(centroids, pixpos, data, background="global", r_aper=3., calc_moments
y2 = (Y * Y * momdata).sum() / total - y ** 2
xy = (X * Y * momdata).sum() / total - x * y
# if unphysical moments measured or centroid outside measurement area, mask out all results for
# if unphysical moments measured or centroid outside measurement area, spectrumMask out all results for
# this source
if x2 <= 0 or y2 <= 0 or xy ** 2 >= (x2 * y2) or x < X.min() or x > X.max() or y < Y.min() \
or y > Y.max():
......
......@@ -200,8 +200,8 @@ class BackgroundGrid(Canvas):
# 'used' is an array that indicates for each background patch which spaxels contribute
# There are two possibilities that lead to spaxels spaxels being excluded from one or more patches:
# a) They are located at distances >'maxrad' to a gridpoint
# b) They are included in a user-provided bad-pixel mask
# To make sure that spaxels excluded based on criterion (a) are not included again when the user provides a mask,
# b) They are included in a user-provided bad-pixel spectrumMask
# To make sure that spaxels excluded based on criterion (a) are not included again when the user provides a spectrumMask,
# the setter method is modified.
def get_used(self):
if self._used is None: # only calculate if not already available
......@@ -209,19 +209,19 @@ class BackgroundGrid(Canvas):
return self._used
def set_used(self, value):
self._used = None # remove possibly existing mask
self._used = None # remove possibly existing spectrumMask
try:
value = np.asarray(value, dtype=np.bool)
except:
logging.critical("Invalid input for background spaxels mask: {0}".format(value))
logging.critical("Invalid input for background spaxels spectrumMask: {0}".format(value))
if value.size != self.used.shape[-1]:
logging.critical(
"Provided background spaxels mask has invalid size ({0} instead of {1}).".format(value.size,
"Provided background spaxels spectrumMask has invalid size ({0} instead of {1}).".format(value.size,
self.used.shape[-1]))
self._used = self.used & value # note call to 'self.used' leads to recalculation of included pixels based
# on distance wrt. 'maxrad'
used = property(get_used, set_used, None, "The mask indicating which spaxels are used to measure the background.")
used = property(get_used, set_used, None, "The spectrumMask indicating which spaxels are used to measure the background.")
def get_flux(self, i):
"""
......@@ -307,7 +307,7 @@ class BackgroundGrid(Canvas):
# self.weights = self.get_weights(data)
# self.weights /= self.weights.sum(axis=0)
#
# def prepare_sparse(self, mask=None):
# def prepare_sparse(self, spectrumMask=None):
# """
# This method prepares a sparse matrix using the weights as values and
# the spaxel and patch indices as column and row indices. Note that the
......@@ -316,8 +316,8 @@ class BackgroundGrid(Canvas):
#
# Parameters
# ----------
# mask : nd_array, optional
# A mask indicating invalid spaxels/coordinates. Must have a length
# spectrumMask : nd_array, optional
# A spectrumMask indicating invalid spaxels/coordinates. Must have a length
# equal to the number of spaxels for which weights were calculated.
# The idea is that a single call to Background.calculate_weights -
# which can be quite time-consuming for large arrays - can be
......@@ -332,11 +332,11 @@ class BackgroundGrid(Canvas):
# """
# assert hasattr(self, "weights"), "Need to calculate weights first."
#
# if mask==None:
# if spectrumMask==None:
# used = np.ones(self.weights.shape[1], dtype=np.bool)
# else:
# assert len(mask)==self.weights.shape[1], "Invalid mask size."
# used = (mask==False)
# assert len(spectrumMask)==self.weights.shape[1], "Invalid spectrumMask size."
# used = (spectrumMask==False)
#
# coeffs = []
# indices0 = []
......
......@@ -609,11 +609,11 @@ class FitCube(object):
mask = np.isnan(data)
logger.debug("Layer contains {0} masked pixels".format(mask.sum()))
# apply mask - note that any 2D data will be flattened by this
# apply spectrumMask - note that any 2D data will be flattened by this
data = data[~mask]
# Set spaxel to (x,y) transformation of the PSF-instances, using the transformation of the Instrument instance
# and the mask
# and the spectrumMask
transform = self.ifs_data.transform[~mask]
return data, variances, transform, wave
......
......@@ -405,7 +405,7 @@ class FitLayer(object):
# fig = plt.figure(figsize=(8, 8))
# ax = fig.add_axes([0.12, 0.12, 0.83, 0.83])
# ax.scatter(self.transformation[:, 0], self.transformation[:, 1], marker='o', s=5, c=1./self.fit_weights,
# cmap=plt.cm.hot, edgecolors='face', vmin=-100000, vmax=1000000)
# cmap=plt.cm.hot, edgeColors='face', vmin=-100000, vmax=1000000)
# plt.show()
# The fit for the source fluxes is carried out on the residuals, not the data itself. The fitted residual
......
......@@ -440,7 +440,7 @@ class Parameters(object):
"""
Fit a parameter using a smooth function. Currently, the smooth function
can be either a plain polynomial, a broken polynomial, or a Chebyshev
polynomial. A mask may be provided to exclude certain data from the fit.
polynomial. A spectrumMask may be provided to exclude certain data from the fit.
Parameters
----------
......@@ -452,7 +452,7 @@ class Parameters(object):
polynomial.
mask : ndarray, optional
If provided, it must be a 1dim. boolean array of the same length as
the parameter value array. Each data point where 'mask' is True will
the parameter value array. Each data point where 'spectrumMask' is True will
be excluded from the fit.
function : str, optional
The function used in the fitting. May be either 'plain', 'legendre',
......@@ -478,7 +478,7 @@ class Parameters(object):
abscissa = np.arange(self.ndisp, dtype=np.float32)
# create pseudo-mask if None provided
# create pseudo-spectrumMask if None provided
if mask is not None:
mask |= self.mask[:, i, 0]
else:
......
......@@ -1500,7 +1500,7 @@ class Sources(object):
function. IMPORTANT: Not used anymore because step polynomials
are not used anymore.
mask : array_like or None, optional
An optional bad-pixel mask. If specified, must have as many pixels
An optional bad-pixel spectrumMask. If specified, must have as many pixels
as spectral pixels are available. Bad pixels should be set to
True, good ones to False.
function : string, optional
......@@ -1532,7 +1532,7 @@ class Sources(object):
logging.critical("Unknown fitting function provided: {0}".format(function))
fitfunction = self.available[function.lower()]
# create pseudo-mask if None provided
# create pseudo-spectrumMask if None provided
valid = ~mask if mask is not None else np.ones((self.ndisp,), dtype=np.bool)
if self.transformation.valid:
valid &= (self.transformation.mask[..., 0] == 0).all(axis=1) # in case coordinates where interpolated
......@@ -1562,11 +1562,11 @@ class Sources(object):
order = 0 # all individual coordinates are now "fitted" with zeroth order polynomials
# TODO _i = self.ifs_coordinates_loaded.cumsum()[indices_to_fit] - 1
# TODO slc = np.ix_(mask.nonzero()[0], _i)
# TODO slc = np.ix_(spectrumMask.nonzero()[0], _i)
# TODO
# TODO t0 = time.time()
# TODO xfit = np.polynomial.polynomial.polyfit(self.wave[mask], self.ifs_coordinates[slc][..., 0, 0], order)
# TODO yfit = np.polynomial.polynomial.polyfit(self.wave[mask], self.ifs_coordinates[slc][..., 1, 0], order)
# TODO xfit = np.polynomial.polynomial.polyfit(self.wave[spectrumMask], self.ifs_coordinates[slc][..., 0, 0], order)
# TODO yfit = np.polynomial.polynomial.polyfit(self.wave[spectrumMask], self.ifs_coordinates[slc][..., 1, 0], order)
# TODO t1 = time.time()
# TODO print t1-t0, type(xfit), type(yfit)
......
......@@ -395,7 +395,7 @@ class DynamicImaCanvas(FigureCanvasQTAgg):
@property
def edgecolors(self):
"""
Return the edgecolors of the markers of the data set overplotted
Return the edgeColors of the markers of the data set overplotted
on an image. The return value will be an array of the same length
as the dataset even if all markers have the same edgecolor.
"""
......@@ -403,7 +403,7 @@ class DynamicImaCanvas(FigureCanvasQTAgg):
if self.data_plot is None:
return None
# get current edgecolors from dataset, they are returned as RGBA values, so the length of the second dimension
# get current edgeColors from dataset, they are returned as RGBA values, so the length of the second dimension
# of the return value is 4, the length of the first depends on how the colors were initialized
edgecolors = self.data_plot.get_edgecolors()
......
......@@ -62,7 +62,7 @@ class DynamicPlotCanvas(FigureCanvasQTAgg):
"""
This class can be used to display a matplotlib lineplot and interact with
it by selecting or delescting horizontal ranges. In PampelMuse, this
feature is used to create a mask in wavelength space.
feature is used to create a spectrumMask in wavelength space.
"""
background = None
......
This diff is collapsed.
......@@ -98,8 +98,8 @@ class GenericIFS(Instrument):
the extracted spectrum
var : nd_array, if return_var is True
the variance spectrum
mask : nd_array, if return_mask is True
the bad-pixel mask of the spectrum
spectrumMask : nd_array, if return_mask is True
the bad-pixel spectrumMask of the spectrum
"""
if self.transform is None:
logging.error('Cannot provide spectrum unless a FITS cube has been opened.')
......
......@@ -61,7 +61,7 @@ def makecube(pampelmuse):
Create a data cube from 2dim. IFS data. If available, also add WCS informations
to the header of the output FITS-file. The resulting cube will be stored under
<pampelmuse.prefix>.cube.fits, a possibly existing file will be overwritten.
Note that currently only the data is stored, not the uncertainties or the mask.
Note that currently only the data is stored, not the uncertainties or the spectrumMask.
"""
logging.info("Executing requested routine MAKECUBE [Revision {0:d}].".format(__revision__))
......
......@@ -129,7 +129,7 @@ def polyfit(pampelmuse):
if pampelmuse.polyfit.exclude is not None:
for wmin, wmax in pampelmuse.polyfit.exclude:
ui.modifyMask((wmin, wmax), True)
logging.info("Added wavelength range to mask: {0}--{1}".format(wmin, wmax))
logging.info("Added wavelength range to spectrumMask: {0}--{1}".format(wmin, wmax))
ui.show()
......@@ -137,7 +137,7 @@ def polyfit(pampelmuse):
else: # automatically fit PSF parameters and source positions using the predefined polynomial type and degree
# prepare mask
# prepare spectrumMask
if pampelmuse.polyfit.exclude is not None:
logging.info("Masked wavelength ranges: {0}".format(pampelmuse.polyfit.exclude))
_mask = [(sources.wave >= wmin) & (sources.wave <= wmax) for wmin, wmax in pampelmuse.polyfit.exclude]
......
......@@ -60,12 +60,12 @@ def open_ifs_data(prefix, **kwargs):
prefix : string
The common prefix of the FITS files to be opened. The code will look
for several files that may contain the IFS data, variances, a bad-
pixel mask, or fit residuals:
pixel spectrumMask, or fit residuals:
* <prefix>.fits, <prefix>.dat.fits - data (extension DATA or first
extension containing data)
* <prefix>.fits, <prefix>.err.fits, <prefix>.var.fits - variances
(extension STAT, ERROR, or SIGMA)
* <prefix>.fits, <prefix>.msk.fits - a bad pixel-mask (extension MASK)
* <prefix>.fits, <prefix>.msk.fits - a bad pixel-spectrumMask (extension MASK)
* <prefix>.res.fits - residuals from a previous fit (first extension
containing data)
kwargs
......@@ -141,14 +141,14 @@ def open_ifs_data(prefix, **kwargs):
if instrument.varhdu is None:
logging.error('Did not find variances for IFS data.')
# open (optional) HDU with mask
# open (optional) HDU with spectrumMask
if os.path.exists("{0}.msk.fits".format(prefix)):
instrument.open("{0}.msk.fits".format(prefix), extno=0, ismask=True, **kwargs)
else:
if 'MASK' in fitsdata:
instrument.open(datafile, extno=fitsdata.index_of('MASK'), ismask=True, **kwargs)
if instrument.maskhdu is None:
logging.warning('Did not find bad-pixel mask for IFS mask.')
logging.warning('Did not find bad-pixel spectrumMask for IFS spectrumMask.')
return instrument
......
......@@ -136,7 +136,7 @@ def clip_sigma(data, axis=None, kappa=3.):
else:
workdata = np.sort(data, axis=0)
# view the data as a masked array (no copy!) and mask NaN pixels
# view the data as a masked array (no copy!) and spectrumMask NaN pixels
workdata_ma = np.ma.array(workdata, mask=(workdata!=workdata))
i = 0 # the iteration index
......
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