Source: public/javascript/olqv.js

  1. import { velocity2Redshift, redshift2Velocity, getRadiusInDegrees } from "./modules/utils.js";
  2. import { withSAMP, dataPaths, URL_ROOT, header, default_lut_index } from './modules/init.js';
  3. import { SpectroscopyUI, SpectroscopyQuery, SpectroscopyFormatter } from './modules/olqv_spectro.js';
  4. import { FITS_HEADER } from './modules/fitsheader.js';
  5. import { DEFAULT_INTENSITY, DEFAULT_EUP, SPECTRO_COLLECTIONS } from "./modules/constants.js";
  6. //import { DisplayVotable } from "./modules/samp_utils.js";
  7. import { FITSHeaderTable, LicensePanel } from "./modules/page_overlay.js";
  8. import { getViewLinker } from "./modules/olqv_linkedviews.js";
  9. import { CubeSmoother } from "./modules/olqv_smooth.js";
  10. import { SourceTable } from "./modules/olqv_ned.js";
  11. import { MarkerList } from "./modules/olqv_markers.js";
  12. import { getVelocityField, getRedshiftField, showLoaderAction } from "./modules/domelements.js";
  13. let viewLinker;
  14. // list of sources downloaded from NED catalog
  15. let sourceTable;
  16. // samp connection buttons container
  17. let publishSpectrumDiv = $("#publish-spectrum");
  18. // get user input from spectroscopy form
  19. let spectroUI = new SpectroscopyUI();
  20. // perform spectroscopy requests
  21. let spectroq = new SpectroscopyQuery();
  22. // when switching modal display mode
  23. $('#ned-modal').on('show.bs.modal', function(event) {
  24. let selectRadius = document.getElementById("ned-search-radius");
  25. let radius = getRadiusInDegrees(selectRadius.options[selectRadius.selectedIndex].value, FITS_HEADER);
  26. let Hnot = parseFloat(document.getElementById("lines-hnot").value);
  27. let OmegaM = parseFloat(document.getElementById("lines-omegam").value);
  28. sourceTable.getSources(header["CRVAL1"], header["CRVAL2"], radius, Hnot, OmegaM);
  29. });
  30. // synchronizes velocity and redshift values when user changes it manually
  31. getVelocityField().addEventListener("keyup", function() {
  32. const v = getVelocityField().value;
  33. if (v.trim() !== "") {
  34. spectroUI.setVelocity(v);
  35. spectroUI.setRedshift(velocity2Redshift(v));
  36. } else {
  37. spectroUI.setVelocity("");
  38. spectroUI.setRedshift("");
  39. }
  40. });
  41. getRedshiftField().addEventListener("keyup", function() {
  42. const z = getRedshiftField().value;
  43. if (z.trim() !== "") {
  44. spectroUI.setRedshift(z);
  45. spectroUI.setVelocity(redshift2Velocity(z));
  46. } else {
  47. spectroUI.setRedshift("");
  48. spectroUI.setVelocity("");
  49. }
  50. });
  51. /* opens 3D visualization page, deactivated for now
  52. document.getElementById("show-3d-model").addEventListener("click", () => {
  53. window.open("getYtObj?relFITSFilePath=" + dataPaths.relFITSFilePath +
  54. "&iRA0=" + viewLinker.summedSlicesImage.ROI.iRA0 + "&iRA1=" + viewLinker.summedSlicesImage.ROI.iRA1 +
  55. "&iDEC0=" + viewLinker.summedSlicesImage.ROI.iDEC0 + "&iDEC1=" + viewLinker.summedSlicesImage.ROI.iDEC1 +
  56. "&iFREQ0=" + viewLinker.summedSlicesImage.ROI.iFREQ0 + "&iFREQ1=" + viewLinker.summedSlicesImage.ROI.iFREQ1);
  57. return false;
  58. });
  59. */
  60. /**
  61. * Removes the selected box on the summedslice viewer when user push X key on keyboard
  62. *
  63. * @param {Event} evt
  64. */
  65. var deleteFeature = function(evt) {
  66. console.log("var deleteFeature = function(evt){ : entering");
  67. if (evt.keyCode == 88) {
  68. viewLinker.forgetSelectedBox();
  69. }
  70. console.log("var deleteFeature = function(evt){ : exiting");
  71. };
  72. function changeDatabase(spectroq, spectroUI, dbname) {
  73. spectroq.getMetadata(function(metadata) { spectroUI.initSpeciesSelection(dbname, metadata) });
  74. document.getElementById("intensity").value = DEFAULT_INTENSITY;
  75. document.getElementById("intensityrange").value = DEFAULT_INTENSITY;
  76. }
  77. /**
  78. * Changes list of spectral lines displayed in table next to the spectrum.
  79. * Only a few lines are displayed at a time to avoid list becoming too long.
  80. *
  81. * @param {int} newGroupIndex index of displayed lines group
  82. */
  83. function changeLinesGroup(newGroupIndex) {
  84. spectroUI.changeGroupAction(newGroupIndex, () => {
  85. viewLinker.summedPixelsSpectrumViewer.linePlotter.plotTransitionGroup(newGroupIndex);
  86. spectroUI.showEnergyGroupLines(viewLinker.summedPixelsSpectrumViewer.linePlotter.transitionGroups[newGroupIndex]);
  87. });
  88. }
  89. $(document).ready(function() {
  90. console.log("$( document ).ready(function() {: entering");
  91. // Set up everything required to fill and display the FITS header.
  92. let FITSHDR = new FITSHeaderTable(document.getElementById("fitshdr"), header);
  93. //Software licenses
  94. let Licences = new LicensePanel(document.getElementById("licences"));
  95. // local db is selected by default for spectroscopy
  96. spectroUI.setDefaultDatabase();
  97. // fill species autocomplete accordingly
  98. spectroq.getMetadata(function(metadata) { spectroUI.initSpeciesSelection("local", metadata) });
  99. spectroUI.disable();
  100. // by default spectro UI checkbox is hidden
  101. spectroUI.hideToggler();
  102. // check that there are lines in spectro db
  103. // UI remains hidden if nothing is found
  104. spectroq.getStatuses(spectroUI.toggleDatabaseSelector);
  105. // remove box selection in slice viewer
  106. document.addEventListener('keydown', deleteFeature, false);
  107. $('#LUT-selector').prop('selectedIndex', default_lut_index);
  108. // set default values for z and spectroscopy
  109. spectroUI.clearRedshift();
  110. spectroUI.clearVelocity();
  111. spectroUI.setIntensity(DEFAULT_INTENSITY);
  112. spectroUI.setEnergyUp(DEFAULT_EUP);
  113. showLoaderAction(true);
  114. $("#spectroscopy-menu").className = "hidden";
  115. $("#toggle-lines-search").checked = false;
  116. // hide/show spectroscopy search form
  117. $("#toggle-lines-search").on("click", function() {
  118. if (document.getElementById("toggle-lines-search").checked) {
  119. spectroUI.showSpectroscopyMenu();
  120. } else {
  121. spectroUI.hideSpectroscopyMenu();
  122. }
  123. });
  124. // buttons to navigate list of spectral lines
  125. $("#goto-previous-group").on("click", () => {
  126. changeLinesGroup(spectroUI.currentGroup - 1);
  127. });
  128. $("#goto-next-group").on("click", () => {
  129. changeLinesGroup(spectroUI.currentGroup + 1);
  130. });
  131. $("#goto-last-group").on("click", () => {
  132. changeLinesGroup(viewLinker.summedPixelsSpectrumViewer.linePlotter.transitionGroups.length - 1);
  133. });
  134. $("#goto-first-group").on("click", () => {
  135. changeLinesGroup(0);
  136. });
  137. // user select a datasource
  138. $("#localdatasource").on("click", function() {
  139. spectroUI.disable();
  140. spectroq.getMetadata(function(metadata) { spectroUI.initSpeciesSelection("local", metadata) });
  141. changeDatabase(spectroq, spectroUI, SPECTRO_COLLECTIONS.local);
  142. });
  143. $("#ismdatasource").on("click", function() {
  144. spectroUI.enable();
  145. changeDatabase(spectroq, spectroUI, SPECTRO_COLLECTIONS.ism);
  146. });
  147. $("#ismcsmdatasource").on("click", function() {
  148. spectroUI.enable();
  149. changeDatabase(spectroq, spectroUI, SPECTRO_COLLECTIONS.ismcsm);
  150. });
  151. $("#jpldatasource").on("click", function() {
  152. spectroUI.enable();
  153. changeDatabase(spectroq, spectroUI, SPECTRO_COLLECTIONS.jpl);
  154. });
  155. $("#cdmsdatasource").on("click", function() {
  156. spectroUI.enable();
  157. changeDatabase(spectroq, spectroUI, SPECTRO_COLLECTIONS.cdms);
  158. });
  159. // user wants to display all lines for a dataset
  160. document.getElementById("selectedspecies").addEventListener("getdataset", (event) => {
  161. spectroq.getDataset(event.detail.db, event.detail.dataset, (result) => {
  162. const obsFreqMin = viewLinker.summedPixelsSpectrumViewer.summedPixelsSpectrumChart.obsFreqMin;
  163. const obsFreqMax = viewLinker.summedPixelsSpectrumViewer.summedPixelsSpectrumChart.obsFreqMax;
  164. if (event.detail.db !== SPECTRO_COLLECTIONS.local) {
  165. let shift = spectroUI.getShift();
  166. const formatter = new SpectroscopyFormatter();
  167. const content = formatter.linesTofile(result, shift["shiftValue"], shift["shiftType"], obsFreqMin, obsFreqMax);
  168. document.getElementById("spetro-modal-lines").innerText = content;
  169. $('#spectro-modal').modal('show');
  170. } else {
  171. alert("Not available for local database");
  172. }
  173. })
  174. });
  175. $("#spectrum-info-title").html(FITS_HEADER.getSpectrumTitle());
  176. $("#cube-infos").html(FITS_HEADER.getFitsSummary());
  177. $('#show-fits-header').click(function() {
  178. FITSHDR.show()
  179. });
  180. $('#show-license').click(function() {
  181. Licences.show()
  182. });
  183. // zoom buttons for both spectra
  184. $("#zoom-in").on('click', function() {
  185. let factor = Math.abs((viewLinker.spectrumViewer.spectrumChart.xAxis[0].min - viewLinker.spectrumViewer.spectrumChart.xAxis[0].max) * 0.2);
  186. let minVal = viewLinker.spectrumViewer.spectrumChart.xAxis[0].min + factor;
  187. let maxVal = viewLinker.spectrumViewer.spectrumChart.xAxis[0].max - factor;
  188. viewLinker.spectrumViewer.spectrumChart.xAxis[0].setExtremes(minVal, maxVal);
  189. });
  190. $("#zoom-out").on('click', function() {
  191. let factor = Math.abs((viewLinker.spectrumViewer.spectrumChart.xAxis[0].min - viewLinker.spectrumViewer.spectrumChart.xAxis[0].max) * 0.2);
  192. let minVal = viewLinker.spectrumViewer.spectrumChart.xAxis[0].min - factor;
  193. let maxVal = viewLinker.spectrumViewer.spectrumChart.xAxis[0].max + factor;
  194. viewLinker.spectrumViewer.spectrumChart.xAxis[0].setExtremes(minVal, maxVal);
  195. });
  196. $("#zoom-reset").on('click', () => {
  197. viewLinker.spectrumViewer.spectrumChart.xAxis[0].setExtremes(undefined, undefined);
  198. });
  199. // checks conformity of number of channels to smooth
  200. $("#get-nbox").keyup(function() {
  201. var nbox = $(this).val();
  202. if (nbox !== "" && isNaN(parseInt(nbox)))
  203. alert("nbox must be a number");
  204. });
  205. $("#get-smooth-cube").on('click', function() {
  206. showLoaderAction(true);
  207. let cubeSmoother = new CubeSmoother(viewLinker, dataPaths.relFITSFilePath);
  208. $.when(cubeSmoother.createSmoothedCube(parseInt($("#get-nbox").val()))).done(function() {
  209. var url = URL_ROOT + cubeSmoother.getSmoothedCubePath();
  210. showLoaderAction(false);
  211. window.open(url, '_blank');
  212. });
  213. });
  214. $("#view-smooth-cube").on('click', function() {
  215. showLoaderAction(true);
  216. let cubeSmoother = new CubeSmoother(viewLinker, dataPaths.relFITSFilePath);
  217. $.when(cubeSmoother.createSmoothedCube(parseInt($("#get-nbox").val()))).done(function() {
  218. var url = URL_ROOT + "/visit/?relFITSFilePath=//SMOOTH" + cubeSmoother.getSmoothedCubePath();
  219. showLoaderAction(false);
  220. window.open(url);
  221. });
  222. });
  223. $("#slice").on('mouseenter', function() {
  224. viewLinker.singleSliceImage._map_controls.forEach(function(ctrl) {
  225. viewLinker.singleSliceImage._map.addControl(ctrl);
  226. });
  227. });
  228. $("#slice").on('mouseleave', function() {
  229. viewLinker.singleSliceImage._map_controls.forEach(function(ctrl) {
  230. viewLinker.singleSliceImage._map.removeControl(ctrl);
  231. });
  232. });
  233. $("#summed-slices").on("mouseenter", function() {
  234. viewLinker.summedSlicesImage._map_controls.forEach(function(ctrl) {
  235. viewLinker.summedSlicesImage._map.addControl(ctrl);
  236. });
  237. });
  238. $("#summed-slices").on("mouseleave", function() {
  239. viewLinker.summedSlicesImage._map_controls.forEach(function(ctrl) {
  240. viewLinker.summedSlicesImage._map.removeControl(ctrl);
  241. });
  242. });
  243. // Shows SAMP connector logo if SAMP is activated
  244. if (!withSAMP) {
  245. $(publishSpectrumDiv).css("display", "none");
  246. $('#samp-img').css("display", "none");
  247. }
  248. /**
  249. Get RA/DEC ranges corresponding to opened fits file
  250. response format is a pair of pairs of float values `[[ra0, dec0], [ra1, dec1], [ra2, dec2]]`
  251. expressing angles in decimal degrees where :
  252. * `ra0` corresponds to the index 0 along the RA axis.
  253. * `ra1` corresponds to the index NAXIS1-1 along the RA axis.
  254. * `dec0` corresponds to the index 0 along the DEC axis.
  255. * `dec1` corresponds to the index NAXIS2-1 along the DEC axis.
  256. * `ra2` corresponds to the index max(NAXIS1, NAXIS2)-1 along the RA axis.
  257. * `dec2` corresponds to the index max(NAXIS1, NAXIS2)-1 along the DEC axis.
  258. */
  259. $.post("", {
  260. "method": "RADECRangeInDegrees",
  261. "relFITSFilePath": dataPaths.relFITSFilePath,
  262. "sessionID": 0
  263. }).done(function(resp) {
  264. console.log('$.post("", {"method": "RADECRangeInDegrees", "relFITSFilePath": dataPaths.relFITSFilePath}).done(function (resp) { : entering');
  265. let markerList = new MarkerList("input-markers", "show-markers", "clear-markers");
  266. //ned data selection
  267. sourceTable = new SourceTable('ned-data', 'ned-modal-title', spectroUI);
  268. sourceTable.addListener(markerList);
  269. viewLinker = getViewLinker(resp.data["result"], spectroUI, sourceTable, markerList);
  270. $('#rccap').click(function() {
  271. viewLinker.refresh()
  272. });
  273. console.log('$.post("", {"method": "RADECRangeInDegrees", "relFITSFilePath": dataPaths.relFITSFilePath}).done(function(resp) {: exiting');
  274. });
  275. console.log("$( document ).ready(function() {: exiting");
  276. });