Skip to content

Commit

Permalink
Merge pull request #2 from Samreay/gh-pages
Browse files Browse the repository at this point in the history
Merging back gh-pages to master
  • Loading branch information
Samreay committed Mar 21, 2014
2 parents a35c292 + 5e83ed4 commit f2f9d04
Show file tree
Hide file tree
Showing 10 changed files with 1,080 additions and 867 deletions.
14 changes: 8 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
<link href="css/style.css" rel="stylesheet"/>
<script src="js/jquery-2.1.0.js"></script>
<script src="js/amcharts.js"></script>
<script src="js/serial.js"></script>
<script src="js/xy.js"></script>
<script src="js/light.js"></script>
<script src="js/amexport.js"></script>

<script src="js/angular.js"></script>
<script src="js/angular-animate.js"></script>
<script src="js/angular-drop.js"></script>
<script src="js/serial.js"></script>
<script src="js/light.js"></script>

<script src="js/fits.js"></script>
<script src="js/regression.js"></script>
Expand All @@ -30,7 +32,7 @@
<h1>InterfaceZ</h1>
<nav class="menu" ng-click="$event.preventDefault()">
<ul>
<li ng-repeat="i in interfaceManager.menuOptions" ng-click="$parent.interfaceManager.menuActive=i" ng-class="{active:i==interfaceManager.menuActive}">
<li ng-repeat="i in interfaceManager.menuOptions" ng-click="$parent.goToMenu(i)" ng-class="{active:i==interfaceManager.menuActive}">
<h2>{{i}}</h2>
</li>
</ul>
Expand All @@ -52,7 +54,7 @@ <h3>{{fits.properties[0].value}}</h3>
<p>{{i.id}}</p>
<div class="info" id="spectra{{i.id}}">
<p ng-show="i.templateIndex==null">Not analysed</p>
<p ng-show="i.templateIndex!=null">{{i.templateIndex}}, z={{i.templateZ.toFixed(4)}} Chi2: {{i.templateChi2.toFixed(0)}}</p>
<p ng-show="i.templateIndex!=null">{{i.getTemplateId()}}, z={{i.templateZ.toFixed(4)}} Chi2: {{i.templateChi2.toFixed(0)}}</p>
</div>
</li>
</ul>
Expand All @@ -70,15 +72,15 @@ <h3>{{fits.properties[0].value}}</h3>
<div class="overviewList" ng-show="interfaceManager.menuActive=='Overview'">
<ul>
<li class="overviewItem lined overviewSmall" ng-dblclick="$parent.goToDetailed()" ng-click="$parent.setSpectraIndex(i.index)" ng-class="{activeSelect:interfaceManager.spectraIndex==i.index}" ng-repeat="i in spectraManager.getAll() track by i.id">
<div class="topbar"><b>ID: {{i.id}}</b><p ng-show="i.templateIndex!=null">T: {{i.templateIndex}}, z={{i.templateZ.toFixed(4)}} Chi2: {{i.templateChi2.toFixed(0)}}</p></div>
<div class="topbar"><b>ID: {{i.id}}</b><p ng-show="i.templateIndex!=null">T: {{i.getTemplateId()}}, z={{i.templateZ.toFixed(4)}} Chi2: {{i.templateChi2.toFixed(0)}}</p></div>
<div class="graph"><canvas id="smallGraphCanvas{{$index}}" style="width:100%; height:100%;"></canvas>{{interfaceManager.renderOverview($index)}}</div>
</li>
</ul>
</div>
<div class="templateList" ng-show="interfaceManager.menuActive=='Templates'">
<ul>
<li class="overviewItem lined overviewLarge" ng-repeat="t in templateManager.getAll() track by t.id">
<div class="topbar"><b>Template ID: {{t.id}}</b><p>Name: {{t.name}}, Lambda_start: {{t.start_lambda.toFixed(2)}} Lambda_end: {{t.end_lambda.toFixed(2)}}</p></div>
<div class="topbar"><b>Template ID: {{t.id}}</b><p>Name: {{t.name}}, Lambda Start: {{t.start_lambda_linear.toFixed(2)}} Lambda End: {{t.end_lambda_linear.toFixed(2)}}</p></div>
<div class="graph"><canvas id="smallTemplateCanvas{{$index}}" style="width:100%; height:100%;"></canvas>{{interfaceManager.renderTemplate($index)}}</div>
</li>
</ul>
Expand Down
548 changes: 275 additions & 273 deletions js/amcharts.js

Large diffs are not rendered by default.

