olqv.ejs 84.5 KB
Newer Older
1
2
<!DOCTYPE html>
<html>
3

4
5
6
7
8
9
10
<head>
  <title><%= title %></title>

  <link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" rel="stylesheet" />

  <!--script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script> -->
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js" type="text/javascript"></script>
11
12
13
14
15
16
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"
    integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49"
    crossorigin="anonymous"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"
    integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T"
    crossorigin="anonymous"></script>
17
  <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.full.js"></script>
18
19
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css"
    integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
20
21
  <script src="https://code.highcharts.com/highcharts.src.js"></script>
  <script src="https://code.highcharts.com/modules/boost.js"></script>
22
23
24
25
  <script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js"></script>
  <link rel="stylesheet" href="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/css/ol.css">

  <link rel="stylesheet" type="text/css" href="/stylesheets/overlay.css">
26
  <link rel="stylesheet" type="text/css" href="/stylesheets/olqv.css">
27
28
29
30

  <script src="../javascript/FITSHeaderTable.js"></script>
  <script src="../javascript/olqv_utils.js"></script>

31
  <!--  <script src="https://openlayers.org/en/v4.6.4/build/ol.js" type="text/javascript"></script> -->
32
  <!-- Conditional code generation -->
33
  <%if(useSAMP){%>
34
  <script src="../javascript/samp.js"></script>
35
  <script src="../javascript/samp_utils.js"></script>
36
  <%}%>
Caillat Michel's avatar
Caillat Michel committed
37
  <!-- End of conditional code generation -->
38
39
40
41
42
43
44
</head>

<body>

<div id="loading"></div>
<div id="FITSHDR" class="overlay" style="overflow:scroll"></div>
<div class="pos-f-t">
45
  <div class="collapse" id="sampRegistry"></div>
46
  <div class="collapse" id="navbarToggleExternalContent">
Caillat Michel's avatar
Caillat Michel committed
47
    <div class="p-4">
48
<% if (renderingCapabilities) { %>
Caillat Michel's avatar
Caillat Michel committed
49
50
  <nav class="navbar navbar-light bg-light">
    <ul class="list-group list-group-horizontal img-configuration">
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
      <li class="list-group-item ">
        <label for="LUTSelector">LUTs</label>
        <select name="LUTs" class="form-control" id="LUTSelector">
          <% renderingCapabilities["luts"].forEach(function(lut) { %>
          <option> <%=lut%></option>
          <% }) %>
        </select>
      </li>
      <li class="list-group-item ">
        <label for="ITTSelector">ITTs</label>
        <select class="form-control" id="ITTSelector">
          <% renderingCapabilities["itts"].forEach(function(itt) { %>
          <option> <%=itt%></option>
          <% }) %>
        </select>
      </li>
      <li class="list-group-item ">
        <label for="VideoModeSelector">Video mode</label>
        <select class="form-control" id="VideoModeSelector">
70
          <% renderingCapabilities["vmodes"].forEach(function(vmode) { %>
71
          <option> <%=vmode%></option>
72
          <% }) %>
73
74
75
        </select>
      </li>
      <li class="list-group-item">
Caillat Michel's avatar
Caillat Michel committed
76
        <button id="rccap" class="btn btn-default btn-control">Apply</button>
77
78
79
80
      </li>
    </ul>
  </nav>
  </div>
81

82
  <%}%>
83
84
    </div>
  </div>
Caillat Michel's avatar
Caillat Michel committed
85
86
87
88
89
  <nav class="navbar navbar-light" style="background-color: #FFFFFF;">
    <button class="navbar-toggler" type="button"
            data-toggle="collapse" data-target="#navbarToggleExternalContent"
            aria-controls="navbarToggleExternalContent" aria-expanded="false"
            aria-label="Toggle navigation">
90
91
      <span class="navbar-toggler-icon"></span>
    </button>
92
    <!--<div><a id="jupyter" href="#" target="_blank"><img src="../jupyter.png" style="width:30px; height:30px" title="jupyter"/></a></div>-->
Caillat Michel's avatar
Caillat Michel committed
93
94
95
96
97
98
    <a href="#" class="btn btn-link btn-sm" onclick="viewIn3D(); return false;"> Show 3D model </a>
    <div><a href="http://artemix.obspm.fr/fits/browse" target="_blank" class="btn btn-link btn-sm">Show Fits file browser</a></div>
    <div id="cubeInfos" class="cube-infos"></div>
    <img  src="../samphub.png" class="samp-img"
          data-toggle="collapse" data-target="#sampRegistry" title="Transfer data to another application with SAMP protocol"
          aria-controls="sampRegistry" aria-expanded="false" aria-label="Toggle navigation"/>
