diff --git a/app/actions/magnetopause.js b/app/actions/magnetopause.js index 214fd1f..a56890c 100644 --- a/app/actions/magnetopause.js +++ b/app/actions/magnetopause.js @@ -15,33 +15,56 @@ export function setData(payload) { }; } -export function prepareDataSet() { +function prepareDataSet(dataSetValues, field) { + let data; + + if (field && dataSetValues.hasOwnProperty(field)) { + data = {}; + dataSetValues[field].forEach((item) => { + data[item.time] = item.value; + }); + } + + return data; +} + +export function calculateMagnetopause() { return (dispatch, getState) => { const field = getState().main.settings.project.magnetopause; const {dataSetValues} = getState().dataSet; let chartPoints = null; let data = null; - if (dataSetValues && field && field.b && field.bz && field.pressureSolar) { - chartPoints = []; - data = {}; - dataSetValues[field.b].forEach((value, i) => { - let time = new Date(value.time); + + if (dataSetValues && field) { + const fieldData = { + b: prepareDataSet(dataSetValues, field.b), + bz: prepareDataSet(dataSetValues, field.bz), + pressureSolar: prepareDataSet(dataSetValues, field.pressureSolar), + }; + + for (let timeStr in fieldData.b) { + const time = new Date(timeStr); let values = { - b: dataSetValues[field.b][i].value, - bz: dataSetValues[field.bz][i].value, - pressureSolar: dataSetValues[field.pressureSolar][i].value / 10, - time: new Date(time.getTime() - time.getTimezoneOffset() * 60000) + b: fieldData.b[timeStr], + bz: fieldData.bz[timeStr], + pressureSolar: fieldData.pressureSolar[timeStr], + time: new Date(time - time.getTimezoneOffset() * 60000) }; - let point = new MagnetopausePoint(values).calculate(0, 0).toCartesian(); + let point = new MagnetopausePoint(values).calculate(0, 0); + + if (!chartPoints) { + chartPoints = []; + data = {} + } chartPoints.push({ x: time, - y: point.x + y: point ? point.toCartesian().x : null, }); data[time] = values; - }); + } } dispatch(setChart(chartPoints)); diff --git a/app/components/magnetopause/MagnetopauseDashboard.js b/app/components/magnetopause/MagnetopauseDashboard.js index c597df0..4869400 100644 --- a/app/components/magnetopause/MagnetopauseDashboard.js +++ b/app/components/magnetopause/MagnetopauseDashboard.js @@ -10,7 +10,7 @@ import * as MagnetopauseActions from './../../actions/magnetopause'; class MagnetopauseDashboard extends Component { componentWillMount = () => { - this.props.magnetopauseActions.prepareDataSet(); + this.props.magnetopauseActions.calculateMagnetopause(); }; // componentWillReceiveProps = (nextProps) => { diff --git a/app/components/magnetopause/MagnetopauseHeader.js b/app/components/magnetopause/MagnetopauseHeader.js index 0943a4c..c7ebc9a 100644 --- a/app/components/magnetopause/MagnetopauseHeader.js +++ b/app/components/magnetopause/MagnetopauseHeader.js @@ -11,7 +11,6 @@ class MagnetopauseHeader extends Component { render = () => { const field = this.props.settings.project.magnetopause; const modalVisible = !(field && field.b && field.bz && field.pressureSolar); - console.log({modalVisible, field}); return (
diff --git a/app/components/magnetopause/MagnetopauseSettings.js b/app/components/magnetopause/MagnetopauseSettings.js index e2a1503..4050f71 100644 --- a/app/components/magnetopause/MagnetopauseSettings.js +++ b/app/components/magnetopause/MagnetopauseSettings.js @@ -25,7 +25,7 @@ class MagnetopauseSettings extends Component { handlerModalClose = () => { this.setState({modalVisible: false}, () => { - this.props.magnetopauseActions.prepareDataSet(); + this.props.magnetopauseActions.calculateMagnetopause(); }); }; diff --git a/app/lib/geomagneticData/parsers/cdaweb.js b/app/lib/geomagneticData/parsers/cdaweb.js index 9a6729d..36327f6 100644 --- a/app/lib/geomagneticData/parsers/cdaweb.js +++ b/app/lib/geomagneticData/parsers/cdaweb.js @@ -50,7 +50,7 @@ export default function (filePath) { } } else { let lineSplit = line.split(/\s+/); - if (['UT','EPOCH_TIME','TIME','DATE'].indexOf(lineSplit[0]) !== -1) { + if (['UT','EPOCH_TIME','EPOCH','TIME','DATE'].indexOf(lineSplit[0]) !== -1) { lineSplit.forEach((item, i) => { data.columns.push({ name: item, diff --git a/app/lib/geopack/magnetopausePoint.js b/app/lib/geopack/magnetopausePoint.js index 14b0581..982f28a 100644 --- a/app/lib/geopack/magnetopausePoint.js +++ b/app/lib/geopack/magnetopausePoint.js @@ -34,7 +34,7 @@ export default class MagnetopausePoint { constructor(props) { for (let name in this) { - if (props.hasOwnProperty(name)) { + if (props.hasOwnProperty(name) && props[name] != null) { this[name] = props[name]; } } @@ -52,9 +52,7 @@ export default class MagnetopausePoint { const latitudeRad = latitude * M2R; const longitudeRad = longitude * M2R; - if (pressureMagnetic < 0 || pressureSolar < 0 || bz < -200) { - return null; - } else { + if (pressureMagnetic > 0 && pressureSolar > 0 && bz > -200) { let te = Math.cos(latitudeRad) * Math.cos(longitudeRad); if (te > 1) { te = 1 @@ -116,5 +114,7 @@ export default class MagnetopausePoint { } } } + + return null; } }