/
data.php
148 lines (137 loc) · 3.84 KB
/
data.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
class Data {
public static function getSummaries() {
$summaries = array();
foreach(get_declared_classes() as $model) {
if(is_subclass_of($model, 'Table')) {
$summaries[$model::$id] = array(
'name' => $model::$name,
'types' => $model::$types
);
}
}
# Sort by name
$names = array();
foreach($summaries as $key => $row) {
$names[$key] = $row['name'];
}
array_multisort($names, $summaries);
echo json_encode($summaries);
}
public static function plotSellmeier() {
$plot = new Plot();
$plot->title("N Vs. Wavelength");
$plot->xlabel("Wavelength (micrometers)");
$plot->ylabel("Index of Refraction");
$sell = new Sellmeier();
$sell->loadMaterialsData();
// Make material selection if it exists
if(isset($_GET['selection'])) {
// Parse selection
$selection = json_decode(urldecode($_GET['selection']));
// print_r($selection);
if(!$sell->selectMaterials($selection)) {
$errors[] = new UserError("Materials do not exist", 1);
}
// Parse legend
$legend = array();
if(isset($_GET['legend']) && is_array($_GET['legend']) && count($_GET['legend']) == count($selection)) {
$legend = $_GET['legend'];
} else {
foreach($selection as $material => $array) {
foreach($array as $key => $axis) {
$legend[] = $material . " (axis " . $axis . ")";
}
}
}
$plot->legend($legend);
// Parse title
if(isset($_GET['title'])) {
$title = $_GET['title'];
$sell->title($title);
}
// Parse domain
$xmin = .4;
$xmax = 1;
$step = .001;
if(isset($_GET['xmin']) && isset($_GET['xmax']) && isset($_GET['step'])) {
if(is_numeric($_GET['xmin']) && is_numeric($_GET['xmax']) && is_numeric($_GET['step'])) {
$xmin = $_GET['xmin'] + 0;
$xmax = $_GET['xmax'] + 0;
$step = $_GET['step'] + 0;
} else {
$errors[] = new UserError("Wavelength range must be a number", 1);
}
}
$plot->setX(range($xmin, $xmax, $step));
$ydata = array();
foreach($sell->getSelection() as $name => $axis_array) {
foreach($axis_array as $axis => $coeffs) {
$legend = $name.'.'.$axis;
$ydata[$legend] = array();
foreach($plot->getX() as $x) {
$ydata[$legend][] = $sell->calcSellmeier($x,
$coeffs['a'],
$coeffs['b'],
$coeffs['c'],
$coeffs['d'],
$coeffs['e']
);
}
}
}
$plot->setY($ydata);
// Output plot data
echo $plot->getJson();
} else {
// Output materials list
echo $sell->getMaterialsJson();
}
}
public static function plotSpectra() {
$plot = new Plot();
$plot->xlabel("Wavelength (nm)");
$spectra = new Spectra();
$spectra->loadOptions();
// Make material selection if it exists
if(isset($_GET['selection'])) {
$selection = json_decode(urldecode($_GET['selection']));
// print_r($selection);
$x = array();
$y = array();
$legend = array();
foreach($selection as $type => $name_array) {
$plot->ylabel($type." (cm^2)");
foreach($name_array as $name => $axis_array) {
$plot->title($name." ".$type." Vs. Wavelength");
$n = 0;
foreach($axis_array as $axis => $range_array) {
// print_r($axis);
$legend[$n] = $axis." axis";
$y[$legend[$n]] = array();
foreach($range_array as $range => $empty) {
if(!$spectra->selectOptions($type, $name, $axis, $range)) {
$errors[] = new UserError("Options do not exist", 1);
}
if($n == 0) { // only need wavelengths once
$x = array_merge($x, $spectra->getWavelengths());
}
$y[$legend[$n]] = array_merge($y[$legend[$n]], $spectra->getSignals());
$spectra->clearSelection();
}
$n = $n + 1;
}
}
}
$plot->setX($x);
$plot->setY($y);
$plot->legend($legend);
// Output plot data
echo $plot->getJson();
} else {
// Output materials list
echo $spectra->getJson();
}
}
}
?>