23 changes: 13 additions & 10 deletions js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,24 @@ function MainController($scope, $timeout) {

// Model managers
$scope.templateManager = new TemplateManager();
$scope.processorManager = new ProcessorManager(1, $scope); //TODO: Core estimation
$scope.processorManager = new ProcessorManager(3, $scope); //TODO: Core estimation
$scope.spectraManager = new SpectraManager($scope.processorManager, $scope.templateManager);
$scope.interfaceManager = new InterfaceManager($scope, $scope.spectraManager, $scope.templateManager);
$scope.fits = null; // Initialise new FitsFile on drop.

$scope.goToMenu = function(menuOption) {
if (menuOption == 'Detailed') {
$scope.goToDetailed();
}
$scope.interfaceManager.menuActive = menuOption;
}
$scope.goToDetailed = function() {

var tid = $scope.spectraManager.getSpectra($scope.interfaceManager.spectraIndex).templateIndex;
var tz = $scope.spectraManager.getSpectra($scope.interfaceManager.spectraIndex).templateZ;
var spectra = $scope.spectraManager.getSpectra($scope.interfaceManager.spectraIndex);
if (spectra != null) {
var tid = spectra.templateIndex;
var tz = spectra.templateZ;
}
$scope.interfaceManager.detailedViewTemplate = tid == null ? 0 : tid;
$scope.interfaceManager.detailedViewZ = tz == null? 0 : tz;
$scope.interfaceManager.detailedUpdateRequired = true;
$scope.interfaceManager.menuActive = 'Detailed';
this.interfaceManager.updateDetailedData();

Expand All @@ -50,10 +56,7 @@ function MainController($scope, $timeout) {
$scope.setSpectraIndex = function(i) {
$scope.interfaceManager.spectraIndex = i;
//TODO: Remove duplicate code
var tid = $scope.spectraManager.getSpectra($scope.interfaceManager.spectraIndex).templateIndex;
var tz = $scope.spectraManager.getSpectra($scope.interfaceManager.spectraIndex).templateZ;
$scope.interfaceManager.detailedViewTemplate = tid == null ? 0 : tid;
$scope.interfaceManager.detailedViewZ = tz == null? 0 : tz;
if ($scope.interfaceManager.menuActive == 'Detailed') $scope.goToDetailed();
$timeout(function() {
var leftrel = $('.spectralList ul li.activeSelect').position().top;
var leftheight = $('.spectralList').height();
Expand Down
114 changes: 65 additions & 49 deletions js/classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ FitsFile.prototype.getFibres = function(fits) {
fits.getDataUnit(2).getColumn("TYPE", function(data, opt) {
var ind = 0;
for (var i = 0; i < data.length; i++) {
if (data[i] == "P" && i < 50) {
if (data[i] == "P" && i < 100) {
opt.spectra.push({index: ind++, id: i+1, lambda: opt.lambda.slice(0), intensity: [], variance: [], miniRendered: 0});
}
}
opt.getSpectra(fits);
}, this);
}
};
FitsFile.prototype.getSpectra = function(fits) {

fits.getDataUnit(0).getFrame(0, function(data, opt) {
Expand All @@ -105,7 +105,7 @@ FitsFile.prototype.getSpectra = function(fits) {
}
opt.getVariances(fits);
}, this)
}
};
FitsFile.prototype.getVariances = function(fits) {
fits.getDataUnit(1).getFrame(0, function(data, opt) {
var d = Array.prototype.slice.call(data);
Expand All @@ -119,79 +119,107 @@ FitsFile.prototype.getVariances = function(fits) {
opt.scope.spectraManager.setSpectra(spec);
opt.scope.$digest();
}, this);
}
};



function Spectra(index, id, lambda, intensity, variance) {
//TODO: Remove index, use $index instead
this.index = index;
this.id = id;

this.lambda = lambda;
this.intensity = intensity;
this.variance = variance;

// All these plotting variables are used to make interpolation faster
// when generating the data for the detailed view
this.gap = 1;
this.plotData = [];
this.plotLambda = linearSep(Math.floor(lambda[0]), Math.ceil(lambda[lambda.length - 1]), this.gap);
this.plotIntensity = interpolate(this.plotLambda, lambda, intensity);
this.plotVariance = interpolate(this.plotLambda, lambda, variance);
for (var i = 0; i < this.plotLambda.length; i++) {
this.plotData.push({lambda: this.plotLambda[i], raw: this.plotIntensity[i]});
}


this.processedLambda = null;
this.processedIntensity = null;
this.processedVariance = null;
this.plotProcessedLambda = null;
this.plotProcessedIntensity = null
this.plotProcessedVariance = null;


this.templateIndex = null;
this.templateZ = null;
this.templateChi2 = null;
this.templateLambda = null
this.templateIntensity = null;
this.plotTemplateLambda = null
this.plotTemplateIntensity = null;
}
Spectra.prototype.setTemplateManager = function(templateManager) {
this.templateManager = templateManager;
};
Spectra.prototype.getTemplateId = function() {
if (this.templateIndex == null || this.templateManager == null) return null;
return this.templateManager.get(this.templateIndex).id;
}
Spectra.prototype.setProcessedValues = function(pi, pv, ti, tz, tc) {
Spectra.prototype.setProcessedValues = function(pl, pi, pv, ti, tr) {
this.processedLambda = pl.map(function(x) {return Math.pow(10, x);});
this.processedIntensity = pi;
this.processedVariance = pv;

this.plotProcessedLambda = linearSep(Math.floor(this.processedLambda[0]), Math.ceil(this.processedLambda[this.processedLambda.length - 1]), this.gap);
this.plotProcessedIntensity = interpolate(this.plotProcessedLambda, this.processedLambda, pi);
this.plotProcessedVariance = interpolate(this.plotProcessedLambda, this.processedLambda, pv);

addValuesToDataDictionary(this.plotData, this.plotProcessedLambda, this.plotProcessedIntensity, 'pre', this.gap);


this.templateIndex = ti;
this.templateZ = tz;
this.templateChi2 = tc;
this.templateZ = tr[ti].z;
this.templateChi2 = tr[ti].chi2;

var result = this.templateManager.getShiftedTemplate(ti, tz);
this.templateLambda = result[0];
this.templateIntensity = result[1];
this.templateResults = tr;
// var result = this.templateManager.getShiftedLinearTemplate(ti, tz);
// this.templateLambda = result[0];
// this.templateIntensity = result[1];
// this.plotTemplateIntensity = this.templateManager.getPlottingShiftedLinearLambda(ti, tz, this.plotProcessedLambda);
this.templateLambda = this.plotProcessedLambda;
this.templateIntensity = this.templateManager.getPlottingShiftedLinearLambda(ti, this.templateZ, this.plotProcessedLambda);

}
};
Spectra.prototype.getAsJson = function() {
return {'index':this.index, 'start_lambda':this.lambda[0], 'end_lambda':this.lambda[this.lambda.length - 1], 'intensity':this.intensity, 'variance':this.variance};
}
};
Spectra.prototype.isProcessed = function() {
return this.processedIntensity != null;
}
};
Spectra.prototype.isMatched = function() {
return this.templateIndex != null;
}
};



function SpectraManager(processorManager, templateManager) {
this.spectraList = [];
this.processorManager = processorManager;
this.templateManager = templateManager;
}
};
SpectraManager.prototype.setSpectra = function(spectraList) {
this.spectraList = spectraList;
for (var i = 0; i < spectraList.length; i++) {
this.spectraList[i].setTemplateManager(this.templateManager);
}
this.processorManager.setSpectra(this);
}
};
SpectraManager.prototype.getAll = function() {
return this.spectraList;
}
};
SpectraManager.prototype.getSpectra = function(i) {
return this.spectraList[i];
}
//SpectraManager.prototype.getUnprocessed = function() {
// for (var i = 0; i < this.spectraList.length; i++) {
// if (this.spectraList[i].processedIntensity == null) {
// return this.spectraList[i].getAsJson(i);
// }
// }
//}
};