99
100
101
  </nav>
</div>
<div>
102
103
104
<div class="container chart-container">
      <div class="row">
        <div class="col">
Caillat Michel's avatar
Caillat Michel committed
105
          <div id="external_mouse_position_1" class="external_mouse_position"></div>
106
107
        </div>
        <div class="col">
Caillat Michel's avatar
Caillat Michel committed
108
          <div id="debug_jpk"></div>          
109
110
111
112
113
114
115
        </div>
      </div>
      <div class="row">
        <div class="col chart-img">
          <div id="slice" class="map" style="background-color:darkblue"></div>
        </div>
        <div class="col chart-plot">
Caillat Michel's avatar
Caillat Michel committed
116
          <div id="spectrum"></div>
117
118
        </div>
        <div class="col">
Caillat Michel's avatar
Caillat Michel committed
119
120
121
122
123
          <div>
            <p><button id="zoomin" class="btn btn-default btn-control">Zoom in</button></p>
            <p><button id="zoomout" class="btn btn-default btn-control">Zoom out</button></p>
            <p><button id="zoomreset" class="btn btn-default btn-control">Reset</button></p>
            <div id="publish_spectrum"></div>
Caillat Michel's avatar
Caillat Michel committed
124
125
          </div>
        </div>
Caillat Michel's avatar
Caillat Michel committed
126
127
128
      </div>
      <div class="row">

Caillat Michel's avatar
Caillat Michel committed
129
130
131
132
      </div>
      <div class="row">
        <div class="col">
          <div id="external_mouse_position_2" class="external_mouse_position"></div>
133
134
135
136
137
138
139
140
141
        </div>
      </div>
      <div class="row">
        <div class="col chart-img">
          <div id="summedslices" class="map"></div>
        </div>
        <div class="col chart-plot">
          <div id="summedpixelsspectrum"></div>
        </div>
Caillat Michel's avatar
Caillat Michel committed
142
143
144
        <div class="col">
          <div id="publish_summedpixelsspectrum"></div>
        </div>
145
      </div>
Caillat Michel's avatar
Caillat Michel committed
146
147
148
149
150
151
152
      <div class="row">
        <div class="col">
          <div class="chart-title">
            <span id="chart_title"></span>
          </div>
        </div>
      </div>
153
    </div>
154

155
156
157
158
159
160
161
162
163
    <div class="container chart-container hidden">
      <div class="row">
        <div class="col">
          <canvas id="hiddenSlice"></canvas>
        </div>
        <div class="col">
          <canvas id="hiddenSummedSlices"></canvas>
        </div>
      </div>
Caillat Michel's avatar
Caillat Michel committed
164
165
    </div>

166
167

  <div class="hidden">
168
169
170
171
172
173
    <div id="popup" class="ol-popup">
      <a href="#" id="popup-closer" class="ol-popup-closer"></a>
      <div id="popup-content"></div>
    </div>
  </div>

ba yaye-awa's avatar
ba yaye-awa committed
174
  <!-- Modal for samp cassis-->
175
  <div class="modal fade hidden" id="sampModal" role="dialog">
176
177
178
179
180
181
182
183
    <div class="modal-dialog">
      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Send spectrum by SAMP (Cassis)</h4>
        </div>
        <div class="modal-body">
184
          <p>
Caillat Michel's avatar
Caillat Michel committed
185
            This link is intended to send the current artemix spectrum to Cassis tool,
186
187
188
189
            or any other tool that runs with the SAMP protocol and accepts our file fits format.
          </p>
          <p>
            For the transfer to work, Check that Cassis is running.
Caillat Michel's avatar
Caillat Michel committed
190
          </p>
191
192
193
194
195
196
197
198
199
200
          <h3>How to launch Cassis</h3>
          <p>
            <strong>- Cassis with command line:</strong>
          </p>
          <p>
            Open a terminal and run: javaws http://cassis.irap.omp.eu/online/cassis.jnlp
          </p>
          <p>
            <strong>- Cassis online:</strong>
          </p>
201
202
          <ul>
            <li>1- Go to the Cassis <a href="http://cassis.irap.omp.eu/?page=installation"> website</a></li>
203
204
205
            <li>2- Use Cassis online application or download the latest version </li>
          </ul>
          <p>
Caillat Michel's avatar
Caillat Michel committed
206
207
            If you encounter a problem during the installation, check that you have the correct Java version
            compatible with Cassis, and allow the installation in your computer.
