##// END OF EJS Templates
Fixing plots
jespinoza -
r7:4e0b343b0c61
parent child
Show More
@@ -1,68 +1,68
1 {% extends "base.html" %}
1 {% extends "base.html" %}
2
2
3 {% comment %}
3 {% comment %}
4 Written by Bill Rideout brideout@haystack.mit.edu
4 Written by Bill Rideout brideout@haystack.mit.edu
5
5
6 Base template for Madrigal show experiment web interface
6 Base template for Madrigal show experiment web interface
7
7
8 $Id: show_experiment.html 7310 2021-03-02 14:31:06Z brideout $
8 $Id: show_experiment.html 7310 2021-03-02 14:31:06Z brideout $
9 {% endcomment %}
9 {% endcomment %}
10
10
11 {% block title %}Show Madrigal experiment{% endblock %}
11 {% block title %}Show Madrigal experiment{% endblock %}
12
12
13 {% block extra_head %}
13 {% block extra_head %}
14 <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
14 <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
15 <script>
15 <script>
16
16
17 function changeFile (select) {
17 function changeFile (select) {
18 var basename = select.options[select.selectedIndex].value;
18 var basename = select.options[select.selectedIndex].value;
19 {% if form.exp_id %}
19 {% if form.exp_id %}
20 var url = '{% url 'change_files' %}' + '?experiment_list={{ form.exp_id.label }}&file_list=' + basename;
20 var url = '{% url 'change_files' %}' + '?experiment_list={{ form.exp_id.label }}&file_list=' + basename;
21 {% else %}
21 {% else %}
22 var exp_id = $("#id_experiment_list")[0].options[$("#id_experiment_list")[0].selectedIndex].value;
22 var exp_id = $("#id_experiment_list")[0].options[$("#id_experiment_list")[0].selectedIndex].value;
23 var url = '{% url 'change_files' %}' + '?experiment_list=' + exp_id + '&file_list=' + basename;
23 var url = '{% url 'change_files' %}' + '?experiment_list=' + exp_id + '&file_list=' + basename;
24 {% endif %}
24 {% endif %}
25 // first delete all forms that are now out of date
25 // first delete all forms that are now out of date
26 divIndex = $(".single_form").index($( "#file_buttons" ))
26 divIndex = $(".single_form").index($( "#file_buttons" ))
27 $(".single_form").slice(divIndex).empty()
27 $(".single_form").slice(divIndex).empty()
28 // second populate the file_list html if '0' not selected
28 // second populate the file_list html if '0' not selected
29 if (basename != '0') {
29 if (basename != '0') {
30 $(".single_form").slice(divIndex,divIndex+1).load(url);
30 $(".single_form").slice(divIndex,divIndex+1).load(url);
31 }
31 }
32 }
32 }
33
33
34 {% include "madweb/fileDownload.js" %}
34 {% include "madweb/fileDownload.js" %}
35
35
36 </script>
36 </script>
37 {% endblock %}
37 {% endblock %}
38
38
39 {% block content %}
39 {% block content %}
40 <center><h4> {{ form.exp_desc.label }} </h4></center>
40 <center><h4> {{ form.exp_desc.label }} </h4></center>
41
41
42 {% include "madweb/file_list.html" %}
42 {% include "madweb/file_list.html" %}
43
43
44 <!-- file select div -->
44 <!-- file select div -->
45 <div class="col-md-12 single_form" id="file_buttons">
45 <div class="col-md-12 single_form" id="file_buttons">
46 {% if form.file_buttons %}
46 {% if form.file_buttons %}
47 {% include "madweb/file_buttons.html" %}
47 {% include "madweb/file_buttons.html" %}
48 {% endif %}
48 {% endif %}
49 </div> <!-- end subdivide -->
49 </div> <!-- end subdivide -->
50 <div>&nbsp;</div>
50 <div>&nbsp;</div>
51
51
52 <!-- file select div -->
52 <!-- file select div -->
53 <div class="col-md-12 single_form" id="file_data">
53 <div class="col-md-12 single_form" id="file_data">
54 {% if form.show_plots %}
54 {% if form.show_plots %}
55 {% include "madweb/show_plots.html" %}
55 {% include "madweb/show_plots.html" %}
56 {% elif form.plot_list %}
56 {% elif form.plot_list %}
57 {% include "madweb/show_plots.html" %}
57 {% include "madweb/show_plots.html" %}
58 {% endif %}
58 {% endif %}
59 </div> <!-- end subdivide -->
59 </div> <!-- end subdivide -->
60
60
61 <!-- file select div -->
61 <!-- file select div -->
62 <div class="col-md-12 single_form" id="file_plot">
62 <div class="col-md-9 single_form" id="file_plot">
63 {% if form.show_plots %}
63 {% if form.show_plots %}
64 {% include "madweb/parameter_selection.html" %}
64 {% include "madweb/parameter_selection.html" %}
65 {% endif %}
65 {% endif %}
66 </div> <!-- end subdivide -->
66 </div> <!-- end subdivide -->
67
67
68 {% endblock %} No newline at end of file
68 {% endblock %}
@@ -1,268 +1,268
1 {% extends "base_single.html" %}
1 {% extends "base_single.html" %}
2
2
3 {% comment %}
3 {% comment %}
4 Written by Bill Rideout brideout@haystack.mit.edu
4 Written by Bill Rideout brideout@haystack.mit.edu
5
5
6 Final template for Madrigal single experiment web interface
6 Final template for Madrigal single experiment web interface
7
7
8 $Id: single.html 7290 2021-01-13 21:07:21Z brideout $
8 $Id: single.html 7290 2021-01-13 21:07:21Z brideout $
9 {% endcomment %}
9 {% endcomment %}
10
10
11
11
12 {% block ajax_js %}
12 {% block ajax_js %}
13 <script type="text/javascript">
13 <script type="text/javascript">
14
14
15
15
16 {% if years %}
16 {% if years %}
17 $( document ).ready(function() {
17 $( document ).ready(function() {
18 createCalendar();
18 createCalendar();
19 });
19 });
20 {% endif %}
20 {% endif %}
21
21
22 var redirectLookup = {
22 var redirectLookup = {
23 "0": function() { return ""; },
23 "0": function() { return ""; },
24 {% for redirect in redirect_list %}
24 {% for redirect in redirect_list %}
25 "{{ redirect.0 }}": function() { return "{{ redirect.1|safe }}"; },
25 "{{ redirect.0 }}": function() { return "{{ redirect.1|safe }}"; },
26 {% endfor %}
26 {% endfor %}
27 };
27 };
28
28
29 function populateCat (checkbox) {
29 function populateCat (checkbox) {
30 var is_global = 0;
30 var is_global = 0;
31 if (checkbox.checked) {
31 if (checkbox.checked) {
32 is_global = 1;
32 is_global = 1;
33 }
33 }
34 var url = '{% url 'get_categories' %}' + '?isGlobal=' + is_global;
34 var url = '{% url 'get_categories' %}' + '?isGlobal=' + is_global;
35 // first delete all forms that are now out of date
35 // first delete all forms that are now out of date
36 divIndex = $(".single_form").index($( "#categories" ))
36 divIndex = $(".single_form").index($( "#categories" ))
37 $(".single_form").slice(divIndex).empty()
37 $(".single_form").slice(divIndex).empty()
38 // second populate the categories html
38 // second populate the categories html
39 $(".single_form").slice(divIndex,divIndex+1).load(url);
39 $(".single_form").slice(divIndex,divIndex+1).load(url);
40 }
40 }
41
41
42 function populateInst (select) {
42 function populateInst (select) {
43 var is_global = 0;
43 var is_global = 0;
44 if ($("#id_isGlobal")[0].checked) {
44 if ($("#id_isGlobal")[0].checked) {
45 is_global = 1;
45 is_global = 1;
46 }
46 }
47 var category = select.options[select.selectedIndex].value;
47 var category = select.options[select.selectedIndex].value;
48 var url = '{% url 'get_instruments' %}' + '?isGlobal=' + is_global + '&categories=' + category;
48 var url = '{% url 'get_instruments' %}' + '?isGlobal=' + is_global + '&categories=' + category;
49 // first delete all forms that are now out of date
49 // first delete all forms that are now out of date
50 divIndex = $(".single_form").index($( "#instruments" ))
50 divIndex = $(".single_form").index($( "#instruments" ))
51 $(".single_form").slice(divIndex).empty()
51 $(".single_form").slice(divIndex).empty()
52 // second populate the instruments html if '0' not selected
52 // second populate the instruments html if '0' not selected
53 if (category != '0') {
53 if (category != '0') {
54 $(".single_form").slice(divIndex,divIndex+1).load(url);
54 $(".single_form").slice(divIndex,divIndex+1).load(url);
55 }
55 }
56 }
56 }
57
57
58 function populateYear (select) {
58 function populateYear (select) {
59 var is_global = 0;
59 var is_global = 0;
60 if ($("#id_isGlobal")[0].checked) {
60 if ($("#id_isGlobal")[0].checked) {
61 is_global = 1;
61 is_global = 1;
62 }
62 }
63 // this method may redirect if instrument is not local
63 // this method may redirect if instrument is not local
64 var kinst = select.options[select.selectedIndex].value;
64 var kinst = select.options[select.selectedIndex].value;
65 var redirectUrl = redirectLookup[kinst]();
65 var redirectUrl = redirectLookup[kinst]();
66 if (redirectUrl.length > 0) {
66 if (redirectUrl.length > 0) {
67 // redirect
67 // redirect
68 alert('Because this data is not local, you will be redirected to ' + redirectUrl);
68 alert('Because this data is not local, you will be redirected to ' + redirectUrl);
69 window.location.href = redirectUrl;
69 window.location.href = redirectUrl;
70 } else {
70 } else {
71 var url = '{% url 'get_years' %}' + '?isGlobal=' + is_global + '&instruments=' + kinst;
71 var url = '{% url 'get_years' %}' + '?isGlobal=' + is_global + '&instruments=' + kinst;
72 // first delete all forms that are now out of date
72 // first delete all forms that are now out of date
73 divIndex = $(".single_form").index($( "#years" ))
73 divIndex = $(".single_form").index($( "#years" ))
74 $(".single_form").slice(divIndex).empty()
74 $(".single_form").slice(divIndex).empty()
75 // second populate the years html if '0' not selected
75 // second populate the years html if '0' not selected
76 if (kinst != '0') {
76 if (kinst != '0') {
77 $(".single_form").slice(divIndex,divIndex+1).load(url);
77 $(".single_form").slice(divIndex,divIndex+1).load(url);
78 }
78 }
79 }
79 }
80 }
80 }
81
81
82 function populateMonth (select) {
82 function populateMonth (select) {
83 var year = select.options[select.selectedIndex].value;
83 var year = select.options[select.selectedIndex].value;
84 var kinst = $("#id_instruments")[0].options[$("#id_instruments")[0].selectedIndex].value;
84 var kinst = $("#id_instruments")[0].options[$("#id_instruments")[0].selectedIndex].value;
85 var is_global = 0;
85 var is_global = 0;
86 if ($("#id_isGlobal")[0].checked) {
86 if ($("#id_isGlobal")[0].checked) {
87 is_global = 1;
87 is_global = 1;
88 }
88 }
89
89
90 var url = '{% url 'get_months' %}' + '?isGlobal=' + is_global + '&instruments=' + kinst + '&years=' + year;
90 var url = '{% url 'get_months' %}' + '?isGlobal=' + is_global + '&instruments=' + kinst + '&years=' + year;
91 // first delete all forms that are now out of date
91 // first delete all forms that are now out of date
92 divIndex = $(".single_form").index($( "#months" ))
92 divIndex = $(".single_form").index($( "#months" ))
93 $(".single_form").slice(divIndex).empty()
93 $(".single_form").slice(divIndex).empty()
94 // second populate the years html if '0' not selected
94 // second populate the years html if '0' not selected
95 if (kinst != '0') {
95 if (kinst != '0') {
96 $(".single_form").slice(divIndex,divIndex+1).load(url);
96 $(".single_form").slice(divIndex,divIndex+1).load(url);
97 }
97 }
98 }
98 }
99
99
100 function populateCalendar (select) {
100 function populateCalendar (select) {
101 var year = $("#id_years")[0].options[$("#id_years")[0].selectedIndex].value;
101 var year = $("#id_years")[0].options[$("#id_years")[0].selectedIndex].value;
102 var month = select.options[select.selectedIndex].value;
102 var month = select.options[select.selectedIndex].value;
103 var kinst = $("#id_instruments")[0].options[$("#id_instruments")[0].selectedIndex].value;
103 var kinst = $("#id_instruments")[0].options[$("#id_instruments")[0].selectedIndex].value;
104 var is_global = 0;
104 var is_global = 0;
105 if ($("#id_isGlobal")[0].checked) {
105 if ($("#id_isGlobal")[0].checked) {
106 is_global = 1;
106 is_global = 1;
107 }
107 }
108 var url = '{% url 'get_calendar' %}' + '?isGlobal=' + is_global + '&instruments=' + kinst + '&years=' + year + '&months=' + month;
108 var url = '{% url 'get_calendar' %}' + '?isGlobal=' + is_global + '&instruments=' + kinst + '&years=' + year + '&months=' + month;
109 // first delete all forms that are now out of date
109 // first delete all forms that are now out of date
110 divIndex = $(".single_form").index($( "#calendar" ))
110 divIndex = $(".single_form").index($( "#calendar" ))
111 $(".single_form").slice(divIndex).empty()
111 $(".single_form").slice(divIndex).empty()
112 // second populate the calendar html if '0' not selected
112 // second populate the calendar html if '0' not selected
113 if (year != '0') {
113 if (year != '0') {
114 $(".single_form").slice(divIndex,divIndex+1).load(url, function() {
114 $(".single_form").slice(divIndex,divIndex+1).load(url, function() {
115 createCalendar();
115 createCalendar();
116 });
116 });
117 }
117 }
118 }
118 }
119
119
120 function populateFile (select) {
120 function populateFile (select) {
121 var expId = select.options[select.selectedIndex].value;
121 var expId = select.options[select.selectedIndex].value;
122 var url = '{% url 'get_files' %}' + '?experiment_list=' + expId;
122 var url = '{% url 'get_files' %}' + '?experiment_list=' + expId;
123 // first delete all forms that are now out of date
123 // first delete all forms that are now out of date
124 divIndex = $(".single_form").index($( "#file_select" ))
124 divIndex = $(".single_form").index($( "#file_select" ))
125 $(".single_form").slice(divIndex).empty()
125 $(".single_form").slice(divIndex).empty()
126 // second populate the file_list html if '0' not selected
126 // second populate the file_list html if '0' not selected
127 if (expId != '0') {
127 if (expId != '0') {
128 $(".single_form").slice(divIndex,divIndex+1).load(url);
128 $(".single_form").slice(divIndex,divIndex+1).load(url);
129 }
129 }
130 }
130 }
131
131
132 function changeFile (select) {
132 function changeFile (select) {
133 var basename = select.options[select.selectedIndex].value;
133 var basename = select.options[select.selectedIndex].value;
134 {% if form.exp_id %}
134 {% if form.exp_id %}
135 var url = '{% url 'change_files' %}' + '?experiment_list={{ form.exp_id.label }}&file_list=' + basename;
135 var url = '{% url 'change_files' %}' + '?experiment_list={{ form.exp_id.label }}&file_list=' + basename;
136 {% else %}
136 {% else %}
137 var exp_id = $("#id_experiment_list")[0].options[$("#id_experiment_list")[0].selectedIndex].value;
137 var exp_id = $("#id_experiment_list")[0].options[$("#id_experiment_list")[0].selectedIndex].value;
138 var url = '{% url 'change_files' %}' + '?experiment_list=' + exp_id + '&file_list=' + basename;
138 var url = '{% url 'change_files' %}' + '?experiment_list=' + exp_id + '&file_list=' + basename;
139 {% endif %}
139 {% endif %}
140 // first delete all forms that are now out of date
140 // first delete all forms that are now out of date
141 divIndex = $(".single_form").index($( "#file_buttons" ))
141 divIndex = $(".single_form").index($( "#file_buttons" ))
142 $(".single_form").slice(divIndex).empty()
142 $(".single_form").slice(divIndex).empty()
143 // second populate the file_list html if '0' not selected
143 // second populate the file_list html if '0' not selected
144 if (basename != '0') {
144 if (basename != '0') {
145 $(".single_form").slice(divIndex,divIndex+1).load(url);
145 $(".single_form").slice(divIndex,divIndex+1).load(url);
146 }
146 }
147 }
147 }
148
148
149 {% include "madweb/fileDownload.js" %}
149 {% include "madweb/fileDownload.js" %}
150
150
151 </script>
151 </script>
152 {% endblock %}
152 {% endblock %}
153
153
154
154
155 {% block isGlobal %}
155 {% block isGlobal %}
156 <div class="col-md-12 single_form" id="isGlobal">
156 <div class="col-md-12 single_form" id="isGlobal">
157 {{ form.isGlobal.label }} {{ form.isGlobal }}
157 {{ form.isGlobal.label }} {{ form.isGlobal }}
158 </div> <!-- end subdivide -->
158 </div> <!-- end subdivide -->
159 {% endblock %}
159 {% endblock %}
160
160
161 {% block categories %}
161 {% block categories %}
162 <!-- subdivide selection column for categories to be possibly filled in by ajax - single_form 0 -->
162 <!-- subdivide selection column for categories to be possibly filled in by ajax - single_form 0 -->
163 <div class="col-md-12 single_form" id="categories">
163 <div class="col-md-12 single_form" id="categories">
164
164
165 {% if form.categories %}
165 {% if form.categories %}
166 {% include "madweb/categories.html" %}
166 {% include "madweb/categories.html" %}
167 {% endif %}
167 {% endif %}
168
168
169 </div> <!-- end subdivide -->
169 </div> <!-- end subdivide -->
170 {% endblock %}
170 {% endblock %}
171
171
172
172
173 {% block instruments %}
173 {% block instruments %}
174 <!-- subdivide selection column for instruments to be possibly filled in by ajax - single_form 0 -->
174 <!-- subdivide selection column for instruments to be possibly filled in by ajax - single_form 0 -->
175 <div class="col-md-12 single_form" id="instruments">
175 <div class="col-md-12 single_form" id="instruments">
176
176
177 {% if form.instruments %}
177 {% if form.instruments %}
178 {% include "madweb/instruments.html" %}
178 {% include "madweb/instruments.html" %}
179 {% endif %}
179 {% endif %}
180
180
181 </div> <!-- end subdivide -->
181 </div> <!-- end subdivide -->
182 {% endblock %}
182 {% endblock %}
183
183
184
184
185 {% block years %}
185 {% block years %}
186 <!-- subdivide selection column for year to be possibly filled in by ajax - single_form 1 -->
186 <!-- subdivide selection column for year to be possibly filled in by ajax - single_form 1 -->
187 <div class="col-md-12 single_form" id="years">
187 <div class="col-md-12 single_form" id="years">
188
188
189 {% if form.years %}
189 {% if form.years %}
190 {% include "madweb/years.html" %}
190 {% include "madweb/years.html" %}
191 {% endif %}
191 {% endif %}
192
192
193 </div> <!-- end subdivide -->
193 </div> <!-- end subdivide -->
194 {% endblock %}
194 {% endblock %}
195
195
196
196
197 {% block months %}
197 {% block months %}
198 <!-- subdivide selection column for month to be possibly filled in by ajax - single_form 1 -->
198 <!-- subdivide selection column for month to be possibly filled in by ajax - single_form 1 -->
199 <div class="col-md-12 single_form" id="months">
199 <div class="col-md-12 single_form" id="months">
200
200
201 {% if form.months %}
201 {% if form.months %}
202 {% include "madweb/months.html" %}
202 {% include "madweb/months.html" %}
203 {% endif %}
203 {% endif %}
204
204
205 </div> <!-- end subdivide -->
205 </div> <!-- end subdivide -->
206 {% endblock %}
206 {% endblock %}
207
207
208
208
209 {% block calendar %}
209 {% block calendar %}
210 <!-- subdivide selection column for calendar to be possibly filled in by ajax - single_form 2 -->
210 <!-- subdivide selection column for calendar to be possibly filled in by ajax - single_form 2 -->
211 <div class="col-md-12 single_form" id="calendar">
211 <div class="col-md-12 single_form" id="calendar">
212
212
213 {% if form.days %}
213 {% if form.days %}
214 {% include "madweb/calendar.html" %}
214 {% include "madweb/calendar.html" %}
215 {% endif %}
215 {% endif %}
216
216
217 </div> <!-- end subdivide -->
217 </div> <!-- end subdivide -->
218 {% endblock %}
218 {% endblock %}
219
219
220 {% block experiment_select %}
220 {% block experiment_select %}
221 <!-- this select only appears if there are multiple experiments in the day -->
221 <!-- this select only appears if there are multiple experiments in the day -->
222 <div class="col-md-12 single_form" id="experiment_select">
222 <div class="col-md-12 single_form" id="experiment_select">
223 {% if form.experiment_list %}
223 {% if form.experiment_list %}
224 {% include "madweb/exp_list.html" %}
224 {% include "madweb/exp_list.html" %}
225 {% endif %}
225 {% endif %}
226 </div> <!-- end subdivide -->
226 </div> <!-- end subdivide -->
227 {% endblock %}
227 {% endblock %}
228
228
229 {% block file_select %}
229 {% block file_select %}
230 <!-- file select div -->
230 <!-- file select div -->
231 <div class="col-md-12 single_form" id="file_select">
231 <div class="col-md-12 single_form" id="file_select">
232 {% if form.file_list|length > 1 %}
232 {% if form.file_list|length > 1 %}
233 {% include "madweb/file_list.html" %}
233 {% include "madweb/file_list.html" %}
234 {% elif form.days and not form.experiment_list %}
234 {% elif form.days and not form.experiment_list %}
235 <center><p> This experiment has no Madrigal CEDAR format Hdf5 files. Showing only plots and auxillary files instead.</p></center>
235 <center><p> This experiment has no Madrigal CEDAR format Hdf5 files. Showing only plots and auxillary files instead.</p></center>
236 {% include "madweb/show_plots.html" %}
236 {% include "madweb/show_plots.html" %}
237 {% endif %}
237 {% endif %}
238 </div> <!-- end subdivide -->
238 </div> <!-- end subdivide -->
239 {% endblock %}
239 {% endblock %}
240
240
241 {% block file_buttons %}
241 {% block file_buttons %}
242 <!-- file select div -->
242 <!-- file select div -->
243 <div class="col-md-12 single_form" id="file_buttons">
243 <div class="col-md-12 single_form" id="file_buttons">
244 {% if form.file_buttons %}
244 {% if form.file_buttons %}
245 {% include "madweb/file_buttons.html" %}
245 {% include "madweb/file_buttons.html" %}
246 {% endif %}
246 {% endif %}
247 </div> <!-- end subdivide -->
247 </div> <!-- end subdivide -->
248 <div>&nbsp;</div>
248 <div>&nbsp;</div>
249 {% endblock %}
249 {% endblock %}
250
250
251 {% block file_data %}
251 {% block file_data %}
252 <!-- file select div -->
252 <!-- file select div -->
253 <div class="col-md-12 single_form" id="file_data">
253 <div class="col-md-12 single_form" id="file_data">
254 {% if form.show_plots %}
254 {% if form.show_plots %}
255 {% include "madweb/show_plots.html" %}
255 {% include "madweb/show_plots.html" %}
256 {% endif %}
256 {% endif %}
257 </div> <!-- end subdivide -->
257 </div> <!-- end subdivide -->
258 {% endblock %}
258 {% endblock %}
259
259
260 {% block file_plot %}
260 {% block file_plot %}
261 <!-- file select div -->
261 <!-- file select div -->
262 <div class="col-md-12 single_form" id="file_plot">
262 <div class="col-md-9 single_form" id="file_plot">
263 {% if form.show_plots %}
263 {% if form.show_plots %}
264 {% include "madweb/parameter_selection.html" %}
264 {% include "madweb/parameter_selection.html" %}
265 {% endif %}
265 {% endif %}
266 </div> <!-- end subdivide -->
266 </div> <!-- end subdivide -->
267 {% endblock %}
267 {% endblock %}
268
268
@@ -1,68 +1,68
1 {% load static %}
1 {% load static %}
2
2
3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/doc_template.dwt" codeOutsideHTMLIsLocked="false" -->
4 <html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/doc_template.dwt" codeOutsideHTMLIsLocked="false" -->
5 <head>
5 <head>
6 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
6 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
7 <!-- InstanceBeginEditable name="doctitle" -->
7 <!-- InstanceBeginEditable name="doctitle" -->
8 <title>Madrigal users guide</title>
8 <title>Madrigal users guide</title>
9 <!-- InstanceEndEditable --><!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
9 <!-- InstanceEndEditable --><!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
10 <link href="/static/madrigal.css" rel="stylesheet" type="text/css" />
10 <link href="/static/madrigal.css" rel="stylesheet" type="text/css" />
11 <style type="text/css">
11 <style type="text/css">
12 html body {
12 html body {
13 background-color: {{bg_color}};
13 background-color: {{bg_color}};
14 }
14 }
15 </style>
15 </style>
16 <!-- InstanceParam name="href_up_top" type="text" value="madContents.html" --><!-- InstanceParam name="href_next_top" type="text" value="wt_contents.html" --><!-- InstanceParam name="href_back_top" type="text" value="whatsNew.html" --><!-- InstanceParam name="href_back_bottom" type="text" value="whatsNew.html" --><!-- InstanceParam name="href_up_bottom" type="text" value="madContents.html" --><!-- InstanceParam name="href_next_bottom" type="text" value="wt_contents.html" --><!-- InstanceParam name="href_prev_top" type="text" value="whatsNew.html" --><!-- InstanceParam name="href_uptitle_top" type="text" value="madContents.html" --><!-- InstanceParam name="href_nexttitle_top" type="text" value="wt_contents.html" --><!-- InstanceParam name="href_prevtitle_bottom" type="text" value="whatsNew.html" --><!-- InstanceParam name="href_uptitle_bottom" type="text" value="madContents.html" --><!-- InstanceParam name="href_nexttitle_bottom" type="text" value="wt_contents.html" -->
16 <!-- InstanceParam name="href_up_top" type="text" value="madContents.html" --><!-- InstanceParam name="href_next_top" type="text" value="wt_contents.html" --><!-- InstanceParam name="href_back_top" type="text" value="whatsNew.html" --><!-- InstanceParam name="href_back_bottom" type="text" value="whatsNew.html" --><!-- InstanceParam name="href_up_bottom" type="text" value="madContents.html" --><!-- InstanceParam name="href_next_bottom" type="text" value="wt_contents.html" --><!-- InstanceParam name="href_prev_top" type="text" value="whatsNew.html" --><!-- InstanceParam name="href_uptitle_top" type="text" value="madContents.html" --><!-- InstanceParam name="href_nexttitle_top" type="text" value="wt_contents.html" --><!-- InstanceParam name="href_prevtitle_bottom" type="text" value="whatsNew.html" --><!-- InstanceParam name="href_uptitle_bottom" type="text" value="madContents.html" --><!-- InstanceParam name="href_nexttitle_bottom" type="text" value="wt_contents.html" -->
17 </head>
17 </head>
18
18
19 <body>
19 <body>
20 <table width="100%" border="1" cellpadding="0" cellspacing="2" class="navigation">
20 <table width="100%" border="1" cellpadding="0" cellspacing="2" class="navigation">
21 <tr>
21 <tr>
22 <td width="5%"><a href="{% url 'docs' 'whatsNew.html' %}"><img src="/static/previous.png" alt="previous" width="32" height="32" /></a></td>
22 <td width="5%"><a href="{% url 'docs' 'whatsNew.html' %}"><img src="{% static 'previous.png' %}" alt="previous" width="32" height="32" /></a></td>
23 <td width="5%"><a href="{% url 'docs' 'madContents.html' %}"><img src="/static/up.png" alt="up" width="32" height="32" /></a></td>
23 <td width="5%"><a href="{% url 'docs' 'madContents.html' %}"><img src="{% static 'up.png' %}" alt="up" width="32" height="32" /></a></td>
24 <td width="5%"><a href="{% url 'docs' 'wt_contents.html' %}"><img src="/static/next.png" alt="next" width="32" height="32" /></a></td>
24 <td width="5%"><a href="{% url 'docs' 'wt_contents.html' %}"><img src="{% static 'next.png' %}" alt="next" width="32" height="32" /></a></td>
25 <td width="54%"><!-- InstanceBeginEditable name="EditTitleTop" -->Madrigal user's guide (How do I access Madrigal data?)<!-- InstanceEndEditable --></td>
25 <td width="54%"><!-- InstanceBeginEditable name="EditTitleTop" -->Madrigal user's guide (How do I access Madrigal data?)<!-- InstanceEndEditable --></td>
26 <td width="13%"><a href="{% url 'docs' 'madContents.html' %}">Doc home </a></td>
26 <td width="13%"><a href="{% url 'docs' 'madContents.html' %}">Doc home </a></td>
27 <td width="18%"><a href="/">Madrigal home</a></td>
27 <td width="18%"><a href="/">Madrigal home</a></td>
28 </tr>
28 </tr>
29 </table>
29 </table>
30 <div class='online-navigation'>
30 <div class='online-navigation'>
31 <b class="navlabel">Previous:</b>
31 <b class="navlabel">Previous:</b>
32 <a class="sectref" href="{% url 'docs' 'whatsNew.html' %}"><!-- InstanceBeginEditable name="PreviousTitle" -->What's new <!-- InstanceEndEditable --></A>
32 <a class="sectref" href="{% url 'docs' 'whatsNew.html' %}"><!-- InstanceBeginEditable name="PreviousTitle" -->What's new <!-- InstanceEndEditable --></A>
33 <b class="navlabel">&nbsp;&nbsp;Up:</b>
33 <b class="navlabel">&nbsp;&nbsp;Up:</b>
34 <a class="sectref" href="{% url 'docs' 'madContents.html' %}"><!-- InstanceBeginEditable name="UpTitle" -->Doc home <!-- InstanceEndEditable --></A>
34 <a class="sectref" href="{% url 'docs' 'madContents.html' %}"><!-- InstanceBeginEditable name="UpTitle" -->Doc home <!-- InstanceEndEditable --></A>
35 <b class="navlabel">&nbsp;&nbsp;Next:</b>
35 <b class="navlabel">&nbsp;&nbsp;Next:</b>
36 <a class="sectref" href="{% url 'docs' 'wt_contents.html' %}"><!-- InstanceBeginEditable name="NextTitle" -->Web interface tutorial TOC <!-- InstanceEndEditable --></A></div>
36 <a class="sectref" href="{% url 'docs' 'wt_contents.html' %}"><!-- InstanceBeginEditable name="NextTitle" -->Web interface tutorial TOC <!-- InstanceEndEditable --></A></div>
37 <hr/>
37 <hr/>
38 <!-- InstanceBeginEditable name="EditDoc" -->
38 <!-- InstanceBeginEditable name="EditDoc" -->
39 <h1 align="center">Madrigal user's guide (How do I access Madrigal data?)</h1>
39 <h1 align="center">Madrigal user's guide (How do I access Madrigal data?)</h1>
40 <p>There are two basic ways to access Madrigal data - through a web browser, or through the API using the programming languages Matlab, IDL, Python, or Fortran95. The Madrigal web interface will also allow you to create the most common commands you would need to run these API's. That is, with just a few click you can create a command to download whatever files you want from any number of experiments in any format. You can also create a command to download just the parameters you want with any filter you might want.</p>
40 <p>There are two basic ways to access Madrigal data - through a web browser, or through the API using the programming languages Matlab, IDL, Python, or Fortran95. The Madrigal web interface will also allow you to create the most common commands you would need to run these API's. That is, with just a few click you can create a command to download whatever files you want from any number of experiments in any format. You can also create a command to download just the parameters you want with any filter you might want.</p>
41 <p>This user's guide consists of a brief tutorial on using the web interface, and a tutorial and a reference manual for remote data access. The last section also documents some command line interfaces into Madrigal.</p>
41 <p>This user's guide consists of a brief tutorial on using the web interface, and a tutorial and a reference manual for remote data access. The last section also documents some command line interfaces into Madrigal.</p>
42 <ul>
42 <ul>
43 <li><a href="{% url 'docs' 'wt_contents.html' %}">Web interface tutorial</a></li>
43 <li><a href="{% url 'docs' 'wt_contents.html' %}">Web interface tutorial</a></li>
44 <li><a href="{% url 'docs' 'rt_contents.html' %}">Remote API tutorial</a></li>
44 <li><a href="{% url 'docs' 'rt_contents.html' %}">Remote API tutorial</a></li>
45 <li><a href="{% url 'docs' 'rr_contents.html' %}">Remote API reference guide</a></li>
45 <li><a href="{% url 'docs' 'rr_contents.html' %}">Remote API reference guide</a></li>
46 </ul>
46 </ul>
47 <!-- InstanceEndEditable -->
47 <!-- InstanceEndEditable -->
48 <table width="100%" border="1" cellpadding="0" cellspacing="2" class="navigation">
48 <table width="100%" border="1" cellpadding="0" cellspacing="2" class="navigation">
49 <tr>
49 <tr>
50 <td width="5%"><a href="{% url 'docs' 'whatsNew.html' %}"><img src="/static/previous.png" alt="previous" width="32" height="32" /></a></td>
50 <td width="5%"><a href="{% url 'docs' 'whatsNew.html' %}"><img src="{% static 'previous.png' %}" alt="previous" width="32" height="32" /></a></td>
51 <td width="5%"><a href="{% url 'docs' 'madContents.html' %}"><img src="/static/up.png" alt="up" width="32" height="32" /></a></td>
51 <td width="5%"><a href="{% url 'docs' 'madContents.html' %}"><img src="{% static 'up.png' %}" alt="up" width="32" height="32" /></a></td>
52 <td width="5%"><a href="{% url 'docs' 'wt_contents.html' %}"><img src="/static/next.png" alt="next" width="32" height="32" /></a></td>
52 <td width="5%"><a href="{% url 'docs' 'wt_contents.html' %}"><img src="{% static 'next.png' %}" alt="next" width="32" height="32" /></a></td>
53 <td width="54%"><!-- InstanceBeginEditable name="EditTitleBottom" -->Madrigal user's guide (How do I access Madrigal data?)<!-- InstanceEndEditable --></td>
53 <td width="54%"><!-- InstanceBeginEditable name="EditTitleBottom" -->Madrigal user's guide (How do I access Madrigal data?)<!-- InstanceEndEditable --></td>
54 <td width="13%"><a href="{% url 'docs' 'madContents.html' %}">Doc home </a></td>
54 <td width="13%"><a href="{% url 'docs' 'madContents.html' %}">Doc home </a></td>
55 <td width="18%"><a href="/">Madrigal home</a></td>
55 <td width="18%"><a href="/">Madrigal home</a></td>
56 </tr>
56 </tr>
57 </table>
57 </table>
58 <div class='online-navigation'>
58 <div class='online-navigation'>
59 <b class="navlabel">Previous:</b>
59 <b class="navlabel">Previous:</b>
60 <a class="sectref" href="{% url 'docs' 'whatsNew.html' %}"><!-- InstanceBeginEditable name="PreviousTitle2" -->What's new <!-- InstanceEndEditable --></A>
60 <a class="sectref" href="{% url 'docs' 'whatsNew.html' %}"><!-- InstanceBeginEditable name="PreviousTitle2" -->What's new <!-- InstanceEndEditable --></A>
61 <b class="navlabel">&nbsp;&nbsp;Up:</b>
61 <b class="navlabel">&nbsp;&nbsp;Up:</b>
62 <a class="sectref" href="{% url 'docs' 'madContents.html' %}"><!-- InstanceBeginEditable name="UpTitle2" -->Doc home <!-- InstanceEndEditable --></A>
62 <a class="sectref" href="{% url 'docs' 'madContents.html' %}"><!-- InstanceBeginEditable name="UpTitle2" -->Doc home <!-- InstanceEndEditable --></A>
63 <b class="navlabel">&nbsp;&nbsp;Next:</b>
63 <b class="navlabel">&nbsp;&nbsp;Next:</b>
64 <a class="sectref" href="{% url 'docs' 'wt_contents.html' %}"><!-- InstanceBeginEditable name="NextTitle2" -->Web interface tutorial TOC<!-- InstanceEndEditable --></A></div>
64 <a class="sectref" href="{% url 'docs' 'wt_contents.html' %}"><!-- InstanceBeginEditable name="NextTitle2" -->Web interface tutorial TOC<!-- InstanceEndEditable --></A></div>
65 <hr/>
65 <hr/>
66 <p>&nbsp;</p>
66 <p>&nbsp;</p>
67 </body>
67 </body>
68 <!-- InstanceEnd --></html>
68 <!-- InstanceEnd --></html>
@@ -1,3530 +1,3540
1 '''
1 '''
2
2
3 @author: Bill Rideout
3 @author: Bill Rideout
4 @contact: brideout@haystack.mit.edu
4 @contact: brideout@haystack.mit.edu
5
5
6 $Id: views.py 7345 2021-03-30 18:30:32Z brideout $
6 $Id: views.py 7345 2021-03-30 18:30:32Z brideout $
7 '''
7 '''
8 # standard python imports
8 # standard python imports
9 import os.path
9 import os.path
10 import urllib
10 import urllib
11 import os, sys
11 import os, sys
12 import json
12 import json
13 import datetime, time
13 import datetime, time
14 import glob
14 import glob
15 import re
15 import re
16 import subprocess
16 import subprocess
17 import io
17 import io
18 import collections
18 import collections
19 import shutil
19 import shutil
20 import mimetypes
20 import mimetypes
21 import tempfile
21 import tempfile
22 import random
22 import random
23
23
24 # django imports
24 # django imports
25 from django.shortcuts import render, redirect
25 from django.shortcuts import render, redirect
26 from django.views.decorators.csrf import csrf_exempt
26 from django.views.decorators.csrf import csrf_exempt
27 from django.template.context import RequestContext
27 from django.template.context import RequestContext
28 #from django.conf import settings
28 #from django.conf import settings
29 try:
29 try:
30 from django.urls import reverse
30 from django.urls import reverse
31 except ImportError:
31 except ImportError:
32 from django.core.urlresolvers import reverse
32 from django.core.urlresolvers import reverse
33 from django.http import HttpResponse, HttpResponseRedirect, StreamingHttpResponse
33 from django.http import HttpResponse, HttpResponseRedirect, StreamingHttpResponse
34 import django.utils.http
34 import django.utils.http
35 import django.core.files
35 import django.core.files
36 import django.utils.safestring
36 import django.utils.safestring
37 from wsgiref.util import FileWrapper
37 from wsgiref.util import FileWrapper
38
38
39 # third party imports
39 # third party imports
40 import numpy
40 import numpy
41 import plotly.offline as py
41 import plotly.offline as py
42 import plotly.graph_objs as go
42 import plotly.graph_objs as go
43 import h5py
43 import h5py
44
44
45
45
46 # madrigal imports
46 # madrigal imports
47 import madrigal._derive
47 import madrigal._derive
48 import madrigal.metadata
48 import madrigal.metadata
49 import madrigal.ui.web
49 import madrigal.ui.web
50 import madrigal.cedar
50 import madrigal.cedar
51 import madrigal.isprint
51 import madrigal.isprint
52 import madweb.forms
52 import madweb.forms
53
53
54
54
55 # temp only
55 # temp only
56 import logging
56 import logging
57
57
58
58
59 # constants
59 # constants
60 formatDict = collections.OrderedDict()
60 formatDict = collections.OrderedDict()
61 formatDict['hdf5'] = 'Hdf5'
61 formatDict['hdf5'] = 'Hdf5'
62 formatDict['netCDF4'] = 'netCDF4'
62 formatDict['netCDF4'] = 'netCDF4'
63 formatDict['ascii'] = 'Column-delimited ascii'
63 formatDict['ascii'] = 'Column-delimited ascii'
64 maxSize = 50000000 # 50 MB cutoff
64 maxSize = 50000000 # 50 MB cutoff
65
65
66
66
67
67
68
68
69 def index(request):
69 def index(request):
70 """index is the home page view
70 """index is the home page view
71 """
71 """
72 madDB = madrigal.metadata.MadrigalDB()
72 madDB = madrigal.metadata.MadrigalDB()
73 bg_color = madDB.getBackgroundColor()
73 bg_color = madDB.getBackgroundColor()
74 welcome = madDB.getIndexHead()
74 welcome = madDB.getIndexHead()
75 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
75 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
76 siteName, siteList = madWebObj.getSiteInfo()
76 siteName, siteList = madWebObj.getSiteInfo()
77 rulesRoadHtml = madDB.getLocalRulesOfRoad()
77 rulesRoadHtml = madDB.getLocalRulesOfRoad()
78 template_dict = {'home_active': 'class="active"', 'site_name': siteName, 'site_list': siteList,
78 template_dict = {'home_active': 'class="active"', 'site_name': siteName, 'site_list': siteList,
79 'rulesOfRoad':django.utils.safestring.mark_safe(rulesRoadHtml),
79 'rulesOfRoad':django.utils.safestring.mark_safe(rulesRoadHtml),
80 'bg_color': bg_color, 'welcome': welcome}
80 'bg_color': bg_color, 'welcome': welcome}
81 return render(request, 'madweb/index.html', template_dict)
81 return render(request, 'madweb/index.html', template_dict)
82
82
83 @csrf_exempt
83 @csrf_exempt
84 def check_registration(view):
84 def check_registration(view):
85 def check_cookies(request, *args, **kwargs):
85 def check_cookies(request, *args, **kwargs):
86 # this view checks if all the needed cookies are set
86 # this view checks if all the needed cookies are set
87 cookieDict = request.COOKIES
87 cookieDict = request.COOKIES
88 try:
88 try:
89 cookieDict['user_fullname']
89 cookieDict['user_fullname']
90 cookieDict['user_email']
90 cookieDict['user_email']
91 cookieDict['user_affiliation']
91 cookieDict['user_affiliation']
92 # no need to register
92 # no need to register
93 return(view(request, *args, **kwargs))
93 return(view(request, *args, **kwargs))
94 except KeyError:
94 except KeyError:
95 return(HttpResponseRedirect(reverse('view_registration') + '?redirect=%s' % (request.get_full_path())))
95 return(HttpResponseRedirect(reverse('view_registration') + '?redirect=%s' % (request.get_full_path())))
96
96
97 return(check_cookies)
97 return(check_cookies)
98
98
99
99
100 def view_registration(request):
100 def view_registration(request):
101 madDB = madrigal.metadata.MadrigalDB()
101 madDB = madrigal.metadata.MadrigalDB()
102 madWeb = madrigal.ui.web.MadrigalWeb(madDB)
102 madWeb = madrigal.ui.web.MadrigalWeb(madDB)
103 siteName, siteList = madWeb.getSiteInfo()
103 siteName, siteList = madWeb.getSiteInfo()
104 redirect = 'index' # default is to redirect to home page
104 redirect = 'index' # default is to redirect to home page
105 if request.method == 'GET':
105 if request.method == 'GET':
106 if 'redirect' in request.GET:
106 if 'redirect' in request.GET:
107 redirect = request.GET['redirect']
107 redirect = request.GET['redirect']
108 for key in request.GET:
108 for key in request.GET:
109 if key not in ('redirect', 'user_fullname', 'user_email', 'user_affiliation'):
109 if key not in ('redirect', 'user_fullname', 'user_email', 'user_affiliation'):
110 redirect += '&%s=%s' % (key, request.GET[key])
110 redirect += '&%s=%s' % (key, request.GET[key])
111 if len(list(request.GET.keys())) > 0 and 'user_fullname' in request.GET:
111 if len(list(request.GET.keys())) > 0 and 'user_fullname' in request.GET:
112 form = madweb.forms.RegisterForm(request.GET)
112 form = madweb.forms.RegisterForm(request.GET)
113 if form.is_valid():
113 if form.is_valid():
114 # write cookies and continue to main page
114 # write cookies and continue to main page
115 max_age = 3600*24*365 # one year
115 max_age = 3600*24*365 # one year
116 if redirect == 'index':
116 if redirect == 'index':
117 response = HttpResponseRedirect(reverse('index'))
117 response = HttpResponseRedirect(reverse('index'))
118 else:
118 else:
119 response = HttpResponseRedirect(redirect)
119 response = HttpResponseRedirect(redirect)
120 response.set_cookie('user_fullname', form.cleaned_data['user_fullname'], max_age=max_age, samesite='Strict')
120 response.set_cookie('user_fullname', form.cleaned_data['user_fullname'], max_age=max_age, samesite='Strict')
121 response.set_cookie('user_email', form.cleaned_data['user_email'], max_age=max_age, samesite='Strict')
121 response.set_cookie('user_email', form.cleaned_data['user_email'], max_age=max_age, samesite='Strict')
122 response.set_cookie('user_affiliation', form.cleaned_data['user_affiliation'], max_age=max_age, samesite='Strict')
122 response.set_cookie('user_affiliation', form.cleaned_data['user_affiliation'], max_age=max_age, samesite='Strict')
123 return(response)
123 return(response)
124 else:
124 else:
125 form = madweb.forms.RegisterForm()
125 form = madweb.forms.RegisterForm()
126
126
127 else:
127 else:
128 form = madweb.forms.RegisterForm()
128 form = madweb.forms.RegisterForm()
129 return render(request, 'madweb/register.html', {'form': form, 'home_active': 'class="active"',
129 return render(request, 'madweb/register.html', {'form': form, 'home_active': 'class="active"',
130 'site_name': siteName, 'site_list': siteList,
130 'site_name': siteName, 'site_list': siteList,
131 'redirect': redirect})
131 'redirect': redirect})
132
132
133
133
134
134
135
135
136
136
137
137
138 def view_single(request):
138 def view_single(request):
139 """view_single is the single experiment view. It is supplemented by ajax views to speed performamnce,
139 """view_single is the single experiment view. It is supplemented by ajax views to speed performamnce,
140 but this view can also create the entire page given a complete query string
140 but this view can also create the entire page given a complete query string
141 """
141 """
142 responseDict = {'single_active': 'class="active"'}
142 responseDict = {'single_active': 'class="active"'}
143 cookieDict = request.COOKIES
143 cookieDict = request.COOKIES
144 user_email = cookieDict['user_email']
144 user_email = cookieDict['user_email']
145 queryDict = request.GET.copy()
145 queryDict = request.GET.copy()
146 queryDict['user_email'] = user_email
146 queryDict['user_email'] = user_email
147 madDB = madrigal.metadata.MadrigalDB()
147 madDB = madrigal.metadata.MadrigalDB()
148 bg_color = madDB.getBackgroundColor()
148 bg_color = madDB.getBackgroundColor()
149 madWeb = madrigal.ui.web.MadrigalWeb(madDB)
149 madWeb = madrigal.ui.web.MadrigalWeb(madDB)
150 siteName, siteList = madWeb.getSiteInfo()
150 siteName, siteList = madWeb.getSiteInfo()
151 form = madweb.forms.SingleExpDefaultForm(queryDict)
151 form = madweb.forms.SingleExpDefaultForm(queryDict)
152 if not form.is_valid():
152 if not form.is_valid():
153 # new page
153 # new page
154 form = madweb.forms.SingleExpDefaultForm()
154 form = madweb.forms.SingleExpDefaultForm()
155 responseDict['form'] = form
155 responseDict['form'] = form
156 responseDict['site_name'] = siteName
156 responseDict['site_name'] = siteName
157 responseDict['site_list'] = siteList
157 responseDict['site_list'] = siteList
158 responseDict['redirect_list'] = madWeb.getSingleRedirectList()
158 responseDict['redirect_list'] = madWeb.getSingleRedirectList()
159 if 'instruments' in request.GET:
159 if 'instruments' in request.GET:
160 responseDict['instruments'] = request.GET['instruments']
160 responseDict['instruments'] = request.GET['instruments']
161 if 'years' in request.GET:
161 if 'years' in request.GET:
162 responseDict['years'] = request.GET['years']
162 responseDict['years'] = request.GET['years']
163 if 'months' in request.GET:
163 if 'months' in request.GET:
164 responseDict['months'] = request.GET['months']
164 responseDict['months'] = request.GET['months']
165 try:
165 try:
166 # add extra keys if choosing a file
166 # add extra keys if choosing a file
167 form.fields['file_list']
167 form.fields['file_list']
168 responseDict['loader'] = 'loadSingleForm'
168 responseDict['loader'] = 'loadSingleForm'
169 responseDict['redirect'] = reverse('get_files')
169 responseDict['redirect'] = reverse('get_files')
170 # handle the case with no files
170 # handle the case with no files
171 if len(form.fields['file_list'].choices) < 2:
171 if len(form.fields['file_list'].choices) < 2:
172 form2 = madweb.forms.SingleExpPlotsForm({'experiment_list':form['exp_id'].initial})
172 form2 = madweb.forms.SingleExpPlotsForm({'experiment_list':form['exp_id'].initial})
173 form.fields['plot_list'] = form2.fields['plot_list']
173 form.fields['plot_list'] = form2.fields['plot_list']
174 except:
174 except:
175 pass
175 pass
176 responseDict['bg_color'] = bg_color
176 responseDict['bg_color'] = bg_color
177 return render(request, 'madweb/single.html', responseDict)
177 return render(request, 'madweb/single.html', responseDict)
178
178
179
179
180 def get_categories(request):
180 def get_categories(request):
181 """get_categories is a Ajax call that returns the categories select html to support the
181 """get_categories is a Ajax call that returns the categories select html to support the
182 single experiment UI. Called when a user modifies the isGlobal checkbox.
182 single experiment UI. Called when a user modifies the isGlobal checkbox.
183
183
184 Inputs:
184 Inputs:
185 request
185 request
186 """
186 """
187 form = madweb.forms.SingleExpDefaultForm(request.GET)
187 form = madweb.forms.SingleExpDefaultForm(request.GET)
188
188
189 return render(request, 'madweb/categories.html', {'form': form})
189 return render(request, 'madweb/categories.html', {'form': form})
190
190
191
191
192 def get_instruments(request):
192 def get_instruments(request):
193 """get_instruments is a Ajax call that returns the instruments select html to support the
193 """get_instruments is a Ajax call that returns the instruments select html to support the
194 single experiment UI. Called when a user modifies the categories select field.
194 single experiment UI. Called when a user modifies the categories select field.
195
195
196 Inputs:
196 Inputs:
197 request
197 request
198 """
198 """
199 form = madweb.forms.SingleExpInstForm(request.GET)
199 form = madweb.forms.SingleExpInstForm(request.GET)
200
200
201 return render(request, 'madweb/instruments.html', {'form': form})
201 return render(request, 'madweb/instruments.html', {'form': form})
202
202
203
203
204 def get_years(request):
204 def get_years(request):
205 """get_years is a Ajax call that returns the years select html to support the
205 """get_years is a Ajax call that returns the years select html to support the
206 single experiment UI. Called when a user modifies the instruments select field.
206 single experiment UI. Called when a user modifies the instruments select field.
207
207
208 Inputs:
208 Inputs:
209 request
209 request
210 """
210 """
211 form = madweb.forms.SingleExpYearForm(request.GET)
211 form = madweb.forms.SingleExpYearForm(request.GET)
212
212
213 is_global = madweb.forms.getIsGlobal([], request.GET)
213 is_global = madweb.forms.getIsGlobal([], request.GET)
214
214
215 return render(request, 'madweb/years.html', {'isGlobal': is_global,
215 return render(request, 'madweb/years.html', {'isGlobal': is_global,
216 'form': form})
216 'form': form})
217
217
218
218
219 def get_months(request):
219 def get_months(request):
220 """get_months is a Ajax call that returns the months select html to support the
220 """get_months is a Ajax call that returns the months select html to support the
221 single experiment UI. Called when a user modifies the years select field.
221 single experiment UI. Called when a user modifies the years select field.
222
222
223 Inputs:
223 Inputs:
224 request
224 request
225 """
225 """
226 form = madweb.forms.SingleExpMonthForm(request.GET)
226 form = madweb.forms.SingleExpMonthForm(request.GET)
227
227
228 is_global = madweb.forms.getIsGlobal([], request.GET)
228 is_global = madweb.forms.getIsGlobal([], request.GET)
229 year = int(request.GET['years'])
229 year = int(request.GET['years'])
230 kinst =int(request.GET['instruments'])
230 kinst =int(request.GET['instruments'])
231
231
232 return render(request, 'madweb/months.html', {'isGlobal': is_global,
232 return render(request, 'madweb/months.html', {'isGlobal': is_global,
233 'years': year,
233 'years': year,
234 'form': form})
234 'form': form})
235
235
236
236
237 def get_calendar(request):
237 def get_calendar(request):
238 """get_calendar is a Ajax call that returns the calendar html to support the
238 """get_calendar is a Ajax call that returns the calendar html to support the
239 single experiment UI. Called when a user selects month field.
239 single experiment UI. Called when a user selects month field.
240
240
241 Inputs:
241 Inputs:
242 request
242 request
243 """
243 """
244 is_global = madweb.forms.getIsGlobal([], request.GET)
244 is_global = madweb.forms.getIsGlobal([], request.GET)
245 year = int(request.GET['years'])
245 year = int(request.GET['years'])
246 month = int(request.GET['months'])
246 month = int(request.GET['months'])
247 kinst =int(request.GET['instruments'])
247 kinst =int(request.GET['instruments'])
248
248
249 form = madweb.forms.SingleExpCalendarForm({'years': year,
249 form = madweb.forms.SingleExpCalendarForm({'years': year,
250 'months': month,
250 'months': month,
251 'instruments': kinst})
251 'instruments': kinst})
252
252
253 return render(request, 'madweb/calendar.html', {'isGlobal': is_global,
253 return render(request, 'madweb/calendar.html', {'isGlobal': is_global,
254 'years': year,
254 'years': year,
255 'months': month,
255 'months': month,
256 'instruments': kinst,
256 'instruments': kinst,
257 'form': form})
257 'form': form})
258
258
259
259
260 def populate_calendar_experiment(request):
260 def populate_calendar_experiment(request):
261 """populate_calendar_experiment is a ajax view that returns a json object used by the
261 """populate_calendar_experiment is a ajax view that returns a json object used by the
262 calender widget to populate itself.
262 calender widget to populate itself.
263
263
264 Inputs:
264 Inputs:
265 request
265 request
266 """
266 """
267 is_global = madweb.forms.getIsGlobal([], request.GET)
267 is_global = madweb.forms.getIsGlobal([], request.GET)
268 year = int(request.GET['years'])
268 year = int(request.GET['years'])
269 month = int(request.GET['months'])
269 month = int(request.GET['months'])
270 kinst =int(request.GET['instruments'])
270 kinst =int(request.GET['instruments'])
271 madDB = madrigal.metadata.MadrigalDB()
271 madDB = madrigal.metadata.MadrigalDB()
272 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
272 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
273 madInstObj = madrigal.metadata.MadrigalInstrument(madDB)
273 madInstObj = madrigal.metadata.MadrigalInstrument(madDB)
274 catId = madInstObj.getCategoryId(kinst)
274 catId = madInstObj.getCategoryId(kinst)
275
275
276 expDays = madWebObj.getDays(kinst, year, month)
276 expDays = madWebObj.getDays(kinst, year, month)
277
277
278 if len(expDays) == 0:
278 if len(expDays) == 0:
279 expDays = madWebObj.getDays(kinst, year, month, optimize=False)
279 expDays = madWebObj.getDays(kinst, year, month, optimize=False)
280
280
281 color = "#999"
281 color = "#999"
282 jsonListFinal = []
282 jsonListFinal = []
283 for expDay in expDays:
283 for expDay in expDays:
284 newdate = '%i/%i/%i' % (expDay.day, expDay.month, expDay.year)
284 newdate = '%i/%i/%i' % (expDay.day, expDay.month, expDay.year)
285 urlperDate = reverse('view_single')
285 urlperDate = reverse('view_single')
286 query_str = '?'
286 query_str = '?'
287 if is_global:
287 if is_global:
288 query_str += 'isGlobal=on&'
288 query_str += 'isGlobal=on&'
289 query_str += 'categories=%i&instruments=%i&years=%i&months=%i&days=%i' % (catId, kinst, year,
289 query_str += 'categories=%i&instruments=%i&years=%i&months=%i&days=%i' % (catId, kinst, year,
290 expDay.month, expDay.day)
290 expDay.month, expDay.day)
291 urlperDate += query_str
291 urlperDate += query_str
292 dayList = [newdate, "", urlperDate, color]
292 dayList = [newdate, "", urlperDate, color]
293 jsonListFinal.append(dayList)
293 jsonListFinal.append(dayList)
294
294
295 return HttpResponse(json.dumps(jsonListFinal), content_type='application/json')
295 return HttpResponse(json.dumps(jsonListFinal), content_type='application/json')
296
296
297
297
298 def get_files(request):
298 def get_files(request):
299 """get_files is a Ajax call that returns the files select html to support the
299 """get_files is a Ajax call that returns the files select html to support the
300 single experiment UI. Called when a user modifies the calendar or experiments fields.
300 single experiment UI. Called when a user modifies the calendar or experiments fields.
301
301
302 Inputs:
302 Inputs:
303 request
303 request
304 """
304 """
305 cookieDict = request.COOKIES
305 cookieDict = request.COOKIES
306 user_email = cookieDict['user_email']
306 user_email = cookieDict['user_email']
307 queryDict = request.GET.copy()
307 queryDict = request.GET.copy()
308 queryDict['user_email'] = user_email
308 queryDict['user_email'] = user_email
309 form = madweb.forms.SingleExpFileForm(queryDict)
309 form = madweb.forms.SingleExpFileForm(queryDict)
310
310
311 is_global = madweb.forms.getIsGlobal([], request.GET)
311 is_global = madweb.forms.getIsGlobal([], request.GET)
312
312
313 return render(request, 'madweb/file_list.html', {'isGlobal': is_global,
313 return render(request, 'madweb/file_list.html', {'isGlobal': is_global,
314 'form': form,
314 'form': form,
315 'loader': 'loadSingleForm',
315 'loader': 'loadSingleForm',
316 'redirect': reverse('get_files')})
316 'redirect': reverse('get_files')})
317
317
318
318
319 def change_files(request):
319 def change_files(request):
320 """change_files is a Ajax call that returns the files options html to support the
320 """change_files is a Ajax call that returns the files options html to support the
321 single experiment UI. Called when a user modifies the files select field.
321 single experiment UI. Called when a user modifies the files select field.
322
322
323 Inputs:
323 Inputs:
324 request
324 request
325 """
325 """
326 expID =int(request.GET['experiment_list'])
326 expID =int(request.GET['experiment_list'])
327 basename = request.GET['file_list']
327 basename = request.GET['file_list']
328 madDB = madrigal.metadata.MadrigalDB()
328 madDB = madrigal.metadata.MadrigalDB()
329 form = madweb.forms.SingleExpButtonsForm(request.GET)
329 form = madweb.forms.SingleExpButtonsForm(request.GET)
330
330
331 return render(request, 'madweb/file_buttons.html', {'form': form,
331 return render(request, 'madweb/file_buttons.html', {'form': form,
332 'plot_label': madDB.getPlotButtonLabel()})
332 'plot_label': madDB.getPlotButtonLabel()})
333
333
334
334
335 def show_plots(request):
335 def show_plots(request):
336 """show_plots is a Ajax call that returns the files data html with plots to support the
336 """show_plots is a Ajax call that returns the files data html with plots to support the
337 single experiment UI. Called when a user modifies the files select field.
337 single experiment UI. Called when a user modifies the files select field.
338
338
339 Inputs:
339 Inputs:
340 request
340 request
341 """
341 """
342 madDB = madrigal.metadata.MadrigalDB()
342 madDB = madrigal.metadata.MadrigalDB()
343 madExpObj = madrigal.metadata.MadrigalExperiment(madDB)
343 madExpObj = madrigal.metadata.MadrigalExperiment(madDB)
344 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
344 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
345
345
346 try:
346 try:
347 expID = int(request.GET['experiment_list'])
347 expID = int(request.GET['experiment_list'])
348 except ValueError:
348 except ValueError:
349 # convert expPath to expID
349 # convert expPath to expID
350 expID = madWebObj.getExpIDFromExpPath(request.GET['experiment_list'], True)
350 expID = madWebObj.getExpIDFromExpPath(request.GET['experiment_list'], True)
351 plotList = madExpObj.getExpLinksByExpId(expID)
351 plotList = madExpObj.getExpLinksByExpId(expID)
352 if len(plotList) != 0:
352 if len(plotList) != 0:
353 form = madweb.forms.SingleExpPlotsForm(request.GET)
353 form = madweb.forms.SingleExpPlotsForm(request.GET)
354 template = 'madweb/show_plots.html'
354 template = 'madweb/show_plots.html'
355 context = {'form': form}
355 context = {'form': form}
356 else:
356 else:
357 template = 'madweb/parameter_selection.html'
357 template = 'madweb/parameter_selection.html'
358 form = madweb.forms.SingleExpPlotsSelectionForm(request.GET)
358 form = madweb.forms.SingleExpPlotsSelectionForm(request.GET)
359 context = {'form': form, 'expID': expID}
359 context = {'form': form, 'expID': expID}
360
360
361 return render(request, template, context)
361 return render(request, template, context)
362
362
363
363
364 def view_plot(request):
364 def view_plot(request):
365
365
366 param1d = request.GET.get('param1d', 0)
366 param1d = request.GET.get('param1d', 0)
367 param2d = request.GET.get('param2d', 0)
367 param2d = request.GET.get('param2d', 0)
368
368
369 madDB = madrigal.metadata.MadrigalDB()
369 madDB = madrigal.metadata.MadrigalDB()
370 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
370 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
371 madExpObj = madrigal.metadata.MadrigalExperiment(madDB)
371 madExpObj = madrigal.metadata.MadrigalExperiment(madDB)
372
372
373 expID =int(request.GET['expID'])
373 expID =int(request.GET['expID'])
374 expDir = madExpObj.getExpDirByExpId(expID)
374 expDir = madExpObj.getExpDirByExpId(expID)
375 if expDir is None:
375 if expDir is None:
376 raise ValueError('No expDir found for exp_id %i' % (int(expID)))
376 raise ValueError('No expDir found for exp_id %i' % (int(expID)))
377
377
378 # fileList = madWebObj.getFileFromExpID(expID, False)
378 # fileList = madWebObj.getFileFromExpID(expID, False)
379 # firsttuple = [a_tuple[0] for a_tuple in fileList]
379 # firsttuple = [a_tuple[0] for a_tuple in fileList]
380 basename = request.GET['filename']#firsttuple[0]
380 basename = request.GET['filename']#firsttuple[0]
381 fullFilename = os.path.join(expDir, basename)
381 fullFilename = os.path.join(expDir, basename)
382
382
383 with h5py.File(fullFilename, "r") as f:
383 with h5py.File(fullFilename, "r") as f:
384
384
385 # Get the data
385 # Get the data
386
386
387 data = f['Data']
387 data = f['Data']
388
388
389 if 'Array Layout' in data:
389 if 'Array Layout' in data:
390 array = data['Array Layout']
390 array = data['Array Layout']
391 datatime = [datetime.datetime.utcfromtimestamp(t-5*60*60) for t in array['timestamps']]
391 datatime = [datetime.datetime.utcfromtimestamp(t-5*60*60) for t in array['timestamps']]
392 if 'gdalt' in array:
392 if 'gdalt' in array:
393 yrange = array['gdalt']
393 yrange = array['gdalt']
394 elif 'range' in array:
394 elif 'range' in array:
395 yrange = array['range']
395 yrange = array['range']
396 else:
396 else:
397 return HttpResponse("There is no valid data for this plot: gdalt and/or range missing")
397 return HttpResponse("There is no valid data for this plot: gdalt and/or range missing")
398
398
399 if param1d==0:
399 if param1d==0:
400 kindat = data['Table Layout']['kindat'][0]
400 kindat = data['Table Layout']['kindat'][0]
401 if kindat in (1950, 1911, 1913):
401 if kindat in (1950, 1911, 1913):
402 plot = plot_scatter(datatime, array['2D Parameters'][param2d][0], param2d, array['2D Parameters']['d'+param2d][0])
402 ecode = 'd'+param2d
403 if ecode.startswith('dd'):
404 plot = plot_scatter(datatime, array['2D Parameters'][param2d][0], param2d)
405 else:
406 plot = plot_scatter(datatime, array['2D Parameters'][param2d][0], param2d, array['2D Parameters']['d'+param2d][0])
403 else:
407 else:
404 plot = plot_heatmap(datatime, yrange, array['2D Parameters'][param2d], param2d)
408 plot = plot_heatmap(datatime, yrange, array['2D Parameters'][param2d], param2d)
405 else:
409 else:
406 plot = plot_scatter(datatime, array['1D Parameters'][param1d], param1d)
410 plot = plot_scatter(datatime, array['1D Parameters'][param1d], param1d)
407
411
408 else:
412 else:
409 table = data['Table Layout']
413 table = data['Table Layout']
410 datatime = [datetime.datetime.fromtimestamp(t) for t in table['ut2_unix']]
414 datatime = [datetime.datetime.fromtimestamp(t) for t in table['ut2_unix']]
411 plot = plot_scatter(datatime,table[param1d],param1d)
415 plot = plot_scatter(datatime,table[param1d],param1d)
412
416
413 return HttpResponse(plot)
417 return HttpResponse(plot)
414
418
415 def plot_scatter(datatime,dataparam,paramname, error=[]):
419 def plot_scatter(datatime,dataparam,paramname, error=[]):
416 if (numpy.isnan(dataparam).all()):
420 if (numpy.isnan(dataparam).all()):
417 plot = "There is no valid data available for this plot: Empty array"
421 plot = "There is no valid data available for this plot: Empty array"
418
422
419 else:
423 else:
420 mode = 'markers' if len(error)>0 else 'lines'
424 mode = 'markers' if len(error)>0 else 'lines'
421 fig = go.Figure()
425 fig = go.Figure()
422 fig.add_trace(go.Scatter(x=datatime, y=dataparam, mode=mode, error_y={'type':'data', 'array':error, 'visible':True, 'color':'rgba(255, 144, 14, 0.7)'}))
426 fig.add_trace(go.Scatter(x=datatime, y=dataparam, mode=mode, error_y={'type':'data', 'array':error, 'visible':True, 'color':'rgba(255, 144, 14, 0.7)'}))
423 fig.update_yaxes(title_text=paramname)
427 fig.update_yaxes(title_text=paramname)
424 fig.update_xaxes(title_text='Time [LT]')
428 fig.update_xaxes(title_text='Time [LT]')
425
429
426 delta = datatime[-1] - datatime[1]
430 delta = datatime[-1] - datatime[1]
427
431
428 if (delta>datetime.timedelta(days=30)):
432 if (delta>datetime.timedelta(days=30)):
429 # Add range slider
433 # Add range slider
430 fig.update_layout(
434 fig.update_layout(
431 xaxis=dict(
435 xaxis=dict(
432 rangeselector=dict(
436 rangeselector=dict(
433 buttons=list([
437 buttons=list([
434 dict(count=1,
438 dict(count=1,
435 label="1m",
439 label="1m",
436 step="month",
440 step="month",
437 stepmode="backward"),
441 stepmode="backward"),
438 dict(count=6,
442 dict(count=6,
439 label="6m",
443 label="6m",
440 step="month",
444 step="month",
441 stepmode="backward"),
445 stepmode="backward"),
442 dict(count=1,
446 dict(count=1,
443 label="1y",
447 label="1y",
444 step="year",
448 step="year",
445 stepmode="backward"),
449 stepmode="backward"),
446 dict(step="all")
450 dict(step="all")
447 ])
451 ])
448 ),
452 ),
449 rangeslider=dict(
453 rangeslider=dict(
450 visible=True
454 visible=True
451 ),
455 ),
452 type="date"
456 type="date"
453 )
457 )
454 )
458 )
459 fig.update_layout(
460 width=900,
461 height=600,
462 )
455
463
456
464
457 plot = py.plot(fig, include_plotlyjs=False, output_type='div')
465 plot = py.plot(fig, include_plotlyjs=False, output_type='div')
458
466
459
467
460 return plot
468 return plot
461
469
462
470
463 def plot_heatmap(datatime,datarange,dataparam,paramname):
471 def plot_heatmap(datatime,datarange,dataparam,paramname):
464 if (numpy.all(numpy.isnan(dataparam))):
472 if (numpy.all(numpy.isnan(dataparam))):
465 plot = "There is no valid data available for this plot: Empty array"
473 plot = "There is no valid data available for this plot: Empty array"
466 else:
474 else:
467 fig = go.Figure()
475 fig = go.Figure()
468 fig.add_trace(go.Heatmap(x=datatime,y=datarange,z= dataparam,colorscale='Jet',colorbar={"title":paramname}))
476 fig.add_trace(go.Heatmap(x=datatime,y=datarange,z= dataparam,colorscale='Jet',colorbar={"title":paramname}))
469 fig.update_yaxes(title_text="range")
477 fig.update_yaxes(title_text="range")
470 fig.update_xaxes(title_text="Time [LT]")
478 fig.update_xaxes(title_text="Time [LT]")
471 fig.update_layout(
479 fig.update_layout(
472 updatemenus=[
480 updatemenus=[
473 dict(
481 dict(
474 buttons=list([
482 buttons=list([
475 dict(
483 dict(
476 args=["colorscale", "Jet"],
484 args=["colorscale", "Jet"],
477 label="Jet",
485 label="Jet",
478 method="restyle"
486 method="restyle"
479 ),
487 ),
480 dict(
488 dict(
481 args=["colorscale", "RdBu"],
489 args=["colorscale", "RdBu"],
482 label="Red-Blue",
490 label="Red-Blue",
483 method="restyle"
491 method="restyle"
484 ),
492 ),
485 dict(
493 dict(
486 args=["colorscale", "Viridis"],
494 args=["colorscale", "Viridis"],
487 label="Viridis",
495 label="Viridis",
488 method="restyle"
496 method="restyle"
489 ),
497 ),
490 dict(
498 dict(
491 args=["colorscale", "Cividis"],
499 args=["colorscale", "Cividis"],
492 label="Cividis",
500 label="Cividis",
493 method="restyle"
501 method="restyle"
494 ),
502 ),
495 dict(
503 dict(
496 args=["colorscale", "Greens"],
504 args=["colorscale", "Greens"],
497 label="Greens",
505 label="Greens",
498 method="restyle"
506 method="restyle"
499 ),
507 ),
500 ]),
508 ]),
501 type = "dropdown",
509 type = "dropdown",
502 direction="down",
510 direction="down",
503 pad={"r": 10, "t": -10},
511 pad={"r": 10, "t": -10},
504 showactive=True,
512 showactive=True,
505 x=0.1,
513 x=0.1,
506 xanchor="left",
514 xanchor="left",
507 y=1.05,
515 y=1.05,
508 yanchor="top"
516 yanchor="top"
509 ),
517 ),
510 dict(
518 dict(
511 buttons=list([
519 buttons=list([
512 dict(
520 dict(
513 args=[{"contours.showlines": False, "type": "contour"}],
521 args=[{"contours.showlines": False, "type": "contour"}],
514 label="Hide lines",
522 label="Hide lines",
515 method="restyle"
523 method="restyle"
516 ),
524 ),
517 dict(
525 dict(
518 args=[{"contours.showlines": True, "type": "contour"}],
526 args=[{"contours.showlines": True, "type": "contour"}],
519 label="Show lines",
527 label="Show lines",
520 method="restyle"
528 method="restyle"
521 ),
529 ),
522 ]),
530 ]),
523 direction="down",
531 direction="down",
524 pad={"r": 10, "t": -10},
532 pad={"r": 10, "t": -10},
525 showactive=True,
533 showactive=True,
526 x=0.32,
534 x=0.32,
527 xanchor="left",
535 xanchor="left",
528 y=1.05,
536 y=1.05,
529 yanchor="top"
537 yanchor="top"
530 ),
538 ),
531
539
532 ]
540 ]
533 )
541 )
534
542
535 fig.update_layout(
543 fig.update_layout(
544 width=900,
545 height=600,
536 annotations=[
546 annotations=[
537 dict(text="Colorscale", showarrow=False,
547 dict(text="Colorscale", showarrow=False,
538 x=0, xref="paper", y=1.05, yref="paper", align="left"),
548 x=0, xref="paper", y=1.05, yref="paper", align="left"),
539 dict(text="Lines", x=0.25, xref="paper", y=1.05, yref="paper",
549 dict(text="Lines", x=0.25, xref="paper", y=1.05, yref="paper",
540 showarrow=False)
550 showarrow=False)
541 ]
551 ]
542 )
552 )
543
553
544
554
545 plot = py.plot(fig, include_plotlyjs=False, output_type='div')
555 plot = py.plot(fig, include_plotlyjs=False, output_type='div')
546
556
547 return plot
557 return plot
548
558
549
559
550 def download_as_is(request):
560 def download_as_is(request):
551 """download_as_is is a Ajax call that returns the download as is html to support the
561 """download_as_is is a Ajax call that returns the download as is html to support the
552 single experiment UI. Called when a user selects download/as is link.
562 single experiment UI. Called when a user selects download/as is link.
553
563
554 Inputs:
564 Inputs:
555 request
565 request
556 """
566 """
557 cookieDict = request.COOKIES
567 cookieDict = request.COOKIES
558 if not 'user_fullname' in cookieDict:
568 if not 'user_fullname' in cookieDict:
559 return(HttpResponse('<p>Cookie with user_fullname required for downloadAsIs</p>'))
569 return(HttpResponse('<p>Cookie with user_fullname required for downloadAsIs</p>'))
560 user_fullname = django.utils.http.urlquote_plus(cookieDict['user_fullname'])
570 user_fullname = django.utils.http.urlquote_plus(cookieDict['user_fullname'])
561 user_email = cookieDict['user_email']
571 user_email = cookieDict['user_email']
562 user_affiliation = django.utils.http.urlquote_plus(cookieDict['user_affiliation'])
572 user_affiliation = django.utils.http.urlquote_plus(cookieDict['user_affiliation'])
563 expID =int(request.GET['experiment_list'])
573 expID =int(request.GET['experiment_list'])
564 file_list = request.GET['file_list']
574 file_list = request.GET['file_list']
565 form = madweb.forms.SingleExpDownloadAsIsForm({'format_select':file_list,
575 form = madweb.forms.SingleExpDownloadAsIsForm({'format_select':file_list,
566 'expID': expID})
576 'expID': expID})
567
577
568 return render(request, 'madweb/download_as_is.html', {'form': form, 'exp_id':expID,
578 return render(request, 'madweb/download_as_is.html', {'form': form, 'exp_id':expID,
569 'user_fullname':user_fullname,
579 'user_fullname':user_fullname,
570 'user_email':user_email,
580 'user_email':user_email,
571 'user_affiliation': user_affiliation})
581 'user_affiliation': user_affiliation})
572
582
573
583
574 def download_file_as_is(request):
584 def download_file_as_is(request):
575 """download_file_as_is is a Ajax call that actually downloads a madrigal file.
585 """download_file_as_is is a Ajax call that actually downloads a madrigal file.
576
586
577 Inputs:
587 Inputs:
578 request
588 request
579 """
589 """
580 madDB = madrigal.metadata.MadrigalDB()
590 madDB = madrigal.metadata.MadrigalDB()
581 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
591 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
582 user_fullname = urllib.parse.unquote_plus(request.GET['user_fullname'])
592 user_fullname = urllib.parse.unquote_plus(request.GET['user_fullname'])
583 user_email = request.GET['user_email']
593 user_email = request.GET['user_email']
584 user_affiliation = urllib.parse.unquote_plus(request.GET['user_affiliation'])
594 user_affiliation = urllib.parse.unquote_plus(request.GET['user_affiliation'])
585 exp_id = request.GET['exp_id']
595 exp_id = request.GET['exp_id']
586 basename = request.GET['basename']
596 basename = request.GET['basename']
587 downloadFile = madWebObj.downloadFileAsIs(exp_id, basename, user_fullname, user_email, user_affiliation)
597 downloadFile = madWebObj.downloadFileAsIs(exp_id, basename, user_fullname, user_email, user_affiliation)
588 f = open(downloadFile, 'rb')
598 f = open(downloadFile, 'rb')
589 filename = os.path.basename(downloadFile)
599 filename = os.path.basename(downloadFile)
590 chunk_size = 8192
600 chunk_size = 8192
591 file_type = mimetypes.guess_type(downloadFile)[0]
601 file_type = mimetypes.guess_type(downloadFile)[0]
592 if file_type is None:
602 if file_type is None:
593 file_type = 'application/octet-stream'
603 file_type = 'application/octet-stream'
594 response = StreamingHttpResponse(FileWrapper(f, chunk_size),
604 response = StreamingHttpResponse(FileWrapper(f, chunk_size),
595 content_type=file_type)
605 content_type=file_type)
596 response['Content-Length'] = os.path.getsize(downloadFile)
606 response['Content-Length'] = os.path.getsize(downloadFile)
597 response['Content-Disposition'] = "attachment; filename=%s" % (filename)
607 response['Content-Disposition'] = "attachment; filename=%s" % (filename)
598 response.set_cookie('fileDownload', 'true', path='/', samesite='Strict')
608 response.set_cookie('fileDownload', 'true', path='/', samesite='Strict')
599 return(response)
609 return(response)
600
610
601
611
602 def print_as_is(request):
612 def print_as_is(request):
603 """print_as_is is a Ajax call that returns the text of the ascii file to support the
613 """print_as_is is a Ajax call that returns the text of the ascii file to support the
604 single experiment UI if request.GET has key "text", or the length of the file to be
614 single experiment UI if request.GET has key "text", or the length of the file to be
605 downloaded if not. Called when a user selects print/as is link.
615 downloaded if not. Called when a user selects print/as is link.
606
616
607 Inputs:
617 Inputs:
608 request
618 request
609 """
619 """
610 madDB = madrigal.metadata.MadrigalDB()
620 madDB = madrigal.metadata.MadrigalDB()
611 madExpObj = madrigal.metadata.MadrigalExperiment(madDB)
621 madExpObj = madrigal.metadata.MadrigalExperiment(madDB)
612 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
622 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
613 madParmObj = madrigal.data.MadrigalParameters(madDB)
623 madParmObj = madrigal.data.MadrigalParameters(madDB)
614
624
615 cookieDict = request.COOKIES
625 cookieDict = request.COOKIES
616 if not 'user_fullname' in cookieDict:
626 if not 'user_fullname' in cookieDict:
617 return(HttpResponse('<p>Cookie with user_fullname required for printAsIs</p>'))
627 return(HttpResponse('<p>Cookie with user_fullname required for printAsIs</p>'))
618 user_fullname = django.utils.http.urlquote_plus(cookieDict['user_fullname'])
628 user_fullname = django.utils.http.urlquote_plus(cookieDict['user_fullname'])
619 user_email = cookieDict['user_email']
629 user_email = cookieDict['user_email']
620 user_affiliation = django.utils.http.urlquote_plus(cookieDict['user_affiliation'])
630 user_affiliation = django.utils.http.urlquote_plus(cookieDict['user_affiliation'])
621 expID =int(request.GET['experiment_list'])
631 expID =int(request.GET['experiment_list'])
622 basename = request.GET['file_list']
632 basename = request.GET['file_list']
623 expDir = madExpObj.getExpDirByExpId(int(expID))
633 expDir = madExpObj.getExpDirByExpId(int(expID))
624 if expDir is None:
634 if expDir is None:
625 raise ValueError('No expDir found for exp_id %i' % (int(expID)))
635 raise ValueError('No expDir found for exp_id %i' % (int(expID)))
626 fullFilename = os.path.join(expDir, basename)
636 fullFilename = os.path.join(expDir, basename)
627
637
628 # determine if we need to return the full file text, or just the size and name
638 # determine if we need to return the full file text, or just the size and name
629 if 'text' in request.GET:
639 if 'text' in request.GET:
630 madFileObj = madrigal.data.MadrigalFile(fullFilename, madDB)
640 madFileObj = madrigal.data.MadrigalFile(fullFilename, madDB)
631 measParms = madFileObj.getMeasuredParmList()
641 measParms = madFileObj.getMeasuredParmList()
632 measParmMnemList = madParmObj.getParmMnemonicList(measParms) + madFileObj.getStandardParms(upper=True)
642 measParmMnemList = madParmObj.getParmMnemonicList(measParms) + madFileObj.getStandardParms(upper=True)
633 measParmDescList = madParmObj.getParmDescriptionList(measParmMnemList)
643 measParmDescList = madParmObj.getParmDescriptionList(measParmMnemList)
634 parmList = list(zip(measParmMnemList, measParmDescList))
644 parmList = list(zip(measParmMnemList, measParmDescList))
635 f = open(request.GET['text'])
645 f = open(request.GET['text'])
636 text = f.read()
646 text = f.read()
637 f.close()
647 f.close()
638
648
639 return render(request, 'madweb/print_as_is.html', {'text': text, 'parmList': parmList})
649 return render(request, 'madweb/print_as_is.html', {'text': text, 'parmList': parmList})
640
650
641 else:
651 else:
642 tmpFilename = madWebObj.printFileAsIs(fullFilename, user_fullname, user_email, user_affiliation)
652 tmpFilename = madWebObj.printFileAsIs(fullFilename, user_fullname, user_email, user_affiliation)
643 filesize = os.path.getsize(tmpFilename)
653 filesize = os.path.getsize(tmpFilename)
644 return(HttpResponse('%s:%s' % (filesize, tmpFilename)))
654 return(HttpResponse('%s:%s' % (filesize, tmpFilename)))
645
655
646
656
647 def list_records(request):
657 def list_records(request):
648 """list_records is a Ajax call that returns the list records text.
658 """list_records is a Ajax call that returns the list records text.
649
659
650 Inputs:
660 Inputs:
651 request
661 request
652 """
662 """
653 madDB = madrigal.metadata.MadrigalDB()
663 madDB = madrigal.metadata.MadrigalDB()
654 madExpObj = madrigal.metadata.MadrigalExperiment(madDB)
664 madExpObj = madrigal.metadata.MadrigalExperiment(madDB)
655 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
665 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
656
666
657 expID =int(request.GET['experiment_list'])
667 expID =int(request.GET['experiment_list'])
658 basename = request.GET['file_list']
668 basename = request.GET['file_list']
659 expDir = madExpObj.getExpDirByExpId(int(expID))
669 expDir = madExpObj.getExpDirByExpId(int(expID))
660 if expDir is None:
670 if expDir is None:
661 raise ValueError('No expDir found for exp_id %i' % (int(expID)))
671 raise ValueError('No expDir found for exp_id %i' % (int(expID)))
662 fullFilename = os.path.join(expDir, basename)
672 fullFilename = os.path.join(expDir, basename)
663
673
664 text = madWebObj.listRecords(fullFilename)
674 text = madWebObj.listRecords(fullFilename)
665
675
666 return render(request, 'madweb/list_records.html', {'expDir': expDir,
676 return render(request, 'madweb/list_records.html', {'expDir': expDir,
667 'basename': basename,
677 'basename': basename,
668 'text': text})
678 'text': text})
669
679
670
680
671 def view_record_plot(request):
681 def view_record_plot(request):
672 """view_record_plot returns the view individual record page.
682 """view_record_plot returns the view individual record page.
673
683
674 Inputs:
684 Inputs:
675 request
685 request
676 """
686 """
677 expDir = request.GET['expDir']
687 expDir = request.GET['expDir']
678 basename = request.GET['basename']
688 basename = request.GET['basename']
679 recno = int(request.GET['recno'])
689 recno = int(request.GET['recno'])
680
690
681 return render(request, 'madweb/view_record_plot.html', {'expDir': expDir,
691 return render(request, 'madweb/view_record_plot.html', {'expDir': expDir,
682 'basename': basename,
692 'basename': basename,
683 'recno': recno})
693 'recno': recno})
684
694
685
695
686 def view_record_image(request):
696 def view_record_image(request):
687 """view_record_plot is a Ajax call that returns the record plot.
697 """view_record_plot is a Ajax call that returns the record plot.
688
698
689 Inputs:
699 Inputs:
690 request
700 request
691 """
701 """
692 expDir = request.GET['expDir']
702 expDir = request.GET['expDir']
693 basename = request.GET['basename']
703 basename = request.GET['basename']
694 recno = int(request.GET['recno'])
704 recno = int(request.GET['recno'])
695 pngFiles = glob.glob(os.path.join(expDir, 'plots', basename, 'records/*%05i*.png' % (recno)))
705 pngFiles = glob.glob(os.path.join(expDir, 'plots', basename, 'records/*%05i*.png' % (recno)))
696
706
697 image_data = open(pngFiles[0], "rb").read()
707 image_data = open(pngFiles[0], "rb").read()
698 return HttpResponse(image_data, content_type="image/png")
708 return HttpResponse(image_data, content_type="image/png")
699
709
700
710
701
711
702
712
703 def show_info(request):
713 def show_info(request):
704 """show_info is a Ajax call that returns the text of the catalog/header text to support the
714 """show_info is a Ajax call that returns the text of the catalog/header text to support the
705 single experiment UI. Called when a user selects show info link.
715 single experiment UI. Called when a user selects show info link.
706
716
707 Inputs:
717 Inputs:
708 request
718 request
709 """
719 """
710 madDB = madrigal.metadata.MadrigalDB()
720 madDB = madrigal.metadata.MadrigalDB()
711 madExpObj = madrigal.metadata.MadrigalExperiment(madDB)
721 madExpObj = madrigal.metadata.MadrigalExperiment(madDB)
712
722
713 expID =int(request.GET['experiment_list'])
723 expID =int(request.GET['experiment_list'])
714 basename = request.GET['file_list']
724 basename = request.GET['file_list']
715 expDir = madExpObj.getExpDirByExpId(int(expID))
725 expDir = madExpObj.getExpDirByExpId(int(expID))
716 if expDir is None:
726 if expDir is None:
717 raise ValueError('No expDir found for exp_id %i' % (int(expID)))
727 raise ValueError('No expDir found for exp_id %i' % (int(expID)))
718 fullFilename = os.path.join(expDir, basename)
728 fullFilename = os.path.join(expDir, basename)
719
729
720 madFileObj = madrigal.data.MadrigalFile(fullFilename, madDB)
730 madFileObj = madrigal.data.MadrigalFile(fullFilename, madDB)
721 text = madFileObj.getCatalogHeaderStr()
731 text = madFileObj.getCatalogHeaderStr()
722
732
723 return render(request, 'madweb/show_info.html', {'text':text})
733 return render(request, 'madweb/show_info.html', {'text':text})
724
734
725
735
726 def show_doi(request):
736 def show_doi(request):
727 """show_doi is a Ajax call that returns the permanent url for references to support the
737 """show_doi is a Ajax call that returns the permanent url for references to support the
728 single experiment UI. Called when a user selects show doi link.
738 single experiment UI. Called when a user selects show doi link.
729
739
730 Inputs:
740 Inputs:
731 request
741 request
732 """
742 """
733 madDB = madrigal.metadata.MadrigalDB()
743 madDB = madrigal.metadata.MadrigalDB()
734 madExpObj = madrigal.metadata.MadrigalExperiment(madDB)
744 madExpObj = madrigal.metadata.MadrigalExperiment(madDB)
735 madInstObj = madrigal.metadata.MadrigalInstrument(madDB)
745 madInstObj = madrigal.metadata.MadrigalInstrument(madDB)
736
746
737 expID =request.GET['experiment_list']
747 expID =request.GET['experiment_list']
738 basename = request.GET['file_list']
748 basename = request.GET['file_list']
739 expDir = madExpObj.getExpDirByExpId(int(expID))
749 expDir = madExpObj.getExpDirByExpId(int(expID))
740 # get experiment PI and institution
750 # get experiment PI and institution
741 PI = madExpObj.getPIByExpId(int(expID))
751 PI = madExpObj.getPIByExpId(int(expID))
742 kinst = madExpObj.getKinstByExpId(int(expID))
752 kinst = madExpObj.getKinstByExpId(int(expID))
743 startDTList = madExpObj.getExpStartDateTimeByExpId(int(expID))
753 startDTList = madExpObj.getExpStartDateTimeByExpId(int(expID))
744 yearStr = str(startDTList[0])
754 yearStr = str(startDTList[0])
745 if PI is None:
755 if PI is None:
746 PI = madInstObj.getContactName(kinst)
756 PI = madInstObj.getContactName(kinst)
747 institution = madInstObj.getContactAddress1(kinst)
757 institution = madInstObj.getContactAddress1(kinst)
748
758
749 try:
759 try:
750 madFileObj = madrigal.metadata.MadrigalMetaFile(madDB, os.path.join(expDir, 'fileTab.txt'))
760 madFileObj = madrigal.metadata.MadrigalMetaFile(madDB, os.path.join(expDir, 'fileTab.txt'))
751 url = madFileObj.getFileDOIUrlByFilename(basename)
761 url = madFileObj.getFileDOIUrlByFilename(basename)
752 except:
762 except:
753 url = 'Unknown - please contact madrigal@haystack.mit.edu'
763 url = 'Unknown - please contact madrigal@haystack.mit.edu'
754
764
755 return render(request, 'madweb/show_doi.html', {'url':url, 'PI': PI, 'year': yearStr,
765 return render(request, 'madweb/show_doi.html', {'url':url, 'PI': PI, 'year': yearStr,
756 'institution': institution})
766 'institution': institution})
757
767
758
768
759 def get_advanced(request):
769 def get_advanced(request):
760 """get_advanced is a view that allows user to download/print files with selected parms
770 """get_advanced is a view that allows user to download/print files with selected parms
761 and filters.
771 and filters.
762
772
763 Inputs:
773 Inputs:
764 request
774 request
765 """
775 """
766 madDB = madrigal.metadata.MadrigalDB()
776 madDB = madrigal.metadata.MadrigalDB()
767 bg_color = madDB.getBackgroundColor()
777 bg_color = madDB.getBackgroundColor()
768 madWeb = madrigal.ui.web.MadrigalWeb(madDB)
778 madWeb = madrigal.ui.web.MadrigalWeb(madDB)
769 siteName, siteList = madWeb.getSiteInfo()
779 siteName, siteList = madWeb.getSiteInfo()
770 madExpObj = madrigal.metadata.MadrigalExperiment(madDB)
780 madExpObj = madrigal.metadata.MadrigalExperiment(madDB)
771 webFormatObj = madrigal.ui.web.MadrigalWebFormat()
781 webFormatObj = madrigal.ui.web.MadrigalWebFormat()
772 madParmObj = madrigal.data.MadrigalParameters(madDB)
782 madParmObj = madrigal.data.MadrigalParameters(madDB)
773 parmList = webFormatObj.getFormat('Comprehensive')
783 parmList = webFormatObj.getFormat('Comprehensive')
774 measParmList = []
784 measParmList = []
775 derivedParmList = []
785 derivedParmList = []
776 allParmList = []
786 allParmList = []
777 sureParmList = []
787 sureParmList = []
778
788
779 if 'experiment_list' in request.GET:
789 if 'experiment_list' in request.GET:
780 expID = int(request.GET['experiment_list'])
790 expID = int(request.GET['experiment_list'])
781 else:
791 else:
782 return(HttpResponse('<p>experiment_list required for getAdvanced</p>'))
792 return(HttpResponse('<p>experiment_list required for getAdvanced</p>'))
783 basename = request.GET['file_list']
793 basename = request.GET['file_list']
784 type = request.GET['type']
794 type = request.GET['type']
785 expDir = madExpObj.getExpDirByExpId(int(expID))
795 expDir = madExpObj.getExpDirByExpId(int(expID))
786 if expDir is None:
796 if expDir is None:
787 raise ValueError('No expDir found for exp_id %i' % (int(expID)))
797 raise ValueError('No expDir found for exp_id %i' % (int(expID)))
788 fullFilename = os.path.join(expDir, basename)
798 fullFilename = os.path.join(expDir, basename)
789 expName, kindatDesc = madWeb.getInfoFromFile(fullFilename)
799 expName, kindatDesc = madWeb.getInfoFromFile(fullFilename)
790 madFileObj = madrigal.data.MadrigalFile(fullFilename, madDB)
800 madFileObj = madrigal.data.MadrigalFile(fullFilename, madDB)
791 earliestTime = madFileObj.getEarliestTime()
801 earliestTime = madFileObj.getEarliestTime()
792 latestTime = madFileObj.getLatestTime()
802 latestTime = madFileObj.getLatestTime()
793 earliestDT = datetime.datetime(*earliestTime)
803 earliestDT = datetime.datetime(*earliestTime)
794 latestDT = datetime.datetime(*latestTime)
804 latestDT = datetime.datetime(*latestTime)
795 madFileObj.getMeasDervBothParmLists(parmList, measParmList, derivedParmList, allParmList, sureParmList)
805 madFileObj.getMeasDervBothParmLists(parmList, measParmList, derivedParmList, allParmList, sureParmList)
796 allParmDescList = madParmObj.getParmDescriptionList(allParmList)
806 allParmDescList = madParmObj.getParmDescriptionList(allParmList)
797
807
798 dataDict = {'type': type,
808 dataDict = {'type': type,
799 'fullFilename': fullFilename,
809 'fullFilename': fullFilename,
800 'madFileObj': madFileObj, 'parameters': [],
810 'madFileObj': madFileObj, 'parameters': [],
801 'measParmList': measParmList, 'derivedParmList': derivedParmList,
811 'measParmList': measParmList, 'derivedParmList': derivedParmList,
802 'allParmList': allParmList, 'allParmDescList': allParmDescList,
812 'allParmList': allParmList, 'allParmDescList': allParmDescList,
803 'madDB': madDB, 'madParmObj': madParmObj}
813 'madDB': madDB, 'madParmObj': madParmObj}
804
814
805 min_alt = madFileObj.getMinValidAltitude()
815 min_alt = madFileObj.getMinValidAltitude()
806 max_alt = madFileObj.getMaxValidAltitude()
816 max_alt = madFileObj.getMaxValidAltitude()
807 try:
817 try:
808 float(min_alt)
818 float(min_alt)
809 float(max_alt)
819 float(max_alt)
810 dataDict['min_alt'] = '%9.2f' % (min_alt)
820 dataDict['min_alt'] = '%9.2f' % (min_alt)
811 dataDict['max_alt'] = '%9.2f' % (max_alt)
821 dataDict['max_alt'] = '%9.2f' % (max_alt)
812 except:
822 except:
813 pass
823 pass
814
824
815 if 'AZM' in allParmList:
825 if 'AZM' in allParmList:
816 dataDict['min_az'] = '-180.0'
826 dataDict['min_az'] = '-180.0'
817 dataDict['max_az'] = '180.0'
827 dataDict['max_az'] = '180.0'
818 dataDict['min_az2'] = '0.0'
828 dataDict['min_az2'] = '0.0'
819 dataDict['max_az2'] = '0.0'
829 dataDict['max_az2'] = '0.0'
820
830
821 if 'ELM' in allParmList:
831 if 'ELM' in allParmList:
822 dataDict['min_el'] = '0.0'
832 dataDict['min_el'] = '0.0'
823 dataDict['max_el'] = '90.0'
833 dataDict['max_el'] = '90.0'
824 dataDict['min_el2'] = '0.0'
834 dataDict['min_el2'] = '0.0'
825 dataDict['max_el2'] = '0.0'
835 dataDict['max_el2'] = '0.0'
826
836
827 if 'PL' in allParmList:
837 if 'PL' in allParmList:
828 min_pl = madFileObj.getMinPulseLength()
838 min_pl = madFileObj.getMinPulseLength()
829 max_pl = madFileObj.getMaxPulseLength()
839 max_pl = madFileObj.getMaxPulseLength()
830 try:
840 try:
831 float(min_pl)
841 float(min_pl)
832 float(max_pl)
842 float(max_pl)
833 dataDict['min_pl'] = '%9.2f' % (min_pl)
843 dataDict['min_pl'] = '%9.2f' % (min_pl)
834 dataDict['max_pl'] = '%9.2f' % (max_pl)
844 dataDict['max_pl'] = '%9.2f' % (max_pl)
835 except:
845 except:
836 pass
846 pass
837
847
838 if type == 'download':
848 if type == 'download':
839 defaultFormat = 'Hdf5'
849 defaultFormat = 'Hdf5'
840 else:
850 else:
841 defaultFormat = 'ascii'
851 defaultFormat = 'ascii'
842 dataDict['formats'] = defaultFormat
852 dataDict['formats'] = defaultFormat
843 dataDict['missing'] = 'NaN'
853 dataDict['missing'] = 'NaN'
844 dataDict['start_date'] = earliestDT
854 dataDict['start_date'] = earliestDT
845 dataDict['end_date'] = latestDT
855 dataDict['end_date'] = latestDT
846
856
847
857
848 isprintForm = madweb.forms.IsprintForm(dataDict)
858 isprintForm = madweb.forms.IsprintForm(dataDict)
849
859
850 return render(request, 'madweb/get_advanced.html', {'form': isprintForm,
860 return render(request, 'madweb/get_advanced.html', {'form': isprintForm,
851 'parmList': isprintForm.parmList,
861 'parmList': isprintForm.parmList,
852 'measParmList': measParmList,
862 'measParmList': measParmList,
853 'site_name': siteName, 'site_list': siteList,
863 'site_name': siteName, 'site_list': siteList,
854 'expName': expName, 'kindatDesc': kindatDesc,
864 'expName': expName, 'kindatDesc': kindatDesc,
855 'basename': os.path.basename(fullFilename),
865 'basename': os.path.basename(fullFilename),
856 'type': type, 'bg_color': bg_color,
866 'type': type, 'bg_color': bg_color,
857 'datetime': True})
867 'datetime': True})
858
868
859 def advanced_download(request):
869 def advanced_download(request):
860 """advanced_download is a view that downloads a file with selected parms
870 """advanced_download is a view that downloads a file with selected parms
861 and filters.
871 and filters.
862
872
863 Inputs:
873 Inputs:
864 request
874 request
865 """
875 """
866 madDB = madrigal.metadata.MadrigalDB()
876 madDB = madrigal.metadata.MadrigalDB()
867 madWeb = madrigal.ui.web.MadrigalWeb(madDB)
877 madWeb = madrigal.ui.web.MadrigalWeb(madDB)
868 webFormatObj = madrigal.ui.web.MadrigalWebFormat()
878 webFormatObj = madrigal.ui.web.MadrigalWebFormat()
869 madParmObj = madrigal.data.MadrigalParameters(madDB)
879 madParmObj = madrigal.data.MadrigalParameters(madDB)
870
880
871 cookieDict = request.COOKIES
881 cookieDict = request.COOKIES
872 if not 'user_fullname' in cookieDict:
882 if not 'user_fullname' in cookieDict:
873 return(HttpResponse('<p>Cookie with user_fullname required for advancedDownload</p>'))
883 return(HttpResponse('<p>Cookie with user_fullname required for advancedDownload</p>'))
874 user_fullname = django.utils.http.urlquote_plus(cookieDict['user_fullname'])
884 user_fullname = django.utils.http.urlquote_plus(cookieDict['user_fullname'])
875 user_email = cookieDict['user_email']
885 user_email = cookieDict['user_email']
876 user_affiliation = django.utils.http.urlquote_plus(cookieDict['user_affiliation'])
886 user_affiliation = django.utils.http.urlquote_plus(cookieDict['user_affiliation'])
877
887
878 parmList = webFormatObj.getFormat('Comprehensive')
888 parmList = webFormatObj.getFormat('Comprehensive')
879 measParmList = []
889 measParmList = []
880 derivedParmList = []
890 derivedParmList = []
881 allParmList = []
891 allParmList = []
882 sureParmList = []
892 sureParmList = []
883 madFileObj = madrigal.data.MadrigalFile(request.GET['fullFilename'], madDB)
893 madFileObj = madrigal.data.MadrigalFile(request.GET['fullFilename'], madDB)
884 madFileObj.getMeasDervBothParmLists(parmList, measParmList, derivedParmList, allParmList, sureParmList)
894 madFileObj.getMeasDervBothParmLists(parmList, measParmList, derivedParmList, allParmList, sureParmList)
885 allParmDescList = madParmObj.getParmDescriptionList(allParmList)
895 allParmDescList = madParmObj.getParmDescriptionList(allParmList)
886
896
887 request.GET._mutable = True
897 request.GET._mutable = True
888 request.GET['madFileObj']=madFileObj
898 request.GET['madFileObj']=madFileObj
889 request.GET['measParmList']=measParmList
899 request.GET['measParmList']=measParmList
890 request.GET['derivedParmList']=derivedParmList
900 request.GET['derivedParmList']=derivedParmList
891 request.GET['allParmList']=allParmList
901 request.GET['allParmList']=allParmList
892 request.GET['allParmDescList']=allParmDescList
902 request.GET['allParmDescList']=allParmDescList
893 request.GET['start_date'] = request.GET['start_date'].strip()
903 request.GET['start_date'] = request.GET['start_date'].strip()
894 request.GET['end_date'] = request.GET['end_date'].strip()
904 request.GET['end_date'] = request.GET['end_date'].strip()
895 # convert dates to datetime
905 # convert dates to datetime
896 request.GET['start_date'] = datetime.datetime.strptime(request.GET['start_date'], '%Y-%m-%dT%H:%M:%S')
906 request.GET['start_date'] = datetime.datetime.strptime(request.GET['start_date'], '%Y-%m-%dT%H:%M:%S')
897 request.GET['end_date'] = datetime.datetime.strptime(request.GET['end_date'], '%Y-%m-%dT%H:%M:%S')
907 request.GET['end_date'] = datetime.datetime.strptime(request.GET['end_date'], '%Y-%m-%dT%H:%M:%S')
898 request.GET['madDB'] = madDB
908 request.GET['madDB'] = madDB
899 request.GET['madParmObj'] = madParmObj
909 request.GET['madParmObj'] = madParmObj
900
910
901
911
902 isprintForm = madweb.forms.IsprintForm(request.GET)
912 isprintForm = madweb.forms.IsprintForm(request.GET)
903
913
904
914
905 if not isprintForm.is_valid():
915 if not isprintForm.is_valid():
906 raise ValueError(str(isprintForm.errors))
916 raise ValueError(str(isprintForm.errors))
907
917
908 downloadFile = madWeb.downloadIsprintFileFromIsprintForm(isprintForm.cleaned_data, user_fullname, user_email, user_affiliation)
918 downloadFile = madWeb.downloadIsprintFileFromIsprintForm(isprintForm.cleaned_data, user_fullname, user_email, user_affiliation)
909
919
910
920
911 f = open(downloadFile, 'rb')
921 f = open(downloadFile, 'rb')
912 filename = os.path.basename(downloadFile)
922 filename = os.path.basename(downloadFile)
913 chunk_size = 8192
923 chunk_size = 8192
914 file_type = mimetypes.guess_type(downloadFile)[0]
924 file_type = mimetypes.guess_type(downloadFile)[0]
915 if file_type is None:
925 if file_type is None:
916 file_type = 'application/octet-stream'
926 file_type = 'application/octet-stream'
917 response = StreamingHttpResponse(FileWrapper(f, chunk_size),
927 response = StreamingHttpResponse(FileWrapper(f, chunk_size),
918 content_type=file_type)
928 content_type=file_type)
919 response['Content-Length'] = os.path.getsize(downloadFile)
929 response['Content-Length'] = os.path.getsize(downloadFile)
920 response['Content-Disposition'] = "attachment; filename=%s" % (filename)
930 response['Content-Disposition'] = "attachment; filename=%s" % (filename)
921 return(response)
931 return(response)
922
932
923
933
924 def advanced_print(request):
934 def advanced_print(request):
925 """advanced_download is a view that print a file with selected parms
935 """advanced_download is a view that print a file with selected parms
926 and filters.
936 and filters.
927
937
928 Inputs:
938 Inputs:
929 request
939 request
930 """
940 """
931 madDB = madrigal.metadata.MadrigalDB()
941 madDB = madrigal.metadata.MadrigalDB()
932 bg_color = madDB.getBackgroundColor()
942 bg_color = madDB.getBackgroundColor()
933 madWeb = madrigal.ui.web.MadrigalWeb(madDB)
943 madWeb = madrigal.ui.web.MadrigalWeb(madDB)
934 webFormatObj = madrigal.ui.web.MadrigalWebFormat()
944 webFormatObj = madrigal.ui.web.MadrigalWebFormat()
935 madParmObj = madrigal.data.MadrigalParameters(madDB)
945 madParmObj = madrigal.data.MadrigalParameters(madDB)
936
946
937 cookieDict = request.COOKIES
947 cookieDict = request.COOKIES
938 if not 'user_fullname' in cookieDict:
948 if not 'user_fullname' in cookieDict:
939 return(HttpResponse('<p>Cookie with user_fullname required for advancedPrint</p>'))
949 return(HttpResponse('<p>Cookie with user_fullname required for advancedPrint</p>'))
940 user_fullname = django.utils.http.urlquote_plus(cookieDict['user_fullname'])
950 user_fullname = django.utils.http.urlquote_plus(cookieDict['user_fullname'])
941 user_email = cookieDict['user_email']
951 user_email = cookieDict['user_email']
942 user_affiliation = django.utils.http.urlquote_plus(cookieDict['user_affiliation'])
952 user_affiliation = django.utils.http.urlquote_plus(cookieDict['user_affiliation'])
943
953
944 parmList = webFormatObj.getFormat('Comprehensive')
954 parmList = webFormatObj.getFormat('Comprehensive')
945 measParmList = []
955 measParmList = []
946 derivedParmList = []
956 derivedParmList = []
947 allParmList = []
957 allParmList = []
948 sureParmList = []
958 sureParmList = []
949 madFileObj = madrigal.data.MadrigalFile(request.GET['fullFilename'], madDB)
959 madFileObj = madrigal.data.MadrigalFile(request.GET['fullFilename'], madDB)
950 madFileObj.getMeasDervBothParmLists(parmList, measParmList, derivedParmList, allParmList, sureParmList)
960 madFileObj.getMeasDervBothParmLists(parmList, measParmList, derivedParmList, allParmList, sureParmList)
951 allParmDescList = madParmObj.getParmDescriptionList(allParmList)
961 allParmDescList = madParmObj.getParmDescriptionList(allParmList)
952 fullFilename = request.GET['fullFilename']
962 fullFilename = request.GET['fullFilename']
953 expName, kindatDesc = madWeb.getInfoFromFile(fullFilename)
963 expName, kindatDesc = madWeb.getInfoFromFile(fullFilename)
954
964
955 request.GET._mutable = True
965 request.GET._mutable = True
956 request.GET['madFileObj']=madFileObj
966 request.GET['madFileObj']=madFileObj
957 request.GET['measParmList']=measParmList
967 request.GET['measParmList']=measParmList
958 request.GET['derivedParmList']=derivedParmList
968 request.GET['derivedParmList']=derivedParmList
959 request.GET['allParmList']=allParmList
969 request.GET['allParmList']=allParmList
960 request.GET['allParmDescList']=allParmDescList
970 request.GET['allParmDescList']=allParmDescList
961 request.GET['start_date'] = request.GET['start_date'].strip()
971 request.GET['start_date'] = request.GET['start_date'].strip()
962 request.GET['end_date'] = request.GET['end_date'].strip()
972 request.GET['end_date'] = request.GET['end_date'].strip()
963 # convert dates to datetime
973 # convert dates to datetime
964 request.GET['start_date'] = datetime.datetime.strptime(request.GET['start_date'], '%Y-%m-%dT%H:%M:%S')
974 request.GET['start_date'] = datetime.datetime.strptime(request.GET['start_date'], '%Y-%m-%dT%H:%M:%S')
965 request.GET['end_date'] = datetime.datetime.strptime(request.GET['end_date'], '%Y-%m-%dT%H:%M:%S')
975 request.GET['end_date'] = datetime.datetime.strptime(request.GET['end_date'], '%Y-%m-%dT%H:%M:%S')
966 request.GET['madDB'] = madDB
976 request.GET['madDB'] = madDB
967 request.GET['madParmObj'] = madParmObj
977 request.GET['madParmObj'] = madParmObj
968
978
969 isprintForm = madweb.forms.IsprintForm(request.GET)
979 isprintForm = madweb.forms.IsprintForm(request.GET)
970
980
971
981
972 if not isprintForm.is_valid():
982 if not isprintForm.is_valid():
973 raise ValueError(str(isprintForm.errors))
983 raise ValueError(str(isprintForm.errors))
974
984
975 downloadFile = madWeb.downloadIsprintFileFromIsprintForm(isprintForm.cleaned_data, user_fullname, user_email, user_affiliation)
985 downloadFile = madWeb.downloadIsprintFileFromIsprintForm(isprintForm.cleaned_data, user_fullname, user_email, user_affiliation)
976
986
977 f = open(downloadFile, 'r')
987 f = open(downloadFile, 'r')
978 file_text = f.read()
988 file_text = f.read()
979 f.close()
989 f.close()
980 os.remove(downloadFile)
990 os.remove(downloadFile)
981 return render(request, 'madweb/advanced_print.html', {'expName': expName, 'kindatDesc': kindatDesc,
991 return render(request, 'madweb/advanced_print.html', {'expName': expName, 'kindatDesc': kindatDesc,
982 'basename': os.path.basename(fullFilename),
992 'basename': os.path.basename(fullFilename),
983 'file_text': file_text, 'bg_color': bg_color})
993 'file_text': file_text, 'bg_color': bg_color})
984
994
985
995
986 def view_list(request):
996 def view_list(request):
987 """view_list is the list experiment view.
997 """view_list is the list experiment view.
988 """
998 """
989 madDB = madrigal.metadata.MadrigalDB()
999 madDB = madrigal.metadata.MadrigalDB()
990 bg_color = madDB.getBackgroundColor()
1000 bg_color = madDB.getBackgroundColor()
991 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1001 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
992 siteName, siteList = madWebObj.getSiteInfo()
1002 siteName, siteList = madWebObj.getSiteInfo()
993 responseDict = {'list_active': 'class="active"'}
1003 responseDict = {'list_active': 'class="active"'}
994 form = madweb.forms.ListExpForm()
1004 form = madweb.forms.ListExpForm()
995 responseDict['form'] = form
1005 responseDict['form'] = form
996 responseDict['categoryList'] = form.categories
1006 responseDict['categoryList'] = form.categories
997 responseDict['instrumentList'] = form.instruments
1007 responseDict['instrumentList'] = form.instruments
998 responseDict['site_name'] = siteName
1008 responseDict['site_name'] = siteName
999 responseDict['site_list'] = siteList
1009 responseDict['site_list'] = siteList
1000 responseDict['datetime'] = True
1010 responseDict['datetime'] = True
1001 responseDict['bg_color'] = bg_color
1011 responseDict['bg_color'] = bg_color
1002
1012
1003 return render(request, 'madweb/list.html', responseDict)
1013 return render(request, 'madweb/list.html', responseDict)
1004
1014
1005
1015
1006 def list_experiments(request):
1016 def list_experiments(request):
1007 """list_experiments is a view that lists all selected experiments.
1017 """list_experiments is a view that lists all selected experiments.
1008
1018
1009 Inputs:
1019 Inputs:
1010 request
1020 request
1011 """
1021 """
1012 madDB = madrigal.metadata.MadrigalDB()
1022 madDB = madrigal.metadata.MadrigalDB()
1013 bg_color = madDB.getBackgroundColor()
1023 bg_color = madDB.getBackgroundColor()
1014 madWeb = madrigal.ui.web.MadrigalWeb(madDB)
1024 madWeb = madrigal.ui.web.MadrigalWeb(madDB)
1015 siteName, siteList = madWeb.getSiteInfo()
1025 siteName, siteList = madWeb.getSiteInfo()
1016
1026
1017 listForm = madweb.forms.ListExpForm(request.GET)
1027 listForm = madweb.forms.ListExpForm(request.GET)
1018 try:
1028 try:
1019 if not listForm.is_valid():
1029 if not listForm.is_valid():
1020 return(HttpResponse(str(listForm.errors)))
1030 return(HttpResponse(str(listForm.errors)))
1021 except KeyError:
1031 except KeyError:
1022 return(HttpResponse('<p>Missing arguments in list_experiments</p>'))
1032 return(HttpResponse('<p>Missing arguments in list_experiments</p>'))
1023
1033
1024 kinstList = [int(kinst) for kinst in listForm.cleaned_data['instruments']]
1034 kinstList = [int(kinst) for kinst in listForm.cleaned_data['instruments']]
1025 startDate = listForm.cleaned_data['start_date']
1035 startDate = listForm.cleaned_data['start_date']
1026 startDT = datetime.datetime(startDate.year, startDate.month, startDate.day, 0, 0, 0)
1036 startDT = datetime.datetime(startDate.year, startDate.month, startDate.day, 0, 0, 0)
1027 endDate = listForm.cleaned_data['end_date']
1037 endDate = listForm.cleaned_data['end_date']
1028 endDT = datetime.datetime(endDate.year, endDate.month, endDate.day, 23, 59, 59)
1038 endDT = datetime.datetime(endDate.year, endDate.month, endDate.day, 23, 59, 59)
1029 localOnly = not listForm.cleaned_data['isGlobal']
1039 localOnly = not listForm.cleaned_data['isGlobal']
1030 expList = madWeb.getExperimentList(kinstList, startDT, endDT, localOnly)
1040 expList = madWeb.getExperimentList(kinstList, startDT, endDT, localOnly)
1031
1041
1032 return render(request, 'madweb/list_experiments.html', {'expList':expList, 'localOnly':localOnly,
1042 return render(request, 'madweb/list_experiments.html', {'expList':expList, 'localOnly':localOnly,
1033 'list_active': 'class="active"', 'site_name': siteName,
1043 'list_active': 'class="active"', 'site_name': siteName,
1034 'site_list': siteList, 'bg_color': bg_color})
1044 'site_list': siteList, 'bg_color': bg_color})
1035
1045
1036
1046
1037 def show_experiment(request):
1047 def show_experiment(request):
1038 """show_experiment call that returns the experiment page to support the list experiments UI.
1048 """show_experiment call that returns the experiment page to support the list experiments UI.
1039
1049
1040 Inputs:
1050 Inputs:
1041 request
1051 request
1042 """
1052 """
1043 madDB = madrigal.metadata.MadrigalDB()
1053 madDB = madrigal.metadata.MadrigalDB()
1044 bg_color = madDB.getBackgroundColor()
1054 bg_color = madDB.getBackgroundColor()
1045 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1055 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1046 siteName, siteList = madWebObj.getSiteInfo()
1056 siteName, siteList = madWebObj.getSiteInfo()
1047 cookieDict = request.COOKIES
1057 cookieDict = request.COOKIES
1048 user_email = cookieDict['user_email']
1058 user_email = cookieDict['user_email']
1049 queryDict = request.GET.copy()
1059 queryDict = request.GET.copy()
1050 queryDict['user_email'] = user_email
1060 queryDict['user_email'] = user_email
1051 if 'show_plots' in queryDict:
1061 if 'show_plots' in queryDict:
1052 plotsForm = madweb.forms.SingleExpPlotsForm(queryDict)
1062 plotsForm = madweb.forms.SingleExpPlotsForm(queryDict)
1053 form = madweb.forms.SingleExpFileForm(queryDict)
1063 form = madweb.forms.SingleExpFileForm(queryDict)
1054 if 'show_plots' in queryDict:
1064 if 'show_plots' in queryDict:
1055 form.fields['plot_list'] = plotsForm.fields['plot_list']
1065 form.fields['plot_list'] = plotsForm.fields['plot_list']
1056 if len(form.fields['file_list'].choices) > 1:
1066 if len(form.fields['file_list'].choices) > 1:
1057 # this experiment has data files
1067 # this experiment has data files
1058 return render(request, 'madweb/show_experiment.html', {'list_active': 'class="active"',
1068 return render(request, 'madweb/show_experiment.html', {'list_active': 'class="active"',
1059 'form': form, 'site_name': siteName,
1069 'form': form, 'site_name': siteName,
1060 'site_list': siteList,
1070 'site_list': siteList,
1061 'loader': 'loadPage',
1071 'loader': 'loadPage',
1062 'bg_color': bg_color,
1072 'bg_color': bg_color,
1063 'redirect': reverse('show_experiment')})
1073 'redirect': reverse('show_experiment')})
1064
1074
1065 else:
1075 else:
1066 # this experiment has no data files
1076 # this experiment has no data files
1067 form2 = madweb.forms.SingleExpPlotsForm(request.GET)
1077 form2 = madweb.forms.SingleExpPlotsForm(request.GET)
1068 exp_desc = form.fields['exp_desc'].label
1078 exp_desc = form.fields['exp_desc'].label
1069 return render(request, 'madweb/show_exp_no_files.html', {'list_active': 'class="active"',
1079 return render(request, 'madweb/show_exp_no_files.html', {'list_active': 'class="active"',
1070 'form': form2, 'exp_desc': exp_desc,
1080 'form': form2, 'exp_desc': exp_desc,
1071 'site_name': siteName,
1081 'site_name': siteName,
1072 'site_list': siteList,
1082 'site_list': siteList,
1073 'loader': 'loadPage',
1083 'loader': 'loadPage',
1074 'bg_color': bg_color,
1084 'bg_color': bg_color,
1075 'redirect': reverse('show_experiment')})
1085 'redirect': reverse('show_experiment')})
1076
1086
1077
1087
1078 def show_experiment_v2(request):
1088 def show_experiment_v2(request):
1079 """show_experiment_v2 is a slight variant of show_experiment to accept old form
1089 """show_experiment_v2 is a slight variant of show_experiment to accept old form
1080 calls from Madrigal2 sites.
1090 calls from Madrigal2 sites.
1081
1091
1082 Inputs:
1092 Inputs:
1083 request
1093 request
1084 """
1094 """
1085 madDB = madrigal.metadata.MadrigalDB()
1095 madDB = madrigal.metadata.MadrigalDB()
1086 bg_color = madDB.getBackgroundColor()
1096 bg_color = madDB.getBackgroundColor()
1087 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1097 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1088 siteName, siteList = madWebObj.getSiteInfo()
1098 siteName, siteList = madWebObj.getSiteInfo()
1089 cookieDict = request.COOKIES
1099 cookieDict = request.COOKIES
1090 user_email = cookieDict['user_email']
1100 user_email = cookieDict['user_email']
1091 queryDict = request.GET.copy()
1101 queryDict = request.GET.copy()
1092 queryDict['user_email'] = user_email
1102 queryDict['user_email'] = user_email
1093 queryDict['experiment_list'] = queryDict['exp']
1103 queryDict['experiment_list'] = queryDict['exp']
1094 form = madweb.forms.SingleExpFileForm(queryDict)
1104 form = madweb.forms.SingleExpFileForm(queryDict)
1095
1105
1096 return render(request, 'madweb/show_experiment.html', {'list_active': 'class="active"',
1106 return render(request, 'madweb/show_experiment.html', {'list_active': 'class="active"',
1097 'form': form, 'site_name': siteName,
1107 'form': form, 'site_name': siteName,
1098 'site_list': siteList,
1108 'site_list': siteList,
1099 'loader': 'loadPage',
1109 'loader': 'loadPage',
1100 'bg_color': bg_color,
1110 'bg_color': bg_color,
1101 'redirect': reverse('show_experiment')})
1111 'redirect': reverse('show_experiment')})
1102
1112
1103
1113
1104 def choose_script(request):
1114 def choose_script(request):
1105 """choose_script that returns the choose script page.
1115 """choose_script that returns the choose script page.
1106
1116
1107 Inputs:
1117 Inputs:
1108 request
1118 request
1109 """
1119 """
1110 madDB = madrigal.metadata.MadrigalDB()
1120 madDB = madrigal.metadata.MadrigalDB()
1111 bg_color = madDB.getBackgroundColor()
1121 bg_color = madDB.getBackgroundColor()
1112 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1122 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1113 siteName, siteList = madWebObj.getSiteInfo()
1123 siteName, siteList = madWebObj.getSiteInfo()
1114 return render(request, 'madweb/choose_script.html', {'script_active': 'class="active"', 'site_name': siteName,
1124 return render(request, 'madweb/choose_script.html', {'script_active': 'class="active"', 'site_name': siteName,
1115 'site_list': siteList, 'bg_color': bg_color})
1125 'site_list': siteList, 'bg_color': bg_color})
1116
1126
1117
1127
1118 def download_as_is_script(request):
1128 def download_as_is_script(request):
1119 """download_as_is_script that returns the download_as_is_script script page.
1129 """download_as_is_script that returns the download_as_is_script script page.
1120
1130
1121 Inputs:
1131 Inputs:
1122 request
1132 request
1123 """
1133 """
1124 madDB = madrigal.metadata.MadrigalDB()
1134 madDB = madrigal.metadata.MadrigalDB()
1125 bg_color = madDB.getBackgroundColor()
1135 bg_color = madDB.getBackgroundColor()
1126 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1136 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1127 siteName, siteList = madWebObj.getSiteInfo()
1137 siteName, siteList = madWebObj.getSiteInfo()
1128 responseDict = {'script_active': 'class="active"'}
1138 responseDict = {'script_active': 'class="active"'}
1129 form = madweb.forms.DownloadAsIsScriptForm()
1139 form = madweb.forms.DownloadAsIsScriptForm()
1130 responseDict['form'] = form
1140 responseDict['form'] = form
1131 responseDict['categoryList'] = form.categories
1141 responseDict['categoryList'] = form.categories
1132 responseDict['instrumentList'] = form.instruments
1142 responseDict['instrumentList'] = form.instruments
1133 responseDict['kindatList'] = form.kindats
1143 responseDict['kindatList'] = form.kindats
1134 responseDict['site_name'] = siteName
1144 responseDict['site_name'] = siteName
1135 responseDict['site_list'] = siteList
1145 responseDict['site_list'] = siteList
1136 responseDict['datetime'] = True
1146 responseDict['datetime'] = True
1137 responseDict['bg_color'] = bg_color
1147 responseDict['bg_color'] = bg_color
1138
1148
1139 return render(request, 'madweb/download_as_is_script.html', responseDict)
1149 return render(request, 'madweb/download_as_is_script.html', responseDict)
1140
1150
1141
1151
1142 def generate_download_files_script(request):
1152 def generate_download_files_script(request):
1143 """generate_download_files_script is a Ajax call that returns the generated file download script.
1153 """generate_download_files_script is a Ajax call that returns the generated file download script.
1144
1154
1145 Inputs:
1155 Inputs:
1146 request
1156 request
1147 """
1157 """
1148 form = madweb.forms.DownloadAsIsScriptForm(request.GET)
1158 form = madweb.forms.DownloadAsIsScriptForm(request.GET)
1149 if not form.is_valid():
1159 if not form.is_valid():
1150 raise ValueError('Form error: %s' % (form.errors))
1160 raise ValueError('Form error: %s' % (form.errors))
1151 cookieDict = request.COOKIES
1161 cookieDict = request.COOKIES
1152 if not 'user_fullname' in cookieDict:
1162 if not 'user_fullname' in cookieDict:
1153 return(HttpResponse('<p>Cookie with user_fullname required for generateDownloadFilesScript</p>'))
1163 return(HttpResponse('<p>Cookie with user_fullname required for generateDownloadFilesScript</p>'))
1154 user_fullname = django.utils.http.urlquote_plus(cookieDict['user_fullname'])
1164 user_fullname = django.utils.http.urlquote_plus(cookieDict['user_fullname'])
1155 user_email = cookieDict['user_email']
1165 user_email = cookieDict['user_email']
1156 user_affiliation = django.utils.http.urlquote_plus(cookieDict['user_affiliation'])
1166 user_affiliation = django.utils.http.urlquote_plus(cookieDict['user_affiliation'])
1157 madWebObj = madrigal.ui.web.MadrigalWeb()
1167 madWebObj = madrigal.ui.web.MadrigalWeb()
1158 script_text = madWebObj.generateDownloadFileScriptFromForm(form.cleaned_data, user_fullname,
1168 script_text = madWebObj.generateDownloadFileScriptFromForm(form.cleaned_data, user_fullname,
1159 user_email, user_affiliation)
1169 user_email, user_affiliation)
1160 return render(request, 'madweb/download_files_script.html', {'script_text': script_text})
1170 return render(request, 'madweb/download_files_script.html', {'script_text': script_text})
1161
1171
1162
1172
1163 def download_advanced_script(request):
1173 def download_advanced_script(request):
1164 """download_advanced_script that returns the download_advanced_script script page.
1174 """download_advanced_script that returns the download_advanced_script script page.
1165
1175
1166 Inputs:
1176 Inputs:
1167 request
1177 request
1168 """
1178 """
1169 madDB = madrigal.metadata.MadrigalDB()
1179 madDB = madrigal.metadata.MadrigalDB()
1170 bg_color = madDB.getBackgroundColor()
1180 bg_color = madDB.getBackgroundColor()
1171 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1181 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1172 siteName, siteList = madWebObj.getSiteInfo()
1182 siteName, siteList = madWebObj.getSiteInfo()
1173 responseDict = {'script_active': 'class="active"'}
1183 responseDict = {'script_active': 'class="active"'}
1174 form = madweb.forms.DownloadAdvancedScriptForm()
1184 form = madweb.forms.DownloadAdvancedScriptForm()
1175 responseDict['form'] = form
1185 responseDict['form'] = form
1176 responseDict['categoryList'] = form.categories
1186 responseDict['categoryList'] = form.categories
1177 responseDict['instrumentList'] = form.instruments
1187 responseDict['instrumentList'] = form.instruments
1178 responseDict['kindatList'] = form.kindats
1188 responseDict['kindatList'] = form.kindats
1179 responseDict['site_name'] = siteName
1189 responseDict['site_name'] = siteName
1180 responseDict['site_list'] = siteList
1190 responseDict['site_list'] = siteList
1181 responseDict['datetime'] = True
1191 responseDict['datetime'] = True
1182 responseDict['bg_color'] = bg_color
1192 responseDict['bg_color'] = bg_color
1183
1193
1184 return render(request, 'madweb/download_advanced_script.html', responseDict)
1194 return render(request, 'madweb/download_advanced_script.html', responseDict)
1185
1195
1186
1196
1187 def generate_download_advanced_script(request):
1197 def generate_download_advanced_script(request):
1188 """generate_download_advanced_script is a Ajax call that returns the generated advanced download script.
1198 """generate_download_advanced_script is a Ajax call that returns the generated advanced download script.
1189
1199
1190 Inputs:
1200 Inputs:
1191 request
1201 request
1192 """
1202 """
1193 form1 = madweb.forms.DownloadAdvancedScriptForm(request.GET)
1203 form1 = madweb.forms.DownloadAdvancedScriptForm(request.GET)
1194 if not form1.is_valid():
1204 if not form1.is_valid():
1195 raise ValueError('Form error: %s' % (form1.errors))
1205 raise ValueError('Form error: %s' % (form1.errors))
1196 form2 = madweb.forms.AdvScriptParmsForm(request.GET)
1206 form2 = madweb.forms.AdvScriptParmsForm(request.GET)
1197 if not form2.is_valid():
1207 if not form2.is_valid():
1198 raise ValueError('Form error: %s' % (form2.errors))
1208 raise ValueError('Form error: %s' % (form2.errors))
1199 form3 = madweb.forms.AdvScriptParmsFiltersForm(request.GET)
1209 form3 = madweb.forms.AdvScriptParmsFiltersForm(request.GET)
1200 if not form3.is_valid():
1210 if not form3.is_valid():
1201 raise ValueError('Form error: %s' % (form3.errors))
1211 raise ValueError('Form error: %s' % (form3.errors))
1202 cookieDict = request.COOKIES
1212 cookieDict = request.COOKIES
1203 if not 'user_fullname' in cookieDict:
1213 if not 'user_fullname' in cookieDict:
1204 return(HttpResponse('<p>Cookie with user_fullname required for generateAdvancedDownloadScript</p>'))
1214 return(HttpResponse('<p>Cookie with user_fullname required for generateAdvancedDownloadScript</p>'))
1205 user_fullname = django.utils.http.urlquote_plus(cookieDict['user_fullname'])
1215 user_fullname = django.utils.http.urlquote_plus(cookieDict['user_fullname'])
1206 user_email = cookieDict['user_email']
1216 user_email = cookieDict['user_email']
1207 user_affiliation = django.utils.http.urlquote_plus(cookieDict['user_affiliation'])
1217 user_affiliation = django.utils.http.urlquote_plus(cookieDict['user_affiliation'])
1208 madWebObj = madrigal.ui.web.MadrigalWeb()
1218 madWebObj = madrigal.ui.web.MadrigalWeb()
1209 script_text = madWebObj.generateGlobalIsprintScriptFromForm(form1.cleaned_data, form2.cleaned_data,
1219 script_text = madWebObj.generateGlobalIsprintScriptFromForm(form1.cleaned_data, form2.cleaned_data,
1210 form3.cleaned_data, user_fullname,
1220 form3.cleaned_data, user_fullname,
1211 user_email, user_affiliation)
1221 user_email, user_affiliation)
1212 return render(request, 'madweb/download_files_script.html', {'script_text': script_text})
1222 return render(request, 'madweb/download_files_script.html', {'script_text': script_text})
1213
1223
1214
1224
1215 def generate_parms_script(request):
1225 def generate_parms_script(request):
1216 """generate_parms_script is a Ajax call that returns the generated parameter script.
1226 """generate_parms_script is a Ajax call that returns the generated parameter script.
1217
1227
1218 Inputs:
1228 Inputs:
1219 request
1229 request
1220 """
1230 """
1221 form = madweb.forms.AdvScriptParmsForm(request.GET)
1231 form = madweb.forms.AdvScriptParmsForm(request.GET)
1222 return render(request, 'madweb/download_adv_parms_script.html', {'form': form,
1232 return render(request, 'madweb/download_adv_parms_script.html', {'form': form,
1223 'parmList': form.parmList})
1233 'parmList': form.parmList})
1224
1234
1225
1235
1226 def generate_parms_filters_script(request):
1236 def generate_parms_filters_script(request):
1227 """generate_parms_filters_script is a Ajax call that returns the generated parameter filters script.
1237 """generate_parms_filters_script is a Ajax call that returns the generated parameter filters script.
1228
1238
1229 Inputs:
1239 Inputs:
1230 request
1240 request
1231 """
1241 """
1232 form = madweb.forms.AdvScriptParmsFiltersForm(request.GET)
1242 form = madweb.forms.AdvScriptParmsFiltersForm(request.GET)
1233 return render(request, 'madweb/download_adv_parms_filters_script.html', {'form': form})
1243 return render(request, 'madweb/download_adv_parms_filters_script.html', {'form': form})
1234
1244
1235
1245
1236 def ftp(request):
1246 def ftp(request):
1237 """ftp creates the first ftp page listing instruments
1247 """ftp creates the first ftp page listing instruments
1238 """
1248 """
1239 madDB = madrigal.metadata.MadrigalDB()
1249 madDB = madrigal.metadata.MadrigalDB()
1240 bg_color = madDB.getBackgroundColor()
1250 bg_color = madDB.getBackgroundColor()
1241 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1251 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1242 siteName, siteList = madWebObj.getSiteInfo()
1252 siteName, siteList = madWebObj.getSiteInfo()
1243 cookieDict = request.COOKIES
1253 cookieDict = request.COOKIES
1244 if not 'user_fullname' in cookieDict:
1254 if not 'user_fullname' in cookieDict:
1245 return(HttpResponse('<p>Cookie with user_fullname required for ftp</p>'))
1255 return(HttpResponse('<p>Cookie with user_fullname required for ftp</p>'))
1246 fullname = django.utils.http.urlquote_plus(cookieDict['user_fullname'])
1256 fullname = django.utils.http.urlquote_plus(cookieDict['user_fullname'])
1247 email = cookieDict['user_email']
1257 email = cookieDict['user_email']
1248 affiliation = django.utils.http.urlquote_plus(cookieDict['user_affiliation'])
1258 affiliation = django.utils.http.urlquote_plus(cookieDict['user_affiliation'])
1249 # create instrument with data list with tuple (instrument_name, kinst)
1259 # create instrument with data list with tuple (instrument_name, kinst)
1250 madInstDataObj = madrigal.metadata.MadrigalInstrumentData(madDB)
1260 madInstDataObj = madrigal.metadata.MadrigalInstrumentData(madDB)
1251 madInstList = [(instrument_name, kinst) for kinst, instrument_name, site_id in madInstDataObj.getInstruments(local=True)]
1261 madInstList = [(instrument_name, kinst) for kinst, instrument_name, site_id in madInstDataObj.getInstruments(local=True)]
1252 return render(request, 'madweb/ftp_instruments.html', {'madInstList': madInstList, 'fullname': fullname,
1262 return render(request, 'madweb/ftp_instruments.html', {'madInstList': madInstList, 'fullname': fullname,
1253 'email': email, 'affiliation':affiliation, 'site_name': siteName,
1263 'email': email, 'affiliation':affiliation, 'site_name': siteName,
1254 'site_list': siteList, 'bg_color': bg_color})
1264 'site_list': siteList, 'bg_color': bg_color})
1255
1265
1256
1266
1257 def ftp_instrument(request, fullname, email, affiliation, kinst):
1267 def ftp_instrument(request, fullname, email, affiliation, kinst):
1258 """ftp_instrument creates the first ftp instrument page listing years
1268 """ftp_instrument creates the first ftp instrument page listing years
1259 Inputs: kinst selected
1269 Inputs: kinst selected
1260 """
1270 """
1261 kinst = int(kinst)
1271 kinst = int(kinst)
1262 madDB = madrigal.metadata.MadrigalDB()
1272 madDB = madrigal.metadata.MadrigalDB()
1263 bg_color = madDB.getBackgroundColor()
1273 bg_color = madDB.getBackgroundColor()
1264 madInstDataObj = madrigal.metadata.MadrigalInstrumentData(madDB)
1274 madInstDataObj = madrigal.metadata.MadrigalInstrumentData(madDB)
1265 madInstObj = madrigal.metadata.MadrigalInstrument(madDB)
1275 madInstObj = madrigal.metadata.MadrigalInstrument(madDB)
1266 inst_name = madInstObj.getInstrumentName(kinst)
1276 inst_name = madInstObj.getInstrumentName(kinst)
1267 yearList = madInstDataObj.getInstrumentYears(kinst)
1277 yearList = madInstDataObj.getInstrumentYears(kinst)
1268 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1278 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1269 siteName, siteList = madWebObj.getSiteInfo()
1279 siteName, siteList = madWebObj.getSiteInfo()
1270 return render(request, 'madweb/ftp_years.html',{'yearList':yearList, 'kinst':kinst,
1280 return render(request, 'madweb/ftp_years.html',{'yearList':yearList, 'kinst':kinst,
1271 'inst_name':inst_name, 'fullname': fullname,
1281 'inst_name':inst_name, 'fullname': fullname,
1272 'email': email, 'affiliation':affiliation,
1282 'email': email, 'affiliation':affiliation,
1273 'site_name': siteName, 'site_list': siteList,
1283 'site_name': siteName, 'site_list': siteList,
1274 'bg_color': bg_color })
1284 'bg_color': bg_color })
1275
1285
1276
1286
1277 def ftp_year(request, fullname, email, affiliation, kinst, year):
1287 def ftp_year(request, fullname, email, affiliation, kinst, year):
1278 """ftp_year creates the first ftp year page listing kindats
1288 """ftp_year creates the first ftp year page listing kindats
1279 Inputs: kinst selected, year selected
1289 Inputs: kinst selected, year selected
1280 """
1290 """
1281 kinst = int(kinst)
1291 kinst = int(kinst)
1282 year = int(year)
1292 year = int(year)
1283 madDB = madrigal.metadata.MadrigalDB()
1293 madDB = madrigal.metadata.MadrigalDB()
1284 bg_color = madDB.getBackgroundColor()
1294 bg_color = madDB.getBackgroundColor()
1285 madInstObj = madrigal.metadata.MadrigalInstrument(madDB)
1295 madInstObj = madrigal.metadata.MadrigalInstrument(madDB)
1286 inst_name = madInstObj.getInstrumentName(kinst)
1296 inst_name = madInstObj.getInstrumentName(kinst)
1287 madInstKindatObj = madrigal.metadata.MadrigalInstrumentKindats(madDB)
1297 madInstKindatObj = madrigal.metadata.MadrigalInstrumentKindats(madDB)
1288 kindatList = madInstKindatObj.getKindatListForInstrumentYear(kinst, year)
1298 kindatList = madInstKindatObj.getKindatListForInstrumentYear(kinst, year)
1289 madKindatObj = madrigal.metadata.MadrigalKindat(madDB)
1299 madKindatObj = madrigal.metadata.MadrigalKindat(madDB)
1290 # create kindatDescList, a list of tuples of (kindat_desc, kindat) for that kinst, year
1300 # create kindatDescList, a list of tuples of (kindat_desc, kindat) for that kinst, year
1291 kindatDescList = []
1301 kindatDescList = []
1292 for kindat in kindatList:
1302 for kindat in kindatList:
1293 kindatDescList.append((madKindatObj.getKindatDescription(kindat, kinst), kindat))
1303 kindatDescList.append((madKindatObj.getKindatDescription(kindat, kinst), kindat))
1294 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1304 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1295 siteName, siteList = madWebObj.getSiteInfo()
1305 siteName, siteList = madWebObj.getSiteInfo()
1296 return render(request, 'madweb/ftp_kindats.html', {'kindatDescList': kindatDescList, 'year': year,
1306 return render(request, 'madweb/ftp_kindats.html', {'kindatDescList': kindatDescList, 'year': year,
1297 'kinst': kinst, 'inst_name':inst_name, 'fullname': fullname,
1307 'kinst': kinst, 'inst_name':inst_name, 'fullname': fullname,
1298 'email': email, 'affiliation':affiliation,
1308 'email': email, 'affiliation':affiliation,
1299 'site_name': siteName, 'site_list': siteList,
1309 'site_name': siteName, 'site_list': siteList,
1300 'bg_color': bg_color })
1310 'bg_color': bg_color })
1301
1311
1302
1312
1303 def ftp_kindat(request, fullname, email, affiliation, kinst, year, kindat):
1313 def ftp_kindat(request, fullname, email, affiliation, kinst, year, kindat):
1304 """ftp_kindat creates the first ftp format page listing formats to choose from
1314 """ftp_kindat creates the first ftp format page listing formats to choose from
1305 Inputs: kinst selected, year selected, kindat selected
1315 Inputs: kinst selected, year selected, kindat selected
1306 """
1316 """
1307 kinst = int(kinst)
1317 kinst = int(kinst)
1308 kindat = int(kindat)
1318 kindat = int(kindat)
1309 madDB = madrigal.metadata.MadrigalDB()
1319 madDB = madrigal.metadata.MadrigalDB()
1310 bg_color = madDB.getBackgroundColor()
1320 bg_color = madDB.getBackgroundColor()
1311 madKindatObj = madrigal.metadata.MadrigalKindat(madDB)
1321 madKindatObj = madrigal.metadata.MadrigalKindat(madDB)
1312 kindat_desc = madKindatObj.getKindatDescription(kindat, kinst)
1322 kindat_desc = madKindatObj.getKindatDescription(kindat, kinst)
1313 madInstObj = madrigal.metadata.MadrigalInstrument(madDB)
1323 madInstObj = madrigal.metadata.MadrigalInstrument(madDB)
1314 inst_name = madInstObj.getInstrumentName(kinst)
1324 inst_name = madInstObj.getInstrumentName(kinst)
1315 formatDescList = [(formatDict[key], key) for key in list(formatDict.keys())]
1325 formatDescList = [(formatDict[key], key) for key in list(formatDict.keys())]
1316 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1326 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1317 siteName, siteList = madWebObj.getSiteInfo()
1327 siteName, siteList = madWebObj.getSiteInfo()
1318 return render(request, 'madweb/ftp_formats.html', {'formatDescList': formatDescList, 'year': year,
1328 return render(request, 'madweb/ftp_formats.html', {'formatDescList': formatDescList, 'year': year,
1319 'kinst': kinst, 'inst_name': inst_name, 'kindat': kindat,
1329 'kinst': kinst, 'inst_name': inst_name, 'kindat': kindat,
1320 'kindat_desc': kindat_desc, 'fullname': fullname,
1330 'kindat_desc': kindat_desc, 'fullname': fullname,
1321 'email': email, 'affiliation': affiliation,
1331 'email': email, 'affiliation': affiliation,
1322 'site_name': siteName, 'site_list': siteList,
1332 'site_name': siteName, 'site_list': siteList,
1323 'bg_color': bg_color } )
1333 'bg_color': bg_color } )
1324
1334
1325
1335
1326 def ftp_files(request, fullname, email, affiliation, kinst, year, kindat, format):
1336 def ftp_files(request, fullname, email, affiliation, kinst, year, kindat, format):
1327 """ftp_files creates the ftp files page listing individual files
1337 """ftp_files creates the ftp files page listing individual files
1328 Inputs: kinst selected, year selected, kindat selected
1338 Inputs: kinst selected, year selected, kindat selected
1329 """
1339 """
1330 kinst = int(kinst)
1340 kinst = int(kinst)
1331 year = int(year)
1341 year = int(year)
1332 dt = datetime.datetime(year,1,1) # speed up search
1342 dt = datetime.datetime(year,1,1) # speed up search
1333 kindat = int(kindat)
1343 kindat = int(kindat)
1334 if format not in ('hdf5', 'netCDF4', 'ascii'):
1344 if format not in ('hdf5', 'netCDF4', 'ascii'):
1335 raise ValueError('Unknown format %s' % (format))
1345 raise ValueError('Unknown format %s' % (format))
1336 if format == 'netCDF4':
1346 if format == 'netCDF4':
1337 thisExt = '.nc'
1347 thisExt = '.nc'
1338 elif format == 'ascii':
1348 elif format == 'ascii':
1339 thisExt = '.txt'
1349 thisExt = '.txt'
1340 format_desc = formatDict[format]
1350 format_desc = formatDict[format]
1341 # create a list of full names, where each item is a tuple of
1351 # create a list of full names, where each item is a tuple of
1342 # (fullFilename in Madrigal, output basename with correct extension, date string)
1352 # (fullFilename in Madrigal, output basename with correct extension, date string)
1343 fileList = []
1353 fileList = []
1344 madDB = madrigal.metadata.MadrigalDB()
1354 madDB = madrigal.metadata.MadrigalDB()
1345 bg_color = madDB.getBackgroundColor()
1355 bg_color = madDB.getBackgroundColor()
1346 madKindatObj = madrigal.metadata.MadrigalKindat(madDB)
1356 madKindatObj = madrigal.metadata.MadrigalKindat(madDB)
1347 kindat_desc = madKindatObj.getKindatDescription(kindat, kinst)
1357 kindat_desc = madKindatObj.getKindatDescription(kindat, kinst)
1348 madInstObj = madrigal.metadata.MadrigalInstrument(madDB)
1358 madInstObj = madrigal.metadata.MadrigalInstrument(madDB)
1349 inst_name = madInstObj.getInstrumentName(kinst)
1359 inst_name = madInstObj.getInstrumentName(kinst)
1350 pi = madInstObj.getContactName(kinst)
1360 pi = madInstObj.getContactName(kinst)
1351 pi_email = madInstObj.getContactEmail(kinst)
1361 pi_email = madInstObj.getContactEmail(kinst)
1352 madExpObj = madrigal.metadata.MadrigalExperiment(madDB)
1362 madExpObj = madrigal.metadata.MadrigalExperiment(madDB)
1353 startIndex = madExpObj.getStartPosition(dt) + 1
1363 startIndex = madExpObj.getStartPosition(dt) + 1
1354 for loop in (0,1):
1364 for loop in (0,1):
1355 # we normally only loop once, but sometimes multi-year experiments require a slow full search
1365 # we normally only loop once, but sometimes multi-year experiments require a slow full search
1356 if loop == 0:
1366 if loop == 0:
1357 thisStartIndex = startIndex
1367 thisStartIndex = startIndex
1358 else:
1368 else:
1359 thisStartIndex = 0 # should only get to this case for rare multi-year experiments
1369 thisStartIndex = 0 # should only get to this case for rare multi-year experiments
1360 for i in range(thisStartIndex, madExpObj.getExpCount()):
1370 for i in range(thisStartIndex, madExpObj.getExpCount()):
1361 if kinst != madExpObj.getKinstByPosition(i):
1371 if kinst != madExpObj.getKinstByPosition(i):
1362 continue
1372 continue
1363 stTuple = madExpObj.getExpStartDateTimeByPosition(i)[0:6]
1373 stTuple = madExpObj.getExpStartDateTimeByPosition(i)[0:6]
1364 etTuple = madExpObj.getExpEndDateTimeByPosition(i)[0:6]
1374 etTuple = madExpObj.getExpEndDateTimeByPosition(i)[0:6]
1365 expTitle = madExpObj.getExpNameByPosition(i)
1375 expTitle = madExpObj.getExpNameByPosition(i)
1366 sDT = datetime.datetime(*stTuple)
1376 sDT = datetime.datetime(*stTuple)
1367 eDT = datetime.datetime(*etTuple)
1377 eDT = datetime.datetime(*etTuple)
1368 if sDT.year > year:
1378 if sDT.year > year:
1369 break
1379 break
1370 if eDT.year < year:
1380 if eDT.year < year:
1371 continue
1381 continue
1372 dateStr = ' From %s to %s: %s' % (sDT.strftime('%Y-%m-%d %H:%M:%S'), eDT.strftime('%Y-%m-%d %H:%M:%S'), str(expTitle))
1382 dateStr = ' From %s to %s: %s' % (sDT.strftime('%Y-%m-%d %H:%M:%S'), eDT.strftime('%Y-%m-%d %H:%M:%S'), str(expTitle))
1373 expDir = madExpObj.getExpDirByPosition(i)
1383 expDir = madExpObj.getExpDirByPosition(i)
1374 # look at this exp for the right kindat
1384 # look at this exp for the right kindat
1375 try:
1385 try:
1376 madFileObj = madrigal.metadata.MadrigalMetaFile(madDB, os.path.join(expDir, 'fileTab.txt'))
1386 madFileObj = madrigal.metadata.MadrigalMetaFile(madDB, os.path.join(expDir, 'fileTab.txt'))
1377 except:
1387 except:
1378 pass
1388 pass
1379 for j in range(madFileObj.getFileCount()):
1389 for j in range(madFileObj.getFileCount()):
1380 if madFileObj.getCategoryByPosition(j) not in (0,1):
1390 if madFileObj.getCategoryByPosition(j) not in (0,1):
1381 # skip history and alternate files
1391 # skip history and alternate files
1382 continue
1392 continue
1383 if madFileObj.getKindatByPosition(j) != kindat:
1393 if madFileObj.getKindatByPosition(j) != kindat:
1384 continue
1394 continue
1385 statusStr = ' : %s' % (str(madFileObj.getStatusByPosition(j)))
1395 statusStr = ' : %s' % (str(madFileObj.getStatusByPosition(j)))
1386 fullFilename = os.path.join(expDir, madFileObj.getFilenameByPosition(j))
1396 fullFilename = os.path.join(expDir, madFileObj.getFilenameByPosition(j))
1387 fullBasename = os.path.basename(fullFilename)
1397 fullBasename = os.path.basename(fullFilename)
1388 if format != 'hdf5':
1398 if format != 'hdf5':
1389 base, file_extension = os.path.splitext(fullFilename)
1399 base, file_extension = os.path.splitext(fullFilename)
1390 basename = os.path.basename(base + thisExt)
1400 basename = os.path.basename(base + thisExt)
1391 else:
1401 else:
1392 basename = os.path.basename(fullFilename)
1402 basename = os.path.basename(fullFilename)
1393 # make sure this file isn't too big to create a cache
1403 # make sure this file isn't too big to create a cache
1394 file_size = os.path.getsize(fullFilename)
1404 file_size = os.path.getsize(fullFilename)
1395 if file_size > maxSize and format != 'hdf5':
1405 if file_size > maxSize and format != 'hdf5':
1396 # make sure cached file exists before adding
1406 # make sure cached file exists before adding
1397 if format == 'netCDF4':
1407 if format == 'netCDF4':
1398 cachedFile = os.path.join(expDir, 'overview', fullBasename + thisExt)
1408 cachedFile = os.path.join(expDir, 'overview', fullBasename + thisExt)
1399 else:
1409 else:
1400 cachedFile = os.path.join(expDir, 'overview', fullBasename + thisExt + '.gz')
1410 cachedFile = os.path.join(expDir, 'overview', fullBasename + thisExt + '.gz')
1401 if not os.path.exists(cachedFile):
1411 if not os.path.exists(cachedFile):
1402 continue
1412 continue
1403 fileList.append((urllib.parse.quote_plus(fullFilename), basename, dateStr + statusStr))
1413 fileList.append((urllib.parse.quote_plus(fullFilename), basename, dateStr + statusStr))
1404
1414
1405 if len(fileList) > 0:
1415 if len(fileList) > 0:
1406 break # usually we avoid the slow full loop
1416 break # usually we avoid the slow full loop
1407
1417
1408
1418
1409 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1419 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1410 siteName, siteList = madWebObj.getSiteInfo()
1420 siteName, siteList = madWebObj.getSiteInfo()
1411
1421
1412 return render(request, 'madweb/ftp_files.html', {'fullFilenames': fileList, 'year': year, 'kindat_desc': kindat_desc,
1422 return render(request, 'madweb/ftp_files.html', {'fullFilenames': fileList, 'year': year, 'kindat_desc': kindat_desc,
1413 'kinst': kinst, 'inst_name':inst_name, 'fullname': fullname,
1423 'kinst': kinst, 'inst_name':inst_name, 'fullname': fullname,
1414 'kindat': kindat, 'format': format, 'format_desc': format_desc,
1424 'kindat': kindat, 'format': format, 'format_desc': format_desc,
1415 'email': email, 'affiliation':affiliation,
1425 'email': email, 'affiliation':affiliation,
1416 'site_name': siteName, 'site_list': siteList,
1426 'site_name': siteName, 'site_list': siteList,
1417 'pi_email': pi_email, 'pi_name': pi,
1427 'pi_email': pi_email, 'pi_name': pi,
1418 'bg_color': bg_color})
1428 'bg_color': bg_color})
1419
1429
1420
1430
1421 def ftp_download(request, user_fullname, user_email, user_affiliation, kinst, year, kindat, format, fullHdf5Filename):
1431 def ftp_download(request, user_fullname, user_email, user_affiliation, kinst, year, kindat, format, fullHdf5Filename):
1422 """ftp_download creates the first ftp kindat page listing individual files
1432 """ftp_download creates the first ftp kindat page listing individual files
1423 Inputs: kinst selected, year selected, kindat selected
1433 Inputs: kinst selected, year selected, kindat selected
1424 """
1434 """
1425 madDB = madrigal.metadata.MadrigalDB()
1435 madDB = madrigal.metadata.MadrigalDB()
1426 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1436 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1427 user_fullname = urllib.parse.unquote_plus(user_fullname)
1437 user_fullname = urllib.parse.unquote_plus(user_fullname)
1428 user_affiliation = urllib.parse.unquote_plus(user_affiliation)
1438 user_affiliation = urllib.parse.unquote_plus(user_affiliation)
1429 fullHdf5Filename = urllib.parse.unquote_plus(fullHdf5Filename)
1439 fullHdf5Filename = urllib.parse.unquote_plus(fullHdf5Filename)
1430 fullFilename = madWebObj.downloadFullFileAsIs(fullHdf5Filename, format, user_fullname, user_email, user_affiliation)
1440 fullFilename = madWebObj.downloadFullFileAsIs(fullHdf5Filename, format, user_fullname, user_email, user_affiliation)
1431
1441
1432 f = open(fullFilename, 'rb')
1442 f = open(fullFilename, 'rb')
1433 filename = os.path.basename(fullFilename)
1443 filename = os.path.basename(fullFilename)
1434 chunk_size = 8192
1444 chunk_size = 8192
1435 file_type = mimetypes.guess_type(fullFilename)[0]
1445 file_type = mimetypes.guess_type(fullFilename)[0]
1436 if file_type is None:
1446 if file_type is None:
1437 file_type = 'application/octet-stream'
1447 file_type = 'application/octet-stream'
1438 response = StreamingHttpResponse(FileWrapper(f, chunk_size),
1448 response = StreamingHttpResponse(FileWrapper(f, chunk_size),
1439 content_type=file_type)
1449 content_type=file_type)
1440 response['Content-Length'] = os.path.getsize(fullFilename)
1450 response['Content-Length'] = os.path.getsize(fullFilename)
1441 response['Content-Disposition'] = "attachment; filename=%s" % (filename)
1451 response['Content-Disposition'] = "attachment; filename=%s" % (filename)
1442 return(response)
1452 return(response)
1443
1453
1444
1454
1445 @csrf_exempt
1455 @csrf_exempt
1446 def ftp_multiple_download(request):
1456 def ftp_multiple_download(request):
1447 """ftp_download creates the first ftp kindat page listing individual files
1457 """ftp_download creates the first ftp kindat page listing individual files
1448 Inputs: kinst selected, year selected, kindat selected
1458 Inputs: kinst selected, year selected, kindat selected
1449 """
1459 """
1450 if request.method == 'POST':
1460 if request.method == 'POST':
1451 reqDict = request.POST
1461 reqDict = request.POST
1452 else:
1462 else:
1453 reqDict = request.GET
1463 reqDict = request.GET
1454 madDB = madrigal.metadata.MadrigalDB()
1464 madDB = madrigal.metadata.MadrigalDB()
1455 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1465 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1456 user_fullname = urllib.parse.unquote_plus(reqDict.get('user_fullname'))
1466 user_fullname = urllib.parse.unquote_plus(reqDict.get('user_fullname'))
1457 user_email = reqDict.get('user_email')
1467 user_email = reqDict.get('user_email')
1458 user_affiliation = urllib.parse.unquote_plus(reqDict.get('user_affiliation'))
1468 user_affiliation = urllib.parse.unquote_plus(reqDict.get('user_affiliation'))
1459 format = reqDict.get('format')
1469 format = reqDict.get('format')
1460 fileList = reqDict.getlist('fullFilename')
1470 fileList = reqDict.getlist('fullFilename')
1461 fileList = [urllib.parse.unquote_plus(filename) for filename in fileList]
1471 fileList = [urllib.parse.unquote_plus(filename) for filename in fileList]
1462 if len(fileList) > 10:
1472 if len(fileList) > 10:
1463 # send user an email with warning
1473 # send user an email with warning
1464 tmpDir = os.path.join(madDB.getMadroot(), 'experiments/stage')
1474 tmpDir = os.path.join(madDB.getMadroot(), 'experiments/stage')
1465 fullFilename = os.path.join(tmpDir, 'result_error_%06i.txt' % (random.randint(0,999999)))
1475 fullFilename = os.path.join(tmpDir, 'result_error_%06i.txt' % (random.randint(0,999999)))
1466 f = open(fullFilename, 'w')
1476 f = open(fullFilename, 'w')
1467 f.write('Error - you requested %i files, maximum is 10\n' % (len(fileList)))
1477 f.write('Error - you requested %i files, maximum is 10\n' % (len(fileList)))
1468 f.close()
1478 f.close()
1469 else:
1479 else:
1470 fullFilename = madWebObj.downloadMultipleFiles(fileList, format, user_fullname, user_email, user_affiliation)
1480 fullFilename = madWebObj.downloadMultipleFiles(fileList, format, user_fullname, user_email, user_affiliation)
1471
1481
1472 f = open(fullFilename, 'rb')
1482 f = open(fullFilename, 'rb')
1473 filename = os.path.basename(fullFilename)
1483 filename = os.path.basename(fullFilename)
1474 chunk_size = 8192
1484 chunk_size = 8192
1475 file_type = mimetypes.guess_type(fullFilename)[0]
1485 file_type = mimetypes.guess_type(fullFilename)[0]
1476 if file_type is None:
1486 if file_type is None:
1477 file_type = 'application/octet-stream'
1487 file_type = 'application/octet-stream'
1478 response = StreamingHttpResponse(FileWrapper(f, chunk_size),
1488 response = StreamingHttpResponse(FileWrapper(f, chunk_size),
1479 content_type=file_type)
1489 content_type=file_type)
1480 response['Content-Length'] = os.path.getsize(fullFilename)
1490 response['Content-Length'] = os.path.getsize(fullFilename)
1481 response['Content-Disposition'] = "attachment; filename=%s" % (filename)
1491 response['Content-Disposition'] = "attachment; filename=%s" % (filename)
1482 return(response)
1492 return(response)
1483
1493
1484
1494
1485 def instrument_metadata(request):
1495 def instrument_metadata(request):
1486 """instrument_metadata returns the instrument_metadata page.
1496 """instrument_metadata returns the instrument_metadata page.
1487
1497
1488 Inputs:
1498 Inputs:
1489 request
1499 request
1490 """
1500 """
1491 # create a list of tuples of (kinst, name, category, latitude, longitude, altitude, pi, pi_email, mnemonic)
1501 # create a list of tuples of (kinst, name, category, latitude, longitude, altitude, pi, pi_email, mnemonic)
1492 madDB = madrigal.metadata.MadrigalDB()
1502 madDB = madrigal.metadata.MadrigalDB()
1493 bg_color = madDB.getBackgroundColor()
1503 bg_color = madDB.getBackgroundColor()
1494 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1504 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1495 siteName, siteList = madWebObj.getSiteInfo()
1505 siteName, siteList = madWebObj.getSiteInfo()
1496 madInstObj = madrigal.metadata.MadrigalInstrument(madDB)
1506 madInstObj = madrigal.metadata.MadrigalInstrument(madDB)
1497 instList = []
1507 instList = []
1498 for name, mnemonic, kinst, category, catID in madInstObj.getOrderedInstrumentList():
1508 for name, mnemonic, kinst, category, catID in madInstObj.getOrderedInstrumentList():
1499 latitude = madInstObj.getLatitude(kinst)
1509 latitude = madInstObj.getLatitude(kinst)
1500 longitude = madInstObj.getLongitude(kinst)
1510 longitude = madInstObj.getLongitude(kinst)
1501 altitude = madInstObj.getAltitude(kinst)
1511 altitude = madInstObj.getAltitude(kinst)
1502 pi = madInstObj.getContactName(kinst)
1512 pi = madInstObj.getContactName(kinst)
1503 pi_email = madInstObj.getContactEmail(kinst)
1513 pi_email = madInstObj.getContactEmail(kinst)
1504 instList.append((kinst, name, category, latitude, longitude, altitude, pi, pi_email, mnemonic))
1514 instList.append((kinst, name, category, latitude, longitude, altitude, pi, pi_email, mnemonic))
1505
1515
1506 responseDict = {'inst_active': 'class="active"', 'instList': instList,
1516 responseDict = {'inst_active': 'class="active"', 'instList': instList,
1507 'site_name': siteName, 'site_list': siteList, 'bg_color': bg_color}
1517 'site_name': siteName, 'site_list': siteList, 'bg_color': bg_color}
1508 return render(request, 'madweb/instrument_metadata.html', responseDict)
1518 return render(request, 'madweb/instrument_metadata.html', responseDict)
1509
1519
1510
1520
1511 def site_metadata(request):
1521 def site_metadata(request):
1512 """site_metadata returns the site_metadata page.
1522 """site_metadata returns the site_metadata page.
1513
1523
1514 Inputs:
1524 Inputs:
1515 request
1525 request
1516 """
1526 """
1517 # create a list of tuples of (siteId, name, url, contact, contact email, version)
1527 # create a list of tuples of (siteId, name, url, contact, contact email, version)
1518 madDB = madrigal.metadata.MadrigalDB()
1528 madDB = madrigal.metadata.MadrigalDB()
1519 bg_color = madDB.getBackgroundColor()
1529 bg_color = madDB.getBackgroundColor()
1520 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1530 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1521 siteName, otherSiteList = madWebObj.getSiteInfo()
1531 siteName, otherSiteList = madWebObj.getSiteInfo()
1522 madSiteObj = madrigal.metadata.MadrigalSite(madDB)
1532 madSiteObj = madrigal.metadata.MadrigalSite(madDB)
1523 siteList = []
1533 siteList = []
1524 for siteId, siteName in madSiteObj.getSiteList():
1534 for siteId, siteName in madSiteObj.getSiteList():
1525 if madSiteObj.getSiteServer(siteId).find('http') == -1:
1535 if madSiteObj.getSiteServer(siteId).find('http') == -1:
1526 url = 'http://' + os.path.join(madSiteObj.getSiteServer(siteId),
1536 url = 'http://' + os.path.join(madSiteObj.getSiteServer(siteId),
1527 madSiteObj.getSiteDocRoot(siteId))
1537 madSiteObj.getSiteDocRoot(siteId))
1528 else:
1538 else:
1529 url = os.path.join(madSiteObj.getSiteServer(siteId),
1539 url = os.path.join(madSiteObj.getSiteServer(siteId),
1530 madSiteObj.getSiteDocRoot(siteId))
1540 madSiteObj.getSiteDocRoot(siteId))
1531 contact = madSiteObj.getSiteContactName(siteId)
1541 contact = madSiteObj.getSiteContactName(siteId)
1532 contact_email = madSiteObj.getSiteEmail(siteId)
1542 contact_email = madSiteObj.getSiteEmail(siteId)
1533 version = madSiteObj.getSiteVersion(siteId)
1543 version = madSiteObj.getSiteVersion(siteId)
1534 siteList.append((siteId, siteName, url, contact, contact_email, version))
1544 siteList.append((siteId, siteName, url, contact, contact_email, version))
1535
1545
1536 responseDict = {'site_active': 'class="active"', 'siteList': siteList,
1546 responseDict = {'site_active': 'class="active"', 'siteList': siteList,
1537 'site_name': siteName, 'site_list': otherSiteList, 'bg_color': bg_color}
1547 'site_name': siteName, 'site_list': otherSiteList, 'bg_color': bg_color}
1538 return render(request, 'madweb/site_metadata.html', responseDict)
1548 return render(request, 'madweb/site_metadata.html', responseDict)
1539
1549
1540
1550
1541 def parameter_metadata(request):
1551 def parameter_metadata(request):
1542 """parameter_metadata returns the site_metadata page.
1552 """parameter_metadata returns the site_metadata page.
1543
1553
1544 Inputs:
1554 Inputs:
1545 request
1555 request
1546 """
1556 """
1547 madDB = madrigal.metadata.MadrigalDB()
1557 madDB = madrigal.metadata.MadrigalDB()
1548 bg_color = madDB.getBackgroundColor()
1558 bg_color = madDB.getBackgroundColor()
1549 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1559 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1550 siteName, siteList = madWebObj.getSiteInfo()
1560 siteName, siteList = madWebObj.getSiteInfo()
1551 madParmObj = madrigal.data.MadrigalParameters(madDB)
1561 madParmObj = madrigal.data.MadrigalParameters(madDB)
1552 madParmCatObj = madrigal.metadata.MadrigalParmCategory(madDB)
1562 madParmCatObj = madrigal.metadata.MadrigalParmCategory(madDB)
1553 parmDict = {} # key is category string, value is list of category tuples (mnemonic, description, units, code)
1563 parmDict = {} # key is category string, value is list of category tuples (mnemonic, description, units, code)
1554 parmList = [] # list of tuples, each tuple either a single category, or (mnemonic, description, units, code)
1564 parmList = [] # list of tuples, each tuple either a single category, or (mnemonic, description, units, code)
1555 categoryList = []
1565 categoryList = []
1556 categoryUrlList = []
1566 categoryUrlList = []
1557 for mnemonic in madParmObj.getSortedMnemonicList():
1567 for mnemonic in madParmObj.getSortedMnemonicList():
1558 description = madParmObj.getSimpleParmDescription(mnemonic)
1568 description = madParmObj.getSimpleParmDescription(mnemonic)
1559 units = madParmObj.getParmUnits(mnemonic)
1569 units = madParmObj.getParmUnits(mnemonic)
1560 code = madParmObj.getParmCodeFromMnemonic(mnemonic)
1570 code = madParmObj.getParmCodeFromMnemonic(mnemonic)
1561 category = madParmObj.getParmCategory(mnemonic)
1571 category = madParmObj.getParmCategory(mnemonic)
1562 if category is None:
1572 if category is None:
1563 # deprecated prolog parm
1573 # deprecated prolog parm
1564 continue
1574 continue
1565 if category in list(parmDict.keys()):
1575 if category in list(parmDict.keys()):
1566 parmDict[category].append((mnemonic, description, units, code))
1576 parmDict[category].append((mnemonic, description, units, code))
1567 else:
1577 else:
1568 parmDict[category] = [(mnemonic, description, units, code)]
1578 parmDict[category] = [(mnemonic, description, units, code)]
1569
1579
1570 # now loop through all categories
1580 # now loop through all categories
1571 for thisCategory, catId in madParmCatObj.getCategoryList():
1581 for thisCategory, catId in madParmCatObj.getCategoryList():
1572 parmList.append((thisCategory,))
1582 parmList.append((thisCategory,))
1573 categoryList.append(thisCategory)
1583 categoryList.append(thisCategory)
1574 categoryAnchor = thisCategory.replace(' ','_')
1584 categoryAnchor = thisCategory.replace(' ','_')
1575 categoryUrlList.append('<a href="#%s">%s</a>' % (categoryAnchor, thisCategory))
1585 categoryUrlList.append('<a href="#%s">%s</a>' % (categoryAnchor, thisCategory))
1576 for values in parmDict[thisCategory]:
1586 for values in parmDict[thisCategory]:
1577 parmList.append(values)
1587 parmList.append(values)
1578
1588
1579 responseDict = {'parm_active': 'class="active"', 'parmList': parmList,
1589 responseDict = {'parm_active': 'class="active"', 'parmList': parmList,
1580 'categoryUrlList':categoryUrlList,
1590 'categoryUrlList':categoryUrlList,
1581 'site_name': siteName, 'site_list': siteList, 'bg_color': bg_color}
1591 'site_name': siteName, 'site_list': siteList, 'bg_color': bg_color}
1582 return render(request, 'madweb/parameter_metadata.html', responseDict)
1592 return render(request, 'madweb/parameter_metadata.html', responseDict)
1583
1593
1584
1594
1585 def kindat_metadata(request):
1595 def kindat_metadata(request):
1586 """kindat_metadata returns the kindat_metadata page.
1596 """kindat_metadata returns the kindat_metadata page.
1587
1597
1588 Inputs:
1598 Inputs:
1589 request
1599 request
1590 """
1600 """
1591 # create a list of tuples of (kindat, description, kinst, instrument_name)
1601 # create a list of tuples of (kindat, description, kinst, instrument_name)
1592 madDB = madrigal.metadata.MadrigalDB()
1602 madDB = madrigal.metadata.MadrigalDB()
1593 bg_color = madDB.getBackgroundColor()
1603 bg_color = madDB.getBackgroundColor()
1594 madKindatObj = madrigal.metadata.MadrigalKindat(madDB)
1604 madKindatObj = madrigal.metadata.MadrigalKindat(madDB)
1595 madInstObj = madrigal.metadata.MadrigalInstrument(madDB)
1605 madInstObj = madrigal.metadata.MadrigalInstrument(madDB)
1596 madInstKindatObj = madrigal.metadata.MadrigalInstrumentKindats(madDB)
1606 madInstKindatObj = madrigal.metadata.MadrigalInstrumentKindats(madDB)
1597 # create a dict of key = kindat code, value list of associated instruments
1607 # create a dict of key = kindat code, value list of associated instruments
1598 kindatDict = {}
1608 kindatDict = {}
1599 for name, mnem, kinst in madInstObj.getInstrumentList():
1609 for name, mnem, kinst in madInstObj.getInstrumentList():
1600 thisKindatList = madInstKindatObj.getKindatListForInstruments(kinst)
1610 thisKindatList = madInstKindatObj.getKindatListForInstruments(kinst)
1601 for kindat in thisKindatList:
1611 for kindat in thisKindatList:
1602 if kindat not in kindatDict:
1612 if kindat not in kindatDict:
1603 kindatDict[kindat] = [kinst]
1613 kindatDict[kindat] = [kinst]
1604 else:
1614 else:
1605 kindatDict[kindat].append(kinst)
1615 kindatDict[kindat].append(kinst)
1606
1616
1607 kindatList = []
1617 kindatList = []
1608 for description, code_str in madKindatObj.getKindatList():
1618 for description, code_str in madKindatObj.getKindatList():
1609 try:
1619 try:
1610 kinst, kindat = code_str.split('_')
1620 kinst, kindat = code_str.split('_')
1611 instName = madInstObj.getInstrumentName(int(kinst))
1621 instName = madInstObj.getInstrumentName(int(kinst))
1612 except:
1622 except:
1613 kindat = code_str
1623 kindat = code_str
1614 try:
1624 try:
1615 kinst = str(kindatDict[int(kindat)][0])
1625 kinst = str(kindatDict[int(kindat)][0])
1616 instName = madInstObj.getInstrumentName(int(kinst))
1626 instName = madInstObj.getInstrumentName(int(kinst))
1617 except KeyError:
1627 except KeyError:
1618 kinst = '-'
1628 kinst = '-'
1619 instName = 'Unspecified'
1629 instName = 'Unspecified'
1620 kindatList.append((kindat, description, kinst, instName))
1630 kindatList.append((kindat, description, kinst, instName))
1621 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1631 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1622 siteName, siteList = madWebObj.getSiteInfo()
1632 siteName, siteList = madWebObj.getSiteInfo()
1623
1633
1624 responseDict = {'kindat_active': 'class="active"', 'kindatList': kindatList,
1634 responseDict = {'kindat_active': 'class="active"', 'kindatList': kindatList,
1625 'site_name': siteName, 'site_list': siteList, 'bg_color': bg_color}
1635 'site_name': siteName, 'site_list': siteList, 'bg_color': bg_color}
1626 return render(request, 'madweb/kindat_metadata.html', responseDict)
1636 return render(request, 'madweb/kindat_metadata.html', responseDict)
1627
1637
1628
1638
1629 def madrigal_calculator(request):
1639 def madrigal_calculator(request):
1630 """madrigal_calculator returns the Madrigal Calculator page.
1640 """madrigal_calculator returns the Madrigal Calculator page.
1631
1641
1632 Inputs:
1642 Inputs:
1633 request
1643 request
1634 """
1644 """
1635 madDB = madrigal.metadata.MadrigalDB()
1645 madDB = madrigal.metadata.MadrigalDB()
1636 bg_color = madDB.getBackgroundColor()
1646 bg_color = madDB.getBackgroundColor()
1637 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1647 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1638 siteName, siteList = madWebObj.getSiteInfo()
1648 siteName, siteList = madWebObj.getSiteInfo()
1639 # original blank form
1649 # original blank form
1640 madCalculatorForm = madweb.forms.MadCalculatorForm()
1650 madCalculatorForm = madweb.forms.MadCalculatorForm()
1641 parmList = [(parm, madCalculatorForm.parmDescDict[parm]) for parm in list(madCalculatorForm.parmDescDict.keys())]
1651 parmList = [(parm, madCalculatorForm.parmDescDict[parm]) for parm in list(madCalculatorForm.parmDescDict.keys())]
1642 return render(request, 'madweb/madrigal_calculator.html', {'madCalculator_active': 'class="active"',
1652 return render(request, 'madweb/madrigal_calculator.html', {'madCalculator_active': 'class="active"',
1643 'form': madCalculatorForm,
1653 'form': madCalculatorForm,
1644 'parmList': parmList,
1654 'parmList': parmList,
1645 'site_name': siteName, 'site_list': siteList,
1655 'site_name': siteName, 'site_list': siteList,
1646 'bg_color': bg_color, 'datetime': True})
1656 'bg_color': bg_color, 'datetime': True})
1647
1657
1648 def madrigal_calculator_output(request):
1658 def madrigal_calculator_output(request):
1649 """madrigal_calculator returns the output from the Madrigal Calculator page.
1659 """madrigal_calculator returns the output from the Madrigal Calculator page.
1650
1660
1651 Inputs:
1661 Inputs:
1652 request
1662 request
1653 """
1663 """
1654 madDB = madrigal.metadata.MadrigalDB()
1664 madDB = madrigal.metadata.MadrigalDB()
1655 bg_color = madDB.getBackgroundColor()
1665 bg_color = madDB.getBackgroundColor()
1656 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1666 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1657 siteName, siteList = madWebObj.getSiteInfo()
1667 siteName, siteList = madWebObj.getSiteInfo()
1658
1668
1659 madCalculatorForm = madweb.forms.MadCalculatorForm(request.GET)
1669 madCalculatorForm = madweb.forms.MadCalculatorForm(request.GET)
1660
1670
1661 try:
1671 try:
1662 if not madCalculatorForm.is_valid():
1672 if not madCalculatorForm.is_valid():
1663 return(HttpResponse(str(madCalculatorForm.errors)))
1673 return(HttpResponse(str(madCalculatorForm.errors)))
1664 except KeyError:
1674 except KeyError:
1665 return(HttpResponse('<p>Missing arguments in madCalculatorOutput</p>'))
1675 return(HttpResponse('<p>Missing arguments in madCalculatorOutput</p>'))
1666
1676
1667 text = madWebObj.runMadrigalCalculatorFromForm(madCalculatorForm.cleaned_data)
1677 text = madWebObj.runMadrigalCalculatorFromForm(madCalculatorForm.cleaned_data)
1668
1678
1669 return render(request, 'madweb/madrigal_calculator_output.html', {'madCalculator_active': 'class="active"',
1679 return render(request, 'madweb/madrigal_calculator_output.html', {'madCalculator_active': 'class="active"',
1670 'text': text,
1680 'text': text,
1671 'site_name': siteName, 'site_list': siteList,
1681 'site_name': siteName, 'site_list': siteList,
1672 'bg_color': bg_color})
1682 'bg_color': bg_color})
1673
1683
1674
1684
1675 def get_metadata(request):
1685 def get_metadata(request):
1676 """get_metadata allows local metadata files to be downloaded.
1686 """get_metadata allows local metadata files to be downloaded.
1677
1687
1678 Inputs:
1688 Inputs:
1679 request
1689 request
1680 """
1690 """
1681 fileDict = {'0':'expTab.txt',
1691 fileDict = {'0':'expTab.txt',
1682 '1': 'fileTab.txt',
1692 '1': 'fileTab.txt',
1683 '3': 'instTab.txt',
1693 '3': 'instTab.txt',
1684 '4': 'parmCodes.txt',
1694 '4': 'parmCodes.txt',
1685 '5': 'siteTab.txt',
1695 '5': 'siteTab.txt',
1686 '6': 'typeTab.txt',
1696 '6': 'typeTab.txt',
1687 '7': 'instKindatTab.txt',
1697 '7': 'instKindatTab.txt',
1688 '8': 'instParmTab.txt',
1698 '8': 'instParmTab.txt',
1689 '9': 'madCatTab.txt',
1699 '9': 'madCatTab.txt',
1690 '10': 'instType.txt'}
1700 '10': 'instType.txt'}
1691 form = madweb.forms.GetMetadataForm(request.GET)
1701 form = madweb.forms.GetMetadataForm(request.GET)
1692 if form.is_valid():
1702 if form.is_valid():
1693 madDB = madrigal.metadata.MadrigalDB()
1703 madDB = madrigal.metadata.MadrigalDB()
1694 downloadFile = os.path.join(madDB.getMetadataDir(),
1704 downloadFile = os.path.join(madDB.getMetadataDir(),
1695 fileDict[form.cleaned_data['fileType']])
1705 fileDict[form.cleaned_data['fileType']])
1696
1706
1697
1707
1698 f = open(downloadFile, 'rb')
1708 f = open(downloadFile, 'rb')
1699 filename = os.path.basename(downloadFile)
1709 filename = os.path.basename(downloadFile)
1700 chunk_size = 8192
1710 chunk_size = 8192
1701 response = StreamingHttpResponse(FileWrapper(f, chunk_size),
1711 response = StreamingHttpResponse(FileWrapper(f, chunk_size),
1702 content_type=mimetypes.guess_type(downloadFile)[0])
1712 content_type=mimetypes.guess_type(downloadFile)[0])
1703 response['Content-Length'] = os.path.getsize(downloadFile)
1713 response['Content-Length'] = os.path.getsize(downloadFile)
1704 response['Content-Disposition'] = "attachment; filename=%s" % (filename)
1714 response['Content-Disposition'] = "attachment; filename=%s" % (filename)
1705 return(response)
1715 return(response)
1706
1716
1707 else:
1717 else:
1708 madDB = madrigal.metadata.MadrigalDB()
1718 madDB = madrigal.metadata.MadrigalDB()
1709 bg_color = madDB.getBackgroundColor()
1719 bg_color = madDB.getBackgroundColor()
1710 form = madweb.forms.GetMetadataForm()
1720 form = madweb.forms.GetMetadataForm()
1711 return render(request, 'madweb/get_metadata.html', {'form': form, 'bg_color': bg_color})
1721 return render(request, 'madweb/get_metadata.html', {'form': form, 'bg_color': bg_color})
1712
1722
1713
1723
1714 def looker_main(request):
1724 def looker_main(request):
1715 """looker_main loads the main looker selection form.
1725 """looker_main loads the main looker selection form.
1716
1726
1717 Inputs:
1727 Inputs:
1718 request
1728 request
1719 """
1729 """
1720 madDB = madrigal.metadata.MadrigalDB()
1730 madDB = madrigal.metadata.MadrigalDB()
1721 bg_color = madDB.getBackgroundColor()
1731 bg_color = madDB.getBackgroundColor()
1722 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1732 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1723 siteName, siteList = madWebObj.getSiteInfo()
1733 siteName, siteList = madWebObj.getSiteInfo()
1724 lookerSelectForm = madweb.forms.LookerSelectForm()
1734 lookerSelectForm = madweb.forms.LookerSelectForm()
1725 return render(request, 'madweb/looker_main.html', {'looker_active': 'class="active"',
1735 return render(request, 'madweb/looker_main.html', {'looker_active': 'class="active"',
1726 'form': lookerSelectForm,
1736 'form': lookerSelectForm,
1727 'site_name': siteName, 'site_list': siteList,
1737 'site_name': siteName, 'site_list': siteList,
1728 'bg_color': bg_color})
1738 'bg_color': bg_color})
1729
1739
1730
1740
1731 def looker_form(request):
1741 def looker_form(request):
1732 """looker_form loads the appropriate looker form.
1742 """looker_form loads the appropriate looker form.
1733
1743
1734 Inputs:
1744 Inputs:
1735 request
1745 request
1736 """
1746 """
1737 madDB = madrigal.metadata.MadrigalDB()
1747 madDB = madrigal.metadata.MadrigalDB()
1738 bg_color = madDB.getBackgroundColor()
1748 bg_color = madDB.getBackgroundColor()
1739 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1749 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1740 siteName, siteList = madWebObj.getSiteInfo()
1750 siteName, siteList = madWebObj.getSiteInfo()
1741 if not 'looker_options' in request.GET:
1751 if not 'looker_options' in request.GET:
1742 return(HttpResponse('<p>looker form requires looker_options</p>'))
1752 return(HttpResponse('<p>looker form requires looker_options</p>'))
1743 form = madweb.forms.LookerSelectForm(request.GET)
1753 form = madweb.forms.LookerSelectForm(request.GET)
1744 if form.is_valid():
1754 if form.is_valid():
1745 option = form.cleaned_data['looker_options']
1755 option = form.cleaned_data['looker_options']
1746 if option == '1':
1756 if option == '1':
1747 form = madweb.forms.LookerGeodeticRadar()
1757 form = madweb.forms.LookerGeodeticRadar()
1748 return render(request, 'madweb/looker_geodetic_to_radar.html', {'looker_active': 'class="active"',
1758 return render(request, 'madweb/looker_geodetic_to_radar.html', {'looker_active': 'class="active"',
1749 'form': form,
1759 'form': form,
1750 'site_name': siteName, 'site_list': siteList,
1760 'site_name': siteName, 'site_list': siteList,
1751 'bg_color': bg_color})
1761 'bg_color': bg_color})
1752 elif option == '2':
1762 elif option == '2':
1753 form = madweb.forms.LookerGeomagRadar()
1763 form = madweb.forms.LookerGeomagRadar()
1754 return render(request, 'madweb/looker_geomagnetic_to_radar.html', {'looker_active': 'class="active"',
1764 return render(request, 'madweb/looker_geomagnetic_to_radar.html', {'looker_active': 'class="active"',
1755 'form': form,
1765 'form': form,
1756 'site_name': siteName, 'site_list': siteList,
1766 'site_name': siteName, 'site_list': siteList,
1757 'bg_color': bg_color})
1767 'bg_color': bg_color})
1758 elif option == '3':
1768 elif option == '3':
1759 form = madweb.forms.LookerGeomagFromGeodetic()
1769 form = madweb.forms.LookerGeomagFromGeodetic()
1760 return render(request, 'madweb/looker_geomagnetic_from_geodetic.html', {'looker_active': 'class="active"',
1770 return render(request, 'madweb/looker_geomagnetic_from_geodetic.html', {'looker_active': 'class="active"',
1761 'form': form,
1771 'form': form,
1762 'site_name': siteName, 'site_list': siteList,
1772 'site_name': siteName, 'site_list': siteList,
1763 'bg_color': bg_color})
1773 'bg_color': bg_color})
1764 elif option == '4':
1774 elif option == '4':
1765 form = madweb.forms.LookerGeomagFromRadar()
1775 form = madweb.forms.LookerGeomagFromRadar()
1766 return render(request, 'madweb/looker_geomagnetic_from_radar.html', {'looker_active': 'class="active"',
1776 return render(request, 'madweb/looker_geomagnetic_from_radar.html', {'looker_active': 'class="active"',
1767 'form': form,
1777 'form': form,
1768 'site_name': siteName, 'site_list': siteList,
1778 'site_name': siteName, 'site_list': siteList,
1769 'bg_color': bg_color})
1779 'bg_color': bg_color})
1770 elif option == '5':
1780 elif option == '5':
1771 form = madweb.forms.LookerFieldLineFromRadar()
1781 form = madweb.forms.LookerFieldLineFromRadar()
1772 return render(request, 'madweb/looker_field_line_from_radar.html', {'looker_active': 'class="active"',
1782 return render(request, 'madweb/looker_field_line_from_radar.html', {'looker_active': 'class="active"',
1773 'form': form,
1783 'form': form,
1774 'site_name': siteName, 'site_list': siteList,
1784 'site_name': siteName, 'site_list': siteList,
1775 'bg_color': bg_color})
1785 'bg_color': bg_color})
1776 elif option == '6':
1786 elif option == '6':
1777 form = madweb.forms.LookerFieldLineFromGeodetic()
1787 form = madweb.forms.LookerFieldLineFromGeodetic()
1778 return render(request, 'madweb/looker_field_line_from_geodetic.html', {'looker_active': 'class="active"',
1788 return render(request, 'madweb/looker_field_line_from_geodetic.html', {'looker_active': 'class="active"',
1779 'form': form,
1789 'form': form,
1780 'site_name': siteName, 'site_list': siteList,
1790 'site_name': siteName, 'site_list': siteList,
1781 'bg_color': bg_color})
1791 'bg_color': bg_color})
1782 elif option == '7':
1792 elif option == '7':
1783 form = madweb.forms.LookerFieldLineFromApex()
1793 form = madweb.forms.LookerFieldLineFromApex()
1784 return render(request, 'madweb/looker_field_line_from_apex.html', {'looker_active': 'class="active"',
1794 return render(request, 'madweb/looker_field_line_from_apex.html', {'looker_active': 'class="active"',
1785 'form': form,
1795 'form': form,
1786 'site_name': siteName, 'site_list': siteList,
1796 'site_name': siteName, 'site_list': siteList,
1787 'bg_color': bg_color})
1797 'bg_color': bg_color})
1788 elif option == '8':
1798 elif option == '8':
1789 form = madweb.forms.LookerConjugateFromGeodetic()
1799 form = madweb.forms.LookerConjugateFromGeodetic()
1790 return render(request, 'madweb/looker_conjugate_from_geodetic.html', {'looker_active': 'class="active"',
1800 return render(request, 'madweb/looker_conjugate_from_geodetic.html', {'looker_active': 'class="active"',
1791 'form': form,
1801 'form': form,
1792 'site_name': siteName, 'site_list': siteList,
1802 'site_name': siteName, 'site_list': siteList,
1793 'bg_color': bg_color,
1803 'bg_color': bg_color,
1794 'datetime': True})
1804 'datetime': True})
1795 else:
1805 else:
1796 raise ValueError(str(form.errors))
1806 raise ValueError(str(form.errors))
1797
1807
1798
1808
1799 def looker_output(request):
1809 def looker_output(request):
1800 """looker_output loads the appropriate looker output.
1810 """looker_output loads the appropriate looker output.
1801
1811
1802 Inputs:
1812 Inputs:
1803 request
1813 request
1804 """
1814 """
1805 madDB = madrigal.metadata.MadrigalDB()
1815 madDB = madrigal.metadata.MadrigalDB()
1806 bg_color = madDB.getBackgroundColor()
1816 bg_color = madDB.getBackgroundColor()
1807 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1817 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
1808 siteName, siteList = madWebObj.getSiteInfo()
1818 siteName, siteList = madWebObj.getSiteInfo()
1809
1819
1810 if not 'looker_options' in request.GET:
1820 if not 'looker_options' in request.GET:
1811 return(HttpResponse('<p>looker missing arguments</p>'))
1821 return(HttpResponse('<p>looker missing arguments</p>'))
1812
1822
1813 if request.GET['looker_options'] == "1":
1823 if request.GET['looker_options'] == "1":
1814 form = madweb.forms.LookerGeodeticRadar(request.GET)
1824 form = madweb.forms.LookerGeodeticRadar(request.GET)
1815 if form.is_valid():
1825 if form.is_valid():
1816 text = madWebObj.runLookerFromForm(form.cleaned_data)
1826 text = madWebObj.runLookerFromForm(form.cleaned_data)
1817 return render(request, 'madweb/looker_output.html', {'looker_active': 'class="active"',
1827 return render(request, 'madweb/looker_output.html', {'looker_active': 'class="active"',
1818 'type': 'Az, El, Range to Geodetic points',
1828 'type': 'Az, El, Range to Geodetic points',
1819 'text': text,
1829 'text': text,
1820 'site_name': siteName, 'site_list': siteList,
1830 'site_name': siteName, 'site_list': siteList,
1821 'bg_color': bg_color})
1831 'bg_color': bg_color})
1822 else:
1832 else:
1823 raise ValueError(str(form.errors))
1833 raise ValueError(str(form.errors))
1824 elif request.GET['looker_options'] == "2":
1834 elif request.GET['looker_options'] == "2":
1825 form = madweb.forms.LookerGeomagRadar(request.GET)
1835 form = madweb.forms.LookerGeomagRadar(request.GET)
1826 if form.is_valid():
1836 if form.is_valid():
1827 text = madWebObj.runLookerFromForm(form.cleaned_data)
1837 text = madWebObj.runLookerFromForm(form.cleaned_data)
1828 return render(request, 'madweb/looker_output.html', {'looker_active': 'class="active"',
1838 return render(request, 'madweb/looker_output.html', {'looker_active': 'class="active"',
1829 'type': 'Az, El, Range to Geomagnetic (apex) points',
1839 'type': 'Az, El, Range to Geomagnetic (apex) points',
1830 'text': text,
1840 'text': text,
1831 'site_name': siteName, 'site_list': siteList,
1841 'site_name': siteName, 'site_list': siteList,
1832 'bg_color': bg_color})
1842 'bg_color': bg_color})
1833 else:
1843 else:
1834 raise ValueError(str(form.errors))
1844 raise ValueError(str(form.errors))
1835 elif request.GET['looker_options'] == "3":
1845 elif request.GET['looker_options'] == "3":
1836 form = madweb.forms.LookerGeomagFromGeodetic(request.GET)
1846 form = madweb.forms.LookerGeomagFromGeodetic(request.GET)
1837 if form.is_valid():
1847 if form.is_valid():
1838 text = madWebObj.runLookerFromForm(form.cleaned_data)
1848 text = madWebObj.runLookerFromForm(form.cleaned_data)
1839 return render(request, 'madweb/looker_output.html', {'looker_active': 'class="active"',
1849 return render(request, 'madweb/looker_output.html', {'looker_active': 'class="active"',
1840 'type': 'Apex Geomagnetic coordinates from Geodetic grid',
1850 'type': 'Apex Geomagnetic coordinates from Geodetic grid',
1841 'text': text,
1851 'text': text,
1842 'site_name': siteName, 'site_list': siteList,
1852 'site_name': siteName, 'site_list': siteList,
1843 'bg_color': bg_color})
1853 'bg_color': bg_color})
1844 else:
1854 else:
1845 raise ValueError(str(form.errors))
1855 raise ValueError(str(form.errors))
1846 elif request.GET['looker_options'] == "4":
1856 elif request.GET['looker_options'] == "4":
1847 form = madweb.forms.LookerGeomagFromRadar(request.GET)
1857 form = madweb.forms.LookerGeomagFromRadar(request.GET)
1848 if form.is_valid():
1858 if form.is_valid():
1849 text = madWebObj.runLookerFromForm(form.cleaned_data)
1859 text = madWebObj.runLookerFromForm(form.cleaned_data)
1850 return render(request, 'madweb/looker_output.html', {'looker_active': 'class="active"',
1860 return render(request, 'madweb/looker_output.html', {'looker_active': 'class="active"',
1851 'type': 'Apex Geomagnetic and geodetic coordinates and aspect angle from a grid of azimuth, elevation, and range',
1861 'type': 'Apex Geomagnetic and geodetic coordinates and aspect angle from a grid of azimuth, elevation, and range',
1852 'text': text,
1862 'text': text,
1853 'site_name': siteName, 'site_list': siteList,
1863 'site_name': siteName, 'site_list': siteList,
1854 'bg_color': bg_color})
1864 'bg_color': bg_color})
1855 else:
1865 else:
1856 raise ValueError(str(form.errors))
1866 raise ValueError(str(form.errors))
1857 elif request.GET['looker_options'] == "5":
1867 elif request.GET['looker_options'] == "5":
1858 form = madweb.forms.LookerFieldLineFromRadar(request.GET)
1868 form = madweb.forms.LookerFieldLineFromRadar(request.GET)
1859 if form.is_valid():
1869 if form.is_valid():
1860 text = madWebObj.runLookerFromForm(form.cleaned_data)
1870 text = madWebObj.runLookerFromForm(form.cleaned_data)
1861 return render(request, 'madweb/looker_output.html', {'looker_active': 'class="active"',
1871 return render(request, 'madweb/looker_output.html', {'looker_active': 'class="active"',
1862 'type': 'Field line coordinates for a field line set by radar parameters',
1872 'type': 'Field line coordinates for a field line set by radar parameters',
1863 'text': text,
1873 'text': text,
1864 'site_name': siteName, 'site_list': siteList,
1874 'site_name': siteName, 'site_list': siteList,
1865 'bg_color': bg_color})
1875 'bg_color': bg_color})
1866 else:
1876 else:
1867 raise ValueError(str(form.errors))
1877 raise ValueError(str(form.errors))
1868 elif request.GET['looker_options'] == "6":
1878 elif request.GET['looker_options'] == "6":
1869 form = madweb.forms.LookerFieldLineFromGeodetic(request.GET)
1879 form = madweb.forms.LookerFieldLineFromGeodetic(request.GET)
1870 if form.is_valid():
1880 if form.is_valid():
1871 text = madWebObj.runLookerFromForm(form.cleaned_data)
1881 text = madWebObj.runLookerFromForm(form.cleaned_data)
1872 return render(request, 'madweb/looker_output.html', {'looker_active': 'class="active"',
1882 return render(request, 'madweb/looker_output.html', {'looker_active': 'class="active"',
1873 'type': 'Field line coordinates and radar look parameters for given field line',
1883 'type': 'Field line coordinates and radar look parameters for given field line',
1874 'text': text,
1884 'text': text,
1875 'site_name': siteName, 'site_list': siteList,
1885 'site_name': siteName, 'site_list': siteList,
1876 'bg_color': bg_color})
1886 'bg_color': bg_color})
1877 else:
1887 else:
1878 raise ValueError(str(form.errors))
1888 raise ValueError(str(form.errors))
1879 elif request.GET['looker_options'] == "7":
1889 elif request.GET['looker_options'] == "7":
1880 form = madweb.forms.LookerFieldLineFromApex(request.GET)
1890 form = madweb.forms.LookerFieldLineFromApex(request.GET)
1881 if form.is_valid():
1891 if form.is_valid():
1882 text = madWebObj.runLookerFromForm(form.cleaned_data)
1892 text = madWebObj.runLookerFromForm(form.cleaned_data)
1883 return render(request, 'madweb/looker_output.html', {'looker_active': 'class="active"',
1893 return render(request, 'madweb/looker_output.html', {'looker_active': 'class="active"',
1884 'type': 'Field line coordinates and radar look parameters for given field line',
1894 'type': 'Field line coordinates and radar look parameters for given field line',
1885 'text': text,
1895 'text': text,
1886 'site_name': siteName, 'site_list': siteList,
1896 'site_name': siteName, 'site_list': siteList,
1887 'bg_color': bg_color})
1897 'bg_color': bg_color})
1888 else:
1898 else:
1889 raise ValueError(str(form.errors))
1899 raise ValueError(str(form.errors))
1890 elif request.GET['looker_options'] == "8":
1900 elif request.GET['looker_options'] == "8":
1891 form = madweb.forms.LookerConjugateFromGeodetic(request.GET)
1901 form = madweb.forms.LookerConjugateFromGeodetic(request.GET)
1892 if form.is_valid():
1902 if form.is_valid():
1893 text = madWebObj.runLookerFromForm(form.cleaned_data)
1903 text = madWebObj.runLookerFromForm(form.cleaned_data)
1894 return render(request, 'madweb/looker_output.html', {'looker_active': 'class="active"',
1904 return render(request, 'madweb/looker_output.html', {'looker_active': 'class="active"',
1895 'type': 'Point/Magnetic Conjugate Point vs Latitude, Longitude, Altitude',
1905 'type': 'Point/Magnetic Conjugate Point vs Latitude, Longitude, Altitude',
1896 'datetime': form.cleaned_data['datetime'],
1906 'datetime': form.cleaned_data['datetime'],
1897 'text': text,
1907 'text': text,
1898 'site_name': siteName, 'site_list': siteList,
1908 'site_name': siteName, 'site_list': siteList,
1899 'bg_color': bg_color})
1909 'bg_color': bg_color})
1900 else:
1910 else:
1901 raise ValueError(str(form.errors))
1911 raise ValueError(str(form.errors))
1902
1912
1903 else:
1913 else:
1904 raise ValueError('Unknown looker_option <%s>' % (str(request.GET['looker_options'])))
1914 raise ValueError('Unknown looker_option <%s>' % (str(request.GET['looker_options'])))
1905
1915
1906
1916
1907
1917
1908 def get_version_service(request):
1918 def get_version_service(request):
1909 """get_version_service runs the getVersionService.py service.
1919 """get_version_service runs the getVersionService.py service.
1910
1920
1911 Inputs:
1921 Inputs:
1912 request (ignored)
1922 request (ignored)
1913
1923
1914 Returns a single line of text, with the version in the form <major_version_int>.<minor_version_int>[.<sub_version_int>]
1924 Returns a single line of text, with the version in the form <major_version_int>.<minor_version_int>[.<sub_version_int>]
1915 """
1925 """
1916 madDB = madrigal.metadata.MadrigalDB()
1926 madDB = madrigal.metadata.MadrigalDB()
1917 siteID = madDB.getSiteID()
1927 siteID = madDB.getSiteID()
1918 madSiteObj = madrigal.metadata.MadrigalSite(madDB)
1928 madSiteObj = madrigal.metadata.MadrigalSite(madDB)
1919 return(HttpResponse(madSiteObj.getSiteVersion(siteID)))
1929 return(HttpResponse(madSiteObj.getSiteVersion(siteID)))
1920
1930
1921
1931
1922
1932
1923 def get_instruments_service(request):
1933 def get_instruments_service(request):
1924 """get_instruments_service runs the getInstrumentsService.py service.
1934 """get_instruments_service runs the getInstrumentsService.py service.
1925
1935
1926 Inputs:
1936 Inputs:
1927 request (ignored)
1937 request (ignored)
1928
1938
1929 Returns comma-delimited data, one line for each experiment, with the following fields:
1939 Returns comma-delimited data, one line for each experiment, with the following fields:
1930
1940
1931 1. instrument.name Example: 'Millstone Hill Incoherent Scatter Radar'
1941 1. instrument.name Example: 'Millstone Hill Incoherent Scatter Radar'
1932
1942
1933 2. instrument.code Example: 30
1943 2. instrument.code Example: 30
1934
1944
1935 3. instrument.mnemonic (3 char string) Example: 'mlh'
1945 3. instrument.mnemonic (3 char string) Example: 'mlh'
1936
1946
1937 4. instrument.latitude Example: 45.0
1947 4. instrument.latitude Example: 45.0
1938
1948
1939 5. instrument.longitude Example: 110.0
1949 5. instrument.longitude Example: 110.0
1940
1950
1941 6. instrument.altitude Example: 0.015 (km)
1951 6. instrument.altitude Example: 0.015 (km)
1942
1952
1943 7. instrument.category Example: 'Incoherent Scatter Radars'
1953 7. instrument.category Example: 'Incoherent Scatter Radars'
1944
1954
1945 8. contact name
1955 8. contact name
1946
1956
1947 9. contact email
1957 9. contact email
1948 """
1958 """
1949 # create MadrigalDB obj
1959 # create MadrigalDB obj
1950 madDBObj = madrigal.metadata.MadrigalDB()
1960 madDBObj = madrigal.metadata.MadrigalDB()
1951
1961
1952 # create MadrigalInstument object
1962 # create MadrigalInstument object
1953 madInst = madrigal.metadata.MadrigalInstrument(madDBObj)
1963 madInst = madrigal.metadata.MadrigalInstrument(madDBObj)
1954
1964
1955 # get instrument list
1965 # get instrument list
1956 instList = madInst.getInstrumentList()
1966 instList = madInst.getInstrumentList()
1957
1967
1958 # loop through each instrument
1968 # loop through each instrument
1959 instStr = ''
1969 instStr = ''
1960 for inst in instList:
1970 for inst in instList:
1961 name = inst[0]
1971 name = inst[0]
1962 code = inst[2]
1972 code = inst[2]
1963 mnemonic = inst[1]
1973 mnemonic = inst[1]
1964 latitude = madInst.getLatitude(code)
1974 latitude = madInst.getLatitude(code)
1965 if latitude == None:
1975 if latitude == None:
1966 latitude = 0.0
1976 latitude = 0.0
1967 longitude = madInst.getLongitude(code)
1977 longitude = madInst.getLongitude(code)
1968 if longitude == None:
1978 if longitude == None:
1969 longitude = 0.0
1979 longitude = 0.0
1970 altitude = madInst.getAltitude(code)
1980 altitude = madInst.getAltitude(code)
1971 if altitude == None:
1981 if altitude == None:
1972 altitude = 0.0
1982 altitude = 0.0
1973 category = madInst.getCategory(code)
1983 category = madInst.getCategory(code)
1974 if category == None:
1984 if category == None:
1975 category = ''
1985 category = ''
1976 # print data
1986 # print data
1977 contactName = madInst.getContactName(code)
1987 contactName = madInst.getContactName(code)
1978 contactEmail = madInst.getContactEmail(code)
1988 contactEmail = madInst.getContactEmail(code)
1979 instStr += '%s,%i,%s,%f,%f,%f,%s,%s,%s\n' % (name,
1989 instStr += '%s,%i,%s,%f,%f,%f,%s,%s,%s\n' % (name,
1980 code,
1990 code,
1981 mnemonic,
1991 mnemonic,
1982 latitude,
1992 latitude,
1983 longitude,
1993 longitude,
1984 altitude,
1994 altitude,
1985 category,
1995 category,
1986 str(contactName),
1996 str(contactName),
1987 str(contactEmail))
1997 str(contactEmail))
1988
1998
1989 return render(request, 'madweb/service.html', {'text': instStr})
1999 return render(request, 'madweb/service.html', {'text': instStr})
1990
2000
1991
2001
1992 def get_experiments_service(request):
2002 def get_experiments_service(request):
1993 """get_experiments_service runs the getExperimentsService.py service.
2003 """get_experiments_service runs the getExperimentsService.py service.
1994
2004
1995 Inputs:
2005 Inputs:
1996 request/url - contains arguments:
2006 request/url - contains arguments:
1997
2007
1998 code - one or more kindat values
2008 code - one or more kindat values
1999
2009
2000 startyear, startmonth, startday, starthour, startmin, startsec
2010 startyear, startmonth, startday, starthour, startmin, startsec
2001
2011
2002 endyear, endmonth, endday, endhour, endmin, endsec
2012 endyear, endmonth, endday, endhour, endmin, endsec
2003
2013
2004 local (defaults to True)
2014 local (defaults to True)
2005
2015
2006 Returns comma-delimited data, one line for each experiment, with the following fields:
2016 Returns comma-delimited data, one line for each experiment, with the following fields:
2007
2017
2008 1. experiment.id (int) Example: 10000111
2018 1. experiment.id (int) Example: 10000111
2009
2019
2010 2. experiment.url (string) Example: 'http://www.haystack.mit.edu/cgi-bin/madtoc/1997/mlh/03dec97'
2020 2. experiment.url (string) Example: 'http://www.haystack.mit.edu/cgi-bin/madtoc/1997/mlh/03dec97'
2011
2021
2012 3. experiment.name (string) Example: 'Wide Latitude Substorm Study'
2022 3. experiment.name (string) Example: 'Wide Latitude Substorm Study'
2013
2023
2014 4. experiment.siteid (int) Example: 1
2024 4. experiment.siteid (int) Example: 1
2015
2025
2016 5. experiment.sitename (string) Example: 'Millstone Hill Observatory'
2026 5. experiment.sitename (string) Example: 'Millstone Hill Observatory'
2017
2027
2018 6. experiment.instcode (int) Code of instrument. Example: 30
2028 6. experiment.instcode (int) Code of instrument. Example: 30
2019
2029
2020 7. experiment.instname (string) Instrument name. Example: 'Millstone Hill Incoherent Scatter Radar'
2030 7. experiment.instname (string) Instrument name. Example: 'Millstone Hill Incoherent Scatter Radar'
2021
2031
2022 8. experiment.start year (int) year of experiment start
2032 8. experiment.start year (int) year of experiment start
2023
2033
2024 9. experiment.start month (int) month of experiment start
2034 9. experiment.start month (int) month of experiment start
2025
2035
2026 10. experiment.start day (int) day of experiment start
2036 10. experiment.start day (int) day of experiment start
2027
2037
2028 11. experiment.start hour (int) hour of experiment start
2038 11. experiment.start hour (int) hour of experiment start
2029
2039
2030 12. experiment.start minute (int) min of experiment start
2040 12. experiment.start minute (int) min of experiment start
2031
2041
2032 13. experiment.start second (int) sec of experiment start
2042 13. experiment.start second (int) sec of experiment start
2033
2043
2034 14. experiment.end year (int) year of experiment end
2044 14. experiment.end year (int) year of experiment end
2035
2045
2036 15. experiment.end month (int) month of experiment end
2046 15. experiment.end month (int) month of experiment end
2037
2047
2038 16. experiment.end day (int) day of experiment end
2048 16. experiment.end day (int) day of experiment end
2039
2049
2040 17. experiment.end hour (int) hour of experiment end
2050 17. experiment.end hour (int) hour of experiment end
2041
2051
2042 18. experiment.end minute (int) min of experiment end
2052 18. experiment.end minute (int) min of experiment end
2043
2053
2044 19. experiment.end second (int) sec of experiment end
2054 19. experiment.end second (int) sec of experiment end
2045
2055
2046 20. experiment.isLocal (int) 1 if local, 0 if not
2056 20. experiment.isLocal (int) 1 if local, 0 if not
2047
2057
2048 21.experiment.PI (string) Experiment PI name Example: 'Phil Erickson'
2058 21.experiment.PI (string) Experiment PI name Example: 'Phil Erickson'
2049
2059
2050 22. experiment.PIEmail (string) Experiment PI email Example: 'perickson@haystack.mit.edu'
2060 22. experiment.PIEmail (string) Experiment PI email Example: 'perickson@haystack.mit.edu'
2051
2061
2052 23. utc timestamp of last update to experiment
2062 23. utc timestamp of last update to experiment
2053
2063
2054 24. security value
2064 24. security value
2055
2065
2056 """
2066 """
2057 codeList = request.GET.getlist('code')
2067 codeList = request.GET.getlist('code')
2058 codeList = [int(code) for code in codeList]
2068 codeList = [int(code) for code in codeList]
2059 startyear = int(request.GET['startyear'])
2069 startyear = int(request.GET['startyear'])
2060 startmonth = int(request.GET['startmonth'])
2070 startmonth = int(request.GET['startmonth'])
2061 startday = int(request.GET['startday'])
2071 startday = int(request.GET['startday'])
2062 starthour = int(request.GET['starthour'])
2072 starthour = int(request.GET['starthour'])
2063 startmin = int(request.GET['startmin'])
2073 startmin = int(request.GET['startmin'])
2064 startsec = int(request.GET['startsec'])
2074 startsec = int(request.GET['startsec'])
2065 endyear = int(request.GET['endyear'])
2075 endyear = int(request.GET['endyear'])
2066 endmonth = int(request.GET['endmonth'])
2076 endmonth = int(request.GET['endmonth'])
2067 endday = int(request.GET['endday'])
2077 endday = int(request.GET['endday'])
2068 endhour = int(request.GET['endhour'])
2078 endhour = int(request.GET['endhour'])
2069 endmin = int(request.GET['endmin'])
2079 endmin = int(request.GET['endmin'])
2070 endsec = int(request.GET['endsec'])
2080 endsec = int(request.GET['endsec'])
2071 try:
2081 try:
2072 local = int(request.GET['local'])
2082 local = int(request.GET['local'])
2073 except:
2083 except:
2074 local = 1
2084 local = 1
2075
2085
2076
2086
2077 # if startsec or endsec in (60, 61), handle correctly
2087 # if startsec or endsec in (60, 61), handle correctly
2078 if startsec in (60, 61):
2088 if startsec in (60, 61):
2079 tmpTime = datetime.datetime(startyear,
2089 tmpTime = datetime.datetime(startyear,
2080 startmonth,
2090 startmonth,
2081 startday,
2091 startday,
2082 starthour,
2092 starthour,
2083 startmin,
2093 startmin,
2084 59)
2094 59)
2085 tmpTime += datetime.timedelta(0, startsec - 59)
2095 tmpTime += datetime.timedelta(0, startsec - 59)
2086 startyear = tmpTime.year
2096 startyear = tmpTime.year
2087 startmonth = tmpTime.month
2097 startmonth = tmpTime.month
2088 startday = tmpTime.day
2098 startday = tmpTime.day
2089 starthour = tmpTime.hour
2099 starthour = tmpTime.hour
2090 startmin = tmpTime.minute
2100 startmin = tmpTime.minute
2091 startsec = tmpTime.second
2101 startsec = tmpTime.second
2092
2102
2093 if endsec in (60, 61):
2103 if endsec in (60, 61):
2094 tmpTime = datetime.datetime(endyear,
2104 tmpTime = datetime.datetime(endyear,
2095 endmonth,
2105 endmonth,
2096 endday,
2106 endday,
2097 endhour,
2107 endhour,
2098 endmin,
2108 endmin,
2099 59)
2109 59)
2100 tmpTime += datetime.timedelta(0, endsec - 59)
2110 tmpTime += datetime.timedelta(0, endsec - 59)
2101 endyear = tmpTime.year
2111 endyear = tmpTime.year
2102 endmonth = tmpTime.month
2112 endmonth = tmpTime.month
2103 endday = tmpTime.day
2113 endday = tmpTime.day
2104 endhour = tmpTime.hour
2114 endhour = tmpTime.hour
2105 endmin = tmpTime.minute
2115 endmin = tmpTime.minute
2106 endsec = tmpTime.second
2116 endsec = tmpTime.second
2107
2117
2108 # if codeList is empty or contains 0, change it to only contain 0
2118 # if codeList is empty or contains 0, change it to only contain 0
2109 if len(codeList) == 0 or 0 in codeList:
2119 if len(codeList) == 0 or 0 in codeList:
2110 codeList = [0]
2120 codeList = [0]
2111
2121
2112 retStr = ''
2122 retStr = ''
2113
2123
2114 # create MadrigalDB obj
2124 # create MadrigalDB obj
2115 madDBObj = madrigal.metadata.MadrigalDB()
2125 madDBObj = madrigal.metadata.MadrigalDB()
2116
2126
2117 # get the local site id
2127 # get the local site id
2118 localSiteId = madDBObj.getSiteID()
2128 localSiteId = madDBObj.getSiteID()
2119
2129
2120 # create MadrigalInstrument obj to convert kinst to instrument names
2130 # create MadrigalInstrument obj to convert kinst to instrument names
2121 madInstObj = madrigal.metadata.MadrigalInstrument(madDBObj)
2131 madInstObj = madrigal.metadata.MadrigalInstrument(madDBObj)
2122
2132
2123 # create MadrigalSite obj to convert site id to site name
2133 # create MadrigalSite obj to convert site id to site name
2124 madSiteObj = madrigal.metadata.MadrigalSite(madDBObj)
2134 madSiteObj = madrigal.metadata.MadrigalSite(madDBObj)
2125
2135
2126 madWebObj = madrigal.ui.web.MadrigalWeb(madDBObj)
2136 madWebObj = madrigal.ui.web.MadrigalWeb(madDBObj)
2127 trusted = madWebObj.isTrusted()
2137 trusted = madWebObj.isTrusted()
2128
2138
2129 # create starttime for filter, if possible
2139 # create starttime for filter, if possible
2130 if startyear != None:
2140 if startyear != None:
2131 startTimeFilter = datetime.datetime(startyear,
2141 startTimeFilter = datetime.datetime(startyear,
2132 startmonth,
2142 startmonth,
2133 startday,
2143 startday,
2134 starthour,
2144 starthour,
2135 startmin,
2145 startmin,
2136 startsec)
2146 startsec)
2137 else:
2147 else:
2138 startTimeFilter = None
2148 startTimeFilter = None
2139
2149
2140 # create endtime for filter, if possible
2150 # create endtime for filter, if possible
2141 if endyear != None:
2151 if endyear != None:
2142 endTimeFilter = datetime.datetime(endyear,
2152 endTimeFilter = datetime.datetime(endyear,
2143 endmonth,
2153 endmonth,
2144 endday,
2154 endday,
2145 endhour,
2155 endhour,
2146 endmin,
2156 endmin,
2147 endsec)
2157 endsec)
2148 else:
2158 else:
2149 endTimeFilter = None
2159 endTimeFilter = None
2150
2160
2151 # create MadrigalExperiments for local or all files
2161 # create MadrigalExperiments for local or all files
2152 if local == 1:
2162 if local == 1:
2153 madExpObj = madrigal.metadata.MadrigalExperiment(madDBObj)
2163 madExpObj = madrigal.metadata.MadrigalExperiment(madDBObj)
2154 else:
2164 else:
2155 # use file expTabAll.txt to get all experiments
2165 # use file expTabAll.txt to get all experiments
2156 filename = madDBObj.getMadroot()
2166 filename = madDBObj.getMadroot()
2157 if filename[-1] != '/':
2167 if filename[-1] != '/':
2158 filename += '/'
2168 filename += '/'
2159 filename += 'metadata/expTabAll.txt'
2169 filename += 'metadata/expTabAll.txt'
2160 madExpObj = madrigal.metadata.MadrigalExperiment(madDBObj, filename)
2170 madExpObj = madrigal.metadata.MadrigalExperiment(madDBObj, filename)
2161
2171
2162 madExpObj.sortByDateSite()
2172 madExpObj.sortByDateSite()
2163
2173
2164
2174
2165 # loop through the data
2175 # loop through the data
2166 if not startTimeFilter is None:
2176 if not startTimeFilter is None:
2167 position = madExpObj.getStartPosition(startTimeFilter)
2177 position = madExpObj.getStartPosition(startTimeFilter)
2168 else:
2178 else:
2169 position = 0
2179 position = 0
2170 while(True):
2180 while(True):
2171 thisId = madExpObj.getExpIdByPosition(position)
2181 thisId = madExpObj.getExpIdByPosition(position)
2172 # check for end
2182 # check for end
2173 if thisId == None:
2183 if thisId == None:
2174 break
2184 break
2175 thisUrl = madExpObj.getExpUrlByPosition(position)
2185 thisUrl = madExpObj.getExpUrlByPosition(position)
2176 thisName = madExpObj.getExpNameByPosition(position)
2186 thisName = madExpObj.getExpNameByPosition(position)
2177 thisSiteId = madExpObj.getExpSiteIdByPosition(position)
2187 thisSiteId = madExpObj.getExpSiteIdByPosition(position)
2178 thisSiteName = madSiteObj.getSiteName(thisSiteId)
2188 thisSiteName = madSiteObj.getSiteName(thisSiteId)
2179 thisInstCode = madExpObj.getKinstByPosition(position)
2189 thisInstCode = madExpObj.getKinstByPosition(position)
2180 thisInstName =madInstObj.getInstrumentName(thisInstCode)
2190 thisInstName =madInstObj.getInstrumentName(thisInstCode)
2181 thisStart = madExpObj.getExpStartDateTimeByPosition(position)
2191 thisStart = madExpObj.getExpStartDateTimeByPosition(position)
2182 thisEnd = madExpObj.getExpEndDateTimeByPosition(position)
2192 thisEnd = madExpObj.getExpEndDateTimeByPosition(position)
2183 thisSecurity = madExpObj.getSecurityByPosition(position)
2193 thisSecurity = madExpObj.getSecurityByPosition(position)
2184 if thisSiteId == localSiteId:
2194 if thisSiteId == localSiteId:
2185 thisLocal = 1
2195 thisLocal = 1
2186 else:
2196 else:
2187 thisLocal = 0
2197 thisLocal = 0
2188 thisPI = madExpObj.getPIByPosition(position)
2198 thisPI = madExpObj.getPIByPosition(position)
2189 if thisPI in (None, ''):
2199 if thisPI in (None, ''):
2190 thisPI = madInstObj.getContactName(thisInstCode)
2200 thisPI = madInstObj.getContactName(thisInstCode)
2191 thisPIEmail = madExpObj.getPIEmailByPosition(position)
2201 thisPIEmail = madExpObj.getPIEmailByPosition(position)
2192 if thisPIEmail in (None, ''):
2202 if thisPIEmail in (None, ''):
2193 thisPIEmail = madInstObj.getContactEmail(thisInstCode)
2203 thisPIEmail = madInstObj.getContactEmail(thisInstCode)
2194 expDir = madExpObj.getExpDirByPosition(position)
2204 expDir = madExpObj.getExpDirByPosition(position)
2195
2205
2196 position += 1
2206 position += 1
2197
2207
2198 # some experiments set the end of the day to 24:00:00 - not
2208 # some experiments set the end of the day to 24:00:00 - not
2199 # technically correct - reset to 23:59:59
2209 # technically correct - reset to 23:59:59
2200
2210
2201 if (thisStart[3] == 24 and thisStart[4] == 0 and thisStart[5] == 0):
2211 if (thisStart[3] == 24 and thisStart[4] == 0 and thisStart[5] == 0):
2202 thisStart[3] = 23
2212 thisStart[3] = 23
2203 thisStart[4] = 59
2213 thisStart[4] = 59
2204 thisStart[5] = 59
2214 thisStart[5] = 59
2205
2215
2206 if (thisEnd[3] == 24 and thisEnd[4] == 0 and thisEnd[5] == 0):
2216 if (thisEnd[3] == 24 and thisEnd[4] == 0 and thisEnd[5] == 0):
2207 thisEnd[3] = 23
2217 thisEnd[3] = 23
2208 thisEnd[4] = 59
2218 thisEnd[4] = 59
2209 thisEnd[5] = 59
2219 thisEnd[5] = 59
2210
2220
2211 # apply filters
2221 # apply filters
2212
2222
2213 # first apply instrument code filter
2223 # first apply instrument code filter
2214 if codeList[0] != 0:
2224 if codeList[0] != 0:
2215 if thisInstCode not in codeList:
2225 if thisInstCode not in codeList:
2216 continue
2226 continue
2217
2227
2218 # apply starttime and endtime filters
2228 # apply starttime and endtime filters
2219 thisStartTime = datetime.datetime(thisStart[0],
2229 thisStartTime = datetime.datetime(thisStart[0],
2220 thisStart[1],
2230 thisStart[1],
2221 thisStart[2],
2231 thisStart[2],
2222 thisStart[3],
2232 thisStart[3],
2223 thisStart[4],
2233 thisStart[4],
2224 thisStart[5])
2234 thisStart[5])
2225
2235
2226 thisEndTime = datetime.datetime(thisEnd[0],
2236 thisEndTime = datetime.datetime(thisEnd[0],
2227 thisEnd[1],
2237 thisEnd[1],
2228 thisEnd[2],
2238 thisEnd[2],
2229 thisEnd[3],
2239 thisEnd[3],
2230 thisEnd[4],
2240 thisEnd[4],
2231 thisEnd[5])
2241 thisEnd[5])
2232
2242
2233 if startTimeFilter != None:
2243 if startTimeFilter != None:
2234 if thisEndTime < startTimeFilter:
2244 if thisEndTime < startTimeFilter:
2235 continue
2245 continue
2236
2246
2237 if endTimeFilter != None:
2247 if endTimeFilter != None:
2238 if thisStartTime > endTimeFilter:
2248 if thisStartTime > endTimeFilter:
2239 continue
2249 continue
2240
2250
2241 # apply local filer
2251 # apply local filer
2242 if local == 1 and thisLocal == 0:
2252 if local == 1 and thisLocal == 0:
2243 continue
2253 continue
2244
2254
2245 # apply security filter
2255 # apply security filter
2246 if trusted == 0 and thisSecurity not in (0,2):
2256 if trusted == 0 and thisSecurity not in (0,2):
2247 continue
2257 continue
2248
2258
2249 # create exp timestamp
2259 # create exp timestamp
2250 if local == 1:
2260 if local == 1:
2251 thisUTTimestamp = int(os.stat(expDir).st_mtime + time.timezone)
2261 thisUTTimestamp = int(os.stat(expDir).st_mtime + time.timezone)
2252 else:
2262 else:
2253 thisUTTimestamp = 0
2263 thisUTTimestamp = 0
2254
2264
2255 # add this experiment
2265 # add this experiment
2256 retStr += '%i,%s,%s,%i,%s,%i,%s,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%s,%s,%i,%i\n' % \
2266 retStr += '%i,%s,%s,%i,%s,%i,%s,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%s,%s,%i,%i\n' % \
2257 (thisId,
2267 (thisId,
2258 thisUrl,
2268 thisUrl,
2259 thisName,
2269 thisName,
2260 thisSiteId,
2270 thisSiteId,
2261 thisSiteName,
2271 thisSiteName,
2262 thisInstCode,
2272 thisInstCode,
2263 thisInstName,
2273 thisInstName,
2264 thisStart[0],
2274 thisStart[0],
2265 thisStart[1],
2275 thisStart[1],
2266 thisStart[2],
2276 thisStart[2],
2267 thisStart[3],
2277 thisStart[3],
2268 thisStart[4],
2278 thisStart[4],
2269 thisStart[5],
2279 thisStart[5],
2270 thisEnd[0],
2280 thisEnd[0],
2271 thisEnd[1],
2281 thisEnd[1],
2272 thisEnd[2],
2282 thisEnd[2],
2273 thisEnd[3],
2283 thisEnd[3],
2274 thisEnd[4],
2284 thisEnd[4],
2275 thisEnd[5],
2285 thisEnd[5],
2276 thisLocal,
2286 thisLocal,
2277 str(thisPI),
2287 str(thisPI),
2278 str(thisPIEmail),
2288 str(thisPIEmail),
2279 thisUTTimestamp,
2289 thisUTTimestamp,
2280 thisSecurity)
2290 thisSecurity)
2281
2291
2282 return render(request, 'madweb/service.html', {'text': retStr})
2292 return render(request, 'madweb/service.html', {'text': retStr})
2283
2293
2284
2294
2285 def get_experiment_files_service(request):
2295 def get_experiment_files_service(request):
2286 """get_experiment_files_service runs the getExperimentFilesService.py service.
2296 """get_experiment_files_service runs the getExperimentFilesService.py service.
2287
2297
2288 Inputs:
2298 Inputs:
2289 request/url - contains arguments:
2299 request/url - contains arguments:
2290
2300
2291 id - local experiment id
2301 id - local experiment id
2292
2302
2293 Returns comma-delimited data, one line for each experiment file, with the following fields:
2303 Returns comma-delimited data, one line for each experiment file, with the following fields:
2294
2304
2295 1. file.name (string) Example '/opt/mdarigal/blah/mlh980120g.001'
2305 1. file.name (string) Example '/opt/mdarigal/blah/mlh980120g.001'
2296
2306
2297 2. file.kindat (int) Kindat code. Example: 3001
2307 2. file.kindat (int) Kindat code. Example: 3001
2298
2308
2299 3. file.kindat desc (string) Kindat description: Example 'Basic Derived Parameters'
2309 3. file.kindat desc (string) Kindat description: Example 'Basic Derived Parameters'
2300
2310
2301 4. file.category (int) (1=default, 2=variant, 3=history, 4=real-time)
2311 4. file.category (int) (1=default, 2=variant, 3=history, 4=real-time)
2302
2312
2303 5. file.status (string)('preliminary', 'final', or any other description)
2313 5. file.status (string)('preliminary', 'final', or any other description)
2304
2314
2305 6. file.permission (int) 0 for public, 1 for private. For now will not return private files.
2315 6. file.permission (int) 0 for public, 1 for private. For now will not return private files.
2306
2316
2307 7. file DOI (string) - citable url to file
2317 7. file DOI (string) - citable url to file
2308
2318
2309 Returns empty string if experiment id not found. Skips files that are not Hdf5
2319 Returns empty string if experiment id not found. Skips files that are not Hdf5
2310 """
2320 """
2311 id = int(request.GET['id'])
2321 id = int(request.GET['id'])
2312
2322
2313 # create MadrigalDB obj
2323 # create MadrigalDB obj
2314 madDBObj = madrigal.metadata.MadrigalDB()
2324 madDBObj = madrigal.metadata.MadrigalDB()
2315
2325
2316 # create MadrigalExperiments object to get full file name
2326 # create MadrigalExperiments object to get full file name
2317 madExpObj = madrigal.metadata.MadrigalExperiment(madDBObj)
2327 madExpObj = madrigal.metadata.MadrigalExperiment(madDBObj)
2318
2328
2319 # create Madrigal Kindat to get Kindat descriptions
2329 # create Madrigal Kindat to get Kindat descriptions
2320 madKindatObj = madrigal.metadata.MadrigalKindat(madDBObj)
2330 madKindatObj = madrigal.metadata.MadrigalKindat(madDBObj)
2321
2331
2322 madWebObj = madrigal.ui.web.MadrigalWeb(madDBObj)
2332 madWebObj = madrigal.ui.web.MadrigalWeb(madDBObj)
2323 trusted = madWebObj.isTrusted()
2333 trusted = madWebObj.isTrusted()
2324
2334
2325
2335
2326 retStr = ''
2336 retStr = ''
2327 thisUrl = madExpObj.getExpUrlByExpId(id)
2337 thisUrl = madExpObj.getExpUrlByExpId(id)
2328 if thisUrl is None:
2338 if thisUrl is None:
2329 raise IOError('No such id: %i' % (id))
2339 raise IOError('No such id: %i' % (id))
2330 expPath = madExpObj.getExpDirByExpId(id)
2340 expPath = madExpObj.getExpDirByExpId(id)
2331 kinst = madExpObj.getKinstByExpId(id)
2341 kinst = madExpObj.getKinstByExpId(id)
2332 if os.access(os.path.join(expPath, 'fileTab.txt'), os.R_OK):
2342 if os.access(os.path.join(expPath, 'fileTab.txt'), os.R_OK):
2333 madFileObj = madrigal.metadata.MadrigalMetaFile(madDBObj, os.path.join(expPath, 'fileTab.txt'))
2343 madFileObj = madrigal.metadata.MadrigalMetaFile(madDBObj, os.path.join(expPath, 'fileTab.txt'))
2334 for i in range(madFileObj.getFileCount()):
2344 for i in range(madFileObj.getFileCount()):
2335 basename = madFileObj.getFilenameByPosition(i)
2345 basename = madFileObj.getFilenameByPosition(i)
2336 name = os.path.join(expPath, basename)
2346 name = os.path.join(expPath, basename)
2337 base_filename, file_extension = os.path.splitext(name)
2347 base_filename, file_extension = os.path.splitext(name)
2338 if file_extension not in ('.hdf5', '.hdf', '.h5'):
2348 if file_extension not in ('.hdf5', '.hdf', '.h5'):
2339 continue
2349 continue
2340 kindat = madFileObj.getKindatByPosition(i)
2350 kindat = madFileObj.getKindatByPosition(i)
2341 kindatdesc = madKindatObj.getKindatDescription(kindat, kinst)
2351 kindatdesc = madKindatObj.getKindatDescription(kindat, kinst)
2342 category = madFileObj.getCategoryByPosition(i)
2352 category = madFileObj.getCategoryByPosition(i)
2343 status = madFileObj.getStatusByPosition(i)
2353 status = madFileObj.getStatusByPosition(i)
2344 permission = madFileObj.getAccessByPosition(i)
2354 permission = madFileObj.getAccessByPosition(i)
2345 doi = madFileObj.getFileDOIUrlByPosition(i)
2355 doi = madFileObj.getFileDOIUrlByPosition(i)
2346
2356
2347 # skip private files if not trusted
2357 # skip private files if not trusted
2348 if trusted == 0 and int(permission) != 0:
2358 if trusted == 0 and int(permission) != 0:
2349 continue
2359 continue
2350
2360
2351 retStr += '%s,%i,%s,%i,%s,%i,%s\n' % \
2361 retStr += '%s,%i,%s,%i,%s,%i,%s\n' % \
2352 (name,
2362 (name,
2353 kindat,
2363 kindat,
2354 kindatdesc,
2364 kindatdesc,
2355 category,
2365 category,
2356 status,
2366 status,
2357 permission,
2367 permission,
2358 doi)
2368 doi)
2359
2369
2360
2370
2361
2371
2362 return render(request, 'madweb/service.html', {'text': django.utils.safestring.mark_safe(retStr)})
2372 return render(request, 'madweb/service.html', {'text': django.utils.safestring.mark_safe(retStr)})
2363
2373
2364
2374
2365 def get_parameters_service(request):
2375 def get_parameters_service(request):
2366 """get_parameters_service runs the getParametersService.py service.
2376 """get_parameters_service runs the getParametersService.py service.
2367
2377
2368 Inputs:
2378 Inputs:
2369 request/url - contains arguments:
2379 request/url - contains arguments:
2370
2380
2371 filename=<full path to data file>
2381 filename=<full path to data file>
2372
2382
2373 Returns backslash-delimited data, one for each parameter either measured or derivable, with the following fields:
2383 Returns backslash-delimited data, one for each parameter either measured or derivable, with the following fields:
2374
2384
2375 1. parameter.mnemonic (string) Example 'dti'
2385 1. parameter.mnemonic (string) Example 'dti'
2376
2386
2377 2. parameter.description (string) Example:
2387 2. parameter.description (string) Example:
2378 "F10.7 Multiday average observed (Ott)"
2388 "F10.7 Multiday average observed (Ott)"
2379
2389
2380 3. parameter.isError (int) 1 if error parameter, 0 if not
2390 3. parameter.isError (int) 1 if error parameter, 0 if not
2381
2391
2382 4. parameter.units (string) Example "W/m2/Hz"
2392 4. parameter.units (string) Example "W/m2/Hz"
2383
2393
2384 5. parameter.isMeasured (int) 1 if measured, 0 if derivable
2394 5. parameter.isMeasured (int) 1 if measured, 0 if derivable
2385
2395
2386 6. parameter.category (string) Example: "Time Related Parameter"
2396 6. parameter.category (string) Example: "Time Related Parameter"
2387
2397
2388 7. parameter.isSure (int) - 1 if parameter can be found for every record, 0 if can only be found for some.
2398 7. parameter.isSure (int) - 1 if parameter can be found for every record, 0 if can only be found for some.
2389 Not relevant to Madrigal 3, where always 1
2399 Not relevant to Madrigal 3, where always 1
2390
2400
2391 8. parameter.isAddIncrement - 1 if additional increment, 0 if normal (Added in Madrigal 2.5)
2401 8. parameter.isAddIncrement - 1 if additional increment, 0 if normal (Added in Madrigal 2.5)
2392 Not relevant to Madrigal 3, where always -1
2402 Not relevant to Madrigal 3, where always -1
2393 """
2403 """
2394 filename = request.GET['filename']
2404 filename = request.GET['filename']
2395
2405
2396 # create MadrigalDB obj
2406 # create MadrigalDB obj
2397 madDBObj = madrigal.metadata.MadrigalDB()
2407 madDBObj = madrigal.metadata.MadrigalDB()
2398
2408
2399 # create Madrigal File object
2409 # create Madrigal File object
2400 madFileObj = madrigal.data.MadrigalFile(filename, madDBObj)
2410 madFileObj = madrigal.data.MadrigalFile(filename, madDBObj)
2401
2411
2402 # create Madrigal Parameter object
2412 # create Madrigal Parameter object
2403 madParmObj = madrigal.data.MadrigalParameters(madDBObj)
2413 madParmObj = madrigal.data.MadrigalParameters(madDBObj)
2404
2414
2405 # create Madrigal web object
2415 # create Madrigal web object
2406 madWebObj = madrigal.ui.web.MadrigalWebFormat()
2416 madWebObj = madrigal.ui.web.MadrigalWebFormat()
2407
2417
2408
2418
2409 # create lists of parameters
2419 # create lists of parameters
2410 measParmList = []
2420 measParmList = []
2411 derivedParmList = []
2421 derivedParmList = []
2412 allParmList = []
2422 allParmList = []
2413 sureParmList = []
2423 sureParmList = []
2414
2424
2415 # use the comprehensive list of parameters to check if derivable
2425 # use the comprehensive list of parameters to check if derivable
2416 parmList = madWebObj.getFormat('Comprehensive')
2426 parmList = madWebObj.getFormat('Comprehensive')
2417
2427
2418 # populate lists
2428 # populate lists
2419 madFileObj.getMeasDervBothParmLists(parmList,
2429 madFileObj.getMeasDervBothParmLists(parmList,
2420 measParmList,
2430 measParmList,
2421 derivedParmList,
2431 derivedParmList,
2422 allParmList,
2432 allParmList,
2423 sureParmList)
2433 sureParmList)
2424
2434
2425 retStr = ''
2435 retStr = ''
2426
2436
2427 # loop through allParmList and output results
2437 # loop through allParmList and output results
2428 for parm in allParmList:
2438 for parm in allParmList:
2429 description = madParmObj.getSimpleParmDescription(parm)
2439 description = madParmObj.getSimpleParmDescription(parm)
2430 isNorm = madParmObj.getParmType(parm)
2440 isNorm = madParmObj.getParmType(parm)
2431 if isNorm == 1:
2441 if isNorm == 1:
2432 isError = 0
2442 isError = 0
2433 else:
2443 else:
2434 isError = 1
2444 isError = 1
2435 units = madParmObj.getParmUnits(parm)
2445 units = madParmObj.getParmUnits(parm)
2436 if parm in measParmList:
2446 if parm in measParmList:
2437 isMeasured = 1
2447 isMeasured = 1
2438 else:
2448 else:
2439 isMeasured = 0
2449 isMeasured = 0
2440 if parm in sureParmList:
2450 if parm in sureParmList:
2441 isSure = 1
2451 isSure = 1
2442 else:
2452 else:
2443 isSure = 0
2453 isSure = 0
2444 category = madParmObj.getParmCategory(parm)
2454 category = madParmObj.getParmCategory(parm)
2445 try:
2455 try:
2446 if madParmObj.isAddIncrement(parm):
2456 if madParmObj.isAddIncrement(parm):
2447 isAddIncrement = 1
2457 isAddIncrement = 1
2448 else:
2458 else:
2449 isAddIncrement = 0
2459 isAddIncrement = 0
2450 except:
2460 except:
2451 isAddIncrement = -1
2461 isAddIncrement = -1
2452 # print out this parm
2462 # print out this parm
2453 retStr += '%s\\%s\\%i\\%s\\%i\\%s\\%i\\%i\n' % (parm,
2463 retStr += '%s\\%s\\%i\\%s\\%i\\%s\\%i\\%i\n' % (parm,
2454 description,
2464 description,
2455 isError,
2465 isError,
2456 units,
2466 units,
2457 isMeasured,
2467 isMeasured,
2458 category,
2468 category,
2459 isSure,
2469 isSure,
2460 isAddIncrement)
2470 isAddIncrement)
2461
2471
2462 return render(request, 'madweb/service.html', {'text': retStr})
2472 return render(request, 'madweb/service.html', {'text': retStr})
2463
2473
2464
2474
2465
2475
2466 def isprint_service(request):
2476 def isprint_service(request):
2467 """isprint_service runs the isprintService.py service.
2477 """isprint_service runs the isprintService.py service.
2468
2478
2469 Inputs:
2479 Inputs:
2470 request/url - contains arguments:
2480 request/url - contains arguments:
2471
2481
2472 'file': The full path to the file to be analyzed by isprint. If over 50 MB, returns error message.
2482 'file': The full path to the file to be analyzed by isprint. If over 50 MB, returns error message.
2473
2483
2474 'parms': Multiple requested parameters, space (+) separated.
2484 'parms': Multiple requested parameters, space (+) separated.
2475
2485
2476 'filters': Multiple of filters desired, as in isprint command
2486 'filters': Multiple of filters desired, as in isprint command
2477
2487
2478 'user_fullname' user name
2488 'user_fullname' user name
2479
2489
2480 'user_email' user email
2490 'user_email' user email
2481
2491
2482 'user_affiliation' user affiliation
2492 'user_affiliation' user affiliation
2483
2493
2484 'output' - option argument specifying output file basename. Will be Hdf5 format if extension in
2494 'output' - option argument specifying output file basename. Will be Hdf5 format if extension in
2485 ('hdf5', 'h5', 'hdf'). Will be netCDF4 is extension is '.nc'. Otherwise ascii. If not
2495 ('hdf5', 'h5', 'hdf'). Will be netCDF4 is extension is '.nc'. Otherwise ascii. If not
2486 given, output is ascii.
2496 given, output is ascii.
2487
2497
2488 'header': t for headers, f for no header. Defaults to no header. Ignored if not ascii output
2498 'header': t for headers, f for no header. Defaults to no header. Ignored if not ascii output
2489
2499
2490 Returns data as either column delimited ascii, Hdf5, or netCDF4.
2500 Returns data as either column delimited ascii, Hdf5, or netCDF4.
2491 """
2501 """
2492 madDB = madrigal.metadata.MadrigalDB()
2502 madDB = madrigal.metadata.MadrigalDB()
2493 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
2503 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
2494
2504
2495 # get required arguments
2505 # get required arguments
2496 thisFile = request.GET['file']
2506 thisFile = request.GET['file']
2497 parms = request.GET.getlist('parms')
2507 parms = request.GET.getlist('parms')
2498 filters = request.GET.getlist('filters')
2508 filters = request.GET.getlist('filters')
2499 user_fullname = request.GET['user_fullname']
2509 user_fullname = request.GET['user_fullname']
2500 user_email = request.GET['user_email']
2510 user_email = request.GET['user_email']
2501 user_affiliation = request.GET['user_affiliation']
2511 user_affiliation = request.GET['user_affiliation']
2502
2512
2503 # get optional arguments
2513 # get optional arguments
2504 try:
2514 try:
2505 output = os.path.basename(request.GET['output'])
2515 output = os.path.basename(request.GET['output'])
2506 filename, file_extension = os.path.splitext(output)
2516 filename, file_extension = os.path.splitext(output)
2507 if file_extension in ('.hdf5', '.h5', '.hdf'):
2517 if file_extension in ('.hdf5', '.h5', '.hdf'):
2508 format = 'Hdf5'
2518 format = 'Hdf5'
2509 elif file_extension in ('.nc',):
2519 elif file_extension in ('.nc',):
2510 format = 'netCDF4'
2520 format = 'netCDF4'
2511 else:
2521 else:
2512 format = 'ascii'
2522 format = 'ascii'
2513 except:
2523 except:
2514 format = 'ascii'
2524 format = 'ascii'
2515 output = None
2525 output = None
2516
2526
2517 # verify thisFile exists, not too big
2527 # verify thisFile exists, not too big
2518 errorMessage = None
2528 errorMessage = None
2519 if not os.access(thisFile, os.R_OK):
2529 if not os.access(thisFile, os.R_OK):
2520 errorMessage = 'File %s not found' % (thisFile)
2530 errorMessage = 'File %s not found' % (thisFile)
2521 elif os.path.getsize(thisFile) > 200.0E6:
2531 elif os.path.getsize(thisFile) > 200.0E6:
2522 errorMessage = 'File %s greater than 200 MB in size - running dynamic file creation not possible. Please use -- download as is -- instead.' % (thisFile)
2532 errorMessage = 'File %s greater than 200 MB in size - running dynamic file creation not possible. Please use -- download as is -- instead.' % (thisFile)
2523 if not errorMessage is None:
2533 if not errorMessage is None:
2524 return render(request, 'madweb/service.html', {'text': errorMessage})
2534 return render(request, 'madweb/service.html', {'text': errorMessage})
2525
2535
2526 if not output is None:
2536 if not output is None:
2527 # we need to write to a download file
2537 # we need to write to a download file
2528 downloadFile = os.path.join(tempfile.gettempdir(), output)
2538 downloadFile = os.path.join(tempfile.gettempdir(), output)
2529 if os.access(downloadFile, os.R_OK):
2539 if os.access(downloadFile, os.R_OK):
2530 try:
2540 try:
2531 os.remove(downloadFile)
2541 os.remove(downloadFile)
2532 except:
2542 except:
2533 pass
2543 pass
2534 try:
2544 try:
2535 header = request.GET['header']
2545 header = request.GET['header']
2536 if header not in ('t', 'f'):
2546 if header not in ('t', 'f'):
2537 raise ValueError('Unknown header value <%s>' % (header))
2547 raise ValueError('Unknown header value <%s>' % (header))
2538 except:
2548 except:
2539 header = 'f'
2549 header = 'f'
2540
2550
2541 # log data access
2551 # log data access
2542 madWebObj.logDataAccess(thisFile, user_fullname, user_email, user_affiliation)
2552 madWebObj.logDataAccess(thisFile, user_fullname, user_email, user_affiliation)
2543
2553
2544 # run isprint command
2554 # run isprint command
2545 cmd = '%s/bin/isprint file=%s ' % (madDB.getMadroot(), thisFile)
2555 cmd = '%s/bin/isprint file=%s ' % (madDB.getMadroot(), thisFile)
2546 if not output is None:
2556 if not output is None:
2547 cmd += 'output=%s ' % (downloadFile)
2557 cmd += 'output=%s ' % (downloadFile)
2548 delimiter = ' '
2558 delimiter = ' '
2549 cmd += delimiter.join(parms) + ' '
2559 cmd += delimiter.join(parms) + ' '
2550 filterStr = delimiter.join(filters)
2560 filterStr = delimiter.join(filters)
2551 cmd += filterStr + ' '
2561 cmd += filterStr + ' '
2552 if format == 'ascii':
2562 if format == 'ascii':
2553 cmd += 'summary=f '
2563 cmd += 'summary=f '
2554 cmd += 'header=%s ' % (header)
2564 cmd += 'header=%s ' % (header)
2555
2565
2556 if output is None:
2566 if output is None:
2557 # text response
2567 # text response
2558 #result = subprocess.check_output(cmd.split())
2568 #result = subprocess.check_output(cmd.split())
2559 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
2569 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
2560 result,errtext = p.communicate()
2570 result,errtext = p.communicate()
2561 if p.returncode != 0:
2571 if p.returncode != 0:
2562 result = errtext
2572 result = errtext
2563 if type(result) in (bytes, numpy.bytes_):
2573 if type(result) in (bytes, numpy.bytes_):
2564 result = result.decode('utf-8')
2574 result = result.decode('utf-8')
2565 if header == 'f':
2575 if header == 'f':
2566 index = result.find('\n')
2576 index = result.find('\n')
2567 result = result[index+1:]
2577 result = result[index+1:]
2568 return render(request, 'madweb/service.html', {'text': result})
2578 return render(request, 'madweb/service.html', {'text': result})
2569 else:
2579 else:
2570 # file download response
2580 # file download response
2571 #subprocess.check_call(cmd.split())
2581 #subprocess.check_call(cmd.split())
2572 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
2582 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
2573 result,errtext = p.communicate()
2583 result,errtext = p.communicate()
2574 if p.returncode != 0:
2584 if p.returncode != 0:
2575 # write the error to result file
2585 # write the error to result file
2576 f = open(downloadFile, 'w')
2586 f = open(downloadFile, 'w')
2577 if type(errtext) in (bytes, numpy.bytes_):
2587 if type(errtext) in (bytes, numpy.bytes_):
2578 errtext = errtext.decode('utf-8')
2588 errtext = errtext.decode('utf-8')
2579 f.write(errtext)
2589 f.write(errtext)
2580 f.close()
2590 f.close()
2581
2591
2582 f = open(downloadFile, 'rb')
2592 f = open(downloadFile, 'rb')
2583 filename = os.path.basename(downloadFile)
2593 filename = os.path.basename(downloadFile)
2584 chunk_size = 8192
2594 chunk_size = 8192
2585 file_type = mimetypes.guess_type(downloadFile)[0]
2595 file_type = mimetypes.guess_type(downloadFile)[0]
2586 if file_type is None:
2596 if file_type is None:
2587 file_type = 'application/octet-stream'
2597 file_type = 'application/octet-stream'
2588 response = StreamingHttpResponse(FileWrapper(f, chunk_size),
2598 response = StreamingHttpResponse(FileWrapper(f, chunk_size),
2589 content_type=file_type)
2599 content_type=file_type)
2590 response['Content-Length'] = os.path.getsize(downloadFile)
2600 response['Content-Length'] = os.path.getsize(downloadFile)
2591 response['Content-Disposition'] = "attachment; filename=%s" % (filename)
2601 response['Content-Disposition'] = "attachment; filename=%s" % (filename)
2592 os.remove(downloadFile)
2602 os.remove(downloadFile)
2593 return(response)
2603 return(response)
2594
2604
2595
2605
2596 def get_madfile_service(request):
2606 def get_madfile_service(request):
2597 """get_madfile_service runs the getMadfile.cgi service.
2607 """get_madfile_service runs the getMadfile.cgi service.
2598
2608
2599 Inputs:
2609 Inputs:
2600 request/url - contains arguments:
2610 request/url - contains arguments:
2601
2611
2602 'fileName': The full path to the file to be downloaded as.
2612 'fileName': The full path to the file to be downloaded as.
2603
2613
2604 'fileType': -1 for ascii, -2 for Hdf5, -3 for netCDF4. No other values supported
2614 'fileType': -1 for ascii, -2 for Hdf5, -3 for netCDF4. No other values supported
2605
2615
2606 'user_fullname' user name
2616 'user_fullname' user name
2607
2617
2608 'user_email' user email
2618 'user_email' user email
2609
2619
2610 'user_affiliation' user affiliation
2620 'user_affiliation' user affiliation
2611
2621
2612 Returns file as either column delimited ascii, Hdf5, or netCDF4.
2622 Returns file as either column delimited ascii, Hdf5, or netCDF4.
2613 """
2623 """
2614 madDB = madrigal.metadata.MadrigalDB()
2624 madDB = madrigal.metadata.MadrigalDB()
2615 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
2625 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
2616
2626
2617 # get required arguments
2627 # get required arguments
2618 fileName = request.GET['fileName']
2628 fileName = request.GET['fileName']
2619 fileType = int(request.GET['fileType'])
2629 fileType = int(request.GET['fileType'])
2620 user_fullname = request.GET['user_fullname']
2630 user_fullname = request.GET['user_fullname']
2621 user_email = request.GET['user_email']
2631 user_email = request.GET['user_email']
2622 user_affiliation = request.GET['user_affiliation']
2632 user_affiliation = request.GET['user_affiliation']
2623
2633
2624 if fileType not in (-1, -2, -3):
2634 if fileType not in (-1, -2, -3):
2625 return(HttpResponse('<p>fileType %i not allowed: -1 for ascii, -2 for Hdf5, -3 for netCDF4</p>' % (fileType)))
2635 return(HttpResponse('<p>fileType %i not allowed: -1 for ascii, -2 for Hdf5, -3 for netCDF4</p>' % (fileType)))
2626
2636
2627 # log data access
2637 # log data access
2628 madWebObj.logDataAccess(fileName, user_fullname, user_email, user_affiliation)
2638 madWebObj.logDataAccess(fileName, user_fullname, user_email, user_affiliation)
2629
2639
2630 if fileType in (-1, -3):
2640 if fileType in (-1, -3):
2631 # may need to create temp file
2641 # may need to create temp file
2632 filepath, file_extension = os.path.splitext(fileName)
2642 filepath, file_extension = os.path.splitext(fileName)
2633 basename = os.path.basename(filepath)
2643 basename = os.path.basename(filepath)
2634 dirname = os.path.dirname(fileName)
2644 dirname = os.path.dirname(fileName)
2635 if fileType == -1:
2645 if fileType == -1:
2636 cachedTxtFile = os.path.join(dirname, 'overview', os.path.basename(fileName) + '.txt.gz')
2646 cachedTxtFile = os.path.join(dirname, 'overview', os.path.basename(fileName) + '.txt.gz')
2637 tmpFile = os.path.join(tempfile.gettempdir(), basename + '.txt.gz')
2647 tmpFile = os.path.join(tempfile.gettempdir(), basename + '.txt.gz')
2638 if os.access(cachedTxtFile, os.R_OK):
2648 if os.access(cachedTxtFile, os.R_OK):
2639 shutil.copy(cachedTxtFile, tmpFile)
2649 shutil.copy(cachedTxtFile, tmpFile)
2640 else:
2650 else:
2641 tmpFile = os.path.join(tempfile.gettempdir(), basename + '.txt')
2651 tmpFile = os.path.join(tempfile.gettempdir(), basename + '.txt')
2642 madrigal.cedar.convertToText(fileName, tmpFile)
2652 madrigal.cedar.convertToText(fileName, tmpFile)
2643 else:
2653 else:
2644 cachedNCFile = os.path.join(dirname, 'overview', os.path.basename(fileName) + '.nc')
2654 cachedNCFile = os.path.join(dirname, 'overview', os.path.basename(fileName) + '.nc')
2645 tmpFile = os.path.join(tempfile.gettempdir(), basename + '.nc')
2655 tmpFile = os.path.join(tempfile.gettempdir(), basename + '.nc')
2646 if os.access(cachedNCFile, os.R_OK):
2656 if os.access(cachedNCFile, os.R_OK):
2647 shutil.copy(cachedNCFile, tmpFile)
2657 shutil.copy(cachedNCFile, tmpFile)
2648 else:
2658 else:
2649 try:
2659 try:
2650 madrigal.cedar.convertToNetCDF4(fileName, tmpFile)
2660 madrigal.cedar.convertToNetCDF4(fileName, tmpFile)
2651 except IOError:
2661 except IOError:
2652 cedarObj = madrigal.cedar.MadrigalCedarFile(fileName)
2662 cedarObj = madrigal.cedar.MadrigalCedarFile(fileName)
2653 cedarObj.write('netCDF4', tmpFile)
2663 cedarObj.write('netCDF4', tmpFile)
2654
2664
2655 else:
2665 else:
2656 tmpFile = fileName
2666 tmpFile = fileName
2657
2667
2658 f = open(tmpFile, 'rb')
2668 f = open(tmpFile, 'rb')
2659 filename = os.path.basename(tmpFile)
2669 filename = os.path.basename(tmpFile)
2660 chunk_size = 8192
2670 chunk_size = 8192
2661 file_type = mimetypes.guess_type(tmpFile)[0]
2671 file_type = mimetypes.guess_type(tmpFile)[0]
2662 if file_type is None:
2672 if file_type is None:
2663 file_type = 'application/octet-stream'
2673 file_type = 'application/octet-stream'
2664 response = StreamingHttpResponse(FileWrapper(f, chunk_size),
2674 response = StreamingHttpResponse(FileWrapper(f, chunk_size),
2665 content_type=file_type)
2675 content_type=file_type)
2666 response['Content-Length'] = os.path.getsize(tmpFile)
2676 response['Content-Length'] = os.path.getsize(tmpFile)
2667 response['Content-Disposition'] = "attachment; filename=%s" % (filename)
2677 response['Content-Disposition'] = "attachment; filename=%s" % (filename)
2668 if fileType in (-1, -3):
2678 if fileType in (-1, -3):
2669 os.remove(tmpFile)
2679 os.remove(tmpFile)
2670 return(response)
2680 return(response)
2671
2681
2672
2682
2673 def mad_calculator_service(request):
2683 def mad_calculator_service(request):
2674 """mad_calculator_service runs the madCalculator service.
2684 """mad_calculator_service runs the madCalculator service.
2675
2685
2676 Inputs:
2686 Inputs:
2677 request/url - contains arguments:
2687 request/url - contains arguments:
2678
2688
2679 year, month, day, hour, min, sec
2689 year, month, day, hour, min, sec
2680
2690
2681 startLat - Starting geodetic latitude, -90 to 90 (float)
2691 startLat - Starting geodetic latitude, -90 to 90 (float)
2682
2692
2683 endLat - Ending geodetic latitude, -90 to 90 (float)
2693 endLat - Ending geodetic latitude, -90 to 90 (float)
2684
2694
2685 stepLat - Latitude step (0.1 to 90) (float)
2695 stepLat - Latitude step (0.1 to 90) (float)
2686
2696
2687 startLong - Starting geodetic longitude, -180 to 180 (float)
2697 startLong - Starting geodetic longitude, -180 to 180 (float)
2688
2698
2689 endLong - Ending geodetic longitude, -180 to 180 (float)
2699 endLong - Ending geodetic longitude, -180 to 180 (float)
2690
2700
2691 stepLong - Longitude step (0.1 to 180) (float)
2701 stepLong - Longitude step (0.1 to 180) (float)
2692
2702
2693 startAlt - Starting geodetic altitude, >= 0 (float)
2703 startAlt - Starting geodetic altitude, >= 0 (float)
2694
2704
2695 endAlt - Ending geodetic altitude, > 0 (float)
2705 endAlt - Ending geodetic altitude, > 0 (float)
2696
2706
2697 stepAlt - Altitude step (>= 0.1) (float)
2707 stepAlt - Altitude step (>= 0.1) (float)
2698
2708
2699 parms - comma delimited string of Madrigal parameters desired
2709 parms - comma delimited string of Madrigal parameters desired
2700
2710
2701 oneD - zero or more mnemonics,float values to set input 1D values
2711 oneD - zero or more mnemonics,float values to set input 1D values
2702
2712
2703 Returns comma-delimited data, one line for each combination of lat, long, and alt,
2713 Returns comma-delimited data, one line for each combination of lat, long, and alt,
2704 with the following fields:
2714 with the following fields:
2705
2715
2706 1. latitude
2716 1. latitude
2707
2717
2708 2. longitude
2718 2. longitude
2709
2719
2710 3. altitude
2720 3. altitude
2711
2721
2712 4. Values for each Madrigal parameter listed in argument parms, separated by whitespace
2722 4. Values for each Madrigal parameter listed in argument parms, separated by whitespace
2713 """
2723 """
2714 year = int(request.GET['year'])
2724 year = int(request.GET['year'])
2715 month = int(request.GET['month'])
2725 month = int(request.GET['month'])
2716 day = int(request.GET['day'])
2726 day = int(request.GET['day'])
2717 hour = int(request.GET['hour'])
2727 hour = int(request.GET['hour'])
2718 minute = int(request.GET['min'])
2728 minute = int(request.GET['min'])
2719 second = int(request.GET['sec'])
2729 second = int(request.GET['sec'])
2720 try:
2730 try:
2721 dt = datetime.datetime(year, month, day, hour, minute, second)
2731 dt = datetime.datetime(year, month, day, hour, minute, second)
2722 except:
2732 except:
2723 return(HttpResponse('Illegal time: year %i, month %i, day %i, hour %i, minute %i, second %i' % (year, month, day, hour, minute, second)))
2733 return(HttpResponse('Illegal time: year %i, month %i, day %i, hour %i, minute %i, second %i' % (year, month, day, hour, minute, second)))
2724
2734
2725 startLat = float(request.GET['startLat'])
2735 startLat = float(request.GET['startLat'])
2726 endLat = float(request.GET['endLat'])
2736 endLat = float(request.GET['endLat'])
2727 if startLat == endLat:
2737 if startLat == endLat:
2728 endLat += 0.001
2738 endLat += 0.001
2729 elif startLat > endLat:
2739 elif startLat > endLat:
2730 return(HttpResponse('startLat %s cannot be greater than endLat %s' % (str(startLat), str(endLat))))
2740 return(HttpResponse('startLat %s cannot be greater than endLat %s' % (str(startLat), str(endLat))))
2731 stepLat = float(request.GET['stepLat'])
2741 stepLat = float(request.GET['stepLat'])
2732 if stepLat < 0.0:
2742 if stepLat < 0.0:
2733 return(HttpResponse('stepLat %s cannot be less than zero' % (str(stepLat))))
2743 return(HttpResponse('stepLat %s cannot be less than zero' % (str(stepLat))))
2734 elif stepLat == 0.0:
2744 elif stepLat == 0.0:
2735 stepLat = 0.001
2745 stepLat = 0.001
2736 latList = list(numpy.arange(startLat, endLat, stepLat))
2746 latList = list(numpy.arange(startLat, endLat, stepLat))
2737
2747
2738 startLong = float(request.GET['startLong'])
2748 startLong = float(request.GET['startLong'])
2739 endLong = float(request.GET['endLong'])
2749 endLong = float(request.GET['endLong'])
2740 if startLong == endLong:
2750 if startLong == endLong:
2741 endLong += 0.001
2751 endLong += 0.001
2742 elif startLong > endLong:
2752 elif startLong > endLong:
2743 return(HttpResponse('startLong %s cannot be greater than endLong %s' % (str(startLong), str(endLong))))
2753 return(HttpResponse('startLong %s cannot be greater than endLong %s' % (str(startLong), str(endLong))))
2744 stepLong = float(request.GET['stepLong'])
2754 stepLong = float(request.GET['stepLong'])
2745 if stepLong < 0.0:
2755 if stepLong < 0.0:
2746 return(HttpResponse('stepLong %s cannot be less than zero' % (str(stepLong))))
2756 return(HttpResponse('stepLong %s cannot be less than zero' % (str(stepLong))))
2747 elif stepLong == 0.0:
2757 elif stepLong == 0.0:
2748 stepLong = 0.001
2758 stepLong = 0.001
2749 lonList = list(numpy.arange(startLong, endLong, stepLong))
2759 lonList = list(numpy.arange(startLong, endLong, stepLong))
2750
2760
2751 startAlt = float(request.GET['startAlt'])
2761 startAlt = float(request.GET['startAlt'])
2752 endAlt = float(request.GET['endAlt'])
2762 endAlt = float(request.GET['endAlt'])
2753 if startAlt == endAlt:
2763 if startAlt == endAlt:
2754 endAlt += 0.001
2764 endAlt += 0.001
2755 elif startAlt > endAlt:
2765 elif startAlt > endAlt:
2756 return(HttpResponse('startAlt %s cannot be greater than endAlt %s' % (str(startAlt), str(endAlt))))
2766 return(HttpResponse('startAlt %s cannot be greater than endAlt %s' % (str(startAlt), str(endAlt))))
2757 stepAlt = float(request.GET['stepAlt'])
2767 stepAlt = float(request.GET['stepAlt'])
2758 if stepAlt < 0.0:
2768 if stepAlt < 0.0:
2759 return(HttpResponse('stepAlt %s cannot be less than zero' % (str(stepAlt))))
2769 return(HttpResponse('stepAlt %s cannot be less than zero' % (str(stepAlt))))
2760 elif stepAlt == 0.0:
2770 elif stepAlt == 0.0:
2761 stepAlt = 0.01
2771 stepAlt = 0.01
2762 altList = list(numpy.arange(startAlt, endAlt, stepAlt))
2772 altList = list(numpy.arange(startAlt, endAlt, stepAlt))
2763
2773
2764 # limit total calculations to 1E5
2774 # limit total calculations to 1E5
2765 total = len(latList) * len(lonList) * len(altList)
2775 total = len(latList) * len(lonList) * len(altList)
2766 if total > 1.0E5:
2776 if total > 1.0E5:
2767 return(HttpResponse('Too many points for madCalculatorService: %i' % (total)))
2777 return(HttpResponse('Too many points for madCalculatorService: %i' % (total)))
2768
2778
2769 parms = request.GET['parms']
2779 parms = request.GET['parms']
2770 desiredParmList = [item.strip() for item in ['gdlat','glon','gdalt'] + parms.split(',')]
2780 desiredParmList = [item.strip() for item in ['gdlat','glon','gdalt'] + parms.split(',')]
2771
2781
2772 oneDList = request.GET.getlist('oneD')
2782 oneDList = request.GET.getlist('oneD')
2773 oneDParmDict = {}
2783 oneDParmDict = {}
2774 for oneDStr in oneDList:
2784 for oneDStr in oneDList:
2775 mnem, strValue = oneDStr.split(',')
2785 mnem, strValue = oneDStr.split(',')
2776 oneDParmDict[mnem] = [float(strValue)]
2786 oneDParmDict[mnem] = [float(strValue)]
2777
2787
2778 # capture stdout
2788 # capture stdout
2779 old_stdout = sys.stdout
2789 old_stdout = sys.stdout
2780 sys.stdout = mystdout = io.StringIO()
2790 sys.stdout = mystdout = io.StringIO()
2781 madrigal.isprint.MadCalculatorGrid(None, desiredParmList, [dt], latList, lonList, altList,
2791 madrigal.isprint.MadCalculatorGrid(None, desiredParmList, [dt], latList, lonList, altList,
2782 oneDParmDict, summary=None)
2792 oneDParmDict, summary=None)
2783 text = mystdout.getvalue()
2793 text = mystdout.getvalue()
2784 sys.stdout = old_stdout
2794 sys.stdout = old_stdout
2785
2795
2786 return render(request, 'madweb/service.html', {'text': text})
2796 return render(request, 'madweb/service.html', {'text': text})
2787
2797
2788
2798
2789 def mad_time_calculator_service(request):
2799 def mad_time_calculator_service(request):
2790 """mad_time_calculator_service runs the madTimeCalculator service. Input parameters must not be location dependent
2800 """mad_time_calculator_service runs the madTimeCalculator service. Input parameters must not be location dependent
2791
2801
2792 Inputs:
2802 Inputs:
2793 request/url - contains arguments:
2803 request/url - contains arguments:
2794
2804
2795 1. startyear - int
2805 1. startyear - int
2796
2806
2797 2. startmonth - int
2807 2. startmonth - int
2798
2808
2799 3. startday - int
2809 3. startday - int
2800
2810
2801 4. starthour - int
2811 4. starthour - int
2802
2812
2803 5. startmin - int
2813 5. startmin - int
2804
2814
2805 6. startsec - int
2815 6. startsec - int
2806
2816
2807 7. endyear - int
2817 7. endyear - int
2808
2818
2809 8. endmonth - int
2819 8. endmonth - int
2810
2820
2811 9. endday - int
2821 9. endday - int
2812
2822
2813 10. endhour - int
2823 10. endhour - int
2814
2824
2815 11. endmin - int
2825 11. endmin - int
2816
2826
2817 12. endsec - int
2827 12. endsec - int
2818
2828
2819 13. stephours - float - number of hours per time step
2829 13. stephours - float - number of hours per time step
2820
2830
2821 14. parms - comma delimited string of Madrigal parameters desired (must not depend on location)
2831 14. parms - comma delimited string of Madrigal parameters desired (must not depend on location)
2822
2832
2823 Returns comma-delimited data, one line for each year, month, day, hour, minute, and second,
2833 Returns comma-delimited data, one line for each year, month, day, hour, minute, and second,
2824 with the following fields:
2834 with the following fields:
2825
2835
2826 1-6: year, month, day, hour, minute, and second
2836 1-6: year, month, day, hour, minute, and second
2827
2837
2828 2. requested parm fields
2838 2. requested parm fields
2829 """
2839 """
2830 startyear = int(request.GET['startyear'])
2840 startyear = int(request.GET['startyear'])
2831 startmonth = int(request.GET['startmonth'])
2841 startmonth = int(request.GET['startmonth'])
2832 startday = int(request.GET['startday'])
2842 startday = int(request.GET['startday'])
2833 starthour = int(request.GET['starthour'])
2843 starthour = int(request.GET['starthour'])
2834 startminute = int(request.GET['startmin'])
2844 startminute = int(request.GET['startmin'])
2835 startsecond = int(request.GET['startsec'])
2845 startsecond = int(request.GET['startsec'])
2836 endyear = int(request.GET['endyear'])
2846 endyear = int(request.GET['endyear'])
2837 endmonth = int(request.GET['endmonth'])
2847 endmonth = int(request.GET['endmonth'])
2838 endday = int(request.GET['endday'])
2848 endday = int(request.GET['endday'])
2839 endhour = int(request.GET['endhour'])
2849 endhour = int(request.GET['endhour'])
2840 endminute = int(request.GET['endmin'])
2850 endminute = int(request.GET['endmin'])
2841 endsecond = int(request.GET['endsec'])
2851 endsecond = int(request.GET['endsec'])
2842 dt1 = datetime.datetime(startyear, startmonth, startday, starthour, startminute, startsecond)
2852 dt1 = datetime.datetime(startyear, startmonth, startday, starthour, startminute, startsecond)
2843 dt2 = datetime.datetime(endyear, endmonth, endday, endhour, endminute, endsecond)
2853 dt2 = datetime.datetime(endyear, endmonth, endday, endhour, endminute, endsecond)
2844 if dt1 > dt2:
2854 if dt1 > dt2:
2845 return(HttpResponse('End Datetime %s cannot be before start datetime %s' % (str(dt2), str(dt1))))
2855 return(HttpResponse('End Datetime %s cannot be before start datetime %s' % (str(dt2), str(dt1))))
2846
2856
2847 stephours = float(request.GET['stephours'])
2857 stephours = float(request.GET['stephours'])
2848 if stephours <= 0.0:
2858 if stephours <= 0.0:
2849 return(HttpResponse('stephours cannot be non-positive: %f' % (stephours)))
2859 return(HttpResponse('stephours cannot be non-positive: %f' % (stephours)))
2850
2860
2851 dtList = []
2861 dtList = []
2852 while dt1 <= dt2:
2862 while dt1 <= dt2:
2853 dtList.append(dt1)
2863 dtList.append(dt1)
2854 dt1 += datetime.timedelta(hours=stephours)
2864 dt1 += datetime.timedelta(hours=stephours)
2855
2865
2856 parms = request.GET['parms']
2866 parms = request.GET['parms']
2857 desiredParmList = [item.strip() for item in ['year','month','day','hour','min','sec'] + parms.split(',')]
2867 desiredParmList = [item.strip() for item in ['year','month','day','hour','min','sec'] + parms.split(',')]
2858
2868
2859 # no spatial data
2869 # no spatial data
2860 latList = lonList = altList = []
2870 latList = lonList = altList = []
2861 # capture stdout
2871 # capture stdout
2862 old_stdout = sys.stdout
2872 old_stdout = sys.stdout
2863 sys.stdout = mystdout = io.StringIO()
2873 sys.stdout = mystdout = io.StringIO()
2864 madrigal.isprint.MadCalculatorGrid(None, desiredParmList, dtList, latList, lonList, altList,
2874 madrigal.isprint.MadCalculatorGrid(None, desiredParmList, dtList, latList, lonList, altList,
2865 summary=None)
2875 summary=None)
2866 text = mystdout.getvalue()
2876 text = mystdout.getvalue()
2867 sys.stdout = old_stdout
2877 sys.stdout = old_stdout
2868
2878
2869 return render(request, 'madweb/service.html', {'text': text})
2879 return render(request, 'madweb/service.html', {'text': text})
2870
2880
2871
2881
2872
2882
2873 @csrf_exempt
2883 @csrf_exempt
2874 def mad_calculator2_service(request):
2884 def mad_calculator2_service(request):
2875 """mad_calculator2_service runs the madCalculator2 service.
2885 """mad_calculator2_service runs the madCalculator2 service.
2876
2886
2877 Differs from madCalulator in that positions are a list rather than a grid.
2887 Differs from madCalulator in that positions are a list rather than a grid.
2878
2888
2879 Inputs:
2889 Inputs:
2880 request/url - contains arguments:
2890 request/url - contains arguments:
2881
2891
2882 year, month, day, hour, min, sec
2892 year, month, day, hour, min, sec
2883
2893
2884 lats - comma separated list of latitudes to analyze
2894 lats - comma separated list of latitudes to analyze
2885
2895
2886 longs - comma separated list of longitudes to analyze. Len must == len(lats)
2896 longs - comma separated list of longitudes to analyze. Len must == len(lats)
2887
2897
2888 alts - comma separated list of altitudes to analyze. Len must == len(lats)
2898 alts - comma separated list of altitudes to analyze. Len must == len(lats)
2889
2899
2890 parms - comma delimited string of Madrigal parameters desired
2900 parms - comma delimited string of Madrigal parameters desired
2891
2901
2892 oneD - zero or more mnemonics,float values to set input 1D values
2902 oneD - zero or more mnemonics,float values to set input 1D values
2893 Example: &oneD=kinst,31.0&oneD=elm,45.0
2903 Example: &oneD=kinst,31.0&oneD=elm,45.0
2894
2904
2895 twoD - zero or more mnemonics,comma-separate float list of len(lats) to set input 2D values
2905 twoD - zero or more mnemonics,comma-separate float list of len(lats) to set input 2D values
2896 Example: twoD=te,1000,1100,1200 twoD=ti,1000,1000,1000
2906 Example: twoD=te,1000,1100,1200 twoD=ti,1000,1000,1000
2897 where there are 3 lats
2907 where there are 3 lats
2898
2908
2899 Returns comma-delimited data, one line for each lat value,
2909 Returns comma-delimited data, one line for each lat value,
2900 with the following fields:
2910 with the following fields:
2901
2911
2902 1. latitude
2912 1. latitude
2903
2913
2904 2. longitude
2914 2. longitude
2905
2915
2906 3. altitude
2916 3. altitude
2907
2917
2908 4. Values for each Madrigal parameter listed in argument parms, separated by whitespace
2918 4. Values for each Madrigal parameter listed in argument parms, separated by whitespace
2909 """
2919 """
2910 if request.method == 'POST':
2920 if request.method == 'POST':
2911 reqDict = request.POST
2921 reqDict = request.POST
2912 else:
2922 else:
2913 reqDict = request.GET
2923 reqDict = request.GET
2914 try:
2924 try:
2915 year = int(reqDict.get('year'))
2925 year = int(reqDict.get('year'))
2916 except TypeError:
2926 except TypeError:
2917 return(HttpResponse('<p>madCalculator2Service requires year</p>'))
2927 return(HttpResponse('<p>madCalculator2Service requires year</p>'))
2918 month = int(reqDict['month'])
2928 month = int(reqDict['month'])
2919 day = int(reqDict['day'])
2929 day = int(reqDict['day'])
2920 hour = int(reqDict['hour'])
2930 hour = int(reqDict['hour'])
2921 minute = int(reqDict['min'])
2931 minute = int(reqDict['min'])
2922 second = int(reqDict['sec'])
2932 second = int(reqDict['sec'])
2923 dt = datetime.datetime(year, month, day, hour, minute, second)
2933 dt = datetime.datetime(year, month, day, hour, minute, second)
2924
2934
2925 latsStr = reqDict['lats']
2935 latsStr = reqDict['lats']
2926 lats = [float(item) for item in latsStr.split(',')]
2936 lats = [float(item) for item in latsStr.split(',')]
2927 longsStr = reqDict['longs']
2937 longsStr = reqDict['longs']
2928 longs = [float(item) for item in longsStr.split(',')]
2938 longs = [float(item) for item in longsStr.split(',')]
2929 altsStr = reqDict['alts']
2939 altsStr = reqDict['alts']
2930 alts = [float(item) for item in altsStr.split(',')]
2940 alts = [float(item) for item in altsStr.split(',')]
2931
2941
2932 parms = reqDict['parms']
2942 parms = reqDict['parms']
2933 desiredParmList = [item.strip() for item in ['gdlat','glon','gdalt'] + parms.split(',')]
2943 desiredParmList = [item.strip() for item in ['gdlat','glon','gdalt'] + parms.split(',')]
2934
2944
2935 oneDList = reqDict.getlist('oneD')
2945 oneDList = reqDict.getlist('oneD')
2936 oneDParmDict = {}
2946 oneDParmDict = {}
2937 for oneDStr in oneDList:
2947 for oneDStr in oneDList:
2938 mnem, strValue = oneDStr.split(',')
2948 mnem, strValue = oneDStr.split(',')
2939 oneDParmDict[mnem] = [float(strValue)]
2949 oneDParmDict[mnem] = [float(strValue)]
2940
2950
2941 twoDList = reqDict.getlist('twoD')
2951 twoDList = reqDict.getlist('twoD')
2942
2952
2943 twoDParmDict = {}
2953 twoDParmDict = {}
2944 for twoDStr in twoDList:
2954 for twoDStr in twoDList:
2945 items = twoDStr.split(',')
2955 items = twoDStr.split(',')
2946 if len(items) != 1 + len(lats):
2956 if len(items) != 1 + len(lats):
2947 raise ValueError('twoDstr %s not correct number of points' % (str(twoDStr)))
2957 raise ValueError('twoDstr %s not correct number of points' % (str(twoDStr)))
2948 mnem = items[0]
2958 mnem = items[0]
2949 floatValues = [float(item) for item in items[1:]]
2959 floatValues = [float(item) for item in items[1:]]
2950 # now we need to expand these values to be two dimensional 1 x len(lats)
2960 # now we need to expand these values to be two dimensional 1 x len(lats)
2951 values = numpy.zeros((1,len(lats)), dtype=numpy.float)
2961 values = numpy.zeros((1,len(lats)), dtype=numpy.float)
2952 values[0][:] = floatValues
2962 values[0][:] = floatValues
2953 twoDParmDict[mnem] = values
2963 twoDParmDict[mnem] = values
2954
2964
2955 # capture stdout
2965 # capture stdout
2956 old_stdout = sys.stdout
2966 old_stdout = sys.stdout
2957 sys.stdout = mystdout = io.StringIO()
2967 sys.stdout = mystdout = io.StringIO()
2958 madrigal.isprint.MadCalculatorList(None, desiredParmList, [dt], lats, longs, alts,
2968 madrigal.isprint.MadCalculatorList(None, desiredParmList, [dt], lats, longs, alts,
2959 oneDParmDict, twoDParmDict, summary=None)
2969 oneDParmDict, twoDParmDict, summary=None)
2960 text = mystdout.getvalue()
2970 text = mystdout.getvalue()
2961 sys.stdout = old_stdout
2971 sys.stdout = old_stdout
2962
2972
2963 return render(request, 'madweb/service.html', {'text': text})
2973 return render(request, 'madweb/service.html', {'text': text})
2964
2974
2965
2975
2966
2976
2967
2977
2968 @csrf_exempt
2978 @csrf_exempt
2969 def mad_calculator3_service(request):
2979 def mad_calculator3_service(request):
2970 """mad_calculator3_service runs the madCalculator3 service.
2980 """mad_calculator3_service runs the madCalculator3 service.
2971
2981
2972 Differs from madCalulator in that multiple times, each with a unique list of positions, can be passed in.
2982 Differs from madCalulator in that multiple times, each with a unique list of positions, can be passed in.
2973
2983
2974 Inputs:
2984 Inputs:
2975 request/url - contains arguments:
2985 request/url - contains arguments:
2976
2986
2977 year - a comma-separated list of years - (required)
2987 year - a comma-separated list of years - (required)
2978
2988
2979 month - a comma-separated list of months - (required)
2989 month - a comma-separated list of months - (required)
2980
2990
2981 day - a comma-separated list of days - (required)
2991 day - a comma-separated list of days - (required)
2982
2992
2983 hour - a comma-separated list of hours - (required)
2993 hour - a comma-separated list of hours - (required)
2984
2994
2985 min - a comma-separated list of minutes - (required)
2995 min - a comma-separated list of minutes - (required)
2986
2996
2987 sec - a comma-separated list of seconds - (required)
2997 sec - a comma-separated list of seconds - (required)
2988
2998
2989 numPos - a comma-sepatated list of the number of positions for each time - (required)
2999 numPos - a comma-sepatated list of the number of positions for each time - (required)
2990
3000
2991 lats - a comma-separated list of geodetic latitudes, -90 to 90 (required). Listed
3001 lats - a comma-separated list of geodetic latitudes, -90 to 90 (required). Listed
2992 for first time, then second, etc. Total must be equal to the sum
3002 for first time, then second, etc. Total must be equal to the sum
2993 of numPos.
3003 of numPos.
2994
3004
2995 longs - a comma-separated list of longitudes (required) Listed
3005 longs - a comma-separated list of longitudes (required) Listed
2996 for first time, then second, etc. Total must be equal to the sum
3006 for first time, then second, etc. Total must be equal to the sum
2997 of numPos.
3007 of numPos.
2998
3008
2999 alts - a comma-separated list of geodetic altitudes in km (required) Listed
3009 alts - a comma-separated list of geodetic altitudes in km (required) Listed
3000 for first time, then second, etc. Total must be equal to the sum
3010 for first time, then second, etc. Total must be equal to the sum
3001 of numPos.
3011 of numPos.
3002
3012
3003 parms - comma delimited string of Madrigal parameters desired (required)
3013 parms - comma delimited string of Madrigal parameters desired (required)
3004
3014
3005 oneD - string in form <parm>,<comma-separated values> This argument allows the user to
3015 oneD - string in form <parm>,<comma-separated values> This argument allows the user to
3006 set any number of one-D parameters to be used in the calculation.
3016 set any number of one-D parameters to be used in the calculation.
3007 Value must be parameter name, comma, list of values as double,
3017 Value must be parameter name, comma, list of values as double,
3008 where length of list is equal to number of times.
3018 where length of list is equal to number of times.
3009 Example: &oneD=kinst,31.0,31.0&oneD=elm,45.0,50
3019 Example: &oneD=kinst,31.0,31.0&oneD=elm,45.0,50
3010 (optional - 0 or more allowed)
3020 (optional - 0 or more allowed)
3011
3021
3012 twoD=<parm>,<values> (optional - 0 or more allowed) This argument allows the user to
3022 twoD=<parm>,<values> (optional - 0 or more allowed) This argument allows the user to
3013 set any number of two-D parameters to be used in the calculation.
3023 set any number of two-D parameters to be used in the calculation.
3014 Value must be parameter name, comma, comma-separated values.
3024 Value must be parameter name, comma, comma-separated values.
3015 Number of values must equal the sum of numPos. Order is
3025 Number of values must equal the sum of numPos. Order is
3016 first time values first, then second time values, etc
3026 first time values first, then second time values, etc
3017 Example: twoD=te,1000,1100,1200,1000,1100,1200 &twoD=ti,1000,1000,1000,1000,1000,1000
3027 Example: twoD=te,1000,1100,1200,1000,1100,1200 &twoD=ti,1000,1000,1000,1000,1000,1000
3018 where numPos=3,3
3028 where numPos=3,3
3019
3029
3020 Returns comma-delimited data, one line for each location. Separate times are delimited by line
3030 Returns comma-delimited data, one line for each location. Separate times are delimited by line
3021
3031
3022 TIME MM/DD/YYYY HH:MM:SS
3032 TIME MM/DD/YYYY HH:MM:SS
3023
3033
3024 Data lines have the following fields:
3034 Data lines have the following fields:
3025
3035
3026 1. latitude
3036 1. latitude
3027
3037
3028 2. longitude
3038 2. longitude
3029
3039
3030 3. altitude
3040 3. altitude
3031
3041
3032 4. Values for each Madrigal parameter listed in argument parms, separated by whitespace
3042 4. Values for each Madrigal parameter listed in argument parms, separated by whitespace
3033 """
3043 """
3034 if request.method == 'POST':
3044 if request.method == 'POST':
3035 reqDict = request.POST
3045 reqDict = request.POST
3036 else:
3046 else:
3037 reqDict = request.GET
3047 reqDict = request.GET
3038 try:
3048 try:
3039 yearList = [int(item) for item in reqDict.get('year').split(',')]
3049 yearList = [int(item) for item in reqDict.get('year').split(',')]
3040 except AttributeError:
3050 except AttributeError:
3041 return(HttpResponse('<p>madCalculator3Service requires year</p>'))
3051 return(HttpResponse('<p>madCalculator3Service requires year</p>'))
3042 monthList = [int(item) for item in reqDict.get('month').split(',')]
3052 monthList = [int(item) for item in reqDict.get('month').split(',')]
3043 dayList = [int(item) for item in reqDict.get('day').split(',')]
3053 dayList = [int(item) for item in reqDict.get('day').split(',')]
3044 hourList = [int(item) for item in reqDict.get('hour').split(',')]
3054 hourList = [int(item) for item in reqDict.get('hour').split(',')]
3045 minList = [int(item) for item in reqDict.get('min').split(',')]
3055 minList = [int(item) for item in reqDict.get('min').split(',')]
3046 secList = [int(item) for item in reqDict.get('sec').split(',')]
3056 secList = [int(item) for item in reqDict.get('sec').split(',')]
3047 dtList = [datetime.datetime(yearList[i], monthList[i], dayList[i],
3057 dtList = [datetime.datetime(yearList[i], monthList[i], dayList[i],
3048 hourList[i], minList[i], secList[i]) for i in range(len(yearList))]
3058 hourList[i], minList[i], secList[i]) for i in range(len(yearList))]
3049 numPosStr = reqDict['numPos']
3059 numPosStr = reqDict['numPos']
3050 numPosList = [int(item) for item in numPosStr.split(',')]
3060 numPosList = [int(item) for item in numPosStr.split(',')]
3051 totalPos = 0
3061 totalPos = 0
3052 for numPos in numPosList:
3062 for numPos in numPosList:
3053 totalPos += numPos
3063 totalPos += numPos
3054 latsStr = reqDict['lats']
3064 latsStr = reqDict['lats']
3055 lats = [float(item) for item in latsStr.split(',')]
3065 lats = [float(item) for item in latsStr.split(',')]
3056 if len(lats) != totalPos:
3066 if len(lats) != totalPos:
3057 return(HttpResponse('wrong number of lats, expected %i' % (totalPos)))
3067 return(HttpResponse('wrong number of lats, expected %i' % (totalPos)))
3058 longsStr = reqDict['longs']
3068 longsStr = reqDict['longs']
3059 longs = [float(item) for item in longsStr.split(',')]
3069 longs = [float(item) for item in longsStr.split(',')]
3060 if len(longs) != totalPos:
3070 if len(longs) != totalPos:
3061 return(HttpResponse('wrong number of longs, expected %i' % (totalPos)))
3071 return(HttpResponse('wrong number of longs, expected %i' % (totalPos)))
3062 altsStr = reqDict['alts']
3072 altsStr = reqDict['alts']
3063 alts = [float(item) for item in altsStr.split(',')]
3073 alts = [float(item) for item in altsStr.split(',')]
3064 if len(alts) != totalPos:
3074 if len(alts) != totalPos:
3065 return(HttpResponse('wrong number of alts, expected %i' % (totalPos)))
3075 return(HttpResponse('wrong number of alts, expected %i' % (totalPos)))
3066
3076
3067 parms = reqDict['parms']
3077 parms = reqDict['parms']
3068 desiredParmList = [item.strip() for item in ['gdlat','glon','gdalt'] + parms.split(',')]
3078 desiredParmList = [item.strip() for item in ['gdlat','glon','gdalt'] + parms.split(',')]
3069
3079
3070 oneDList = reqDict.getlist('oneD')
3080 oneDList = reqDict.getlist('oneD')
3071 twoDList = reqDict.getlist('twoD')
3081 twoDList = reqDict.getlist('twoD')
3072
3082
3073 # since the positions can change with each call, we need to call madrigal.isprint.MadCalculatorGrid once for each time
3083 # since the positions can change with each call, we need to call madrigal.isprint.MadCalculatorGrid once for each time
3074 startIndex = 0
3084 startIndex = 0
3075 endIndex = 0
3085 endIndex = 0
3076 fullText = ''
3086 fullText = ''
3077 for timeIndex, numPos in enumerate(numPosList):
3087 for timeIndex, numPos in enumerate(numPosList):
3078 startIndex = endIndex
3088 startIndex = endIndex
3079 endIndex += numPos
3089 endIndex += numPos
3080 thisLats = lats[startIndex:endIndex]
3090 thisLats = lats[startIndex:endIndex]
3081 thisLongs = longs[startIndex:endIndex]
3091 thisLongs = longs[startIndex:endIndex]
3082 thisAlts = alts[startIndex:endIndex]
3092 thisAlts = alts[startIndex:endIndex]
3083
3093
3084 oneDParmDict = {}
3094 oneDParmDict = {}
3085 for oneDStr in oneDList:
3095 for oneDStr in oneDList:
3086 values = oneDStr.split(',')
3096 values = oneDStr.split(',')
3087 if len(values) != 1+len(dtList):
3097 if len(values) != 1+len(dtList):
3088 return(HttpResponse('wrong number of values given for 1D parm %s' % (values[0])))
3098 return(HttpResponse('wrong number of values given for 1D parm %s' % (values[0])))
3089 oneDParmDict[values[0]] = [float(values[timeIndex+1])]
3099 oneDParmDict[values[0]] = [float(values[timeIndex+1])]
3090
3100
3091 twoDParmDict = {}
3101 twoDParmDict = {}
3092
3102
3093 for twoDStr in twoDList:
3103 for twoDStr in twoDList:
3094 values = twoDStr.split(',')
3104 values = twoDStr.split(',')
3095 if len(values) != 1 + totalPos:
3105 if len(values) != 1 + totalPos:
3096 return(HttpResponse('twoDstr %s not correct number of points' % (str(twoDStr))))
3106 return(HttpResponse('twoDstr %s not correct number of points' % (str(twoDStr))))
3097 mnem = values[0]
3107 mnem = values[0]
3098 floatValues = [float(item) for item in values[1+startIndex:1+endIndex]]
3108 floatValues = [float(item) for item in values[1+startIndex:1+endIndex]]
3099 # now we need to expand these values to be two dimensional - 1,len(thisLats)
3109 # now we need to expand these values to be two dimensional - 1,len(thisLats)
3100 values2D = numpy.zeros((1,len(thisLats)), dtype=numpy.float)
3110 values2D = numpy.zeros((1,len(thisLats)), dtype=numpy.float)
3101 values2D[0][:] = floatValues
3111 values2D[0][:] = floatValues
3102 twoDParmDict[mnem] = values2D
3112 twoDParmDict[mnem] = values2D
3103
3113
3104
3114
3105
3115
3106 # capture stdout
3116 # capture stdout
3107 old_stdout = sys.stdout
3117 old_stdout = sys.stdout
3108 sys.stdout = mystdout = io.StringIO()
3118 sys.stdout = mystdout = io.StringIO()
3109 madrigal.isprint.MadCalculatorList(None, desiredParmList, [dtList[timeIndex]], thisLats,
3119 madrigal.isprint.MadCalculatorList(None, desiredParmList, [dtList[timeIndex]], thisLats,
3110 thisLongs, thisAlts,
3120 thisLongs, thisAlts,
3111 oneDParmDict, twoDParmDict, summary=None)
3121 oneDParmDict, twoDParmDict, summary=None)
3112 text = mystdout.getvalue()
3122 text = mystdout.getvalue()
3113 sys.stdout = old_stdout
3123 sys.stdout = old_stdout
3114
3124
3115 fullText += 'TIME %s\n' % (dtList[timeIndex].strftime('%m/%d/%Y %H:%M:%S'))
3125 fullText += 'TIME %s\n' % (dtList[timeIndex].strftime('%m/%d/%Y %H:%M:%S'))
3116 fullText += text
3126 fullText += text
3117
3127
3118 return render(request, 'madweb/service.html', {'text': fullText})
3128 return render(request, 'madweb/service.html', {'text': fullText})
3119
3129
3120
3130
3121
3131
3122 def geodetic_to_radar_service(request):
3132 def geodetic_to_radar_service(request):
3123 """geodetic_to_radar_service runs the geodeticToRadar service.
3133 """geodetic_to_radar_service runs the geodeticToRadar service.
3124
3134
3125 Inputs:
3135 Inputs:
3126 request/url - contains arguments:
3136 request/url - contains arguments:
3127
3137
3128 slatgd - radar geodetic latitude
3138 slatgd - radar geodetic latitude
3129
3139
3130 slon - radar longitude
3140 slon - radar longitude
3131
3141
3132 saltgd - radar geodetic altitude
3142 saltgd - radar geodetic altitude
3133
3143
3134 gdlat - a comma-separated list of geodetic latitude of point
3144 gdlat - a comma-separated list of geodetic latitude of point
3135
3145
3136 glon - a comma-separated list of longitude of point. Len must be same as gdlat
3146 glon - a comma-separated list of longitude of point. Len must be same as gdlat
3137
3147
3138 gdalt - a comma-separated list of geodetic altitude of point. Len must be same as gdlat
3148 gdalt - a comma-separated list of geodetic altitude of point. Len must be same as gdlat
3139
3149
3140
3150
3141 Returns comma-delimited data, one line for point in lists (points treated as individual combinations, not grids):
3151 Returns comma-delimited data, one line for point in lists (points treated as individual combinations, not grids):
3142
3152
3143 1. radar azimuth in degrees (0 = north)
3153 1. radar azimuth in degrees (0 = north)
3144
3154
3145 2. radar elevation in degrees
3155 2. radar elevation in degrees
3146
3156
3147 3. radar range in km
3157 3. radar range in km
3148 """
3158 """
3149 slatgd = float(request.GET['slatgd'])
3159 slatgd = float(request.GET['slatgd'])
3150 slon = float(request.GET['slon'])
3160 slon = float(request.GET['slon'])
3151 saltgd = float(request.GET['saltgd'])
3161 saltgd = float(request.GET['saltgd'])
3152 oneDParmDict = {'GDLATR': [slatgd],
3162 oneDParmDict = {'GDLATR': [slatgd],
3153 'GDLONR': [slon],
3163 'GDLONR': [slon],
3154 'GALTR': [saltgd]}
3164 'GALTR': [saltgd]}
3155 gdlatStr = request.GET['gdlat']
3165 gdlatStr = request.GET['gdlat']
3156 gdlatList = [float(item) for item in gdlatStr.split(',')]
3166 gdlatList = [float(item) for item in gdlatStr.split(',')]
3157 glonStr = request.GET['glon']
3167 glonStr = request.GET['glon']
3158 glonList = [float(item) for item in glonStr.split(',')]
3168 glonList = [float(item) for item in glonStr.split(',')]
3159 gdaltStr = request.GET['gdalt']
3169 gdaltStr = request.GET['gdalt']
3160 gdaltList = [float(item) for item in gdaltStr.split(',')]
3170 gdaltList = [float(item) for item in gdaltStr.split(',')]
3161 desiredParmList = ['azm', 'elm', 'range']
3171 desiredParmList = ['azm', 'elm', 'range']
3162 dtList = [datetime.datetime(2001,1,1)] # not relevant
3172 dtList = [datetime.datetime(2001,1,1)] # not relevant
3163 if len(gdlatList) != len(glonList) or len(gdlatList) != len(gdaltList):
3173 if len(gdlatList) != len(glonList) or len(gdlatList) != len(gdaltList):
3164 return(HttpResponse('all point list lengths must be equal'))
3174 return(HttpResponse('all point list lengths must be equal'))
3165
3175
3166 fullText = ''
3176 fullText = ''
3167
3177
3168 delimiter = ','
3178 delimiter = ','
3169 for i in range(len(gdlatList)):
3179 for i in range(len(gdlatList)):
3170 # capture stdout
3180 # capture stdout
3171 old_stdout = sys.stdout
3181 old_stdout = sys.stdout
3172 sys.stdout = mystdout = io.StringIO()
3182 sys.stdout = mystdout = io.StringIO()
3173 madrigal.isprint.MadCalculatorGrid(None, desiredParmList, dtList, [gdlatList[i]],
3183 madrigal.isprint.MadCalculatorGrid(None, desiredParmList, dtList, [gdlatList[i]],
3174 [glonList[i]], [gdaltList[i]], summary=None,
3184 [glonList[i]], [gdaltList[i]], summary=None,
3175 oneDParmDict=oneDParmDict)
3185 oneDParmDict=oneDParmDict)
3176 text = mystdout.getvalue()
3186 text = mystdout.getvalue()
3177 sys.stdout = old_stdout
3187 sys.stdout = old_stdout
3178 for line in text.split('\n'):
3188 for line in text.split('\n'):
3179 items = line.split()
3189 items = line.split()
3180 fullText += delimiter.join(items) + '\n'
3190 fullText += delimiter.join(items) + '\n'
3181
3191
3182 return render(request, 'madweb/service.html', {'text': fullText})
3192 return render(request, 'madweb/service.html', {'text': fullText})
3183
3193
3184
3194
3185 def radar_to_geodetic_service(request):
3195 def radar_to_geodetic_service(request):
3186 """radar_to_geodetic_service runs the radarToGeodetic service.
3196 """radar_to_geodetic_service runs the radarToGeodetic service.
3187
3197
3188 Inputs:
3198 Inputs:
3189 request/url - contains arguments:
3199 request/url - contains arguments:
3190
3200
3191 slatgd - radar geodetic latitude
3201 slatgd - radar geodetic latitude
3192
3202
3193 slon - radar longitude
3203 slon - radar longitude
3194
3204
3195 saltgd - radar geodetic altitude
3205 saltgd - radar geodetic altitude
3196
3206
3197 azs - a comma-separated list of azimuths of point
3207 azs - a comma-separated list of azimuths of point
3198
3208
3199 els - a comma-separated list of elevations of point. Len must be same as azs
3209 els - a comma-separated list of elevations of point. Len must be same as azs
3200
3210
3201 ranges - a comma-separated list of ranges to point. Len must be same as azs
3211 ranges - a comma-separated list of ranges to point. Len must be same as azs
3202
3212
3203
3213
3204 Returns comma-delimited data, one line for point in lists (points treated as individual combinations, not grids):
3214 Returns comma-delimited data, one line for point in lists (points treated as individual combinations, not grids):
3205
3215
3206 1. geodetic latitude
3216 1. geodetic latitude
3207
3217
3208 2. longitude (-180 to 180)
3218 2. longitude (-180 to 180)
3209
3219
3210 3. geodetic altitude in km
3220 3. geodetic altitude in km
3211 """
3221 """
3212 slatgd = float(request.GET['slatgd'])
3222 slatgd = float(request.GET['slatgd'])
3213 slon = float(request.GET['slon'])
3223 slon = float(request.GET['slon'])
3214 saltgd = float(request.GET['saltgd'])
3224 saltgd = float(request.GET['saltgd'])
3215 azStr = request.GET['az']
3225 azStr = request.GET['az']
3216 azList = [float(item) for item in azStr.split(',')]
3226 azList = [float(item) for item in azStr.split(',')]
3217 elStr = request.GET['el']
3227 elStr = request.GET['el']
3218 elList = [float(item) for item in elStr.split(',')]
3228 elList = [float(item) for item in elStr.split(',')]
3219 rangeStr = request.GET['range']
3229 rangeStr = request.GET['range']
3220 rangeList = [float(item) for item in rangeStr.split(',')]
3230 rangeList = [float(item) for item in rangeStr.split(',')]
3221 if len(azList) != len(elList) or len(azList) != len(rangeList):
3231 if len(azList) != len(elList) or len(azList) != len(rangeList):
3222 return(HttpResponse('all point list lengths must be equal'))
3232 return(HttpResponse('all point list lengths must be equal'))
3223
3233
3224 fullText = ''
3234 fullText = ''
3225
3235
3226 for i in range(len(azList)):
3236 for i in range(len(azList)):
3227 gdlat,glon,gdalt = madrigal._derive.radarToGeodetic(slatgd, slon, saltgd,
3237 gdlat,glon,gdalt = madrigal._derive.radarToGeodetic(slatgd, slon, saltgd,
3228 azList[i], elList[i], rangeList[i])
3238 azList[i], elList[i], rangeList[i])
3229 fullText += '%f,%f,%f\n' % (gdlat,glon,gdalt)
3239 fullText += '%f,%f,%f\n' % (gdlat,glon,gdalt)
3230
3240
3231 return render(request, 'madweb/service.html', {'text': fullText})
3241 return render(request, 'madweb/service.html', {'text': fullText})
3232
3242
3233
3243
3234
3244
3235 def list_file_times_service(request):
3245 def list_file_times_service(request):
3236 """list_file_times_service runs the listFileTimes service.
3246 """list_file_times_service runs the listFileTimes service.
3237
3247
3238 Inputs:
3248 Inputs:
3239 request/url - contains arguments:
3249 request/url - contains arguments:
3240
3250
3241 Optional: expDir - experiment directory to list. Can be absolute or relative to
3251 Optional: expDir - experiment directory to list. Can be absolute or relative to
3242 experiments[0-9]*. Default is all files in $MADROOT/experiments*
3252 experiments[0-9]*. Default is all files in $MADROOT/experiments*
3243
3253
3244 Returns comma-delimited data, one for each file:
3254 Returns comma-delimited data, one for each file:
3245
3255
3246 1. Full path of file
3256 1. Full path of file
3247
3257
3248 2. File modification time in form YYYY-MM-DD HH:MM:SS (UT time)
3258 2. File modification time in form YYYY-MM-DD HH:MM:SS (UT time)
3249 """
3259 """
3250 expDir = None
3260 expDir = None
3251 try:
3261 try:
3252 expDir = request.GET['expDir']
3262 expDir = request.GET['expDir']
3253 except:
3263 except:
3254 pass
3264 pass
3255 madDB = madrigal.metadata.MadrigalDB()
3265 madDB = madrigal.metadata.MadrigalDB()
3256 fileList = madDB.listFileTimes(expDir)
3266 fileList = madDB.listFileTimes(expDir)
3257 fullText = '\n\n'
3267 fullText = '\n\n'
3258 for filename, filetime in fileList:
3268 for filename, filetime in fileList:
3259 fullText += "\'%s\', %s\n" % (filename, filetime.strftime('%Y-%m-%d %H:%M:%S'))
3269 fullText += "\'%s\', %s\n" % (filename, filetime.strftime('%Y-%m-%d %H:%M:%S'))
3260
3270
3261 return render(request, 'madweb/service.html', {'text': django.utils.safestring.mark_safe(fullText)})
3271 return render(request, 'madweb/service.html', {'text': django.utils.safestring.mark_safe(fullText)})
3262
3272
3263
3273
3264 def download_web_file_service(request):
3274 def download_web_file_service(request):
3265 """download_web_file_service runs the downloadWebFile service.
3275 """download_web_file_service runs the downloadWebFile service.
3266
3276
3267 Inputs:
3277 Inputs:
3268 request/url - contains arguments:
3278 request/url - contains arguments:
3269
3279
3270 expPath - path to file starting at experiments*
3280 expPath - path to file starting at experiments*
3271
3281
3272 Returns comma-delimited data, one for each file:
3282 Returns comma-delimited data, one for each file:
3273
3283
3274 1. Full path of file
3284 1. Full path of file
3275
3285
3276 2. File modification time in form YYYY-MM-DD HH:MM:SS (UT time)
3286 2. File modification time in form YYYY-MM-DD HH:MM:SS (UT time)
3277 """
3287 """
3278 expPath = request.GET['expPath']
3288 expPath = request.GET['expPath']
3279 madDB = madrigal.metadata.MadrigalDB()
3289 madDB = madrigal.metadata.MadrigalDB()
3280 downloadFile = os.path.join(madDB.getMadroot(), expPath)
3290 downloadFile = os.path.join(madDB.getMadroot(), expPath)
3281 f = open(downloadFile, 'rb')
3291 f = open(downloadFile, 'rb')
3282 thisFile = django.core.files.File(f)
3292 thisFile = django.core.files.File(f)
3283 response = HttpResponse(thisFile, content_type='application/x-octet-stream')
3293 response = HttpResponse(thisFile, content_type='application/x-octet-stream')
3284 response['Content-Disposition'] = 'attachment; filename="' + os.path.basename(downloadFile) + '"'
3294 response['Content-Disposition'] = 'attachment; filename="' + os.path.basename(downloadFile) + '"'
3285 response['Content-Length'] = os.path.getsize(downloadFile)
3295 response['Content-Length'] = os.path.getsize(downloadFile)
3286 return(response)
3296 return(response)
3287
3297
3288
3298
3289 def trace_magnetic_field_service(request):
3299 def trace_magnetic_field_service(request):
3290 """trace_magnetic_field_service runs the traceMagneticField service.
3300 """trace_magnetic_field_service runs the traceMagneticField service.
3291
3301
3292 Inputs:
3302 Inputs:
3293 request/url - contains arguments:
3303 request/url - contains arguments:
3294
3304
3295 year, month, day, hour, min, sec
3305 year, month, day, hour, min, sec
3296
3306
3297 inputType (0 for geodetic, 1 for GSM)
3307 inputType (0 for geodetic, 1 for GSM)
3298
3308
3299 outputType (0 for geodetic, 1 for GSM)
3309 outputType (0 for geodetic, 1 for GSM)
3300
3310
3301 The following parameter depend on inputType:
3311 The following parameter depend on inputType:
3302
3312
3303 in1 - a comma-separated list of geodetic altitudes or ZGSMs of starting point
3313 in1 - a comma-separated list of geodetic altitudes or ZGSMs of starting point
3304
3314
3305 in2 - a comma-separated list of geodetic latitudes or XGSMs of starting point
3315 in2 - a comma-separated list of geodetic latitudes or XGSMs of starting point
3306
3316
3307 in3 - a comma-separated list of longitude or YGSM of starting point
3317 in3 - a comma-separated list of longitude or YGSM of starting point
3308
3318
3309 Length of all three lists must be the same
3319 Length of all three lists must be the same
3310
3320
3311 model - 0 for Tsyganenko, 1 for IGRF
3321 model - 0 for Tsyganenko, 1 for IGRF
3312
3322
3313 qualifier - 0 for conjugate, 1 for north_alt, 2 for south_alt, 3 for apex, 4 for GSM XY plane
3323 qualifier - 0 for conjugate, 1 for north_alt, 2 for south_alt, 3 for apex, 4 for GSM XY plane
3314
3324
3315 stopAlt - altitude in km to stop trace at, if qualifier is north_alt or south_alt.
3325 stopAlt - altitude in km to stop trace at, if qualifier is north_alt or south_alt.
3316
3326
3317 If other qualifier, this parameter is not required.
3327 If other qualifier, this parameter is not required.
3318
3328
3319 Returns comma-delimited data, one line for point in in lists:
3329 Returns comma-delimited data, one line for point in in lists:
3320
3330
3321 1. geodetic altitude or ZGSM of ending point
3331 1. geodetic altitude or ZGSM of ending point
3322
3332
3323 2. geodetic latitude or XGSM of ending point
3333 2. geodetic latitude or XGSM of ending point
3324
3334
3325 3. longitude or YGSM of ending point
3335 3. longitude or YGSM of ending point
3326 """
3336 """
3327 year = int(request.GET['year'])
3337 year = int(request.GET['year'])
3328 month = int(request.GET['month'])
3338 month = int(request.GET['month'])
3329 day = int(request.GET['day'])
3339 day = int(request.GET['day'])
3330 hour = int(request.GET['hour'])
3340 hour = int(request.GET['hour'])
3331 minute = int(request.GET['min'])
3341 minute = int(request.GET['min'])
3332 second = int(request.GET['sec'])
3342 second = int(request.GET['sec'])
3333 dt = datetime.datetime(year, month, day, hour, minute, second)
3343 dt = datetime.datetime(year, month, day, hour, minute, second)
3334 inputType = int(request.GET['inputType'])
3344 inputType = int(request.GET['inputType'])
3335 if inputType not in (0,1):
3345 if inputType not in (0,1):
3336 return(HttpResponse('inputType must be 0 or 1, not %i' % (inputType)))
3346 return(HttpResponse('inputType must be 0 or 1, not %i' % (inputType)))
3337 outputType = int(request.GET['outputType'])
3347 outputType = int(request.GET['outputType'])
3338 if outputType not in (0,1):
3348 if outputType not in (0,1):
3339 return(HttpResponse('outputType must be 0 or 1, not %i' % (outputType)))
3349 return(HttpResponse('outputType must be 0 or 1, not %i' % (outputType)))
3340 in1Str = request.GET['in1']
3350 in1Str = request.GET['in1']
3341 in1List = [float(item) for item in in1Str.split(',')]
3351 in1List = [float(item) for item in in1Str.split(',')]
3342 in2Str = request.GET['in2']
3352 in2Str = request.GET['in2']
3343 in2List = [float(item) for item in in2Str.split(',')]
3353 in2List = [float(item) for item in in2Str.split(',')]
3344 in3Str = request.GET['in3']
3354 in3Str = request.GET['in3']
3345 in3List = [float(item) for item in in3Str.split(',')]
3355 in3List = [float(item) for item in in3Str.split(',')]
3346 if len(in1List) != len(in2List) or len(in1List) != len(in3List):
3356 if len(in1List) != len(in2List) or len(in1List) != len(in3List):
3347 return(HttpResponse('All three in* lists must have same length'))
3357 return(HttpResponse('All three in* lists must have same length'))
3348 model = int(request.GET['model'])
3358 model = int(request.GET['model'])
3349 if model not in (0,1):
3359 if model not in (0,1):
3350 return(HttpResponse('model must be 0 or 1, not %i' % (model)))
3360 return(HttpResponse('model must be 0 or 1, not %i' % (model)))
3351 qualifier = int(request.GET['qualifier'])
3361 qualifier = int(request.GET['qualifier'])
3352 if qualifier not in (0,1,2,3,4):
3362 if qualifier not in (0,1,2,3,4):
3353 return(HttpResponse('model must be in 0,1,2,3,4 not %i' % (model)))
3363 return(HttpResponse('model must be in 0,1,2,3,4 not %i' % (model)))
3354 try:
3364 try:
3355 stopAlt = float(request.GET['stopAlt'])
3365 stopAlt = float(request.GET['stopAlt'])
3356 except:
3366 except:
3357 stopAlt = 0.0
3367 stopAlt = 0.0
3358
3368
3359 fullText = ''
3369 fullText = ''
3360 resultArr = numpy.zeros((3,), dtype='f8')
3370 resultArr = numpy.zeros((3,), dtype='f8')
3361 madDB = madrigal.metadata.MadrigalDB()
3371 madDB = madrigal.metadata.MadrigalDB()
3362 madDeriveObj = madrigal.derivation.MadrigalDerivationMethods(madDB.getMadroot())
3372 madDeriveObj = madrigal.derivation.MadrigalDerivationMethods(madDB.getMadroot())
3363 for i in range(len(in1List)):
3373 for i in range(len(in1List)):
3364 madDeriveObj.traceMagneticField(year, month, day, hour, minute, second,
3374 madDeriveObj.traceMagneticField(year, month, day, hour, minute, second,
3365 inputType, outputType, in1List[i], in2List[i], in3List[i],
3375 inputType, outputType, in1List[i], in2List[i], in3List[i],
3366 model, qualifier, stopAlt, resultArr)
3376 model, qualifier, stopAlt, resultArr)
3367 fullText += '%f,%f,%f\n' % (resultArr[0], resultArr[1], resultArr[2])
3377 fullText += '%f,%f,%f\n' % (resultArr[0], resultArr[1], resultArr[2])
3368
3378
3369 return render(request, 'madweb/service.html', {'text': fullText})
3379 return render(request, 'madweb/service.html', {'text': fullText})
3370
3380
3371
3381
3372 def global_file_search_service(request):
3382 def global_file_search_service(request):
3373 """global_file_search_service returns a list of full paths to files or citable urls based on search arguments
3383 """global_file_search_service returns a list of full paths to files or citable urls based on search arguments
3374
3384
3375 Inputs:
3385 Inputs:
3376 request/url - contains arguments:
3386 request/url - contains arguments:
3377
3387
3378 startDate: start date in form YYYY-MM-DD to filter experiments before
3388 startDate: start date in form YYYY-MM-DD to filter experiments before
3379 endDate: end date in form YYYY-MM-DD to filter experiments after
3389 endDate: end date in form YYYY-MM-DD to filter experiments after
3380 inst: (optional, multiple allowed) an instrument code or name. For names,
3390 inst: (optional, multiple allowed) an instrument code or name. For names,
3381 fnmatch will be used. If not set, all instruments used.
3391 fnmatch will be used. If not set, all instruments used.
3382 kindat: (optional, multiple allowed) a kind of data codes or name. For names,
3392 kindat: (optional, multiple allowed) a kind of data codes or name. For names,
3383 fnmatch will be used. If not set, all kinds of data used.
3393 fnmatch will be used. If not set, all kinds of data used.
3384 seasonalStartDate: (optional) in form MM/DD, rejects all days earlier in year. If not set
3394 seasonalStartDate: (optional) in form MM/DD, rejects all days earlier in year. If not set
3385 implies 01/01
3395 implies 01/01
3386 seasonalEndDate: (optional) in form MM/DD, rejects all days later in year. If not set
3396 seasonalEndDate: (optional) in form MM/DD, rejects all days later in year. If not set
3387 implies 12/31
3397 implies 12/31
3388 includeNonDefault: (optional) if "True", include realtime files when there are no default.
3398 includeNonDefault: (optional) if "True", include realtime files when there are no default.
3389 If not set, only default files.
3399 If not set, only default files.
3390 expName: (optional) - filter experiments by the experiment name. fnmatch rules
3400 expName: (optional) - filter experiments by the experiment name. fnmatch rules
3391 If not set, no filtering by experiment name.
3401 If not set, no filtering by experiment name.
3392 excludeExpName: (optional) - exclude experiments by the experiment name. fnmatch rules
3402 excludeExpName: (optional) - exclude experiments by the experiment name. fnmatch rules
3393 If not set, no excluding experiments by experiment name.
3403 If not set, no excluding experiments by experiment name.
3394 fileDesc: (optional) filter files using input file Description string via fnmatch.
3404 fileDesc: (optional) filter files using input file Description string via fnmatch.
3395 If not set, in no filtering by file name
3405 If not set, in no filtering by file name
3396 returnCitation: (optional) if True, return a list of file citations. If not set, return
3406 returnCitation: (optional) if True, return a list of file citations. If not set, return
3397 a list of full paths to the files selected
3407 a list of full paths to the files selected
3398
3408
3399 """
3409 """
3400 madDB = madrigal.metadata.MadrigalDB()
3410 madDB = madrigal.metadata.MadrigalDB()
3401 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
3411 madWebObj = madrigal.ui.web.MadrigalWeb(madDB)
3402
3412
3403 # get required arguments
3413 # get required arguments
3404 startDate = request.GET['startDate']
3414 startDate = request.GET['startDate']
3405 endDate = request.GET['endDate']
3415 endDate = request.GET['endDate']
3406 startDate = datetime.datetime.strptime(startDate, '%Y-%m-%d')
3416 startDate = datetime.datetime.strptime(startDate, '%Y-%m-%d')
3407 endDate = datetime.datetime.strptime(endDate, '%Y-%m-%d')
3417 endDate = datetime.datetime.strptime(endDate, '%Y-%m-%d')
3408
3418
3409 # get optional arguments
3419 # get optional arguments
3410 inst = request.GET.getlist('inst')
3420 inst = request.GET.getlist('inst')
3411 if inst == []:
3421 if inst == []:
3412 inst = None
3422 inst = None
3413 kindat = request.GET.getlist('kindat')
3423 kindat = request.GET.getlist('kindat')
3414 if kindat == []:
3424 if kindat == []:
3415 kindat = None
3425 kindat = None
3416 seasonalStartDate = request.GET.get('seasonalStartDate', default = None)
3426 seasonalStartDate = request.GET.get('seasonalStartDate', default = None)
3417 seasonalEndDate = request.GET.get('seasonalEndDate', default = None)
3427 seasonalEndDate = request.GET.get('seasonalEndDate', default = None)
3418 includeNonDefault = bool(request.GET.get('includeNonDefault', default = False))
3428 includeNonDefault = bool(request.GET.get('includeNonDefault', default = False))
3419 expName = request.GET.get('expName', default = None)
3429 expName = request.GET.get('expName', default = None)
3420 excludeExpName = request.GET.get('excludeExpName', default = None)
3430 excludeExpName = request.GET.get('excludeExpName', default = None)
3421 fileDesc = request.GET.get('fileDesc', default = None)
3431 fileDesc = request.GET.get('fileDesc', default = None)
3422 returnCitation = bool(request.GET.get('returnCitation', default = False))
3432 returnCitation = bool(request.GET.get('returnCitation', default = False))
3423
3433
3424 result = madWebObj.global_file_search(startDate, endDate, inst, kindat,
3434 result = madWebObj.global_file_search(startDate, endDate, inst, kindat,
3425 seasonalStartDate, seasonalEndDate,
3435 seasonalStartDate, seasonalEndDate,
3426 includeNonDefault, expName, excludeExpName,
3436 includeNonDefault, expName, excludeExpName,
3427 fileDesc, returnCitation)
3437 fileDesc, returnCitation)
3428
3438
3429 fullText = ''
3439 fullText = ''
3430 for item in result:
3440 for item in result:
3431 fullText += '%s\n' % (item)
3441 fullText += '%s\n' % (item)
3432
3442
3433 return render(request, 'madweb/service.html', {'text': django.utils.safestring.mark_safe(fullText)})
3443 return render(request, 'madweb/service.html', {'text': django.utils.safestring.mark_safe(fullText)})
3434
3444
3435
3445
3436
3446
3437
3447
3438 def get_url_list_from_group_id_service(request):
3448 def get_url_list_from_group_id_service(request):
3439 """get_url_list_from_group_id_service returns a list of citable urls associated with group id.
3449 """get_url_list_from_group_id_service returns a list of citable urls associated with group id.
3440
3450
3441 Inputs:
3451 Inputs:
3442 request/url - contains arguments:
3452 request/url - contains arguments:
3443
3453
3444 id - group id
3454 id - group id
3445
3455
3446 Returns one line for each citable url
3456 Returns one line for each citable url
3447
3457
3448 Returns empty string if experiment id not found. Skips files that are not Hdf5
3458 Returns empty string if experiment id not found. Skips files that are not Hdf5
3449 """
3459 """
3450 id = int(request.GET['id'])
3460 id = int(request.GET['id'])
3451
3461
3452 # create MadrigalDB obj
3462 # create MadrigalDB obj
3453 madDBObj = madrigal.metadata.MadrigalDB()
3463 madDBObj = madrigal.metadata.MadrigalDB()
3454
3464
3455 urlList = madDBObj.getListFromGroupId(id)
3465 urlList = madDBObj.getListFromGroupId(id)
3456
3466
3457 retStr = ''
3467 retStr = ''
3458 for url in urlList:
3468 for url in urlList:
3459 retStr += '%s\n' % (url)
3469 retStr += '%s\n' % (url)
3460
3470
3461 return render(request, 'madweb/service.html', {'text': django.utils.safestring.mark_safe(retStr)})
3471 return render(request, 'madweb/service.html', {'text': django.utils.safestring.mark_safe(retStr)})
3462
3472
3463
3473
3464 def set_group_id_from_url_list_service(request):
3474 def set_group_id_from_url_list_service(request):
3465 """set_group_id_from_url_list sets a list of citable urls to a group id .
3475 """set_group_id_from_url_list sets a list of citable urls to a group id .
3466
3476
3467 Inputs:
3477 Inputs:
3468 request/url - contains arguments:
3478 request/url - contains arguments:
3469
3479
3470 'user_fullname' user name
3480 'user_fullname' user name
3471
3481
3472 'user_email' user email
3482 'user_email' user email
3473
3483
3474 'user_affiliation' user affiliation
3484 'user_affiliation' user affiliation
3475
3485
3476 'url' - citable url. Multiple arguments allowed
3486 'url' - citable url. Multiple arguments allowed
3477
3487
3478 Returns group id (integer) set
3488 Returns group id (integer) set
3479 """
3489 """
3480 madDB = madrigal.metadata.MadrigalDB()
3490 madDB = madrigal.metadata.MadrigalDB()
3481
3491
3482 print(request.GET)
3492 print(request.GET)
3483
3493
3484 # get required arguments
3494 # get required arguments
3485 urls = request.GET.getlist('url')
3495 urls = request.GET.getlist('url')
3486 user_fullname = request.GET['user_fullname']
3496 user_fullname = request.GET['user_fullname']
3487 user_email = request.GET['user_email']
3497 user_email = request.GET['user_email']
3488 user_affiliation = request.GET['user_affiliation']
3498 user_affiliation = request.GET['user_affiliation']
3489
3499
3490 id = madDB.createGroupIdWithList(user_fullname, user_email, user_affiliation, urls)
3500 id = madDB.createGroupIdWithList(user_fullname, user_email, user_affiliation, urls)
3491
3501
3492 return render(request, 'madweb/service.html', {'text': str(id)})
3502 return render(request, 'madweb/service.html', {'text': str(id)})
3493
3503
3494
3504
3495 ### doc pages ###
3505 ### doc pages ###
3496
3506
3497 def docs(request, name):
3507 def docs(request, name):
3498 madDB = madrigal.metadata.MadrigalDB()
3508 madDB = madrigal.metadata.MadrigalDB()
3499 openMadObj = madrigal.openmadrigal.OpenMadrigal(madDB)
3509 openMadObj = madrigal.openmadrigal.OpenMadrigal(madDB)
3500 bg_color = madDB.getBackgroundColor()
3510 bg_color = madDB.getBackgroundColor()
3501 if name.find('..') != -1:
3511 if name.find('..') != -1:
3502 # no trying to look elsewhere
3512 # no trying to look elsewhere
3503 return(HttpResponse('Illegal name passed to docs: <%s>' % (name)))
3513 return(HttpResponse('Illegal name passed to docs: <%s>' % (name)))
3504 # check if siteSpecitic.html
3514 # check if siteSpecitic.html
3505 siteSpecificPath = os.path.join(madDB.getMadroot(), 'source/madpy/djangoMad/madweb/templates/madweb/siteSpecific.html')
3515 siteSpecificPath = os.path.join(madDB.getMadroot(), 'source/madpy/djangoMad/madweb/templates/madweb/siteSpecific.html')
3506 if os.access(siteSpecificPath, os.R_OK):
3516 if os.access(siteSpecificPath, os.R_OK):
3507 siteSpecific = reverse('docs', args=['siteSpecific.html'])
3517 siteSpecific = reverse('docs', args=['siteSpecific.html'])
3508 else:
3518 else:
3509 siteSpecific = '#'
3519 siteSpecific = '#'
3510 openmadrigal = openMadObj.getOpenMadrigalUrl()
3520 openmadrigal = openMadObj.getOpenMadrigalUrl()
3511 # since google insists filenames are case insensitive, convert to right name if there is no direct match if possible
3521 # since google insists filenames are case insensitive, convert to right name if there is no direct match if possible
3512 this_file = os.path.join(madDB.getMadroot(), 'source/madpy/djangoMad/madweb/templates/madweb', name)
3522 this_file = os.path.join(madDB.getMadroot(), 'source/madpy/djangoMad/madweb/templates/madweb', name)
3513 if not os.access(this_file, os.R_OK):
3523 if not os.access(this_file, os.R_OK):
3514 found = False
3524 found = False
3515 existing_files = glob.glob(os.path.join(madDB.getMadroot(), 'source/madpy/djangoMad/madweb/templates/madweb/*.html'))
3525 existing_files = glob.glob(os.path.join(madDB.getMadroot(), 'source/madpy/djangoMad/madweb/templates/madweb/*.html'))
3516 for existing_file in existing_files:
3526 for existing_file in existing_files:
3517 if name.lower() == os.path.basename(existing_file).lower():
3527 if name.lower() == os.path.basename(existing_file).lower():
3518 name = os.path.basename(existing_file)
3528 name = os.path.basename(existing_file)
3519 found = True
3529 found = True
3520 break # correct name found and name modified
3530 break # correct name found and name modified
3521 if not found:
3531 if not found:
3522 return(HttpResponse('<p>Cannot find %s</p>' % (str(name))))
3532 return(HttpResponse('<p>Cannot find %s</p>' % (str(name))))
3523
3533
3524 if os.path.isdir(this_file):
3534 if os.path.isdir(this_file):
3525 return(HttpResponse('<p>%s is a directory</p>' % (str(name))))
3535 return(HttpResponse('<p>%s is a directory</p>' % (str(name))))
3526
3536
3527 return render(request, 'madweb/%s' % (name), {'bg_color': bg_color, 'siteSpecific': siteSpecific,
3537 return render(request, 'madweb/%s' % (name), {'bg_color': bg_color, 'siteSpecific': siteSpecific,
3528 'openmadrigal': openmadrigal})
3538 'openmadrigal': openmadrigal})
3529
3539
3530
3540
General Comments 0
You need to be logged in to leave comments. Login now