Skip to content

DM-7784-7963 #238

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

Merged
merged 3 commits into from
Dec 8, 2016
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
134 changes: 86 additions & 48 deletions src/firefly/js/templates/lightcurve/LcManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ import {dispatchPlotImage, visRoot, dispatchDeletePlotView,
dispatchChangeActivePlotView} from '../../visualize/ImagePlotCntlr.js';
import {getPlotViewById} from '../../visualize/PlotViewUtil.js';
import {getMultiViewRoot, dispatchReplaceViewerItems, getViewer} from '../../visualize/MultiViewCntlr.js';
import {WebPlotRequest} from '../../visualize/WebPlotRequest.js';
import {WebPlotRequest,TitleOptions} from '../../visualize/WebPlotRequest.js';
import {dispatchTableToIgnore} from '../../visualize/DrawLayerCntlr.js';
import Catlog from '../../drawingLayers/Catalog.js';
import {ServerRequest} from '../../data/ServerRequest.js';
import {CHANGE_VIEWER_LAYOUT} from '../../visualize/MultiViewCntlr.js';
import {LcPFOptionsPanel, grpkey} from './LcPhaseFoldingPanel.jsx';
import FieldGroupUtils, {revalidateFields} from '../../fieldGroup/FieldGroupUtils';

export const RAW_TABLE = 'raw_table';
export const PHASE_FOLDED = 'phase_folded';
Expand All @@ -28,10 +30,23 @@ export const DEF_IMAGE_CNT= 5;
export const MAX_IMAGE_CNT= 7;
const plotIdRoot= 'LC_FRAME-';


var webplotRequestCreator;
/**
* A function to create a WebPlotRequest from the given parameters
* @callback WebplotRequestCreator
* @param {TableModel} tableModel
* @param {number} hlrow
* @param {number} cutoutSize
*/

