Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Companion Relationships table #156

Merged
merged 6 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 70 additions & 67 deletions simple_app/plots.py

Large diffs are not rendered by default.

320 changes: 224 additions & 96 deletions simple_app/simple_callbacks.js
Original file line number Diff line number Diff line change
@@ -1,164 +1,292 @@
function dropdownx_js(fulldata, fullplot, xrange, xbut, xaxis, thisplot) {
function dropdown_x_js(full_data, full_plot, x_range, x_button, x_axis, this_plot) {

// find the selected dropdown option
for (let i = 0; i < this.options.length; i++) {

if (this.value === this.options[i][0]) {

this.label = this.options[i][1];
break;

}
}
let fullvalue = this.value;
if (fullvalue.includes('(')) {
fullvalue = fullvalue.substr(0, fullvalue.indexOf('('));

// work out what mag/colour is being represented by the label
let full_value = this.value;

if (full_value.includes('(')) {

full_value = full_value.substr(0, full_value.indexOf('('));

}
let newx = fulldata[fullvalue];
let newnewx = [];
for (let i = 0; i < newx.length; i++) {
let val = newx[i];

// change what is being shown as the x data
let new_x = full_data[full_value];
let updated_x = [];

for (let i = 0; i < new_x.length; i++) {

let val = new_x[i];

if (isNaN(val)) {

continue;

}
newnewx.push(val);
updated_x.push(val);
}
newx = newnewx;
let minx = Math.min(...newx);
let maxx = Math.max(...newx);
if (xbut.active) {
xrange.start = maxx;
xrange.end = minx;

new_x = updated_x;

// rescale the x axis to match the data
let min_x = Math.min(...new_x);
let max_x = Math.max(...new_x);

if (x_button.active) {

x_range.start = max_x;
x_range.end = min_x;

}

else {
xrange.start = minx;
xrange.end = maxx;

x_range.start = min_x;
x_range.end = max_x;

}

try {
thisplot.glyph.x.field = this.value;
thisplot.glyph.change.emit();

this_plot.glyph.x.field = this.value;
this_plot.glyph.change.emit();

} catch ( error ) {}
fullplot.glyph.x.field = fullvalue;
xaxis.axis_label = this.label;
fullplot.glyph.change.emit();

full_plot.glyph.x.field = full_value;
x_axis.axis_label = this.label;
full_plot.glyph.change.emit();

}

function dropdowny_js(fulldata, fullplot, yrange, ybut, yaxis, thisplot) {
function dropdown_y_js(full_data, full_plot, y_range, y_button, y_axis, this_plot) {

// find the selected dropdown option
for (let i = 0; i < this.options.length; i++) {

if (this.value === this.options[i][0]) {

this.label = this.options[i][1];
break;

}
}
let fullvalue = this.value;
if (fullvalue.includes('(')) {
fullvalue = fullvalue.substr(0, fullvalue.indexOf('('));

// work out what mag/colour is being represented by the label
let full_value = this.value;

if (full_value.includes('(')) {
full_value = full_value.substr(0, full_value.indexOf('('));

}
let newy = fulldata[fullvalue];
let newnewy = [];
for (let i = 0; i < newy.length; i++) {
let val = newy[i];

// change what is being shown as the y data
let new_y = full_data[full_value];
let updated_y = [];

for (let i = 0; i < new_y.length; i++) {

let val = new_y[i];

if (isNaN(val)) {

continue;

}
newnewy.push(val);
updated_y.push(val);
}
newy = newnewy;
let miny = Math.min(...newy);
let maxy = Math.max(...newy);
if (ybut.active) {
yrange.start = maxy;
yrange.end = miny;

new_y = updated_y;

// rescale the y axis to match the data
let miny = Math.min(...new_y);
let maxy = Math.max(...new_y);

if (y_button.active) {

y_range.start = maxy;
y_range.end = miny;

}

else {
yrange.start = miny;
yrange.end = maxy;

y_range.start = miny;
y_range.end = maxy;

}

try {
thisplot.glyph.y.field = this.value;
thisplot.glyph.change.emit();

this_plot.glyph.y.field = this.value;
this_plot.glyph.change.emit();

} catch ( error ) {}
fullplot.glyph.y.field = fullvalue;
yaxis.axis_label = this.label;
fullplot.glyph.change.emit();

full_plot.glyph.y.field = full_value;
y_axis.axis_label = this.label;
full_plot.glyph.change.emit();

}

function button_flip(axrange) {
let newstart = axrange.end;
let newend = axrange.start;
axrange.start = newstart;
axrange.end = newend;
axrange.change.emit()
function button_flip(ax_range) {

// flip the start and end of the axis
let newstart = ax_range.end;
let newend = ax_range.start;
ax_range.start = newstart;
ax_range.end = newend;
ax_range.change.emit()

}

function normalisation_slider(spmin, spmax, cdslist) {
function mincheck (number) {
return number >= this.minpoint;
function normalisation_slider(spectra_min, spectra_max, cds_list) {

function min_check (number) {

// check if a value is greater than a minimum value
return number >= this.min_point;

}
function maxcheck (number) {
return number >= this.maxpoint;

function max_check (number) {

// check if a value is greater than a minimum value
return number >= this.max_point;

}

function median(numbers) {

// find the median of a set of numbers
const sorted = numbers.slice().sort((a, b) => a - b);
const middle = Math.floor(sorted.length / 2);

if (sorted.length % 2 === 0) {

return (sorted[middle - 1] + sorted[middle]) / 2;

}

return sorted[middle];

}
let minwave = this.value[0];
let maxwave = this.value[1];
if (maxwave - minwave < 0.01) {
maxwave = minwave + 0.01;

// pick minimum and maximum wavelengths to normalise by
let min_wave = this.value[0];
let max_wave = this.value[1];

if (max_wave - min_wave < 0.01) {

max_wave = min_wave + 0.01;

}
let cdslen = cdslist.length;
for (let i = 0; i < cdslen; i++) {
let source = cdslist[i];


// for every spectrum being plotted, perform normalisation by the median
let cds_len = cds_list.length;

for (let i = 0; i < cds_len; i++) {

// select initial values
let source = cds_list[i];
let data = source.data;
let wave = data.wave;
let wavestart = wave[0];
let waveend = wave[wave.length - 1];
let objminwave = minwave;
let objmaxwave = maxwave;
if (wavestart > minwave && waveend > minwave && wavestart > maxwave && waveend > maxwave) {
objminwave = wavestart;
objmaxwave = wavestart + 0.01;
let wave_start = wave[0];
let wave_end = wave[wave.length - 1];
let object_min_wave = min_wave;
let object_max_wave = max_wave;

// logic block of finding the minimum/maximum values to be checked, in case normalisation is outside regime
if (wave_start > min_wave && wave_end > min_wave && wave_start > max_wave && wave_end > max_wave) {

object_min_wave = wave_start;
object_max_wave = wave_start + 0.01;

}
else if (wavestart > minwave && waveend > minwave && wavestart < maxwave && waveend >= maxwave) {
objminwave = wavestart;
objmaxwave = maxwave;

else if (wave_start > min_wave && wave_end > min_wave && wave_start < max_wave && wave_end >= max_wave) {

object_min_wave = wave_start;
object_max_wave = max_wave;

}
else if (wavestart <= minwave && waveend > minwave && wavestart < maxwave && waveend >= maxwave) {
objminwave = minwave;
objmaxwave = maxwave;

else if (wave_start <= min_wave && wave_end > min_wave && wave_start < max_wave && wave_end >= max_wave) {

object_min_wave = min_wave;
object_max_wave = max_wave;

}
else if (wavestart <= minwave && waveend > minwave && wavestart < maxwave && waveend < maxwave) {
objminwave = minwave;
objmaxwave = waveend;

else if (wave_start <= min_wave && wave_end > min_wave && wave_start < max_wave && wave_end < max_wave) {

object_min_wave = min_wave;
object_max_wave = wave_end;

}
else if (wavestart < minwave && waveend < minwave && wavestart < maxwave && waveend < maxwave) {
objminwave = waveend - 0.01;
objmaxwave = waveend;

else if (wave_start < min_wave && wave_end < min_wave && wave_start < max_wave && wave_end < max_wave) {

object_min_wave = wave_end - 0.01;
object_max_wave = wave_end;

}
if (objmaxwave - objminwave < 0.01) {
objmaxwave = objminwave + 0.01

if (object_max_wave - object_min_wave < 0.01) {

object_max_wave = object_min_wave + 0.01

}

const comparisons = {
minpoint: objminwave,
maxpoint: objmaxwave

min_point: object_min_wave,
max_point: object_max_wave

}
let indmin = wave.findIndex(mincheck, comparisons);
let indmax = wave.findIndex(maxcheck, comparisons);
let fluxreg = data.flux.slice(indmin, indmax);

// perform the normalisation of the median for given region
let index_min = wave.findIndex(min_check, comparisons);
let index_max = wave.findIndex(max_check, comparisons);
let flux_region = data.flux.slice(index_min, index_max);
let med = median(data.flux);
if (fluxreg.length > 0) {
med = median(fluxreg);

if (flux_region.length > 0) {

med = median(flux_region);

}

for (let j = 0; j < wave.length; j++) {
data.normflux[j] = data.flux[j] / med;

data.normalised_flux[j] = data.flux[j] / med;

}

source.change.emit();
}
spmin.location = minwave;
spmax.location = maxwave;

// update values on slider itself
spectra_min.location = min_wave;
spectra_max.location = max_wave;

}

function reset_slider (spslide) {
spslide.value = [0.81, 0.82];
spslide.change.emit();
function reset_slider (spectra_slide) {

// resetting the spectral normalisation slider to default values 0.81--0.82um
spectra_slide.value = [0.81, 0.82];
spectra_slide.change.emit();

}
Loading
Loading