Commit 1754789b5ec4440eaab15ce21bba967d1cafb186
1 parent
7994cf1a
Exists in
master
and in
2 other branches
Decorate and clean up the start/stop inputs.
Showing
4 changed files
with
48 additions
and
120 deletions
Show diff stats
web/run.py
@@ -339,12 +339,6 @@ def get_target_csv(source, started_at, stopped_at): | @@ -339,12 +339,6 @@ def get_target_csv(source, started_at, stopped_at): | ||
339 | except: | 339 | except: |
340 | abort(400, "Invalid stopped_at parameter : '%s'." % stopped_at) | 340 | abort(400, "Invalid stopped_at parameter : '%s'." % stopped_at) |
341 | 341 | ||
342 | - # todo: iterate on models when there are many | ||
343 | - try: | ||
344 | - model_slug = source_config['models'][0]['slug'] | ||
345 | - except: | ||
346 | - abort(500, "Invalid model configuration for '%s'." % source) | ||
347 | - | ||
348 | filename = "%s_%s_%s.csv" % (source, | 342 | filename = "%s_%s_%s.csv" % (source, |
349 | started_at.strftime(date_fmt), | 343 | started_at.strftime(date_fmt), |
350 | stopped_at.strftime(date_fmt)) | 344 | stopped_at.strftime(date_fmt)) |
@@ -362,125 +356,34 @@ def get_target_csv(source, started_at, stopped_at): | @@ -362,125 +356,34 @@ def get_target_csv(source, started_at, stopped_at): | ||
362 | return send_from_directory(get_path("../cache/"), filename) | 356 | return send_from_directory(get_path("../cache/"), filename) |
363 | 357 | ||
364 | 358 | ||
365 | -# @app.route("/<source>/data.csv") | ||
366 | -# def get_orbiter_csv(source): | 359 | +# DEV TOOLS ################################################################### |
360 | + | ||
361 | +# @app.route("/inspect") | ||
362 | +# def analyze_cdf(): | ||
367 | # """ | 363 | # """ |
368 | -# DEPRECATED | ||
369 | -# Grab data and orbit data for the specified `source`, | ||
370 | -# rearrange it and return it as a CSV file. | 364 | +# For debug purposes. |
371 | # """ | 365 | # """ |
372 | -# # http://cdpp1.cesr.fr/BASE/DDService/getDataUrl.php?dataSet=tao_ros_sw&StartTime=2014-02-23T10:00&StopTime=2016-02-24T23:59 | ||
373 | -# # Process input parameters | ||
374 | -# source_config = get_source_config(source) | ||
375 | -# date_fmt = "%Y-%m-%dT%H:%M:%S" | ||
376 | -# started_at = request.args.get('started_at') | ||
377 | -# try: | ||
378 | -# started_at = datetime.datetime.strptime(started_at, date_fmt) | ||
379 | -# except: | ||
380 | -# abort(400, "Invalid started_at parameter : '%s'." % started_at) | ||
381 | -# stopped_at = request.args.get('stopped_at') | ||
382 | -# try: | ||
383 | -# stopped_at = datetime.datetime.strptime(stopped_at, date_fmt) | ||
384 | -# except: | ||
385 | -# abort(400, "Invalid stopped_at parameter : '%s'." % stopped_at) | ||
386 | -# | ||
387 | -# # todo: iterate on models when there are many | ||
388 | -# try: | ||
389 | -# model_slug = source_config['models'][0]['slug'] | ||
390 | -# except: | ||
391 | -# abort(500, "Invalid model configuration for '%s'." % source) | ||
392 | -# | ||
393 | -# # Grab the list of netCDF files from Myriam's API | ||
394 | -# # http://cdpp.irap.omp.eu/BASE/DDService/getDataUrl.php?dataSet=jupiter_orb_all&StartTime=2014-02-23T10:00:10&StopTime=2017-02-24T23:59:00 | ||
395 | -# # http://cdpp.irap.omp.eu/BASE/DATA/TAO/JUPITER/SW/sw_2014.nc.gz | ||
396 | -# model_files = retrieve_data(source, model_slug, started_at, stopped_at) | ||
397 | -# orbits_files = retrieve_data(source, source_config['orbit']['model'], started_at, stopped_at) | 366 | +# cdf_to_inspect = get_path("../res/dummy.nc") |
367 | +# cdf_to_inspect = get_path("../res/dummy_jupiter_coordinates.nc") | ||
398 | # | 368 | # |
399 | # si = StringIO.StringIO() | 369 | # si = StringIO.StringIO() |
400 | -# cw = csv_writer(si) | ||
401 | -# cw.writerow(( # the order matters ! | ||
402 | -# 'time', | ||
403 | -# 'vrad', 'vtan', 'vlen', | ||
404 | -# 'magn', 'temp', 'pdyn', 'dens', 'angl', | ||
405 | -# 'xhci', 'yhci' | ||
406 | -# )) | ||
407 | -# | ||
408 | -# precision = "%Y-%m-%dT%H" # model and orbits times are equal-ish | ||
409 | -# orbits_data = {} # keys are datetime as str, values arrays of XY | ||
410 | -# for orbits_file in orbits_files: | ||
411 | -# cdf_handle = Dataset(orbits_file, "r", format="NETCDF4") | ||
412 | -# times = cdf_handle.variables['Time'] # YYYY DOY HH MM SS .ms | ||
413 | -# data_hci = cdf_handle.variables['HCI'] | ||
414 | -# for time, datum_hci in zip(times, data_hci): | ||
415 | -# dtime = datetime_from_list(time) | ||
416 | -# if started_at <= dtime <= stopped_at: | ||
417 | -# dkey = dtime.strftime(precision) | ||
418 | -# orbits_data[dkey] = datum_hci | ||
419 | -# all_data = {} # keys are datetime as str, values tuples of data | ||
420 | -# for model_file in model_files: | ||
421 | -# # Time, StartTime, StopTime, V, B, N, T, Delta_angle, P_dyn | ||
422 | -# cdf_handle = Dataset(model_file, "r", format="NETCDF4") | ||
423 | -# times = cdf_handle.variables['Time'] # YYYY DOY HH MM SS .ms | ||
424 | -# data_v = cdf_handle.variables['V'] | ||
425 | -# data_b = cdf_handle.variables['B'] | ||
426 | -# data_t = cdf_handle.variables['T'] | ||
427 | -# data_n = cdf_handle.variables['N'] | ||
428 | -# data_p = cdf_handle.variables['P_dyn'] | ||
429 | -# data_d = cdf_handle.variables['Delta_angle'] | ||
430 | -# for time, datum_v, datum_b, datum_t, datum_p, datum_n, datum_d \ | ||
431 | -# in zip(times, data_v, data_b, data_t, data_n, data_p, data_d): | ||
432 | -# vrad = datum_v[0] | ||
433 | -# vtan = datum_v[1] | ||
434 | -# dtime = datetime_from_list(time) | ||
435 | -# if started_at <= dtime <= stopped_at: | ||
436 | -# dkey = dtime.strftime(precision) | ||
437 | -# x_hci = None | ||
438 | -# y_hci = None | ||
439 | -# if dkey in orbits_data: | ||
440 | -# x_hci = orbits_data[dkey][0] | ||
441 | -# y_hci = orbits_data[dkey][1] | ||
442 | -# all_data[dkey] = ( | ||
443 | -# dtime.strftime("%Y-%m-%dT%H:%M:%S+00:00"), | ||
444 | -# vrad, vtan, sqrt(vrad * vrad + vtan * vtan), | ||
445 | -# datum_b, datum_t, datum_n, datum_p, datum_d, | ||
446 | -# x_hci, y_hci | ||
447 | -# ) | ||
448 | -# cdf_handle.close() | 370 | +# cw = csv.DictWriter(si, fieldnames=['Name', 'Shape', 'Length']) |
371 | +# cw.writeheader() | ||
449 | # | 372 | # |
450 | -# for dkey in sorted(all_data): | ||
451 | -# cw.writerow(all_data[dkey]) | 373 | +# # Time, StartTime, StopTime, V, B, N, T, Delta_angle, P_dyn, QualityFlag |
374 | +# cdf_handle = Dataset(cdf_to_inspect, "r", format="NETCDF4") | ||
375 | +# for variable in cdf_handle.variables: | ||
376 | +# v = cdf_handle.variables[variable] | ||
377 | +# cw.writerow({ | ||
378 | +# 'Name': variable, | ||
379 | +# 'Shape': v.shape, | ||
380 | +# 'Length': v.size, | ||
381 | +# }) | ||
382 | +# cdf_handle.close() | ||
452 | # | 383 | # |
453 | # return si.getvalue() | 384 | # return si.getvalue() |
454 | 385 | ||
455 | 386 | ||
456 | -# DEV TOOLS ################################################################### | ||
457 | - | ||
458 | -@app.route("/inspect") | ||
459 | -def analyze_cdf(): | ||
460 | - """ | ||
461 | - For debug purposes. | ||
462 | - """ | ||
463 | - cdf_to_inspect = get_path("../res/dummy.nc") | ||
464 | - cdf_to_inspect = get_path("../res/dummy_jupiter_coordinates.nc") | ||
465 | - | ||
466 | - si = StringIO.StringIO() | ||
467 | - cw = csv.DictWriter(si, fieldnames=['Name', 'Shape', 'Length']) | ||
468 | - cw.writeheader() | ||
469 | - | ||
470 | - # Time, StartTime, StopTime, V, B, N, T, Delta_angle, P_dyn, QualityFlag | ||
471 | - cdf_handle = Dataset(cdf_to_inspect, "r", format="NETCDF4") | ||
472 | - for variable in cdf_handle.variables: | ||
473 | - v = cdf_handle.variables[variable] | ||
474 | - cw.writerow({ | ||
475 | - 'Name': variable, | ||
476 | - 'Shape': v.shape, | ||
477 | - 'Length': v.size, | ||
478 | - }) | ||
479 | - cdf_handle.close() | ||
480 | - | ||
481 | - return si.getvalue() | ||
482 | - | ||
483 | - | ||
484 | # MAIN ######################################################################## | 387 | # MAIN ######################################################################## |
485 | 388 | ||
486 | if __name__ == "__main__": | 389 | if __name__ == "__main__": |
web/static/js/swapp.js
@@ -258,7 +258,7 @@ | @@ -258,7 +258,7 @@ | ||
258 | return [this.started_at, this.stopped_at]; | 258 | return [this.started_at, this.stopped_at]; |
259 | }; | 259 | }; |
260 | SpaceWeather.prototype.resizeDomain = function(started_at, stopped_at){ | 260 | SpaceWeather.prototype.resizeDomain = function(started_at, stopped_at){ |
261 | - var ref$, formatted_started_at, formatted_stopped_at; | 261 | + var ref$, max_stopped_at, formatted_started_at, formatted_stopped_at; |
262 | if (stopped_at < started_at) { | 262 | if (stopped_at < started_at) { |
263 | ref$ = [stopped_at, started_at], started_at = ref$[0], stopped_at = ref$[1]; | 263 | ref$ = [stopped_at, started_at], started_at = ref$[0], stopped_at = ref$[1]; |
264 | } | 264 | } |
@@ -266,6 +266,11 @@ | @@ -266,6 +266,11 @@ | ||
266 | console.warn("Please provide distinct start and stop dates."); | 266 | console.warn("Please provide distinct start and stop dates."); |
267 | return; | 267 | return; |
268 | } | 268 | } |
269 | + max_stopped_at = started_at.clone().add(2, 'years'); | ||
270 | + if (stopped_at > max_stopped_at) { | ||
271 | + console.warn("The time interval was truncated beacuse it was bigger than two years."); | ||
272 | + stopped_at = max_stopped_at; | ||
273 | + } | ||
269 | this.setStartAndStop(started_at, stopped_at); | 274 | this.setStartAndStop(started_at, stopped_at); |
270 | formatted_started_at = started_at.format(); | 275 | formatted_started_at = started_at.format(); |
271 | formatted_stopped_at = stopped_at.format(); | 276 | formatted_stopped_at = stopped_at.format(); |
web/static/js/swapp.ls
@@ -227,6 +227,10 @@ https://gitlab.irap.omp.eu/CDPP/SPACEWEATHERONLINE | @@ -227,6 +227,10 @@ https://gitlab.irap.omp.eu/CDPP/SPACEWEATHERONLINE | ||
227 | if started_at == stopped_at | 227 | if started_at == stopped_at |
228 | console.warn "Please provide distinct start and stop dates." | 228 | console.warn "Please provide distinct start and stop dates." |
229 | return | 229 | return |
230 | + max_stopped_at = started_at.clone().add(2, 'years') | ||
231 | + if stopped_at > max_stopped_at | ||
232 | + console.warn "The time interval was truncated beacuse it was bigger than two years." | ||
233 | + stopped_at = max_stopped_at | ||
230 | 234 | ||
231 | @setStartAndStop(started_at, stopped_at) | 235 | @setStartAndStop(started_at, stopped_at) |
232 | formatted_started_at = started_at.format() | 236 | formatted_started_at = started_at.format() |
web/view/home.html.jinja2
@@ -31,9 +31,16 @@ | @@ -31,9 +31,16 @@ | ||
31 | 31 | ||
32 | <div class="mdl-layout__drawer"> | 32 | <div class="mdl-layout__drawer"> |
33 | <span class="mdl-layout-title">Time Interval</span> | 33 | <span class="mdl-layout-title">Time Interval</span> |
34 | - <input type="date" id="started_at" name="started_at" title="The date of the beginning of the interval to observe."> | ||
35 | - <input type="date" id="stopped_at" name="stopped_at" title="The date of the end of the interval to observe. (inclusive)"> | ||
36 | - <input type="submit" id="apply_new_interval" value="Load new interval" title="This may take a while if you request a bigger interval."> | 34 | + <form id="form_time_interval" action="#"> |
35 | + <div class="mdl-textfield mdl-js-textfield"> | ||
36 | + <input type="date" id="started_at" name="started_at" title="The date of the beginning of the interval to observe." class="mdl-textfield__input"> | ||
37 | + <input type="date" id="stopped_at" name="stopped_at" title="The date of the end of the interval to observe. (exclusive)" class="mdl-textfield__input"> | ||
38 | + </div> | ||
39 | + <input type="submit" id="apply_new_interval" value="Load new interval" title="This may take a while if you request a bigger interval." class="mdl-button mdl-js-button mdl-js-ripple-effect"> | ||
40 | + </form> | ||
41 | + | ||
42 | + <br> | ||
43 | + <hr class="clear"> | ||
37 | 44 | ||
38 | <span class="mdl-layout-title">Planets</span> | 45 | <span class="mdl-layout-title">Planets</span> |
39 | 46 | ||
@@ -250,6 +257,15 @@ | @@ -250,6 +257,15 @@ | ||
250 | stroke-width: 1px; | 257 | stroke-width: 1px; |
251 | stroke-dasharray: 5px; | 258 | stroke-dasharray: 5px; |
252 | } | 259 | } |
260 | + #form_time_interval { | ||
261 | + padding-left: 30px; | ||
262 | + } | ||
263 | + #form_time_interval .mdl-textfield { | ||
264 | + padding-top: 0; | ||
265 | + } | ||
266 | + #started_at, #stopped_at { | ||
267 | + width: 85%; | ||
268 | + } | ||
253 | .targets-filters { | 269 | .targets-filters { |
254 | padding-left: 17px; | 270 | padding-left: 17px; |
255 | } | 271 | } |