208
209
210
211
212
            Please read <a href="images/enablejava.png">here</a> on how to do with a Mac.
          </p>
          <p>
            In case you encounter any problem with Cassis please contact the Cassis project manager <a href="#">Jean-Michel.Glorian{at}irap.omp.eu</a>
         </p>
Caillat Michel's avatar
Caillat Michel committed
213
214
215
	      </div>
	      <div class="modal-footer">
	          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
216
217
218
219
        </div>
      </div>
    </div>
  </div>
220

ba yaye-awa's avatar
ba yaye-awa committed
221
  <!-- Modal for samp aladin -->
ba yaye-awa's avatar
ba yaye-awa committed
222
223
224
225
226
227
228
229
230
  <div class="modal fade" id="sampModalAladin" role="dialog" style="display:none">
    <div class="modal-dialog">
      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Send image by SAMP (Aladin)</h4>
        </div>
        <div class="modal-body">
Caillat Michel's avatar
Caillat Michel committed
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
          <p>
            This link is intended to send the current Artemix image to Aladin tool,
            or any other tool that runs with the SAMP protocol and accepts our file png format.
          </p>
          <p>
            For the transfer to work, Check that Aladin is running.
          </p>
          <p>
            How to launch Aladin :
          </p>
          <p>
            <strong>- Aladin with command line:</strong>
          </p>
          <p>
            Open a terminal and run: javaws https://aladin.u-strasbg.fr/java/nph-aladin.pl
          </p>
          <p>
            <strong>- Aladin online:</strong>
          </p>
ba yaye-awa's avatar
ba yaye-awa committed
250
251
          <ul>
            <li>1- Go to the Aladin <a href="https://aladin.u-strasbg.fr/java/nph-aladin.pl?frame=downloading"> website</a></li>
Caillat Michel's avatar
Caillat Michel committed
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
            <li>2- Use Aladin online application or download the latest version </li>
          </ul>
          <p>
            If you encounter a problem during the installation, check that you have the correct Java version compatible with Aladin,
            and allow the installation on your computer.
          </p>
          <p>
            Please look <a href="images/enablejava.png">here</a> to know how to do with MacOS.
          </p>
          <p>
           If you encouter any problem with Aladin please contact the Aladin team AT <a href="#"> unistra.fr?Subject=Aladin</a>
          </p>
	      </div>
	      <div class="modal-footer">
	        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
ba yaye-awa's avatar
ba yaye-awa committed
267
268
269
270
        </div>
      </div>
    </div>
  </div>
271
</body>
Caillat Michel's avatar
Caillat Michel committed
272
273
274
<script>
  var ENTER = function () { console.log(arguments.callee.name + ": entering."); };
  var EXIT = function () { console.log(arguments.callee.name + ": exiting."); };
Caillat Michel's avatar
Caillat Michel committed
275
276
277
  const PLOT_WIDTH = 780;
  const PLOT_RATIO = "65%";
  const PLOT_COLOR ="#F5F101";
278

Caillat Michel's avatar
Caillat Michel committed
279
  <%if (useSAMP) {%>
Caillat Michel's avatar
Caillat Michel committed
280
  var sAMPPublisher = null;
281
  <%}%>
282

283
  var ROI;
