SuperDARN / pydarn

Python library for visualizing SuperDARN Data
GNU Lesser General Public License v3.0
31 stars 11 forks source link

EHN: Flexibility on Plotting Summary Plot Variables #400

Closed carleyjmartin closed 1 month ago

carleyjmartin commented 1 month ago

Scope

Following on from #399 Integrated code into the summary plot method to allow user to print a subset of the allowed vector parameters (user requested)

Approval

Number of approvals: 1

Test

matplotlib version: 3.9.1 Note testers: please indicate what version of matplotlib you are using

import matplotlib.pyplot as plt 
import pydarn
import datetime as dt

# Normal data and data that doesnt contain elv anyway so automatically doesn't plot that
files = ["/Users/carley/Documents/data/20211102.0000.00.rkn.a.fitacf",
        "/Users/carley/Documents/data/20231122.0402.00.fhe.fitacf"]

for file in files:
    SDarn_read = pydarn.SuperDARNRead(file)
    fitacf_data = SDarn_read.read_fitacf()

    # Single non list value
    a = pydarn.RTP.plot_summary(fitacf_data, beam_num=5, vector_parameters='v')
    plt.show()

    # This example should raise an error
    #a = pydarn.RTP.plot_summary(fitacf_data, beam_num=5, vector_parameters=['elv', 'vel'])
    #plt.show()

    # Elevation first
    a = pydarn.RTP.plot_summary(fitacf_data, beam_num=5, vector_parameters=['elv', 'v'])
    plt.show()

    # Only v in list
    a = pydarn.RTP.plot_summary(fitacf_data, beam_num=5, vector_parameters=['v'])
    plt.show()

    # Random other example
    a = pydarn.RTP.plot_summary(fitacf_data, beam_num=5, vector_parameters=['v', 'elv', 'p_l'])
    plt.show()

    # Default
    a = pydarn.RTP.plot_summary(fitacf_data, beam_num=5)
    plt.show()

Should all plot a summary plot with the given variables in the order given. I used RKN data for normal data and FHE data to test here to show what would happen if there isn't elevation data anyway (it will just not pot elevation if you ask for it, how it works now).

Doreban commented 1 month ago

Testing on Windows 10, matplotlib version 3.9.1

Summary plots are generated showing only the parameters requested in vector_parameters. My only comment is this now leaves a figure with a fair bit of white space if only plotting a single parameter. Is it possible to adjust the figure size based on how many parameters are in vector parameters?

summary_plot_1param summary_plot_2param summary_plot_all_param

If elevation isn't present in the data, no elevation plot is created as is standard summary plot behaviour. However, since its now possible to be plotting only elevation (passing only 'elv' to vector_parameters, the summary plot now crashes if there is no elevation data with the following traceback:

Traceback (most recent call last):
  File "C:\Users\Dragon\PycharmProjects\pydarn_dev\test_pr400_flexible_summary_plots.py", line 21, in <module>
    a = pydarn.RTP.plot_summary(fitacf_data, beam_num=5, vector_parameters=['elv'])
  File "C:\Users\Dragon\PycharmProjects\pydarn_dev\.venv\lib\site-packages\pydarn\plotting\rtp.py", line 1303, in plot_summary
    plt.title(cls.__generate_title(x[0], x[-1], beam_num,
UnboundLocalError: local variable 'x' referenced before assignment

If you pass in an invalid vector parameter, you get the following exception as expected: Exception: Summary plots allow plotting of the following vector parameters only: v (velocity), p_l (Signal to noise ratio), w_l (spectral width), elv (elevation).

carleyjmartin commented 1 month ago

Thanks Draven, the solution to the white space issue could be cleaner (left note for future work), but I think it's not crazy for the default number of parameters to work with the default figsize, and the user has control over figsize too if they choose to plot less parameters they can make the plot smaller in height themselves - rather than restricting figsize in the code which might give some people issues.

Doreban commented 1 month ago

Second crack of tests:

Now if there is no elevation and that was the only parameter requested we get the following exception:

Exception: The summary plot needs a list of vector parameters to plot. The file you have chosen to plot may not have elevation data. Summary plots allow plotting of the following vector parameters: v (velocity), p_l (Signal to noise ratio), w_l (spectral width), elv (elevation).

If a list is not passed in as the input to vector_parameters we now get the following exception:

Exception: The summary plot needs a formatted list of vector parameters to plot. E.G. ["v", "p_l"]. Summary plots allow plotting of the following vector parameters: v (velocity), p_l (Signal to noise ratio), w_l (spectral width), elv (elevation).

Additionally, now if not all parameters are plotted there is less extra white space: summary_reduced_whitespace

Also changing the figsize doesn't break anything.