Skip to content

Commit

Permalink
Merge pull request #42 from desihub/disp-models
Browse files Browse the repository at this point in the history
Summary of new features from this branch:
- display "second model" which can be the Nth best fit, or standard templates
- table with redrock results shows N best fits
- ivar-weighting when smoothing
- imaging cross-hair
- line list
- several bug fixes + code restructure
- new widgets (eg "standard VI comments") + widget layout
  • Loading branch information
armengau committed Jun 12, 2020
2 parents 6a54012 + 60f418d commit f8eb1bf
Show file tree
Hide file tree
Showing 19 changed files with 1,350 additions and 625 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ distribute-*.tar.gz
.DS_Store

# data directory
data
#data

# Generated HTML
plotframes.html
20 changes: 20 additions & 0 deletions js/CSVtoArray.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Utility javascript function
// (Standalone module)

// Return array of string values
function CSVtoArray(text) {
var re_value = /(?!\s*$)\s*(?:'([^'\\]*(?:\\[\S\s][^'\\]*)*)'|"([^"\\]*(?:\\[\S\s][^"\\]*)*)"|([^,'"\s\\]*(?:\s+[^,'"\s\\]+)*))\s*(?:,|$)/g
var a = []
text.replace(re_value, // "Walk" the string using replace with callback.
function(m0, m1, m2, m3) {
// Remove backslash from \' in single quoted values.
if (m1 !== undefined) a.push(m1.replace(/\\'/g, "'"))
// Remove backslash from \" in double quoted values.
else if (m2 !== undefined) a.push(m2.replace(/\\"/g, '"'))
else if (m3 !== undefined) a.push(m3)
return '' // Return empty string.
})
// Handle special case of empty last value.
if (/,\s*$/.test(text)) a.push('')
return a
}
15 changes: 15 additions & 0 deletions js/adapt_plotrange.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Utility javascript function used in CustomJS callbacks
// (Standalone module)

function adapt_plotrange(pmin, pmax, data) {
// Used to adapt plotting range to a data vector

// copy before sorting to not impact original, and filter out NaN
var dx = data.slice().filter(Boolean)
dx.sort()
var imin = Math.floor(pmin * dx.length)
var imax = Math.floor(pmax * dx.length)

return [dx[imin], dx[imax]]
}

77 changes: 0 additions & 77 deletions js/autosave_vi.js

This file was deleted.

71 changes: 71 additions & 0 deletions js/coadd_brz_cameras.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Utility javascript function used in CustomJS callbacks
// Requires to include functions in: interp_grid.js

function coadd_brz_cameras(wave_in, flux_in, noise_in) {
// Camera-coadd brz spectra.
// each "_in" must have 3 entries (brz)
// TODO handle case of no noise

// Find b,r,z ordering in input arrays
var wave_start = [wave_in[0][0], wave_in[1][0], wave_in[2][0]]
var i_b = wave_start.indexOf(Math.min.apply(Math, wave_start))
var i_z = wave_start.indexOf(Math.max.apply(Math, wave_start))
var i_r = 1
for (var i=0; i<3; i++) {
if ( (i_b != i) && (i_z != i) ) i_r = i
}

var wave_out = []
var flux_out = []
var noise_out = []
var margin = 20
for (var i=0; i<wave_in[i_b].length; i++) { // b
if (wave_in[i_b][i] < wave_in[i_b][wave_in[i_b].length-1] - margin) {
wave_out.push(wave_in[i_b][i])
flux_out.push(flux_in[i_b][i])
noise_out.push(noise_in[i_b][i])
}
}
var the_lim = wave_out[wave_out.length-1]
for (var i=0; i<wave_in[i_r].length; i++) { // r
if ( (wave_in[i_r][i] < wave_in[i_r][wave_in[i_r].length-1] - margin) && (wave_in[i_r][i] > the_lim)) {
wave_out.push(wave_in[i_r][i])
flux_out.push(flux_in[i_r][i])
noise_out.push(noise_in[i_r][i])
}
}
the_lim = wave_out[wave_out.length-1]
for (var i=0; i<wave_in[i_z].length; i++) { // z
if (wave_in[i_z][i] > the_lim) {
wave_out.push(wave_in[i_z][i])
flux_out.push(flux_in[i_z][i])
noise_out.push(noise_in[i_z][i])
}
}
for (var i=0; i<wave_out.length; i++) { // combine in overlapping regions
var b1 = -1
var b2 = -1
if ( (wave_out[i] > wave_in[i_r][0]) && (wave_out[i] < wave_in[i_b][wave_in[i_b].length-1]) ) { // br
b1 = 0
b2 = 1
}
if ( (wave_out[i] > wave_in[i_z][0]) && (wave_out[i] < wave_in[i_r][wave_in[i_r].length-1]) ) { // rz
b1 = 1
b2 = 2
}
if (b1 != -1) {
var phi1 = interp_grid(wave_out[i], wave_in[b1], flux_in[b1])
var noise1 = interp_grid(wave_out[i], wave_in[b1], noise_in[b1])
var phi2 = interp_grid(wave_out[i], wave_in[b2], flux_in[b2])
var noise2 = interp_grid(wave_out[i], wave_in[b2], noise_in[b2])
if ( noise1 > 0 && noise2 > 0 ) {
var iv1 = 1/(noise1*noise1)
var iv2 = 1/(noise2*noise2)
var iv = iv1+iv2
noise_out[i] = 1/Math.sqrt(iv)
flux_out[i] = (iv1*phi1+iv2*phi2)/iv
}
}
}
return [wave_out, flux_out, noise_out]
}
49 changes: 0 additions & 49 deletions js/download_vi.js

This file was deleted.

29 changes: 29 additions & 0 deletions js/interp_grid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Utility javascript functions used in CustomJS callbacks
// (Standalone module)

function index_dichotomy(point, grid) {
// Find nearest index in grid, left from point; use dichotomy method
if ( point < grid[0] ) return 0
if ( point > grid[grid.length-1] ) return grid.length-2
var i_left = 0
var i_center = 0
var i_right = grid.length-1
while ( i_right - i_left != 1) {
i_center = i_left + Math.floor((i_right-i_left)/2)
if ( point >= grid[i_center] ) {
i_left = i_center
} else {
i_right = i_center
}
}
return i_left
}

function interp_grid(xval, xarr, yarr) {
// Basic linear interpolation of [xarr,yarr] on point xval
var index = index_dichotomy(xval, xarr)
var a = (yarr[index+1] - yarr[index])/(xarr[index+1] - xarr[index])
var b = yarr[index]-a*xarr[index]
var yval = a*xval+b
return yval
}
26 changes: 5 additions & 21 deletions js/recover_autosave_vi.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,18 @@
// CustomJS, recover auto-saved VI infos from browser
// recover_vi_callback() CustomJS
// Requires to include functions in: CSVtoArray.js

// Recover auto-saved VI infos from browser's localStorage
// args = title, cds_targetinfo, vi_file_fields, ifiber,
// vi_comment_input, vi_name_input, vi_class_input, vi_issue_input, vi_issue_slabels, vi_class_labels

// Return array of string values
function CSVtoArray(text) {
var re_value = /(?!\s*$)\s*(?:'([^'\\]*(?:\\[\S\s][^'\\]*)*)'|"([^"\\]*(?:\\[\S\s][^"\\]*)*)"|([^,'"\s\\]*(?:\s+[^,'"\s\\]+)*))\s*(?:,|$)/g
var a = []
text.replace(re_value, // "Walk" the string using replace with callback.
function(m0, m1, m2, m3) {
// Remove backslash from \' in single quoted values.
if (m1 !== undefined) a.push(m1.replace(/\\'/g, "'"))
// Remove backslash from \" in double quoted values.
else if (m2 !== undefined) a.push(m2.replace(/\\"/g, '"'))
else if (m3 !== undefined) a.push(m3)
return '' // Return empty string.
})
// Handle special case of empty last value.
if (/,\s*$/.test(text)) a.push('')
return a
}

if (title in localStorage) {
var recovered_csv = localStorage.getItem(title)
var recovered_entries = recovered_csv.split("\n")
for (var j=0; j<recovered_entries.length; j++) {
var row = CSVtoArray(recovered_entries[j])
var i_spec = Number(row[0])
for (var k=1; k<row.length; k++) {
if (vi_file_fields[k-1][1].includes('VI')) {
if (vi_file_fields[k-1][1].includes('VI')) {
cds_targetinfo.data[vi_file_fields[k-1][1]][i_spec] = row[k]
}
}
Expand All @@ -46,4 +31,3 @@ if (title in localStorage) {
}
cds_targetinfo.change.emit()
}

22 changes: 22 additions & 0 deletions js/reset_plotrange.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// CustomJS, callback for the "Reset X-Y range" button
// - Requires to include function in: adapt_plotrange.js
// - args = fig, xmin, xmax, spectra

// x-range : use fixed x-range determined once for all
fig.x_range.start = xmin
fig.x_range.end = xmax

var ymin = 0.0
var ymax = 0.0
for (var i=0; i<spectra.length; i++) {
var data = spectra[i].data
var tmp = adapt_plotrange(0.01, 0.99, data['plotflux'])
ymin = Math.min(ymin, tmp[0])
ymax = Math.max(ymax, tmp[1])
}
if(ymin<0) {
fig.y_range.start = ymin * 1.4
} else {
fig.y_range.start = ymin * 0.6
}
fig.y_range.end = ymax * 1.4

0 comments on commit f8eb1bf

Please sign in to comment.