Skip to content

Commit

Permalink
Fix magnetopause calc
Browse files Browse the repository at this point in the history
  • Loading branch information
sheldhur committed Nov 24, 2017
1 parent 7df8f3d commit d00128a
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 21 deletions.
49 changes: 36 additions & 13 deletions app/actions/magnetopause.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion app/components/magnetopause/MagnetopauseDashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
1 change: 0 additions & 1 deletion app/components/magnetopause/MagnetopauseHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div className="main-page-header">
<MagnetopauseSettings size={this.size} modalVisible={modalVisible}/>
Expand Down
2 changes: 1 addition & 1 deletion app/components/magnetopause/MagnetopauseSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class MagnetopauseSettings extends Component {

handlerModalClose = () => {
this.setState({modalVisible: false}, () => {
this.props.magnetopauseActions.prepareDataSet();
this.props.magnetopauseActions.calculateMagnetopause();
});
};

Expand Down
2 changes: 1 addition & 1 deletion app/lib/geomagneticData/parsers/cdaweb.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions app/lib/geopack/magnetopausePoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
Expand All @@ -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
Expand Down Expand Up @@ -116,5 +114,7 @@ export default class MagnetopausePoint {
}
}
}

return null;
}
}

0 comments on commit d00128a

Please sign in to comment.