/**
* This event manager is custom made for light curve viewer.
* This event manager is custom made for light curve viewer.
* @param {Object} params
* @props {WebplotRequestCreator} params.webplotRequestCreator
*/
export function* lcManager() {
export function* lcManager(params={}) {
webplotRequestCreator = params.WebplotRequestCreator || getWebPlotRequestViaUrl;

while (true) {
const action = yield take([
Expand Down Expand Up @@ -85,7 +100,7 @@ function handleTableLoad(layoutInfo, action) {
if (isImageEnabledTable(tbl_id)) {
layoutInfo = updateSet(layoutInfo, 'showImages', true);
layoutInfo = updateSet(layoutInfo, 'images.activeTableId', tbl_id);
exec(setupImages, tbl_id);
setupImages(tbl_id);
}
return layoutInfo;
}
Expand All @@ -96,15 +111,15 @@ function handleTableActive(layoutInfo, action) {
const {tbl_id} = action.payload;
if (isImageEnabledTable(tbl_id)) {
layoutInfo = updateSet(layoutInfo, 'images.activeTableId', tbl_id);
exec(setupImages, tbl_id);
setupImages(tbl_id);
}
return layoutInfo;
}

function handleTableHighlight(layoutInfo, action) {
const {tbl_id} = action.payload;
if (isImageEnabledTable(tbl_id)) {
exec(setupImages, tbl_id);
setupImages(tbl_id);
}
}

Expand All @@ -115,7 +130,7 @@ function isImageEnabledTable(tbl_id) {
function handleChangeMultiViewLayout(layoutInfo, action) {
const activeTableId = get(layoutInfo, 'images.activeTableId');
const tbl= getTblById(activeTableId);
if (get(tbl, 'totalRows',0)>0) exec(setupImages, activeTableId);
if (get(tbl, 'totalRows',0)>0) setupImages(activeTableId);
return layoutInfo;
}

Expand Down Expand Up @@ -155,39 +170,75 @@ function getWebPlotRequest(tableModel, hlrow) {

}

function getWebPlotRequestViaUrl(tableModel, hlrow, cutoutSize) {
const ra = getCellValue(tableModel, hlrow, 'ra');
const dec = getCellValue(tableModel, hlrow, 'dec');
const frameId = getCellValue(tableModel, hlrow, 'frame_id');
var wise_sexp_ibe = /(\d+)([0-9][a-z])(\w+)/g;
var res = wise_sexp_ibe.exec(frameId);
const scan_id = res[1] + res[2];
const scangrp = res[2];
const frame_num = res[3];

function setupImages(tbl_id) {
const viewer= getViewer(getMultiViewRoot(),IMG_VIEWER_ID);
const count= get(viewer, 'layoutDetail.count',DEF_IMAGE_CNT);
const tableModel = getTblById(tbl_id);
if (!tableModel || isNil(tableModel.highlightedRow)) return;
var vr= visRoot();
const newPlotIdAry= makePlotIds(tableModel.highlightedRow, tableModel.totalRows,count);
const maxPlotIdAry= makePlotIds(tableModel.highlightedRow, tableModel.totalRows,MAX_IMAGE_CNT);


newPlotIdAry.forEach( (plotId) => {
if (!getPlotViewById(vr,plotId)) {
const rowNum= Number(plotId.substring(plotIdRoot.length));
const webPlotReq = getWebPlotRequest(tableModel,rowNum );
dispatchPlotImage({plotId, wpRequest:webPlotReq,
setNewPlotAsActive:false,
holdWcsMatch:true,
pvOptions: { userCanDeletePlots: false}});
}
});
/*the following should be from reading in the url column returned from LC search
we are constructing the url for wise as the LC table does
not have the url colume yet
It is only for WISE, using default cutout size 0.3 deg
const url = `http://irsa.ipac.caltech.edu/ibe/data/wise/merge/merge_p1bm_frm/${scangrp}/${scan_id}/${frame_num}/${scan_id}${frame_num}-w1-int-1b.fits`;
*/
const serverinfo = 'http://irsa.ipac.caltech.edu/ibe/data/wise/merge/merge_p1bm_frm/';
const centerandsize = cutoutSize ? `?center=${ra},${dec}&size=${cutoutSize}&gzip=false` : '';
const url = `${serverinfo}${scangrp}/${scan_id}/${frame_num}/${scan_id}${frame_num}-w1-int-1b.fits${centerandsize}`;
const plot_desc = `WISE-${frameId}`;
const reqParams = WebPlotRequest.makeURLPlotRequest(url, plot_desc);
reqParams.setTitle('WISE-'+ frameId + (cutoutSize ? ` size: ${cutoutSize}(deg)` : ''));
reqParams.setTitleOptions(TitleOptions.NONE);
reqParams.setGroupLocked(true);
reqParams.setPlotGroupId('LightCurveGroup');
reqParams.setPreferenceColorKey('light-curve-color-pref');
return reqParams;


dispatchReplaceViewerItems(IMG_VIEWER_ID, newPlotIdAry);
dispatchChangeActivePlotView(plotIdRoot+tableModel.highlightedRow);

vr= visRoot();
}

vr.plotViewAry
.filter( (pv) => pv.plotId.startsWith(plotIdRoot))
.filter( (pv) => pv.plotId!==vr.mpwWcsPrimId)
.filter( (pv) => !maxPlotIdAry.includes(pv.plotId))
.forEach( (pv) => dispatchDeletePlotView({plotId:pv.plotId, holdWcsMatch:true}));
export function setupImages(tbl_id) {
try {
const viewer= getViewer(getMultiViewRoot(),IMG_VIEWER_ID);
const count= get(viewer, 'layoutDetail.count',DEF_IMAGE_CNT);
const tableModel = getTblById(tbl_id);
if (!tableModel || isNil(tableModel.highlightedRow)) return;
var vr= visRoot();
const newPlotIdAry= makePlotIds(tableModel.highlightedRow, tableModel.totalRows,count);
const maxPlotIdAry= makePlotIds(tableModel.highlightedRow, tableModel.totalRows,MAX_IMAGE_CNT);

const cutoutSize = get(FieldGroupUtils.getGroupFields(grpkey), ['cutoutSize', 'value'], null);

newPlotIdAry.forEach( (plotId) => {
if (!getPlotViewById(vr,plotId)) {
const rowNum= Number(plotId.substring(plotIdRoot.length));
const webPlotReq = webplotRequestCreator(tableModel,rowNum, cutoutSize);
dispatchPlotImage({plotId, wpRequest:webPlotReq,
setNewPlotAsActive:false,
holdWcsMatch:true,
pvOptions: { userCanDeletePlots: false}});
}
});


dispatchReplaceViewerItems(IMG_VIEWER_ID, newPlotIdAry);
dispatchChangeActivePlotView(plotIdRoot+tableModel.highlightedRow);

vr= visRoot();

vr.plotViewAry
.filter( (pv) => pv.plotId.startsWith(plotIdRoot))
.filter( (pv) => pv.plotId!==vr.mpwWcsPrimId)
.filter( (pv) => !maxPlotIdAry.includes(pv.plotId))
.forEach( (pv) => dispatchDeletePlotView({plotId:pv.plotId, holdWcsMatch:true}));
} catch (E){
console.log(E.toString());
}
}


Expand All @@ -206,16 +257,3 @@ function makePlotIds(highlightedRow, totalRows, totalPlots) {
}


/**
* A simple wrapper to catch the exception then log it to console
* @param {function} f function to execute
* @param {*} args function's arguments.
*/
function exec(f, args) {
try {
f(args);
} catch (E){
console.log(E.toString());
}

}
56 changes: 40 additions & 16 deletions src/firefly/js/templates/lightcurve/LcPhaseFoldingPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ import {dispatchShowDialog} from '../../core/ComponentCntlr.js';
import {dispatchTableSearch, TABLE_HIGHLIGHT} from '../../tables/TablesCntlr.js';

import {loadXYPlot} from '../../charts/dataTypes/XYColsCDT.js';
import {RAW_TABLE, PHASE_FOLDED, PERIODOGRAM, PEAK_TABLE} from '../../templates/lightcurve/LcManager.js';
import {RAW_TABLE, PHASE_FOLDED, PERIODOGRAM, PEAK_TABLE, setupImages} from '../../templates/lightcurve/LcManager.js';
import {showPhaseFoldingPopup} from './LcPhaseFoldingPopup.jsx';

import {isUndefined, get,set,isNil} from 'lodash';
import {take} from 'redux-saga/effects';
import './LCPanels.css';

const grpkey = 'LC_FORM_Panel';
export const grpkey = 'LC_FORM_Panel';

function getDialogBuilder() {
var popup= null;
Expand Down Expand Up @@ -228,36 +228,47 @@ export function LcPFOptionsPanel ({fields}) {
<br/>
<ValidationField fieldKey='flux'
initialState= {{
fieldKey: 'flux',
value: '2.0',
validator: Validate.floatRange.bind(null, 2.0, 5.5, 3,'Flux Column'),
tooltip: 'Flux Column, value between 2.0 to 5.5',
label : 'Flux Column:',
labelWidth : 100
fieldKey: 'flux',
value: '2.0',
validator: Validate.floatRange.bind(null, 2.0, 5.5, 3,'Flux Column'),
tooltip: 'Flux Column, value between 2.0 to 5.5',
label : 'Flux Column:',
labelWidth : 100
}} />

<br/>

<ValidationField fieldKey='fluxerror'
initialState= {{
fieldKey: 'fluxerror',
value: '0.02',
validator: Validate.floatRange.bind(null, 0.01, 0.5, 3,'Flux Error'),
tooltip: 'Flux Error, value is between 0.01 to 0.5',
label : 'Flux Error:',
labelWidth : 100
fieldKey: 'fluxerror',
value: '0.02',
validator: Validate.floatRange.bind(null, 0.01, 0.5, 3,'Flux Error'),
tooltip: 'Flux Error, value is between 0.01 to 0.5',
label : 'Flux Error:',
labelWidth : 100
}} />
<br/>

<ValidationField fieldKey='period'
initialState= {{
initialState= {{
fieldKey: 'period',
value: '1.0',
//validator: Validate.floatRange.bind(null, 0.5, 1.5, 3,'period'),
tooltip: 'Period',
label : 'Period:',
labelWidth : 100
}} />
<br/>

<ValidationField fieldKey='cutoutSize'
initialState= {{
fieldKey: 'cutoutSize',
value: '0.3',
//validator: Validate.floatRange.bind(null, 0.1, 1, 3,'cutoutsize'),
tooltip: 'Cutout Size in degrees',
label : 'Cutout Size (deg):',
labelWidth : 100
}} />


<br/> <br/>
Expand Down Expand Up @@ -388,6 +399,8 @@ function doPhaseFolding(fields) {

var tReq = makeTblRequest('PhaseFoldedProcessor', PHASE_FOLDED, {
'period_days': fields.period.value,
'cutout_size': fields.cutoutSize.value,
'flux': fields.flux.value,
'table_name': 'folded_table',
'time_col_name':fields.timeCol.value,
'original_table': tbl.tableMeta.tblFilePath
Expand Down Expand Up @@ -428,7 +441,6 @@ function handleTableHighlight(action) {
if (per) {
dispatchValueChange({fieldKey: 'period', groupKey: grpkey, value: per});
}

}
//export default LcPhaseFoldingForm;

Expand All @@ -445,4 +457,16 @@ function getPeriodFromTable(tbl_id) {
} else if (tbl_id === PEAK_TABLE) {
return getCellValue(tableModel, tableModel.highlightedRow, 'Period');
}
}

/**
* return true if the table is LC raw or phase folded table
* @param {string} tbl_id
* @returns
*/
function isLcTable(tbl_id) {
const tableModel = getTblById(tbl_id);
if (!tableModel || isNil(tableModel.highlightedRow)) return;
return !![RAW_TABLE, PHASE_FOLDED].includes(tbl_id);

}