From ffebe24975a64475fd398a48f32fd4e8d8089658 Mon Sep 17 00:00:00 2001 From: lerma artemix <nicolas.moreau@obspm.fr> Date: Wed, 7 May 2025 16:36:15 +0200 Subject: [PATCH] update the way a pixel value is displayed when it is NaN --- yafitss/dataBlock.py | 21 ++++----- .../javascript/modules/lastclickmarker.js | 1 - .../javascript/modules/olqv_linkedviews.js | 3 +- .../public/javascript/modules/olqv_slice.js | 43 +++++++------------ 4 files changed, 26 insertions(+), 42 deletions(-) diff --git a/yafitss/dataBlock.py b/yafitss/dataBlock.py index 886e7384..1d561766 100644 --- a/yafitss/dataBlock.py +++ b/yafitss/dataBlock.py @@ -769,11 +769,11 @@ class DataBlock: result = (self.__data[iDEC0:iDEC1+1, iRA0:iRA1+1]*cdelt) self.__collectStatistics("%d-%d"%(iFREQ0, iFREQ1), result.compute()) + result = dask.array.where(result== 0, np.NaN, result) self.__logger.debug(f"Returns a {type(result)}") - self.__logger.debug("__getAverage_0: exiting") - - result = dask.array.where(result== 0, np.NaN, result) + self.__logger.debug("__getAverage_0: exiting") + return result # result is a dask array def __getPercentile(self, a, percent): @@ -869,9 +869,6 @@ class DataBlock: # calculate image size dpi = 600 #height, width = self.__image_width, self.__image_height = shape[0], shape[1] - - self.__logger.debug("### SHAPE") - self.__logger.debug(shape) width, height = shape[0], shape[1] #= __image_width, __image_height figsize = width / float(dpi), height / float(dpi) fig = plt.figure(figsize=figsize) @@ -1715,9 +1712,6 @@ class DataBlock: return result def getAverageSpectrum(self, iDEC0=None, iDEC1=None, iRA0=None, iRA1=None) -> Result: - - self.__logger.debug("### getAverageSpectrum") - self.__timer.start() # check that coordinates are in the limits of the plan @@ -1829,12 +1823,14 @@ class DataBlock: try : result = self.__getAverage_0(iFREQ0, iFREQ1, iDEC0, iDEC1, iRA0, iRA1).compute().tolist() - # None value appended to array it is empty + # None value appended to array if it is empty if(np.size(result, 1)) == 0 : - result[0].append(None) + #result[0].append(None) + return Result().wrong("Result is empty") # NaN value replaced by None for json conversion elif np.isnan(result[0][0]): - result[0][0] = None + return Result().wrong("Value is NaN") + #result[0][0] = None self.__logger.debug("returned value = %s"%result) self.__logger.debug("getAverage: exiting") @@ -1997,7 +1993,6 @@ class DataBlock: result = {"path_to_png": relPNGFilePath, "path_to_legend_png": getLegendFilePath(relPNGFilePath), "statistics": self.__statistics["%d-%d"%(iFREQ0, iFREQ1)]} - self.__logger.debug(f"result = {result}") self.__logger.debug("getSummedSliceRangeAsPNG: exiting.") self.__timer.stop("getSummedSliceRangeAsPng", self.__timerPrefix) return Result().ok(result) diff --git a/yafitsv/public/javascript/modules/lastclickmarker.js b/yafitsv/public/javascript/modules/lastclickmarker.js index 0eac9eaa..b005fba1 100644 --- a/yafitsv/public/javascript/modules/lastclickmarker.js +++ b/yafitsv/public/javascript/modules/lastclickmarker.js @@ -94,7 +94,6 @@ import { Constants } from "./constants.js"; } }).on('inserted.bs.popover', function() { const popover = $(`#${self._map.getTarget()}`).find('.popover').last(); - printDebug('inserted popover', popover); popover.css('background-color', Constants.POPOVER_BACKGROUND); }); diff --git a/yafitsv/public/javascript/modules/olqv_linkedviews.js b/yafitsv/public/javascript/modules/olqv_linkedviews.js index 6b562022..24d5d094 100644 --- a/yafitsv/public/javascript/modules/olqv_linkedviews.js +++ b/yafitsv/public/javascript/modules/olqv_linkedviews.js @@ -1,5 +1,5 @@ import { - unitRescale, + unitRescale, printDebug } from "./utils.js"; import { withSAMP, dataPaths, testMode } from './init.js'; import { ServerApi } from './serverApi.js' @@ -230,6 +230,7 @@ class ViewLinker { * @param {array} coordinate a 2 elements array containing the x,y coordinates */ markLastClickInSlices(coordinate) { + printDebug("markLastClickInSlices" ); this._markLastClickInSlice(this._lastClickMarker, coordinate); this._markLastClickInSlice(this._lastClickMarkerSummed, coordinate); }; diff --git a/yafitsv/public/javascript/modules/olqv_slice.js b/yafitsv/public/javascript/modules/olqv_slice.js index 819fadf2..63e0078d 100644 --- a/yafitsv/public/javascript/modules/olqv_slice.js +++ b/yafitsv/public/javascript/modules/olqv_slice.js @@ -269,13 +269,14 @@ class Slice { * @returns {boolean} */ pixelHasValue(x, y) { - let ctx = this._hidden_canvas.getContext('2d'); + return true; + /*let ctx = this._hidden_canvas.getContext('2d'); let pixelAtPosition = ctx.getImageData(x, this._height - y, 1, 1).data; if (pixelAtPosition[0] == 0 && pixelAtPosition[1] == 0 && pixelAtPosition[2] == 0) { return false; } else { return true; - } + }*/ } /** @@ -515,7 +516,6 @@ class SingleSlice extends Slice { constructor(viewLinker, sliceDivId, canvasId, RADECRangeInDegrees, width, height) { super(viewLinker, sliceDivId, canvasId, RADECRangeInDegrees, width, height); this.sliceIndex; - this._lastClickMarker = ''; this._initCommonControl(["boxes"]); this._initAdditionalControl(); this.map_controls = this._getMapControl(); @@ -530,7 +530,6 @@ class SingleSlice extends Slice { onclick(event) { if(!this.selector.isOpened()){ - //is this test still useful ? let localName = ""; try{ localName = event.originalEvent.target.localName; @@ -541,15 +540,15 @@ class SingleSlice extends Slice { if(event.originalEvent == null || localName == "canvas"){ // keep old x axis limits before replot if(this._viewLinker.isRefreshable){ - if (this.pixelHasValue(Math.round(event.coordinate[0]), Math.round(event.coordinate[1]))) { - const minVal = Math.min(...this._viewLinker.spectrumViewer.getContainerData().x); - const maxVal = Math.max(...this._viewLinker.spectrumViewer.getContainerData().x); - this._viewLinker.markLastClickInSlices(event.coordinate); - this._viewLinker.summedSlicesImage.onclick(event); - this._viewLinker.spectrumViewer.setFrequencyMarker(this.sliceIndex); - }else{ + //if (this.pixelHasValue(Math.round(event.coordinate[0]), Math.round(event.coordinate[1]))) { + const minVal = Math.min(...this._viewLinker.spectrumViewer.getContainerData().x); + const maxVal = Math.max(...this._viewLinker.spectrumViewer.getContainerData().x); + this._viewLinker.markLastClickInSlices(event.coordinate); + this._viewLinker.summedSlicesImage.onclick(event); + this._viewLinker.spectrumViewer.setFrequencyMarker(this.sliceIndex); + /*}else{ alert("No value for this pixel"); - } + }*/ }else{ alert("Display can not be refreshed. Velocity or redshift value has changed. Please press enter in this field to validate."); } @@ -925,20 +924,12 @@ class SummedSlice extends Slice { const maxVal = Math.max(...this._viewLinker.spectrumViewer.getContainerData().x); let result = resp["data"]; - if (result["status"] && result["result"] !== null){ + if (result["status"] /*&& result["result"] !== null && result["result"][0] !== null*/){ const pixelValue = result["result"][0][0]; - if(pixelValue === null){ - alert("No value for this pixel"); - }else{ + if(pixelValue !== null){ this._viewLinker.spectrumViewer.setFrequencyMarker(this._viewLinker.getSliceIndex()); - //let self = this; - this._viewLinker.spectrumViewer.plot(this._lastClick.iRA, - this._lastClick.iDEC/*, () => { - // set old x axis limits - self._viewLinker.spectrumViewer.spectrumChart.xAxis[0].setExtremes(minVal, maxVal); - }*/); - - + this._viewLinker.spectrumViewer.plot(this._lastClick.iRA, this._lastClick.iDEC); + if (event.coordinate !== undefined) this._viewLinker.markLastClickInSlices(event.coordinate); @@ -952,9 +943,7 @@ class SummedSlice extends Slice { } } }else{ - if(result["message"]){ - alert("No value for this pixel"); - } + this._viewLinker.markLastClickInSlices(event.coordinate); } }); }else{ -- GitLab