Caillat Michel's avatar
Caillat Michel committed
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
  var summedPixelsSpectrumChart;
  var spectrumChart;
  var viewIn3D = function () {
    window.open("getYtObj?relFITSFilePath=" + relFITSFilePath + "&iRA0=" + ROI.iRA0 + "&iRA1=" + ROI.iRA1 + "&iDEC0=" + ROI.iDEC0 + "&iDEC1=" + ROI.iDEC1 + "&iFREQ0=" + ROI.iFREQ0 + "&iFREQ1=" + ROI.iFREQ1);
  };

  var showLoaderAction = function (enable) {
    if (enable) {
      document.getElementById('loading').style.display = 'block';
    } else {
      document.getElementById('loading').style.display = 'none';
    }
  }

  var handleEvent = function (evt) {
    console.log(JSON.stringify(evt, null, 4));
    return true;
  };

  /**
    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]]
    });

  }

  /**
    calculate the value displayed as title of summed average spectrum
    avgSpectrum array is reversed if data are radial velocities and
    cdelt3 < 0
  */
  function getSummedSpectrumTitle(avgSpectrum, imin, imax, cdelt3prim) {
    let result = 0;
    if (_ctype3 === 'VRAD' && _cdelt3 < 0) {
      let copy = (x) => x;
      let arraycopy = avgSpectrum.map(copy);
      result = sumArr(arraycopy.reverse(), imin, imax, cdelt3prim);
    } else {
      result = sumArr(avgSpectrum, imin, imax, cdelt3prim);
    }
    return result / unitRescale(summedPixelsSpectrumUnit(_bunit));
  }

  function getCalculatedIndex(value) {
    let result = 0;
    if (_ctype3 === 'VRAD') {
      let step1 = (unitFactor[defaultOutputUnit[_ctype3]] / unitFactor[getCunit3()]) / _cdelt3;
      result = Math.abs(value * step1) - _crval3 + _crpix3 - 1;
    } else if (_ctype3 === 'FREQ') {
      // if ctype is FREQ we have to read defaultOutputUnit['VRAD']
      let step1 = v2f(value * unitFactor[defaultOutputUnit['VRAD']], _restfreq);
      let step2 = (step1 - _crval3) / _cdelt3;
      result = step2 + _crpix3 - 1;
    }
    return Math.round(result);
  }

  /*function jyToK(flux) {
    let kb = 1.380649e-23;
    let sec = 4.8481368110954e-06;
    let factor = 1 / (2 * kb * ((_crval3 / speedOfLight) ** 2) * ((_bmaj * _bmin * sec * sec * Math.PI / 4 / Math.log(2)) / 1e-26));

    return flux * factor;
  }*/

  function janskyPerKelvin() {
    let kb = 1.380649e-23;
    let bmin = degToRad(_bmin);
    let bmax = degToRad(_bmaj);

    lambda = null;

    if (_origin.startsWith("GILDAS")){
      lambda = speedOfLight / _restfreq;
    }else{
      lambda = speedOfLight / _crval3;
    }

    let omega = Math.PI * bmin * bmax / 4 / Math.log(2);


    step1 = 2 * kb * omega / (lambda * lambda);
    let result = step1 / 1e-26;    
    return result;
  }

  function kelvinPerJansky() {
    let jperk =  janskyPerKelvin();
    let result = 1. / jperk;
    return result;
  }

  function arcsecToDeg(arcsec) {
    return arcsec / 3600;
  }

  function degToRad(deg) {
    return deg * (Math.PI / 180);
  }


  //
  // 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.
    //
    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
          }
426
        });
427

