biprateep / prospect

DESI spectral visualization tools
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Auto recovery of spectral Line check boxes do not work #2

Closed biprateep closed 1 year ago

armengau commented 1 year ago

@biprateep Finally I had some time to dig in. For this issue, I made some modifs which I tested, seems to work.

I started a branch to your fork but can't write on your repo, so here are the modifs according to git diff:

1) on the recover_autosave code itself (first lines = just comments; main block of '+' = recover those 'spectral_feature_flag'

+++ b/py/prospect/js/recover_autosave_vi.js
@@ -3,7 +3,9 @@

 // Recover auto-saved VI infos from browser's localStorage
 // args = title, cds_metadata, output_file_fields, ispectrumslider,
-//   vi_comment_input, vi_name_input, vi_quality_input, vi_issue_input, vi_issue_slabels, vi_quality_labels
+//   vi_comment_input, vi_name_input, vi_quality_input, vi_issue_input, vi_issue_slabels,
+//   vi_quality_labels, spectral_features_emission_slabels, vi_spectral_feature_input_emission,
+//   spectral_features_absorption_slabels, vi_spectral_feature_input_absorption

 if (title in localStorage) {
     var recovered_csv = localStorage.getItem(title)
@@ -17,7 +19,6 @@ if (title in localStorage) {
             }
         }
         if (i_spec == ispectrumslider.value) { // update VI buttons for current spectrum
             vi_comment_input.value = cds_metadata.data['VI_comment'][i_spec] ;
             vi_name_input.value = cds_metadata.data['VI_scanner'][i_spec] ;
             vi_quality_input.active = vi_quality_labels.indexOf(cds_metadata.data['VI_quality_flag'][i_spec]) ; // -1 if nothing
@@ -28,6 +29,20 @@ if (title in localStorage) {
                 }
             }
             vi_issue_input.active = issues_on
+            var spectral_feature_flag_emission_on = [];
+            for (var i=0; i<spectral_features_emission_slabels.length; i++) {
+                if ( (cds_metadata.data['VI_spectral_feature_flag'][i_spec]).indexOf(spectral_features_emission_slabels[i]) >= 0 ) {
+                    spectral_feature_flag_emission_on.push(i);
+                }
+            }
+            vi_spectral_feature_input_emission.active = spectral_feature_flag_emission_on;
+            var spectral_feature_flag_absorption_on = [];
+            for (var i=0; i<spectral_features_absorption_slabels.length; i++) {
+                if ( (cds_metadata.data['VI_spectral_feature_flag'][i_spec]).indexOf(spectral_features_absorption_slabels[i]) >= 0 ) {
+                    spectral_feature_flag_absorption_on.push(i);
+                }
+            }
+            vi_spectral_feature_input_absorption.active = spectral_feature_flag_absorption_on;
         }
     }
     cds_metadata.change.emit()
armengau commented 1 year ago
  1. Add arguments to the "recover_vi_code" code:
+++ b/py/prospect/viewer/vi_widgets.py
@@ -378,6 +378,10 @@ class ViewerVIWidgets(object):
                 vi_issue_input=self.vi_issue_input,
                 vi_issue_slabels=self.vi_issue_slabels,
                 vi_quality_labels=self.vi_quality_labels,
+                vi_spectral_feature_input_emission=self.vi_spectral_feature_input_emission,
+                vi_spectral_feature_input_absorption=self.vi_spectral_feature_input_absorption,
+                spectral_features_emission_slabels=self.spectral_features_emission_slabels,
+                spectral_features_absorption_slabels=self.spectral_features_absorption_slabels,
             ),
             code=recover_vi_code,
         )
armengau commented 1 year ago
  1. To have this work, the "vi_storage" widget must be added after the "vi_spectral_features" (in the main routine, the order in which widgets are added is important!)
+++ b/py/prospect/viewer/__init__.py
@@ -373,9 +373,9 @@ def plotspectra(spectra, zcatalog=None, redrock_cat=None, notebook=False, html_d
     viewer_vi_widgets.add_vi_quality(viewer_cds, viewer_widgets)
     viewer_vi_widgets.add_vi_scanner(viewer_cds)
     viewer_vi_widgets.add_guidelines()
+    viewer_vi_widgets.add_vi_spectral_features(viewer_cds, viewer_widgets)
     viewer_vi_widgets.add_vi_storage(viewer_cds, viewer_widgets)
     viewer_vi_widgets.add_vi_table(viewer_cds)
-    viewer_vi_widgets.add_vi_spectral_features(viewer_cds, viewer_widgets)

     if (vi_countdown > 0) :
         viewer_vi_widgets.add_countdown(vi_countdown)
biprateep commented 1 year ago

Thanks @armengau I can confirm that these fixes worked. I copied your code to the commit https://github.com/biprateep/prospect/commit/c83c74edd6e99b4d936f0bf2843cd456f2f0bc92 . I added you as an author in case we need it in the future.