Unidata / MetPy

MetPy is a collection of tools in Python for reading, visualizing and performing calculations with weather data.
https://unidata.github.io/MetPy/
BSD 3-Clause "New" or "Revised" License
1.25k stars 416 forks source link

Declarative Plotting Interface Improvements #1016

Open jrleeman opened 5 years ago

jrleeman commented 5 years ago

After using the declarative plotting interface in some examples, here are some suggestions for improvements to the declarative plotting interface. I'd propose that this is a 'living issue' and contributed to by any and all with individual issues/PRs being raised as this wish list is addressed.

kgoebber commented 5 years ago

I've played a bit with the declarative syntax and here are some of the things that would be nice to have incorporated. Some easier than others, but want to document them here.

dopplershift commented 5 years ago

Documentation can be improved by:

  1. Writing non-crappy docstrings for the properties--I just didn't think about them being user-facing when I wrote them.

  2. Can attach documentation to traitlets:

    class Plot2D(HasTraits):
    field = Unicode()
    field.__doc__ = """Name of field to plot
    
    More documentation about field.
    """

    this would override the documentation that's built-in. Unfortunately, as noted in ipython/traitlets#461, providing the help parameter to the Trait constructor does not help the sphinx docs. The solution there about putting triple-quoted string also only works for the class where the trait is defined--subclasses revert back to the regular Trait documentation.

sgdecker commented 3 years ago

I see a checkmark next to "Improve documentation of trait settings..." above, but when I try this in a notebook:

from metpy.plots.declarative import PlotObs
obs = PlotObs()
obs?

I get:

Type:        PlotObs
String form: <metpy.plots.PlotObs object at 0x7fc850162e50>
File:        ~/local/miniconda3/envs/met433/lib/python3.9/site-packages/metpy/plots/__init__.py
Docstring:  
The highest level class related to plotting observed surface and upperair data.

This class collects all common methods no matter whether plotting a upper-level or
surface data using station plots.

List of Traits:
  * level
  * time
  * fields
  * locations (optional)
  * time_window (optional)
  * formats (optional)
  * colors (optional)
  * plot_units (optional)
  * vector_field (optional)
  * vector_field_color (optional)
  * vector_field_length (optional)
  * vector_plot_units (optional)
  * reduce_points (optional)
  * fontsize (optional)

Ideally, each trait would have a one-line definition included (similar to what you see when you first run, say, sfmap)

Then, trying obs.time? produces:

Type:        NoneType
String form: None
Docstring:   <no docstring>

until I define it. Then I get:

Type:        datetime
String form: 2021-08-10 12:00:00
File:        ~/local/miniconda3/envs/met433/lib/python3.9/datetime.py
Docstring:  
datetime(year, month, day[, hour[, minute[, second[, microsecond[,tzinfo]]]]])

The year, month and day arguments are required. tzinfo may be None, or an
instance of a tzinfo subclass. The remaining arguments may be ints.

which is more informative, but presents something of a bootstrap problem to the user, as you don't necessarily know how to define a trait w/o the documentation in the first place. In GEMPAK, I can do (p)help dattim whether I've set that parameter to anything or not. Yes, you can go to documentation in another browser tab, but it does reduce the introspection some.

sgdecker commented 3 years ago

To be more specific, the documentation here is great: https://unidata.github.io/MetPy/latest/api/generated/metpy.plots.PlotObs.html#metpy.plots.PlotObs

The Attributes Summary is basically what I'm looking to be included in the output of ? in the notebook (and note the list of attributes is a superset of the list of traits that appears now).

Actually, doing help(obs) is pretty comprehensive, but the ordering is a bit strange (from a newbie/student perspective) and is a bit excessive in terms of exposing a lot of internals that 99% of users don't need to know.

Maybe what we have is the best it can be, but there is a bit of friction here.

sgdecker commented 3 years ago

It looks like #2016 may address some of this, but looking through the traitlets documentation, I wonder if adding @default functions would address my main issue, so that typing obs.time? would generate documentation even before obs.time is set to some value by the user.

I might play around with this and see what happens.

dopplershift commented 3 years ago

If you come up with any leads on things that help address the shortcomings you're running into, we're happy to take a look.

sgdecker commented 3 years ago

I don't think I see this one above:

1691 is related.

dopplershift commented 3 years ago

@kgoebber I know we talked about coloring map layers before, and now I don't remember where we ended up. I have a fuzzy inkling around "I don't want to add a ton of styling traits..."

kgoebber commented 3 years ago

Yes, I think we want to be choosy, but I think adding a layer_color trait is one that would be worth it…relatively low hanging fruit for quite a bit of gain, especially if plotting satellite data.

-- Kevin Goebbert, Ph.D. Associate Professor of Meteorology Kallay-Christopher Hall, 201-F 1809 Chapel Drive Valparaiso, IN 46383 (219) 464-5517 fax: (219) 548-7738 https://kevingoebbert.youcanbook.me/ On Aug 24, 2021, 3:37 PM -0500, Ryan May @.***>, wrote:

@kgoebber I know we talked about coloring map layers before, and now I don't remember where we ended up. I have a fuzzy inkling around "I don't want to add a ton of styling traits..." — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

sgdecker commented 3 years ago

I know there are ways to accomplish this when using matplotlib directly, but I haven't discovered a way to achieve the same effect with the declarative interface.

Level Value Displayed as
850 1504 504
700 3010 010
500 5524 552
300 9001 900
200 12346 235
dopplershift commented 2 years ago

@sgdecker #2425 gives control to map feature color/linewidth.

sgdecker commented 1 year ago

[ ] When #1689 is solved, add an attribute that ties into the max/min plotting (akin to the GEMPAK HILO parameter).

kgoebber commented 1 year ago

@sgdecker Yes, I think that would be good to do. I do have some code that finds extrema and is in a couple of the examples on the old gallery site, but I need to refine it and make the contribution.