function ProcessorManager(numProcessors, scope) {
Expand All @@ -213,7 +241,7 @@ ProcessorManager.prototype.setSpectra = function(spectraManager) {
}
this.processSpectra();
}
}
};
ProcessorManager.prototype.processSpectra = function() {
if (this.processQueue.length > 0) {
var processor = this.getFreeProcessor();
Expand All @@ -222,25 +250,15 @@ ProcessorManager.prototype.processSpectra = function() {
processor = this.getFreeProcessor();
}
}
}
ProcessorManager.prototype.getFreeProcessor = function() {
for(var i = 0; i < this.processors.length; i++) {
};
ProcessorManager.prototype.getFreeProcessor = function () {
for (var i = 0; i < this.processors.length; i++) {
if (this.processors[i].isIdle()) {
return this.processors[i];
}
}
return null;
}
//ProcessorManager.prototype.setAutomaticProcessing = function(automatic) {
// this.automatic = automatic;
//}
//ProcessorManager.prototype.getAutomaticProcessing = function() {
// return this.automatic;
//}
//ProcessorManager.prototype.hasFreeProcessor = function() {
// return this.getFreeProcessor() != null;
//}

};

/**
* The processor is responsible for hosting the worker and communicating with it.
Expand All @@ -251,19 +269,17 @@ function Processor(manager) {
this.workingSpectra = null;
this.worker = new Worker('js/preprocessor.js');
this.worker.addEventListener('message', function(e) {
this.workingSpectra.setProcessedValues(e.data.processedIntensity,
e.data.processedVariance, e.data.templateIndex, e.data.templateZ,
e.data.templateChi2);
this.workingSpectra.setProcessedValues(e.data.processedLambda, e.data.processedIntensity,
e.data.processedVariance, e.data.bestIndex, e.data.templateResults);
this.manager.scope.updatedSpectra(this.workingSpectra.index);
this.workingSpectra = null;
this.manager.processSpectra();
}.bind(this), false);
}
Processor.prototype.isIdle = function() {
return this.workingSpectra == null;
}
};
Processor.prototype.processSpectra = function(spectra) {
this.workingSpectra = spectra;
var message = spectra.getAsJson();
this.worker.postMessage(message);
}
this.worker.postMessage(spectra.getAsJson());
};
Loading

0 comments on commit f2f9d04

Please sign in to comment.