Caillat Michel's avatar
Caillat Michel committed
428
429
430
431
432
433
434
435
436
        /**
        * 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;
        };
Caillat Michel's avatar
Caillat Michel committed
437

Caillat Michel's avatar
Caillat Michel committed
438
        _map.addOverlay(_overlay);
Caillat Michel's avatar
Caillat Michel committed
439
      }
Caillat Michel's avatar
Caillat Michel committed
440
    };
Caillat Michel's avatar
Caillat Michel committed
441

Caillat Michel's avatar
Caillat Michel committed
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
    //
    // 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);
    }

    //
    // 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");

      _lastChanIndex = data["chanIndex"]
      _lastCoordinate = data["coordinate"];
      _lastRADEC = data["RADEC"];
      _lastFluxDensity = data["fluxDensity"];

      _updateLastClickInfos();

      console.log("this.setPosition = function(coordinate) { : exiting");
    };
475

Caillat Michel's avatar
Caillat Michel committed
476
477
478
479
480
481
482
483
484
485
486
    //
    // 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");
    };
487

Caillat Michel's avatar
Caillat Michel committed
488
489
490
    // create our popup.
    _popupLastClickInfos();
  };
491

Caillat Michel's avatar
Caillat Michel committed
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
  /*
  ** 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 _onError(event) {
    console.error("Error  " + event.target.status + " during the transfert.");
  }

  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);
    }
    showLoaderAction(false);
  }

  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");
    showLoaderAction(true);
    image.getImage().addEventListener('load', function () {
      showLoaderAction(false);
      hidden_canvas_1.getContext('2d').drawImage(image.getImage(), 0, 0);
    });

    image.getImage().src = src;
    image.getImage().crossOrigin = "Anonymous";

    console.log("_imageLoadFunction_1 : exiting");
  };

  //
  // 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");
    showLoaderAction(true);
    image.getImage().addEventListener('load', function () {
      showLoaderAction(false);
      hidden_canvas_2.getContext('2d').drawImage(image.getImage(), 0, 0);
    });

    image.getImage().src = src;
    image.getImage().crossOrigin = "Anonymous";

    console.log("_imageLoadFunction_2 : exiting");
  };


  var SAMPPNGPublishControl = (function (Control) {
    function SAMPPNGPublishControl(opt_options) {
      var options = opt_options || {};
      var button = document.createElement('button');
      button.innerHTML = '&#8663';

      var element = document.createElement('div');
      element.className = 'samp-publish-png ol-unselectable ol-control';
      element.appendChild(button);

      Control.call(this, {
        element: element,
        target: options.target
      });
581

Caillat Michel's avatar
Caillat Michel committed
582
583
584
585
      this.handlePublish = function () { ; }
      button.addEventListener('click', this.handlePublish.bind(this), false);
      this.setHandler = function (handler) { console.log("Changing handler"); button.addEventListener('click', handler.bind(this), false) };
    }
586

Caillat Michel's avatar
Caillat Michel committed
587
588
589
    if (Control) SAMPPNGPublishControl.__proto__ = Control;
    SAMPPNGPublishControl.prototype = Object.create(Control && Control.prototype);
    SAMPPNGPublishControl.prototype.constructor = SAMPPNGPublishControl;
590

Caillat Michel's avatar
Caillat Michel committed
591
592
    return SAMPPNGPublishControl;
  }(ol.control.Control));
593
594


Caillat Michel's avatar
Caillat Michel committed
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
  /*
  ** A class definition for the object in charge of displaying
  ** two imagee - one for a slice ( at a given frequency ), one for the sum of
  ** slices ( belonging to a frequency range) of a data cube.
  */
  var _canvasContext_1 = null;

  function SliceViewer(relFITSFilePath, width, height, RADECRangeInDegrees, FITSHeader, divSlice, divSummedSlices) {
    console.log("SliceViewer : entering");

    let _relFITSFilePath = null;
    let _width;
    let _height;
    let _extent;

    let _divSlice;
    let _divSummedSlices;

    let _projection_1;
    let _map_controls_1;
    let _map_1;
    let _im_layer_1;
    let _graticule_1;
    let _data_steps_1;

    let _lastClickMarker_1;

    let _projection_2;
    let _map_controls_2;
    let _select_2;
    let _map_2;
    let _im_layer_2;
    let _graticule_2;
    let _data_steps_2;
    let _box_source_2;
    let _box_layer_2;
    let _dragBox_2;
    let _box_2_extent;
    let _selected_box_2;

    var _sliceIndex;

    _relFITSFilePath = relFITSFilePath;
    _width = width;
    _height = height;
    _divSlice = divSlice;
    _divSummedSlices = divSummedSlices;

    hidden_canvas_1.width = _width;
    hidden_canvas_1.height = _height;

    hidden_canvas_2.width = _width;
    hidden_canvas_2.height = _height;

    _extent = [0, 0, _width - 1, _height - 1];

    let _ra0 = RADECRangeInDegrees[0][0];
    let _ra1 = RADECRangeInDegrees[1][0];

    console.log("_ra0 = " + DecDeg2HMS(_ra0) + " _ra1 =" + DecDeg2HMS(_ra1));

    let _dec0 = RADECRangeInDegrees[0][1];
    let _dec1 = RADECRangeInDegrees[1][1];

    console.log("_dec0 = " + DecDeg2HMS(_dec0) + " _dec1 =" + DecDeg2HMS(_dec1));

    let _raLabelFormatter = new raLabelFormatter(_extent[0], _extent[2], _ra0, _ra1);
    let _decLabelFormatter = new decLabelFormatter(_extent[1], _extent[3], _dec0, _dec1);

    let _coordinateFormatType_1 = function (olc) {
      let result;
      var ctx = hidden_canvas_1.getContext('2d');
      var pixelAtPosition = ctx.getImageData(olc[0], height - olc[1], 1, 1).data;
      if (pixelAtPosition) {
        var data_steps_index = pixelAtPosition.slice(0, 3).join('_');
        result = 'Chan#' + _sliceIndex
          + ", " + _raLabelFormatter.format(olc[0]) + ', '
          + _decLabelFormatter.format(olc[1]) + ', '
          + (_data_steps_1[data_steps_index]).toExponential(2) + " " + _bunit;
674
      }
Caillat Michel's avatar
Caillat Michel committed
675
676
      else {
        result = "???";
677
      }
Caillat Michel's avatar
Caillat Michel committed
678
679
      return result;
    };
680

Caillat Michel's avatar
Caillat Michel committed
681
682
683
684
685
686
687
688
689
690
691
    let _coordinateFormatType_2 = function (olc) {
      let result;
      var ctx = hidden_canvas_2.getContext('2d');
      var pixelAtPosition = ctx.getImageData(olc[0], height - olc[1], 1, 1).data;
      if (pixelAtPosition) {
        var data_steps_index = pixelAtPosition.slice(0, 3).join('_');
        result = _raLabelFormatter.format(olc[0])
          + ', '
          + _decLabelFormatter.format(olc[1]) + ', '
          + _data_steps_2[data_steps_index].toExponential(1)
          + " " + summedPixelsUnit(_bunit);
692
      }
Caillat Michel's avatar
Caillat Michel committed
693
694
695
696
697
      else {
        result = "???";
      }
      return result;
    };
698

Caillat Michel's avatar
Caillat Michel committed
699
    this.getSliceIndex = function () { return sliceIndex; }
700

Caillat Michel's avatar
Caillat Michel committed
701
702
703
704
705
706
707
708
709
710
711
712
713
    this.getFluxDensity = function (pixelCoordinate) {
      let result = null;
      var ctx = hidden_canvas_1.getContext('2d');
      var pixelAtPosition = ctx.getImageData(pixelCoordinate[0], height - pixelCoordinate[1], 1, 1).data;
      if (pixelAtPosition) {
        var data_steps_index = pixelAtPosition.slice(0, 3).join('_');
        result = _data_steps_1[data_steps_index];
      }
      else {
        result = "???";
      }
      return result;
    };
714

Caillat Michel's avatar
Caillat Michel committed
715
716
717
    this.getRADEC = function (pixelCoordinate) {
      return { 'RA': _raLabelFormatter.format(pixelCoordinate[0]), 'DEC': _decLabelFormatter.format(pixelCoordinate[1]) }
    };
718

Caillat Michel's avatar
Caillat Michel committed
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
    /*
    ** The slice display
    */
    _projection_1 = new ol.proj.Projection({
      code: 'local_image',
      units: 'pixels',
      extent: _extent,
      worldExtent: [..._extent]
    });

    _map_controls_1 = [
      new ol.control.MousePosition({
        className: 'custom-mouse-position',
        target: document.getElementById('external_mouse_position_1'),
        undefinedHTML: '',
        coordinateFormat: _coordinateFormatType_1
      }),
      new ol.control.MousePosition({
        className: 'custom-mouse-position',
        target: document.getElementById('external_mouse_position_2'),
        undefinedHTML: '',
        coordinateFormat: _coordinateFormatType_2
      }),
      new ol.control.FullScreen()
    ];
744
      <%if (useSAMP) {%>
Caillat Michel's avatar
Caillat Michel committed
745
746
      let _sAMPPNGPublishControl_1 = new SAMPPNGPublishControl();
      _sAMPPNGPublishControl_1.setHandler(sAMPPublisher.sendPNGSlice);
747
  <%}%>
Caillat Michel's avatar
Caillat Michel committed
748
749
750
751
752
753
754
755
      _map_1 = new ol.Map({
        target: _divSlice,
        view: new ol.View({
          projection: _projection_1,
          center: ol.extent.getCenter(_extent),
          resolution: hidden_canvas_1.width / 512
        })
          <%if(useSAMP) {%>
756
  ,
Caillat Michel's avatar
Caillat Michel committed
757
758
759
760
            controls: ol.control.defaults().extend([
              _sAMPPNGPublishControl_1
            ])
              <%}%>
761
762
      });

Caillat Michel's avatar
Caillat Michel committed
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
  _graticule_1 = new ol.Graticule({
    showLabels: true,
    strokeStyle: new ol.style.Stroke({
      color: 'rgba(0,0,0,0.9)',
      width: 1,
      lineDash: [0.5, 4]
    }),
    //targetSize: 75,
    lonLabelFormatter: _raLabelFormatter.format,
    lonLabelStyle: new ol.style.Text({
      font: '12px Calibri,sans-serif',
      textBaseline: 'bottom',
      fill: new ol.style.Fill({ color: 'rgba(0,0,0,1)' }),
      stroke: new ol.style.Stroke({ color: 'rgba(255,255,255,1)', width: 3 })
    }),
    latLabelFormatter: _decLabelFormatter.format
  });
780

Caillat Michel's avatar
Caillat Michel committed
781
782
783
784
785
  document.getElementById("slice").addEventListener("mouseenter", function () {
    _map_controls_1.forEach(function (ctrl) {
      _map_1.addControl(ctrl);
    });
  });
786

Caillat Michel's avatar
Caillat Michel committed
787
788
789
790
791
  document.getElementById("slice").addEventListener("mouseleave", function () {
    _map_controls_1.forEach(function (ctrl) {
      _map_1.removeControl(ctrl);
    });
  });
792

Caillat Michel's avatar
Caillat Michel committed
793
  _graticule_1.setMap(_map_1);
794

Caillat Michel's avatar
Caillat Michel committed
795
  _lastClickMarker_1 = new LastClickMarker(_map_1);
796

Caillat Michel's avatar
Caillat Michel committed
797
798
799
800
801
802
803
  this.markLastClickInSlice = function (coordinate) {
    _lastClickMarker_1.setPositionAndFluxDensity(
      {
        "coordinate": coordinate,
        "chanIndex": _sliceIndex,
        "RADEC": this.getRADEC(coordinate),
        "fluxDensity": "t.b.d."
804
      }
Caillat Michel's avatar
Caillat Michel committed
805
806
    );
  };
807

Caillat Michel's avatar
Caillat Michel committed
808
809
810
  this.setFluxDensityInPopup = function (density) {
    _lastClickMarker_1.setFluxDensity(density * unitRescale(_bunit), _sliceIndex);
  }
811

Caillat Michel's avatar
Caillat Michel committed
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
  /*
  ** The sum of slices display
  */
  _projection_2 = new ol.proj.Projection({
    code: 'local_image',
    units: 'pixels',
    extent: _extent,
    worldExtent: [..._extent]
  });

  _map_controls_2 = [
    new ol.control.MousePosition({
      className: 'custom-mouse-position',
      target: document.getElementById('external_mouse_position_1'),
      undefinedHTML: '',
      coordinateFormat: _coordinateFormatType_1
    }),
    new ol.control.MousePosition({
      className: 'custom-mouse-position',
      target: document.getElementById('external_mouse_position_2'),
      undefinedHTML: '',
      coordinateFormat: _coordinateFormatType_2
    }),
    new ol.control.FullScreen()
  ];
837

838
      <%if (useSAMP) {%>
Caillat Michel's avatar
Caillat Michel committed
839
840
    let _sAMPPNGPublishControl_2 = new SAMPPNGPublishControl();
    _sAMPPNGPublishControl_2.setHandler(sAMPPublisher.sendPNGSummedSlices);
841
842
  <%}%>

Caillat Michel's avatar
Caillat Michel committed
843
844
845
846
847
848
849
850
    _map_2 = new ol.Map({
      target: _divSummedSlices,
      view: new ol.View({
        projection: _projection_2,
        center: ol.extent.getCenter(_extent),
        resolution: hidden_canvas_2.width / 512
      })
        <%if(useSAMP) {%>
851
  ,
Caillat Michel's avatar
Caillat Michel committed
852
853
854
855
          controls: ol.control.defaults().extend([
            _sAMPPNGPublishControl_2
          ])
            <%}%>
856
857
      });

Caillat Michel's avatar
Caillat Michel committed
858
859
860
861
862
  document.getElementById("summedslices").addEventListener("mouseenter", function () {
    _map_controls_2.forEach(function (ctrl) {
      _map_2.addControl(ctrl);
    });
  });
863

Caillat Michel's avatar
Caillat Michel committed
864
865
866
867
868
  document.getElementById("summedslices").addEventListener("mouseleave", function () {
    _map_controls_2.forEach(function (ctrl) {
      _map_2.removeControl(ctrl);
    });
  });
869

Caillat Michel's avatar
Caillat Michel committed
870
871
872
873
874
875
876
877
878
879
880
881
882
883
  // Here we have the stuff to generate reticule on summedslices.
  //
  _graticule_2 = new ol.Graticule({
    showLabels: true,
    strokeStyle: new ol.style.Stroke({
      color: 'rgba(0,0,0,0.9)',
      width: 1,
      lineDash: [0.5, 4]
    }),
    targetSize: 100,
    lonLabelFormatter: _raLabelFormatter.format,
    latLabelFormatter: _decLabelFormatter.format,
    decLabelPosition: 0.92
  });
884

Caillat Michel's avatar
Caillat Michel committed
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
  _graticule_2.setMap(_map_2);

  // Here we have all the stuff to create boxes on summedslices
  // and trigger the update of the spectrum of sums of pixels per slice
  _box_source_2 = new ol.source.Vector({ wrapX: false });
  _box_layer_2 = new ol.layer.Vector({ source: _box_source_2 });

  _select_2 = new ol.interaction.Select({ condition: ol.events.pointerMove });
  _select_2.on('select', function (e) {
    console.log(
      e.target.getFeatures().getLength() +
      ' selected features (last operation selected ' + e.selected.length +
      ' and deselected ' + e.deselected.length + ' features)');
    if (e.selected.length) {
      _selected_box_2 = e.selected[0];
      var extent = e.selected[0].getGeometry().getExtent();
      summedPixelsSpectrumViewer.plot(extent[0], extent[2], extent[1], extent[3]);
      ROI.iRA0 = Math.round(extent[0]);
      ROI.iRA1 = Math.round(extent[2]);
      ROI.iDEC0 = Math.round(extent[1]);
      ROI.iDEC1 = Math.round(extent[3]);
    }
  });
908

Caillat Michel's avatar
Caillat Michel committed
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
  _map_2.addInteraction(_select_2);

  _dragBox_2 = new ol.interaction.DragBox();
  _dragBox_2.on('boxend', function () {
    var extent = _dragBox_2.getGeometry().getExtent();
    var tl = ol.extent.getTopLeft(extent);
    var tr = ol.extent.getTopRight(extent);
    var br = ol.extent.getBottomRight(extent);
    var bl = ol.extent.getBottomLeft(extent);

    var corners = []
    corners.push(tl, tr, br, bl, tl);

    var ln = new ol.geom.LinearRing(corners);
    var style = {
      strokeColor: "#00FF00",
      strokeOpacity: 1,
      strokewidth: 3,
      fillColor: "#00FF00",
      fillOpacity: 0.8,
    };
    var pf = new ol.Feature({ geometry: new ol.geom.Polygon([corners]) });
    _box_source_2.addFeature(pf);
  })

  _map_2.addInteraction(_dragBox_2);

  let _updateSliceWithPOST = function () {
    console.log('_updateSliceWithPOST: entering');
    showLoaderAction(true);
    ittName = $('#ITTSelector').find(':selected').text().trim()
    lutName = $('#LUTSelector').find(':selected').text().trim()
    vmName = $('#VideoModeSelector').find(':selected').text().trim()
    $.post('png', { 'si': _sliceIndex, 'relFITSFilePath': _relFITSFilePath, 'ittName': ittName, 'lutName': lutName, 'vmName': vmName }).done(
      function (resp) {
        console.log("$.post('/png', {'si': _sliceIndex, 'relFITSFilePath': _relFITSFilePath}).done(: entering");
        if (resp["status"] == false) {
          alert("Something went wrong during the generation of the image. The message was '" + resp["message"] + "'");
        }
        else {
          _data_steps_1 = resp["result"]["data_steps"];
          if (_instrume == "SITELLE") {
            for (var k in _data_steps_1) {
              if (_data_steps_1.hasOwnProperty(k)) {
                _data_steps_1[k] /= Math.abs(3600. * 3600. * _cdelt1 * _cdelt2);
954
955
              }
            }
956
          }
Caillat Michel's avatar
Caillat Michel committed
957
958
959
960
          var path_to_png = resp["result"]["path_to_png"];
          if (_im_layer_1) {
            _map_1.removeLayer(_im_layer_1);
          }
961

Caillat Michel's avatar
Caillat Michel committed
962
963
964
965
966
967
968
          _im_layer_1 = new ol.layer.Image({
            source: new ol.source.ImageStatic({
              url: "<%=urlRoot%>" + "/" + path_to_png,
              projection: _projection_1,
              imageExtent: _extent,
              imageLoadFunction: _imageLoadFunction_1
            })
969
          });
Caillat Michel's avatar
Caillat Michel committed
970
          _map_1.addLayer(_im_layer_1);
971
        }
Caillat Michel's avatar
Caillat Michel committed
972
973
974
975
976
  <% if (useSAMP) {%>
          sAMPPublisher.setSliceRelPNGPath(path_to_png);
  <%}%>
          showLoaderAction(false);
        console.log("$.post('/png', {'si': _sliceIndex, 'path': _path}).done(: exiting");
977
      }
Caillat Michel's avatar
Caillat Michel committed
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
    )
    console.log('_updateSliceWithPOST: exiting');
  };

  let _displaySlice = function (relFITSFilePath, sliceIndex) {
    console.log('_displaySlice : entering');
    _sliceIndex = sliceIndex;
    _relFITSFilePath = relFITSFilePath;

    _updateSliceWithPOST();
    console.log('_displaySlice : exiting');
  };

  let _updateSummedSlicesWithPOST = function () {
    console.log("_updateSummedSlicesWithPOST : entering");
    showLoaderAction(true);
    ittName = $('#ITTSelector').find(':selected').text().trim()
    lutName = $('#LUTSelector').find(':selected').text().trim()
    vmName = $('#VideoModeSelector').find(':selected').text().trim()
    $.post('sumpng', { 'si0': _sliceIndex0, 'si1': _sliceIndex1, 'relFITSFilePath': _relFITSFilePath, 'ittName': ittName, 'lutName': lutName, 'vmName': vmName }).done(
      function (resp) {
        console.log("$.post('/sumpng', {'si0': _sliceIndex0, 'si1': _sliceIndex1, 'relFITSFilePath': relFITSFilePath}).done() : entering");
        if (resp["status"] == false) {