Commit 72e0cf42 authored by Moreau Nicolas's avatar Moreau Nicolas
Browse files

correction for incorrect summed graph title calculation

parent f2c414d8
......@@ -238,3 +238,19 @@ function EXIT() {
}
console.log(result + ": exiting");
}
/**
Returns the index of the closest element in the array
for tyhe given value or null if not found
*/
function getIndex(array, value){
for(let i = 0; i < array.length; i++){
if(value >= array[i] && value < array[i+1]){
if(Math.abs(array[i+1]-value) > Math.abs(array[i]-value))
return i;
else
return i+1;
}
}
return null;
}
\ No newline at end of file
......@@ -343,165 +343,183 @@
window.open("getYtObj?relFITSFilePath="+relFITSFilePath+"&iRA0="+ROI.iRA0+"&iRA1="+ROI.iRA1+"&iDEC0="+ROI.iDEC0+"&iDEC1="+ROI.iDEC1+"&iFREQ0="+ROI.iFREQ0+"&iFREQ1="+ROI.iFREQ1);
};
var handleEvent = function (evt) {
console.log(JSON.stringify(evt, null, 4));
return true;
};
var handleEvent = function (evt) {
console.log(JSON.stringify(evt, null, 4));
return true;
};
//
// A object to mark informations related to a position
// in a popup bow located close to the position passed
/**
Add a series where Y=0 in the given chart
*/
function addYAxisSeries(chart){
chart.addSeries({
lineWidth : 1,
enableMouseTracking : false,
showInLegend : false,
color : "#000000",
marker : {
enabled : false
},
data : [[chart.xAxis[0].dataMin, 0], [chart.xAxis[0].dataMax, 0]]
});
}
//
// A object to mark informations related to a position
// in a popup bow located close to the position passed
// as a parameter.
//
function LastClickMarker (map) {
var _map = map;
var _overlay = null;
var _container = document.getElementById('popup');
var _content = document.getElementById('popup-content');
var _closer = document.getElementById('popup-closer');
var _lastChanIndex = null;
var _lastCoordinate = null;
var _lastRADEC = null;
var _lastFluxDensity = null;
// popup creation and addition to an ol overlay to the map passed
// as a parameter.
//
function LastClickMarker (map) {
var _map = map;
var _overlay = null;
var _container = document.getElementById('popup');
var _content = document.getElementById('popup-content');
var _closer = document.getElementById('popup-closer');
var _lastChanIndex = null;
var _lastCoordinate = null;
var _lastRADEC = null;
var _lastFluxDensity = null;
// popup creation and addition to an ol overlay to the map passed
// as a parameter.
//
var _popupLastClickInfos = function () {
if (_overlay == null) {
/**
* Create an overlay to anchor the popup to the map.
*/
_overlay = new ol.Overlay({
element: _container,
autoPan: true,
autoPanAnimation: {
duration: 250
}
});
/**
* Add a click handler to hide the popup.
* @return {boolean} Don't follow the href.
*/
_closer.onclick = function() {
_overlay.setPosition(undefined);
_closer.blur();
return false;
};
var _popupLastClickInfos = function () {
if (_overlay == null) {
/**
* Create an overlay to anchor the popup to the map.
*/
_overlay = new ol.Overlay({
element: _container,
autoPan: true,
autoPanAnimation: {
duration: 250
}
});
_map.addOverlay(_overlay);
}
};
/**
* Add a click handler to hide the popup.
* @return {boolean} Don't follow the href.
*/
_closer.onclick = function() {
_overlay.setPosition(undefined);
_closer.blur();
return false;
};
//
// update the content of the popup by using the informations
// stored in _lastCoordinate, _lastRADEC and _lastFluxDensity
//
var _updateLastClickInfos = function () {
if (_lastCoordinate == null ) return;
_content.innerHTML = 'Chan#'+_lastChanIndex + '<br>' + 'x = ' + _lastCoordinate[0].toFixed(0) + ', y = ' + _lastCoordinate[1].toFixed(0) + '<br>' +
'RA=' + _lastRADEC['RA'] + '<br>' +
'DEC=' + _lastRADEC['DEC'] + '<br>' +
'Value=' + Number(_lastFluxDensity).toExponential(4);
_overlay.setPosition(_lastCoordinate);
_map.addOverlay(_overlay);
}
};
//
// public method to register the values to be displayed
// in the popup and update its content.
//
this.setPositionAndFluxDensity = function(data) {
console.log("this.setPosition = function(coordinate) { : entering");
//
// update the content of the popup by using the informations
// stored in _lastCoordinate, _lastRADEC and _lastFluxDensity
//
var _updateLastClickInfos = function () {
if (_lastCoordinate == null ) return;
_content.innerHTML = 'Chan#'+_lastChanIndex + '<br>' + 'x = ' + _lastCoordinate[0].toFixed(0) + ', y = ' + _lastCoordinate[1].toFixed(0) + '<br>' +
'RA=' + _lastRADEC['RA'] + '<br>' +
'DEC=' + _lastRADEC['DEC'] + '<br>' +
'Value=' + Number(_lastFluxDensity).toExponential(4);
_overlay.setPosition(_lastCoordinate);
}
_lastChanIndex = data["chanIndex"]
_lastCoordinate = data["coordinate"];
_lastRADEC = data["RADEC"];
_lastFluxDensity = data["fluxDensity"];
//
// public method to register the values to be displayed
// in the popup and update its content.
//
this.setPositionAndFluxDensity = function(data) {
console.log("this.setPosition = function(coordinate) { : entering");
_updateLastClickInfos();
_lastChanIndex = data["chanIndex"]
_lastCoordinate = data["coordinate"];
_lastRADEC = data["RADEC"];
_lastFluxDensity = data["fluxDensity"];
console.log("this.setPosition = function(coordinate) { : exiting");
};
_updateLastClickInfos();
//
// public method to register the fluxDensity value passed as a parameter
// and update the popup content accordingly.
//
this.setFluxDensity = function(fluxDensity, sliceIndex) {
console.log("this.setFluxDensity = function(fluxDensity) { : entering");
_lastFluxDensity = fluxDensity;
_lastChanIndex = sliceIndex;
_updateLastClickInfos();
console.log("this.setFluxDensity = function(fluxDensity) { : exiting");
};
console.log("this.setPosition = function(coordinate) { : exiting");
};
// create our popup.
_popupLastClickInfos();
//
// public method to register the fluxDensity value passed as a parameter
// and update the popup content accordingly.
//
this.setFluxDensity = function(fluxDensity, sliceIndex) {
console.log("this.setFluxDensity = function(fluxDensity) { : entering");
_lastFluxDensity = fluxDensity;
_lastChanIndex = sliceIndex;
_updateLastClickInfos();
console.log("this.setFluxDensity = function(fluxDensity) { : exiting");
};
/*
** A function to start/stop an hold-on animation while
** an image is prepared by the server until it serves it to the client.
** This function is dedicated to be passed a the value
** of the option imageLoadFunction of an ImageStatic constructor.
**
*/
var _image = null;
function _onProgress(event) {
if (event.lengthComputable) {
var percentComplete = (event.loaded / event.total)*100;
console.log("Transfert: %d%%", percentComplete);
} else {
// Impossible de calculer la progression puisque la taille totale est inconnue
}
}
// create our popup.
_popupLastClickInfos();
};
function _onError(event) {
console.error("Error " + event.target.status + " during the transfert.");
/*
** A function to start/stop an hold-on animation while
** an image is prepared by the server until it serves it to the client.
** This function is dedicated to be passed a the value
** of the option imageLoadFunction of an ImageStatic constructor.
**
*/
var _image = null;
function _onProgress(event) {
if (event.lengthComputable) {
var percentComplete = (event.loaded / event.total)*100;
console.log("Transfert: %d%%", percentComplete);
} else {
// Impossible de calculer la progression puisque la taille totale est inconnue
}
}
function _onLoad(event) {
// Ici, this.readyState XMLHttpRequest.DONE .
if (this.status === 200) {
console.log("Transfert done - " + this.responseText.length + "bytes.");
var _srcURI = "data:image/png," + this.responseText;
console.log("_srcURI=" + _srcURI);
function _onError(event) {
console.error("Error " + event.target.status + " during the transfert.");
}
_image.getImage().src = _srcURI;
} else {
console.log("Response status: %d (%s)", this.status, this.statusText);
}
document.getElementById('loading').style.display='none';
function _onLoad(event) {
// Ici, this.readyState XMLHttpRequest.DONE .
if (this.status === 200) {
console.log("Transfert done - " + this.responseText.length + "bytes.");
var _srcURI = "data:image/png," + this.responseText;
console.log("_srcURI=" + _srcURI);
_image.getImage().src = _srcURI;
} else {
console.log("Response status: %d (%s)", this.status, this.statusText);
}
document.getElementById('loading').style.display='none';
}
let hidden_canvas_1 = document.getElementById("hiddenSlice");
let hidden_canvas_2 = document.getElementById("hiddenSummedSlices");
//
//
// What happends when the image to be displayed in 'image'
// is loaded. To be used for _map_1
//
var _imageLoadFunction_1 = function(image, src) {
console.log("_imageLoadFunction_1 : entering");
document.getElementById('loading').style.display='block';
image.getImage().addEventListener('load', function() {
document.getElementById('loading').style.display='none';
hidden_canvas_1.getContext('2d').drawImage(image.getImage(), 0, 0);
});
let hidden_canvas_1 = document.getElementById("hiddenSlice");
let hidden_canvas_2 = document.getElementById("hiddenSummedSlices");
//
//
// What happends when the image to be displayed in 'image'
// is loaded. To be used for _map_1
//
var _imageLoadFunction_1 = function(image, src) {
console.log("_imageLoadFunction_1 : entering");
document.getElementById('loading').style.display='block';
image.getImage().addEventListener('load', function() {
document.getElementById('loading').style.display='none';
hidden_canvas_1.getContext('2d').drawImage(image.getImage(), 0, 0);
});
image.getImage().src = src;
image.getImage().crossOrigin = "Anonymous";
image.getImage().src = src;
image.getImage().crossOrigin = "Anonymous";
console.log("_imageLoadFunction_1 : exiting");
};
console.log("_imageLoadFunction_1 : exiting");
};
//
// What happends when the image to be displayed in 'image'
// is loaded. To be used for _map_2
//
//
// What happends when the image to be displayed in 'image'
// is loaded. To be used for _map_2
//
var _imageLoadFunction_2 = function(image, src) {
console.log("_imageLoadFunction_2 : entering");
document.getElementById('loading').style.display='block';
......@@ -1597,6 +1615,8 @@ var SAMPPNGPublishControl = (function (Control) {
yAxis: {
gridLineColor: '#000000',
lineColor: '#000000',
lineWidth : 1,
gridLineWidth : 0,
title: {
text: ytitle
}
......@@ -1604,7 +1624,7 @@ var SAMPPNGPublishControl = (function (Control) {
plotOptions: {
series: {
animation: false,
lineWidth : 1
//lineWidth : 1
}
},
series: [
......@@ -1659,6 +1679,7 @@ var SAMPPNGPublishControl = (function (Control) {
var xtitle = "undefined";
var ytitle = "undefined";
var isTitleInitialized = false;
let _averageSpectrum = null;
......@@ -1667,11 +1688,44 @@ var SAMPPNGPublishControl = (function (Control) {
}
this.setAverageSpectrum = function(averageSpectrum){
console.log("### setAverageSpectrum");
console.log(averageSpectrum);
_averageSpectrum = averageSpectrum;
}
this.computeSummedAverageSpectrum =function(min, max){
var imin = Math.round((min - summedData.x[0]) / (summedData.x[1]-summedData.x[0]));
var imax = Math.round((max - summedData.x[0]) / (summedData.x[1]-summedData.x[0]));
if (getCunit3() in unitFactor) {
console.log("### CASE : "+ _ctype3);
switch (_ctype3) {
case 'FREQ':
if (_cdelt3 > 0) {
sliceViewer.updateSummedSlices(summedData.x.length-1-imax, summedData.x.length-1-imin);
}
else {
sliceViewer.updateSummedSlices(imin, imax);
}
break;
case 'VRAD' :
case 'WAVE':
case 'WAVN' :
case 'AWAV':
if (_cdelt3 > 0) {
sliceViewer.updateSummedSlices(imin, imax);
}
else {
sliceViewer.updateSummedSlices(summedData.x.length-1-imax, summedData.x.length-1-imin);
}
break;
default:
console.log("This should not happen");
}
}
summedAverageSpectrum = sumArr(averageSpectrum, 0, averageSpectrum.length, cdelt3prim);
return summedAverageSpectrum;
}
var toptitle_unit = "";
if (_instrume == "SITELLE") {
xtitle = _ctype3 + " (" + getCunit3() + ")";
......@@ -1726,45 +1780,10 @@ var SAMPPNGPublishControl = (function (Control) {
hoverinfo: 'x+y',
xaxis: 'x'
};
var plotData2 = JSON.parse(JSON.stringify(_frequencyPlot));
//let _companion = null;
/*
** set the companion
*/
/*this.setCompanion = function(who) {
_companion = who;
}*/
/*
** get the companion
*/
/*this.getCompanion = function() {
return _companion;
}*/
/*
** Who triggered the relayout ?
*/
//let _relayoutTriggeredBy = null;
/*
** Set who triggered the relayout
*/
/*this.setRelayoutTriggeredBy = function(who) {
_relayoutTriggeredBy = who;
}*/
/*
** Get who triggered the relayout.
*/
/*this.getRelayoutTriggeredBy = function() {
return _relayoutTriggeredBy;
}*/
//Plotly.newPlot(_itsGD, _frequencyPlot, _layout);
var summedData = JSON.parse(JSON.stringify(_frequencyPlot));
this.plot = function (iRA0, iRA1, iDEC0, iDEC1, zmin, zmax) {
ENTER();
var self = this;
summedPixelsSpectrumChart = Highcharts.chart(_itsGD, {
title: {
text: ''
......@@ -1774,46 +1793,44 @@ var SAMPPNGPublishControl = (function (Control) {
panning: true,
panKey: 'shift',
events:{
/*render : function(event){
console.log("### RENDER");
let summedAverageSpectrum = computeSummedAverageSpectrum(this.xAxis[0].dataMin, this.xAxis[0].dataMax);
if(isTitleInitialized === false){
this.setTitle({text:toptitle(summedAverageSpectrum/unitRescale(summedPixelsSpectrumUnit(_bunit)), toptitle_unit)});
isTitleInitialized = true;
}
return false;
},*/
selection: function(event){
this.xAxis[0].update({
plotBands : [{
from: event.xAxis[0].min,
to: event.xAxis[0].max,
color: 'rgba(68, 170, 213, .2)'
}]
});
var imin = Math.round((event.xAxis[0].min - plotData2.x[0]) / (plotData2.x[1]-plotData2.x[0]));
var imax = Math.round((event.xAxis[0].max - plotData2.x[0]) / (plotData2.x[1]-plotData2.x[0]));
console.log("### SELECTION");
this.xAxis[0].update({
plotBands : [{
from: event.xAxis[0].min,
to: event.xAxis[0].max,
color: 'rgba(68, 170, 213, .2)'
}]
});
console.log("### MIN/MAX");
console.log(event.xAxis[0].min + " " + event.xAxis[0].max);
console.log(averageSpectrum);
console.log(this.series[0].data);
let summedSpectrum = self.computeSummedAverageSpectrum(event.xAxis[0].min, event.xAxis[0].max);
let xData = [];
for(let i = 0; i< this.series[0].data.length; i++){
xData.push(this.series[0].data[i].x);
}
if (getCunit3() in unitFactor) {
switch (_ctype3) {
case 'FREQ':
if (_cdelt3 > 0) {
sliceViewer.updateSummedSlices(plotData2.x.length-1-imax, plotData2.x.length-1-imin);
}
else {
sliceViewer.updateSummedSlices(imin, imax);
}
break;
case 'VRAD' :
case 'WAVE':
case 'WAVN' :
case 'AWAV':
if (_cdelt3 > 0) {
sliceViewer.updateSummedSlices(imin, imax);
}
else {
sliceViewer.updateSummedSlices(plotData2.x.length-1-imax, plotData2.x.length-1-imin);
}
break;
default:
console.log("This should not happen");
}
}
summedAverageSpectrum = sumArr(averageSpectrum, 0, averageSpectrum.length, cdelt3prim);
this.setTitle({text:toptitle(summedAverageSpectrum/unitRescale(summedPixelsSpectrumUnit(_bunit)), toptitle_unit)});
return false;
let imin = getIndex(xData, event.xAxis[0].min);
let imax = getIndex(xData, event.xAxis[0].max);
console.log("min / max : "+ imin + " "+ imax);
let summedSp = sumArr(averageSpectrum, imin, imax, cdelt3prim);
this.setTitle({text:toptitle(summedSp/unitRescale(summedPixelsSpectrumUnit(_bunit)), toptitle_unit)});
return false;
/*let summedAverageSpectrum = computeSummedAverageSpectrum(event.xAxis[0].min, event.xAxis[0].max);
this.setTitle({text:toptitle(summedAverageSpectrum/unitRescale(summedPixelsSpectrumUnit(_bunit)), toptitle_unit)});
return false;*/
}
}
......@@ -1834,6 +1851,8 @@ var SAMPPNGPublishControl = (function (Control) {
yAxis: {
gridLineColor: '#000000',
lineColor: '#000000',
lineWidth : 1,
gridLineWidth : 0,
title: {
text: ytitle
}
......@@ -1841,7 +1860,7 @@ var SAMPPNGPublishControl = (function (Control) {
plotOptions: {
series: {
animation: false,
lineWidth : 1
//lineWidth : 1
}
},
tooltip:{
......@@ -1952,15 +1971,15 @@ var SAMPPNGPublishControl = (function (Control) {
}
}
}
plotData2.x = xData;
summedData.x = xData;
switch (_ctype3) {
case 'FREQ' :
if (_cdelt3 > 0) {
plotData2.y = revertArray(averageSpectrum);
summedData.y = revertArray(averageSpectrum);
}
else {
plotData2.y = averageSpectrum;
summedData.y = averageSpectrum;
}
break;
......@@ -1970,10 +1989,10 @@ var SAMPPNGPublishControl = (function (Control) {
case 'AWAV':
averageSpectrum = averageSpectrum.map(function(x) {return x* unitRescale(summedPixelsSpectrumUnit(_bunit))});
if (_cdelt3 > 0) {
plotData2.y = averageSpectrum;
summedData.y = averageSpectrum;
}
else {
plotData2.y = revertArray(averageSpectrum);
summedData.y = revertArray(averageSpectrum);
}
break;
......@@ -1982,12 +2001,12 @@ var SAMPPNGPublishControl = (function (Control) {
break;
}
let highChartData = [];
for(let i=0; i< plotData2.x.length; i++){
highChartData.push([plotData2.x[i], plotData2.y[i]]);
let chartData = [];
for(let i=0; i< summedData.x.length; i++){
chartData.push([summedData.x[i], summedData.y[i]]);
}
summedPixelsSpectrumViewer.setAverageSpectrum(averageSpectrum);
summedPixelsSpectrumChart.setTitle({text:toptitle(summedAverageSpectrum/unitRescale(summedPixelsSpectrumUnit(_bunit)), toptitle_unit)});
//summedPixelsSpectrumChart.setTitle({text:toptitle(summedAverageSpectrum/unitRescale(summedPixelsSpectrumUnit(_bunit)), toptitle_unit)});
summedPixelsSpectrumChart.series[0].update({
name : '',
// unlimited number of points when zooming
......@@ -1996,13 +2015,19 @@ var SAMPPNGPublishControl = (function (Control) {
marker: {