PlotObs#
- class metpy.plots.PlotObs(**kwargs: Any)#
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)
Attributes Summary
List of the scalar and symbol field colors.
A contextmanager for running a block with our cross validation lock set to True.
Pandas dataframe that contains the fields to be plotted.
Name of the scalar or symbol fields to be plotted.
An integer value to set the font size of station plots.
List of the scalar, symbol, and text field data formats.
The level of the field to be plotted.
List of strings for scalar or symbol field plotting locations.
Generate a name for the plot.
Return the internal cached data.
A trait whose value must be an instance of a specified class.
A list of the desired units to plot the fields in.
Return the data for plotting.
Float to reduce number of points plotted.
Set the valid time to be plotted as a datetime object.
Set a range to look for data to plot as a timedelta object.
List of the vector field to be plotted.
String color name to plot the vector.
Integer value to set the length of the plotted vector.
The desired units to plot the vector field in.
Methods Summary
__init__
(*args, **kwargs)add_traits
(**traits)Dynamically add trait attributes to the HasTraits instance.
class_own_trait_events
(name)Get a dict of all event handlers defined on this class, not a parent.
class_own_traits
(**metadata)Get a dict of all the traitlets defined on this class, not a parent.
class_trait_names
(**metadata)Get a list of all the names of this class' traits.
class_traits
(**metadata)Get a
dict
of all the traits of this class.clear
()Clear the plot.
copy
()Return a copy of the plot.
draw
()Draw the plot.
has_trait
(name)Returns True if the object has a trait with the specified name.
Context manager for bundling trait change notifications and cross validation.
notify_change
(change)Notify observers of a change event
observe
(handler[, names, type])Setup a handler to be called when a trait changes.
on_trait_change
([handler, name, remove])DEPRECATED: Setup a handler to be called when a trait changes.
set_trait
(name, value)Forcibly sets trait attribute, including read-only attributes.
setup_instance
(**kwargs)This is called before self.__init__ is called.
trait_defaults
(*names, **metadata)Return a trait's default value or a dictionary of them
trait_events
([name])Get a
dict
of all the event handlers of this class.trait_has_value
(name)Returns True if the specified trait has a value.
trait_metadata
(traitname, key[, default])Get metadata values for trait by key.
trait_names
(**metadata)Get a list of all the names of this class' traits.
trait_values
(**metadata)A
dict
of trait names and their values.traits
(**metadata)Get a
dict
of all the traits of this class.unobserve
(handler[, names, type])Remove a trait change handler.
unobserve_all
([name])Remove trait change handlers of any type for the specified name.
Attributes Documentation
- colors#
List of the scalar and symbol field colors.
List of strings that represent the colors to be used for the variable being plotted. (optional)
- cross_validation_lock#
A contextmanager for running a block with our cross validation lock set to True.
At the end of the block, the lock’s value is restored to its value prior to entering the block.
- data#
Pandas dataframe that contains the fields to be plotted.
- fields#
Name of the scalar or symbol fields to be plotted.
List of parameters to be plotted around station plot (e.g., temperature, dewpoint, skyc).
- fontsize#
An integer value to set the font size of station plots. Default is 10 pt.
- formats#
List of the scalar, symbol, and text field data formats. (optional)
List of scalar parameters formatters or mapping values (if symbol) for plotting text and/or symbols around the station plot (e.g., for pressure variable
`lambda v: format(10 * v, '.0f')[-3:]`
).For symbol mapping the following options are available to be put in as a string: current_weather, sky_cover, low_clouds, mid_clouds, high_clouds, and pressure_tendency.
For plotting text, use the format setting of ‘text’.
- level#
The level of the field to be plotted.
This is a value with units to choose the desired plot level. For example, selecting the 850-hPa level, set this parameter to
850 * units.hPa
. For surface data, parameter must be set to None.
- locations#
List of strings for scalar or symbol field plotting locations.
List of parameters locations for plotting parameters around the station plot (e.g., NW, NE, SW, SE, W, C). (optional)
- name#
Generate a name for the plot.
- obsdata#
Return the internal cached data.
- parent#
A trait whose value must be an instance of a specified class.
The value can also be an instance of a subclass of the specified class.
Subclasses can declare default classes by overriding the klass attribute
- plot_units#
A list of the desired units to plot the fields in.
Setting this attribute will convert the units of the field variable to the given units for plotting using the MetPy Units module, provided that units are attached to the DataFrame.
- plotdata#
Return the data for plotting.
The data arrays, x coordinates, and y coordinates.
- reduce_points#
Float to reduce number of points plotted. (optional)
- time#
Set the valid time to be plotted as a datetime object.
If a forecast hour is to be plotted the time should be set to the valid future time, which can be done using the
datetime
andtimedelta
objects from the Python standard library.
- time_window#
Set a range to look for data to plot as a timedelta object.
If this parameter is set, it will subset the data provided to be within the time and plus or minus the range value given. If there is more than one observation from a given station then it will keep only the most recent one for plotting purposes. Default value is to have no range. (optional)
- vector_field#
List of the vector field to be plotted.
List of vector components to combined and plotted from the center of the station plot (e.g., wind components). (optional)
- vector_field_color#
String color name to plot the vector. (optional)
- vector_field_length#
Integer value to set the length of the plotted vector. (optional)
- vector_plot_units#
The desired units to plot the vector field in.
Setting this attribute will convert the units of the field variable to the given units for plotting using the MetPy Units module, provided that units are attached to the DataFrame.
Methods Documentation
- __init__(*args, **kwargs)#
- add_traits(**traits)#
Dynamically add trait attributes to the HasTraits instance.
- classmethod class_own_trait_events(name)#
Get a dict of all event handlers defined on this class, not a parent.
Works like
event_handlers
, except for excluding traits from parents.
- classmethod class_own_traits(**metadata)#
Get a dict of all the traitlets defined on this class, not a parent.
Works like
class_traits
, except for excluding traits from parents.
- classmethod class_trait_names(**metadata)#
Get a list of all the names of this class’ traits.
This method is just like the
trait_names()
method, but is unbound.
- classmethod class_traits(**metadata)#
Get a
dict
of all the traits of this class. The dictionary is keyed on the name and the values are the TraitType objects.This method is just like the
traits()
method, but is unbound.The TraitTypes returned don’t know anything about the values that the various HasTrait’s instances are holding.
The metadata kwargs allow functions to be passed in which filter traits based on metadata values. The functions should take a single value as an argument and return a boolean. If any function returns False, then the trait is not included in the output. If a metadata key doesn’t exist, None will be passed to the function.
- has_trait(name)#
Returns True if the object has a trait with the specified name.
- hold_trait_notifications()#
Context manager for bundling trait change notifications and cross validation.
Use this when doing multiple trait assignments (init, config), to avoid race conditions in trait notifiers requesting other trait values. All trait notifications will fire after all values have been assigned.
- notify_change(change)#
Notify observers of a change event
- observe(handler, names=traitlets.All, type='change')#
Setup a handler to be called when a trait changes.
This is used to setup dynamic notifications of trait changes.
- Parameters
handler (callable) – A callable that is called when a trait changes. Its signature should be
handler(change)
, wherechange
is a dictionary. The change dictionary at least holds a ‘type’ key. *type
: the type of notification. Other keys may be passed depending on the value of ‘type’. In the case where type is ‘change’, we also have the following keys: *owner
: the HasTraits instance *old
: the old value of the modified trait attribute *new
: the new value of the modified trait attribute *name
: the name of the modified trait attribute.names (list, str, All) – If names is All, the handler will apply to all traits. If a list of str, handler will apply to all names in the list. If a str, the handler will apply just to that name.
type (str, All (default: 'change')) – The type of notification to filter by. If equal to All, then all notifications are passed to the observe handler.
- on_trait_change(handler=None, name=None, remove=False)#
DEPRECATED: Setup a handler to be called when a trait changes.
This is used to setup dynamic notifications of trait changes.
Static handlers can be created by creating methods on a HasTraits subclass with the naming convention ‘_[traitname]_changed’. Thus, to create static handler for the trait ‘a’, create the method _a_changed(self, name, old, new) (fewer arguments can be used, see below).
If remove is True and handler is not specified, all change handlers for the specified name are uninstalled.
- Parameters
handler (callable, None) – A callable that is called when a trait changes. Its signature can be handler(), handler(name), handler(name, new), handler(name, old, new), or handler(name, old, new, self).
name (list, str, None) – If None, the handler will apply to all traits. If a list of str, handler will apply to all names in the list. If a str, the handler will apply just to that name.
remove (bool) – If False (the default), then install the handler. If True then unintall it.
- set_trait(name, value)#
Forcibly sets trait attribute, including read-only attributes.
- setup_instance(**kwargs)#
This is called before self.__init__ is called.
- trait_defaults(*names, **metadata)#
Return a trait’s default value or a dictionary of them
Notes
Dynamically generated default values may depend on the current state of the object.
- classmethod trait_events(name=None)#
Get a
dict
of all the event handlers of this class.- Parameters
name (str (default: None)) – The name of a trait of this class. If name is
None
then all the event handlers of this class will be returned instead.- Returns
The event handlers associated with a trait name, or all event handlers.
- trait_has_value(name)#
Returns True if the specified trait has a value.
This will return false even if
getattr
would return a dynamically generated default value. These default values will be recognized as existing only after they have been generated.Example
class MyClass(HasTraits): i = Int() mc = MyClass() assert not mc.trait_has_value("i") mc.i # generates a default value assert mc.trait_has_value("i")
- trait_metadata(traitname, key, default=None)#
Get metadata values for trait by key.
- trait_names(**metadata)#
Get a list of all the names of this class’ traits.
- trait_values(**metadata)#
A
dict
of trait names and their values.The metadata kwargs allow functions to be passed in which filter traits based on metadata values. The functions should take a single value as an argument and return a boolean. If any function returns False, then the trait is not included in the output. If a metadata key doesn’t exist, None will be passed to the function.
- Returns
A
dict
of trait names and their values.
Notes
Trait values are retrieved via
getattr
, any exceptions raised by traits or the operations they may trigger will result in the absence of a trait value in the resultdict
.
- traits(**metadata)#
Get a
dict
of all the traits of this class. The dictionary is keyed on the name and the values are the TraitType objects.The TraitTypes returned don’t know anything about the values that the various HasTrait’s instances are holding.
The metadata kwargs allow functions to be passed in which filter traits based on metadata values. The functions should take a single value as an argument and return a boolean. If any function returns False, then the trait is not included in the output. If a metadata key doesn’t exist, None will be passed to the function.
- unobserve(handler, names=traitlets.All, type='change')#
Remove a trait change handler.
This is used to unregister handlers to trait change notifications.
- Parameters
handler (callable) – The callable called when a trait attribute changes.
names (list, str, All (default: All)) – The names of the traits for which the specified handler should be uninstalled. If names is All, the specified handler is uninstalled from the list of notifiers corresponding to all changes.
type (str or All (default: 'change')) – The type of notification to filter by. If All, the specified handler is uninstalled from the list of notifiers corresponding to all types.
- unobserve_all(name=traitlets.All)#
Remove trait change handlers of any type for the specified name. If name is not specified, removes all trait notifiers.