@@ -639,6 +639,11 class SingleExpPlotsForm(django.forms.Form): | |||
|
639 | 639 | required=False) |
|
640 | 640 | |
|
641 | 641 | '''get_params2 retrieves a list of 1d and 2d parameters of type 1 hdf5 files''' |
|
642 | ||
|
643 | def check_mnemonic(s): | |
|
644 | ||
|
645 | return s.replace('+', '%2b') | |
|
646 | ||
|
642 | 647 | def get_params1(args, kwargs, madExpObj, madWebObj): |
|
643 | 648 | |
|
644 | 649 | expID = getSelection('experiment_list', args, kwargs) |
@@ -649,47 +654,13 def get_params1(args, kwargs, madExpObj, madWebObj): | |||
|
649 | 654 | basename = firsttuple[0] |
|
650 | 655 | fullFilename = os.path.join(expDir, basename) |
|
651 | 656 | f = h5py.File(fullFilename, "r") |
|
652 | data = f[list(f.keys())[0]] | |
|
653 | array = data[list(data.keys())[0]] | |
|
654 | ||
|
655 | param1d = array[list(array.keys())[0]] | |
|
656 | param2d = array[list(array.keys())[1]] | |
|
657 | paramch1d = list(param1d.keys()) | |
|
658 | paramch2d = list(param2d.keys()) | |
|
659 | ||
|
660 | dataparameters = param1d[list(param1d.keys())[0]] | |
|
661 | paramch_mn_bin = list(dataparameters['mnemonic']) | |
|
662 | paramch_bin = list(dataparameters['description']) | |
|
663 | paramch_mn = list() | |
|
664 | paramch = list() | |
|
665 | ||
|
666 | for i in range(len(paramch_bin)): | |
|
667 | paramch_mn.append(paramch_mn_bin[i].decode("utf-8")) | |
|
668 | paramch.append(paramch_bin[i].decode("utf-8")) | |
|
669 | ||
|
670 | choices1d = ['Select parameter'] | |
|
671 | for ch in paramch1d[1:]: | |
|
672 | aux = paramch[paramch_mn.index(ch.upper())] | |
|
673 | choices1d.append(aux) | |
|
674 | ||
|
675 | ||
|
676 | dataparameters = param2d[list(param2d.keys())[0]] | |
|
677 | paramch_mn_bin = list(dataparameters['mnemonic']) | |
|
678 | paramch_mn = list() | |
|
679 | paramch_bin = list(dataparameters['description']) | |
|
680 | paramch = list() | |
|
681 | ||
|
682 | for i in range(len(paramch_bin)): | |
|
683 | paramch_mn.append(paramch_mn_bin[i].decode("utf-8")) | |
|
684 | paramch.append(paramch_bin[i].decode("utf-8")) | |
|
685 | ||
|
686 | choices2d = ['Select parameter'] | |
|
687 | for ch in paramch2d[1:]: | |
|
688 | aux = paramch[paramch_mn.index(ch.upper())] | |
|
689 | choices2d.append(aux) | |
|
690 | ||
|
691 | ||
|
692 | choices = [choices1d,choices2d] | |
|
657 | ||
|
658 | data = f['Data'] | |
|
659 | ||
|
660 | choices1d = [(check_mnemonic(x[0].decode().lower()), x[1].decode()) for x in data['Array Layout']['1D Parameters']['Data Parameters']] | |
|
661 | choices2d = [(check_mnemonic(x[0].decode().lower()), x[1].decode()) for x in data['Array Layout']['2D Parameters']['Data Parameters']] | |
|
662 | choices = [[('0', 'Select Parameter')] + choices1d, [('0', 'Select Parameter')] + choices2d] | |
|
663 | f.close() | |
|
693 | 664 | return choices |
|
694 | 665 | |
|
695 | 666 | |
@@ -704,21 +675,9 def get_params2(args, kwargs, madExpObj, madWebObj): | |||
|
704 | 675 | basename = firsttuple[0] |
|
705 | 676 | fullFilename = os.path.join(expDir, basename) |
|
706 | 677 | f = h5py.File(fullFilename, "r") |
|
707 | ||
|
708 | metadata = f[list(f.keys())[1]] | |
|
709 | table = metadata[list(metadata.keys())[0]] | |
|
710 | param_mn_bin = list(table['mnemonic']) | |
|
711 | param_mn = list() | |
|
712 | for p in param_mn_bin: | |
|
713 | param_mn.append(p.decode("utf")) | |
|
714 | ||
|
715 | index = param_mn.index('UT2_UNIX') | |
|
716 | params = list(table['description']) | |
|
717 | choices = ['Select parameter'] | |
|
718 | for p in params[index+1:]: | |
|
719 | choices.append(p.decode("utf-8")) | |
|
720 | ||
|
721 | return choices | |
|
678 | parameters = [(x[0].decode().lower(), x[1].decode()) for x in f['Metadata']['Data Parameters']] | |
|
679 | f.close() | |
|
680 | return [('0', 'Select Parameter')] + parameters | |
|
722 | 681 | |
|
723 | 682 | |
|
724 | 683 | class SingleExpPlotsSelectionForm(django.forms.Form): |
@@ -750,28 +709,14 class SingleExpPlotsSelectionForm(django.forms.Form): | |||
|
750 | 709 | choices = get_params1(args, kwargs, madExpObj, madWebObj) |
|
751 | 710 | params1d = choices[0] |
|
752 | 711 | params2d = choices[1] |
|
753 | ||
|
754 | index = list(range(len(params1d))) | |
|
755 | paramchoices1d = list(zip(index, params1d)) | |
|
756 | ||
|
757 | ||
|
758 | index = list(range(len(params2d))) | |
|
759 | paramchoices2d = list(zip(index, params2d)) | |
|
760 | ||
|
761 | ||
|
762 | self.fields['param_list2d'] = django.forms.ChoiceField(widget = django.forms.Select(), choices=paramchoices2d, label="2D Parameters", required=False) | |
|
712 | self.fields['param_list1d'] = django.forms.ChoiceField(widget = django.forms.Select(), choices=params1d, label="1D Parameters", required=False) | |
|
713 | self.fields['param_list2d'] = django.forms.ChoiceField(widget = django.forms.Select(), choices=params2d, label="2D Parameters", required=False) | |
|
763 | 714 | |
|
764 | 715 | else: |
|
765 | 716 | params1d = get_params2(args, kwargs, madExpObj, madWebObj) |
|
766 | #if params1d[0] == 'ut2_unix': | |
|
767 | # params1d[0] = 'Select parameter' | |
|
768 | index = list(range(len(params1d))) | |
|
769 | paramchoices1d = list(zip(index, params1d)) | |
|
770 | ||
|
771 | self.fields['param_list1d'] = django.forms.ChoiceField(widget = django.forms.Select(), choices=paramchoices1d, label="1D Parameters", required=False) | |
|
717 | self.fields['param_list1d'] = django.forms.ChoiceField(widget = django.forms.Select(), choices=params1d, label="1D Parameters", required=False) | |
|
772 | 718 | |
|
773 | 719 | |
|
774 | ||
|
775 | 720 | class SingleExpDownloadAsIsForm(django.forms.Form): |
|
776 | 721 | """SingleExpDownloadAsIsForm is a Form class for the download as is field in the Single Experiment interface. |
|
777 | 722 | Use this because its faster to create than the full SingleExpDefaultForm |
@@ -11,6 +11,7 | |||
|
11 | 11 | {% block title %}Show Madrigal experiment{% endblock %} |
|
12 | 12 | |
|
13 | 13 | {% block extra_head %} |
|
14 | <script src="https://cdn.plot.ly/plotly-latest.min.js"></script> | |
|
14 | 15 | <script> |
|
15 | 16 | |
|
16 | 17 | function changeFile (select) { |
@@ -363,8 +363,8 def show_plots(request): | |||
|
363 | 363 | |
|
364 | 364 | def view_plot(request): |
|
365 | 365 | |
|
366 |
param1d = |
|
|
367 |
param2d = |
|
|
366 | param1d = request.GET.get('param1d', 0) | |
|
367 | param2d = request.GET.get('param2d', 0) | |
|
368 | 368 | |
|
369 | 369 | madDB = madrigal.metadata.MadrigalDB() |
|
370 | 370 | madWebObj = madrigal.ui.web.MadrigalWeb(madDB) |
@@ -384,40 +384,22 def view_plot(request): | |||
|
384 | 384 | |
|
385 | 385 | # Get the data |
|
386 | 386 | |
|
387 |
data = f[ |
|
|
387 | data = f['Data'] | |
|
388 | 388 | |
|
389 |
if 'Array Layout' in |
|
|
390 |
array = data[ |
|
|
391 | timestamps = array[list(array.keys())[4]] | |
|
392 | datatime = [datetime.datetime.fromtimestamp(t) for t in list(timestamps)] | |
|
393 | ||
|
394 | range = array[list(array.keys())[3]] | |
|
395 | datarange = list(range) | |
|
396 | ||
|
389 | if 'Array Layout' in data: | |
|
390 | array = data['Array Layout'] | |
|
391 | datatime = [datetime.datetime.fromtimestamp(t) for t in array['timestamps']] | |
|
392 | yrange = array['gdalt'] | |
|
397 | 393 | |
|
398 | 394 | if param1d==0: |
|
399 | parameters_2d = array[list(array.keys())[1]] | |
|
400 | paramname = list(parameters_2d.keys())[param2d] | |
|
401 | param = parameters_2d[list(parameters_2d.keys())[param2d]] | |
|
402 | dataparam = list(param) | |
|
403 | plot = plot_heatmap(datatime,datarange,dataparam,paramname) | |
|
404 | ||
|
395 | plot = plot_heatmap(datatime, yrange, array['2D Parameters'][param2d], param2d) | |
|
405 | 396 | else: |
|
406 | parameters_1d = array[list(array.keys())[0]] | |
|
407 | paramname = list(parameters_1d.keys())[param1d] | |
|
408 | param = parameters_1d[list(parameters_1d.keys())[param1d]] | |
|
409 | dataparam = list(param) | |
|
410 | plot = plot_scatter(datatime,dataparam,paramname) | |
|
397 | plot = plot_scatter(datatime, array['1D Parameters'][param1d], param1d) | |
|
411 | 398 | |
|
412 | 399 | else: |
|
413 |
table = data[ |
|
|
414 | a = list(table.dtype.fields.keys()) | |
|
415 | index = a.index('ut2_unix') | |
|
416 | v = a[index:] | |
|
417 | paramname = v[param1d] | |
|
418 | dataparam = list(table[paramname]) | |
|
419 | datatime = [datetime.datetime.fromtimestamp(t) for t in list(table['ut2_unix'])] | |
|
420 | plot = plot_scatter(datatime,dataparam,paramname) | |
|
400 | table = data['Table Layout'] | |
|
401 | datatime = [datetime.datetime.fromtimestamp(t) for t in table['ut2_unix']] | |
|
402 | plot = plot_scatter(datatime,table[param1d],param1d) | |
|
421 | 403 | |
|
422 | 404 | return HttpResponse(plot) |
|
423 | 405 | |
@@ -468,7 +450,7 def plot_scatter(datatime,dataparam,paramname): | |||
|
468 | 450 | |
|
469 | 451 | |
|
470 | 452 | def plot_heatmap(datatime,datarange,dataparam,paramname): |
|
471 |
if (numpy.isnan(dataparam) |
|
|
453 | if (numpy.all(numpy.isnan(dataparam))): | |
|
472 | 454 | plot = "There is no valid data available for this plot" |
|
473 | 455 | else: |
|
474 | 456 | fig = go.Figure() |
@@ -506,7 +488,7 def plot_heatmap(datatime,datarange,dataparam,paramname): | |||
|
506 | 488 | ]), |
|
507 | 489 | type = "dropdown", |
|
508 | 490 | direction="down", |
|
509 | pad={"r": 10, "t": 10}, | |
|
491 | pad={"r": 10, "t": -10}, | |
|
510 | 492 | showactive=True, |
|
511 | 493 | x=0.1, |
|
512 | 494 | xanchor="left", |
@@ -527,21 +509,22 def plot_heatmap(datatime,datarange,dataparam,paramname): | |||
|
527 | 509 | ), |
|
528 | 510 | ]), |
|
529 | 511 | direction="down", |
|
530 | pad={"r": 10, "t": 10}, | |
|
512 | pad={"r": 10, "t": -10}, | |
|
531 | 513 | showactive=True, |
|
532 | 514 | x=0.32, |
|
533 | 515 | xanchor="left", |
|
534 | 516 | y=1.05, |
|
535 | 517 | yanchor="top" |
|
536 | 518 | ), |
|
519 | ||
|
537 | 520 | ] |
|
538 | 521 | ) |
|
539 | 522 | |
|
540 | 523 | fig.update_layout( |
|
541 | 524 | annotations=[ |
|
542 | 525 | dict(text="Colorscale", showarrow=False, |
|
543 |
x=0, xref="paper", y=1.0 |
|
|
544 |
dict(text="Lines", x=0.25, xref="paper", y=1.0 |
|
|
526 | x=0, xref="paper", y=1.05, yref="paper", align="left"), | |
|
527 | dict(text="Lines", x=0.25, xref="paper", y=1.05, yref="paper", | |
|
545 | 528 | showarrow=False) |
|
546 | 529 | ] |
|
547 | 530 | ) |
General Comments 0
You need to be logged in to leave comments.
Login now