@@ -639,6 +639,11 class SingleExpPlotsForm(django.forms.Form): | |||||
639 | required=False) |
|
639 | required=False) | |
640 |
|
640 | |||
641 | '''get_params2 retrieves a list of 1d and 2d parameters of type 1 hdf5 files''' |
|
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 | def get_params1(args, kwargs, madExpObj, madWebObj): |
|
647 | def get_params1(args, kwargs, madExpObj, madWebObj): | |
643 |
|
648 | |||
644 | expID = getSelection('experiment_list', args, kwargs) |
|
649 | expID = getSelection('experiment_list', args, kwargs) | |
@@ -649,47 +654,13 def get_params1(args, kwargs, madExpObj, madWebObj): | |||||
649 | basename = firsttuple[0] |
|
654 | basename = firsttuple[0] | |
650 | fullFilename = os.path.join(expDir, basename) |
|
655 | fullFilename = os.path.join(expDir, basename) | |
651 | f = h5py.File(fullFilename, "r") |
|
656 | f = h5py.File(fullFilename, "r") | |
652 | data = f[list(f.keys())[0]] |
|
657 | ||
653 | array = data[list(data.keys())[0]] |
|
658 | data = f['Data'] | |
654 |
|
659 | |||
655 | param1d = array[list(array.keys())[0]] |
|
660 | choices1d = [(check_mnemonic(x[0].decode().lower()), x[1].decode()) for x in data['Array Layout']['1D Parameters']['Data Parameters']] | |
656 | param2d = array[list(array.keys())[1]] |
|
661 | choices2d = [(check_mnemonic(x[0].decode().lower()), x[1].decode()) for x in data['Array Layout']['2D Parameters']['Data Parameters']] | |
657 | paramch1d = list(param1d.keys()) |
|
662 | choices = [[('0', 'Select Parameter')] + choices1d, [('0', 'Select Parameter')] + choices2d] | |
658 | paramch2d = list(param2d.keys()) |
|
663 | f.close() | |
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] |
|
|||
693 | return choices |
|
664 | return choices | |
694 |
|
665 | |||
695 |
|
666 | |||
@@ -704,21 +675,9 def get_params2(args, kwargs, madExpObj, madWebObj): | |||||
704 | basename = firsttuple[0] |
|
675 | basename = firsttuple[0] | |
705 | fullFilename = os.path.join(expDir, basename) |
|
676 | fullFilename = os.path.join(expDir, basename) | |
706 | f = h5py.File(fullFilename, "r") |
|
677 | f = h5py.File(fullFilename, "r") | |
707 |
|
678 | parameters = [(x[0].decode().lower(), x[1].decode()) for x in f['Metadata']['Data Parameters']] | ||
708 | metadata = f[list(f.keys())[1]] |
|
679 | f.close() | |
709 | table = metadata[list(metadata.keys())[0]] |
|
680 | return [('0', 'Select Parameter')] + parameters | |
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 |
|
|||
722 |
|
681 | |||
723 |
|
682 | |||
724 | class SingleExpPlotsSelectionForm(django.forms.Form): |
|
683 | class SingleExpPlotsSelectionForm(django.forms.Form): | |
@@ -750,28 +709,14 class SingleExpPlotsSelectionForm(django.forms.Form): | |||||
750 | choices = get_params1(args, kwargs, madExpObj, madWebObj) |
|
709 | choices = get_params1(args, kwargs, madExpObj, madWebObj) | |
751 | params1d = choices[0] |
|
710 | params1d = choices[0] | |
752 | params2d = choices[1] |
|
711 | params2d = choices[1] | |
753 |
|
712 | self.fields['param_list1d'] = django.forms.ChoiceField(widget = django.forms.Select(), choices=params1d, label="1D Parameters", required=False) | ||
754 | index = list(range(len(params1d))) |
|
713 | self.fields['param_list2d'] = django.forms.ChoiceField(widget = django.forms.Select(), choices=params2d, label="2D Parameters", required=False) | |
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) |
|
|||
763 |
|
714 | |||
764 | else: |
|
715 | else: | |
765 | params1d = get_params2(args, kwargs, madExpObj, madWebObj) |
|
716 | params1d = get_params2(args, kwargs, madExpObj, madWebObj) | |
766 | #if params1d[0] == 'ut2_unix': |
|
717 | self.fields['param_list1d'] = django.forms.ChoiceField(widget = django.forms.Select(), choices=params1d, label="1D Parameters", required=False) | |
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) |
|
|||
772 |
|
718 | |||
773 |
|
719 | |||
774 |
|
||||
775 | class SingleExpDownloadAsIsForm(django.forms.Form): |
|
720 | class SingleExpDownloadAsIsForm(django.forms.Form): | |
776 | """SingleExpDownloadAsIsForm is a Form class for the download as is field in the Single Experiment interface. |
|
721 | """SingleExpDownloadAsIsForm is a Form class for the download as is field in the Single Experiment interface. | |
777 | Use this because its faster to create than the full SingleExpDefaultForm |
|
722 | Use this because its faster to create than the full SingleExpDefaultForm |
@@ -11,6 +11,7 | |||||
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> |
|
15 | <script> | |
15 |
|
16 | |||
16 | function changeFile (select) { |
|
17 | function changeFile (select) { |
@@ -363,8 +363,8 def show_plots(request): | |||||
363 |
|
363 | |||
364 | def view_plot(request): |
|
364 | def view_plot(request): | |
365 |
|
365 | |||
366 |
param1d = |
|
366 | param1d = request.GET.get('param1d', 0) | |
367 |
param2d = |
|
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) | |
@@ -384,40 +384,22 def view_plot(request): | |||||
384 |
|
384 | |||
385 | # Get the data |
|
385 | # Get the data | |
386 |
|
386 | |||
387 |
data = f[ |
|
387 | data = f['Data'] | |
388 |
|
388 | |||
389 |
if 'Array Layout' in |
|
389 | if 'Array Layout' in data: | |
390 |
array = data[ |
|
390 | array = data['Array Layout'] | |
391 | timestamps = array[list(array.keys())[4]] |
|
391 | datatime = [datetime.datetime.fromtimestamp(t) for t in array['timestamps']] | |
392 | datatime = [datetime.datetime.fromtimestamp(t) for t in list(timestamps)] |
|
392 | yrange = array['gdalt'] | |
393 |
|
||||
394 | range = array[list(array.keys())[3]] |
|
|||
395 | datarange = list(range) |
|
|||
396 |
|
||||
397 |
|
393 | |||
398 | if param1d==0: |
|
394 | if param1d==0: | |
399 | parameters_2d = array[list(array.keys())[1]] |
|
395 | plot = plot_heatmap(datatime, yrange, array['2D Parameters'][param2d], param2d) | |
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 |
|
||||
405 | else: |
|
396 | else: | |
406 | parameters_1d = array[list(array.keys())[0]] |
|
397 | plot = plot_scatter(datatime, array['1D Parameters'][param1d], param1d) | |
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) |
|
|||
411 |
|
398 | |||
412 | else: |
|
399 | else: | |
413 |
table = data[ |
|
400 | table = data['Table Layout'] | |
414 | a = list(table.dtype.fields.keys()) |
|
401 | datatime = [datetime.datetime.fromtimestamp(t) for t in table['ut2_unix']] | |
415 | index = a.index('ut2_unix') |
|
402 | plot = plot_scatter(datatime,table[param1d],param1d) | |
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) |
|
|||
421 |
|
403 | |||
422 | return HttpResponse(plot) |
|
404 | return HttpResponse(plot) | |
423 |
|
405 | |||
@@ -468,7 +450,7 def plot_scatter(datatime,dataparam,paramname): | |||||
468 |
|
450 | |||
469 |
|
451 | |||
470 | def plot_heatmap(datatime,datarange,dataparam,paramname): |
|
452 | def plot_heatmap(datatime,datarange,dataparam,paramname): | |
471 |
if (numpy.isnan(dataparam) |
|
453 | if (numpy.all(numpy.isnan(dataparam))): | |
472 | plot = "There is no valid data available for this plot" |
|
454 | plot = "There is no valid data available for this plot" | |
473 | else: |
|
455 | else: | |
474 | fig = go.Figure() |
|
456 | fig = go.Figure() | |
@@ -506,7 +488,7 def plot_heatmap(datatime,datarange,dataparam,paramname): | |||||
506 | ]), |
|
488 | ]), | |
507 | type = "dropdown", |
|
489 | type = "dropdown", | |
508 | direction="down", |
|
490 | direction="down", | |
509 | pad={"r": 10, "t": 10}, |
|
491 | pad={"r": 10, "t": -10}, | |
510 | showactive=True, |
|
492 | showactive=True, | |
511 | x=0.1, |
|
493 | x=0.1, | |
512 | xanchor="left", |
|
494 | xanchor="left", | |
@@ -527,21 +509,22 def plot_heatmap(datatime,datarange,dataparam,paramname): | |||||
527 | ), |
|
509 | ), | |
528 | ]), |
|
510 | ]), | |
529 | direction="down", |
|
511 | direction="down", | |
530 | pad={"r": 10, "t": 10}, |
|
512 | pad={"r": 10, "t": -10}, | |
531 | showactive=True, |
|
513 | showactive=True, | |
532 | x=0.32, |
|
514 | x=0.32, | |
533 | xanchor="left", |
|
515 | xanchor="left", | |
534 | y=1.05, |
|
516 | y=1.05, | |
535 | yanchor="top" |
|
517 | yanchor="top" | |
536 | ), |
|
518 | ), | |
|
519 | ||||
537 | ] |
|
520 | ] | |
538 | ) |
|
521 | ) | |
539 |
|
522 | |||
540 | fig.update_layout( |
|
523 | fig.update_layout( | |
541 | annotations=[ |
|
524 | annotations=[ | |
542 | dict(text="Colorscale", showarrow=False, |
|
525 | dict(text="Colorscale", showarrow=False, | |
543 |
x=0, xref="paper", y=1.0 |
|
526 | x=0, xref="paper", y=1.05, yref="paper", align="left"), | |
544 |
dict(text="Lines", x=0.25, xref="paper", y=1.0 |
|
527 | dict(text="Lines", x=0.25, xref="paper", y=1.05, yref="paper", | |
545 | showarrow=False) |
|
528 | showarrow=False) | |
546 | ] |
|
529 | ] | |
547 | ) |
|
530 | ) |
General Comments 0
You need to be logged in to leave comments.
Login now