Hockey
from sportypy.surfaces.hockey import HockeyRink
HockeyRink
A subclass of BaseSurfacePlot to make a generic hockey rink.
This allows for the creation of the hockey rink in a way that is entirely parameterized by the rink's baseline characteristics.
All attributes should default to 0.0 (if of a numeric type) or an empty string (if of a string type). Customized parameters may be specified via a child class (see below) or by directly specifying all necessary attributes of a valid hockey rink. The attributes needed to instantiate a particular league's surface must be specified in the rink_params dictionary. For many leagues, these will be provided in the surface_dimensions.json file in the data/ subdirectory of sportypy.
See the BaseSurfacePlot and BaseSurface class definitions for full details.
Attributes
-
league_code(str): The league for which the plot should be drawn. This is case-insensitive but should be the shortened name of the league (e.g. "National Hockey League" should be either "NHL" or "nhl"). The default is an empty string -
rotation(float): The angle (in degrees) through which to rotate the final plot. The default is0.0 -
x_trans(float): The amount that thexcoordinates are to be shifted. By convention, the +xaxis extends from the center of the surface towards the right-hand goal when viewing the rink in TV view. The default is0.0 -
y_trans(float): The amount that theycoordinates are to be shifted. By convention, the +yaxis extends from the center of the surface towards the top of the rink when viewing the rink in TV view. The default is0.0 -
rink_updates(dict): A dictionary of updated parameters to use for the hockey rink. The default is an empty dictionary -
color_updates(dict): A dictionary of coloring parameters to pass to the plot. Defaults are provided in the class per each rule book, but this allows the plot to be more heavily customized/styled. The default is an empty dictionary -
units(str): The units that the final plot should utilize. The default units are the units specified in the rule book of the league. The default is"default" -
rink_params(dict): A dictionary containing the following parameters of the rink:rink_length(float): The full length of the rink. Length is defined as the distance between the inner edge of the boards behind each goal at its widest pointrink_width(float): The full width of the rink. Width is defined as the distance between the inner edge of the boards between the team bench and the penalty box on the other side of the icerink_units(str): The units with which to draw the rinkcorner_radius(float): The radius of the circle that comprises the rink's cornersboard_thickness(float): The thickness of the boards. This is to give the boundary of the rink a clearer-to-see definition, although only the inner edge of the boards is considered in play and the boundary of the rinkreferee_crease_radius(float): The outer radius of the semi-circle that comprises the referee's creasenzone_length(float): The length of the neutral zone, measured from the interior edges of the zone lines (blue lines)goal_line_to_boards(float): Thexposition of the center of the right-hand goal line relative to the boards behind the right-hand goalmajor_line_thickness(float): The thickness of the major lines on the ice surface. Major lines are considered to be the center line (red line) and zone lines (blue lines)minor_line_thickness(float): The thickness of the minor lines on the ice surface. Minor lines are those such as goal lines, hash marks, faceoff markings, or circle thicknessesfaceoff_circle_radius(float): The radius of the faceoff circles, both center and non-center, on the icecenter_faceoff_spot_radius(float): The radius of the center faceoff spot on the icecenter_faceoff_spot_gap(float): The gap in the center line that surrounds the center faceoff spot. This is measured between the inner edges of the two halves of the center linenoncenter_faceoff_spot_radius(float): The radius of the non-centered faceoff spots on the ice. These are in the defensive, neutral, and offensive zonesnzone_faceoff_spot_to_zone_line(float): Thexposition of the right-side faceoff spots in the neutral zone relative to the neutral-zone side of the zone (blue) lineodzone_faceoff_spot_to_boards(float): The distance (in thexdirection) from the end of the rink to the center of the defensive/offensive zone faceoff spotnoncenter_faceoff_spot_y(float): Theyposition of the upper faceoff spots in the defensive, neutral, and offensive zones on the icenoncenter_faceoff_spot_gap_width(float): The gap between the interior edge of a non-centered faceoff spot ring and the stripe running across ithashmark_width(float): The width of the hashmarks on the exterior of the defensive and offensive faceoff circles. Note that width refers to a distance solely in theydirectionhashmark_ext_spacing(float): The exterior horizontal spacing between the hashmarks on the exterior of the defensive and offensive faceoff circles. Note that this is solely in thexdirectionfaceoff_line_dist_x(float): The distance from the center of the defensive and offensive faceoff spot to the left-most edge of the upper-right faceoff linefaceoff_line_dist_y(float): The distance from the center of the defensive and offensive faceoff spot to the bottom edge of the upper-right faceoff linefaceoff_line_length(float): The exterior length of the faceoff linefaceoff_line_width(float): The exterior width of the faceoff linehas_trapezoid(bool): Indicator of whether or not the rink has a goalkeeper's restricted area (trapezoid) behind each goalshort_base_width(float): The exterior base-width of the trapezoid (should it exist) that lies along the goal linelong_base_width(float): The exterior base-width of the trapezoid (should it exist) that lies along the boardsgoal_crease_style(str): The style of goal crease to implement. Viable options are:nhl98(the current iteration of the NHL goal crease.): This is what is used for most professional leaguesnhl92(the previous iteration of an NHL goal crease. It): is drawn as a semi-circle with two L-shaped notches at the edge of the crease intersecting the semi-circleushl1(the current iteration of a USA Hockey goal): crease. This is what is currently used in the USHL (United States Hockey League)
goal_crease_radius(float): The radius of the rounded portion of the goal crease, as taken from the center of the goal linegoal_crease_length(float): The distance from the center of the goal line to the start of the arc of the goal creasegoal_crease_width(float): The exterior width of the goal creasegoal_crease_notch_dist_x(float): The distance from the center of the goal line to the notch (if one exists) in the goal creasegoal_crease_notch_width(float): The width of the notch (if one exists) in the goal creasegoal_mouth_width(float): The interior distance between the goalpostsgoal_back_width(float): The exterior distance between the widest part of the goal frame's footprintgoal_depth(float): The depth of the goal frame from the center of the goal line to the exterior of the back pipe of the goal framegoal_post_diameter(float): The diameter of the posts of the goal framegoal_radius(float): The interior radius of the goal framebench_length(float): The exterior length of a single team's bench areabench_depth(float): The interior depth off the boards of a single team's bench areabench_separation(float): The separation between the two teams' bench areaspenalty_box_length(float): The interior length of a single penalty boxpenalty_box_depth(float): The interior depth off of the boards of a single team's penalty boxpenalty_box_separation(float): The distance that separates each team's penalty box area. This should be equivalent to the length of the off-ice officials' box
Leagues
Each class below is a HockeyRink with that league's rule-book dimensions.
| Class | league_code | Description |
|---|---|---|
AHLRink | ahl | A subclass of HockeyRink specific to the AHL. |
ECHLRink | echl | A subclass of HockeyRink specific to the ECHL. |
IIHFRink | iihf | A subclass of HockeyRink specific to the IIHF. |
PHFRink | phf | A subclass of HockeyRink specific to the PHF. |
NCAARink | ncaa | A subclass of HockeyRink specific to the NCAA. |
NHLRink | nhl | A subclass of HockeyRink specific to the NHL. |
NWHLRink | nwhl | A subclass of HockeyRink specific to the NWHL. |
OHLRink | ohl | A subclass of HockeyRink specific to the OHL. |
QMJHLRink | qmjhl | A subclass of HockeyRink specific to the QMJHL. |
USHLRink | ushl | A subclass of HockeyRink specific to the USHL. |
PWHLRink | pwhl | A subclass of HockeyRink specific to the PWHL. |
Methods
draw
HockeyRink.draw(ax = None, display_range = 'full', xlim = None, ylim = None, rotation = None)
Draw the rink.
Parameters
-
ax(matplotlib.Axes): An axes object onto which the plot can be drawn. IfNoneis supplied, then the currently-active Axes object will be used -
display_range(str): The portion of the surface to display. The entire surface will always be drawn under the hood, however this parameter limits what is shown in the final plot. The following explain what each display range corresponds to:"full": The entire ice surface"in bounds only": The full in-bounds area of the rink"in_bounds_only": The full in-bounds area of the rink"offense": the offensive (TV-right) half of the ice surface"offence": the offensive (TV-right) half of the ice surface"defense": the defensive (TV-left) half of the ice surface"defence": the defensive (TV-left) half of the ice surface"nzone": the neutral zone (the area between the zone lines)"neutral: the neutral zone (the area between the zone lines)"neutral_zone": the neutral zone (the area between the zone lines)"neutral zone": the neutral zone (the area between the zone lines)"ozone": the offensive zone. This is the area (TV-right) of the neutral zone"offensive_zone: the offensive zone. This is the area (TV-right) of the neutral zone"offensive zone: the offensive zone. This is the area (TV-right) of the neutral zone"attacking_zone: the offensive zone. This is the area (TV-right) of the neutral zone"attacking zone: the offensive zone. This is the area (TV-right) of the neutral zone"dzone: the defensive zone. This is the area (TV-left) of the neutral zone"defensive_zone: the defensive zone. This is the area (TV-left) of the neutral zone"defensive zone: the defensive zone. This is the area (TV-left) of the neutral zone"defending_zone: the defensive zone. This is the area (TV-left) of the neutral zone"defending zone: the defensive zone. This is the area (TV-left) of the neutral zone
The default is
"full" -
xlim(float or tuple of floats or None): The display range in thexdirection to be used. If a single float is provided, this will be used as the lower bound of thexcoordinates to display and the upper bound will be the +xend of the boards. If a tuple, the two values will be used to determine the bounds. IfNone, then thedisplay_rangewill be used instead to set the bounds. The default isNone -
ylim(float or tuple of floats or None): The display range in theydirection to be used. If a single float is provided, this will be used as the lower bound of theycoordinates to display and the upper bound will be the +yside of the rink. If a tuple, the two values will be used to determine the bounds. IfNone, then the display_rangewillbe used instead to set the bounds. The default isNone -
rotation(float or None): Angle (in degrees) through which to rotate the rink when drawing. If used, this will set the class attribute of_rotation. A value of0.0will correspond to a TV view of the rink, where +xis to the right and +yis on top. The rotation occurs counter clockwise. The default isNone
cani_plot_leagues
HockeyRink.cani_plot_leagues(league_code = None)
Show if a league can be plotted, or what leagues are pre-defined.
A user may wish to know if a specific curling league can be plotted. This method allows a user to check if that specific league code comes shipped with sportypy for easier plotting (if they provide the league code), or can also show what leagues are available to be plotted
Parameters
league_code(str or None): A league code that may or may not be shipped with the package. If the league code isNone, this will display all leagues that do come shipped withsportypy. The default isNone
Returns
Nothing, but a message will be printed out:
cani_color_features
HockeyRink.cani_color_features()
Determine what features of the rink can be colored.
This function is a helper function for the user to aid in plot styling and customization. The printed result of this method will be the names of the features that are able to be colored
Returns
Nothing, but a message will be printed out:
cani_change_dimensions
HockeyRink.cani_change_dimensions()
Determine what features of the rink can be re-parameterized.
This function is a helper function for the user to aid in customizing a rink's parameters. The printed result of this method will be the names of the features that are able to be reparameterized. This method is also useful when defining new features and using an existing league's rink dimensions as a starting point
Returns
Nothing, but a message will be printed out:
update_colors
HockeyRink.update_colors(color_updates = {}, *args, **kwargs)
Update the colors currently used in the plot.
The colors can be passed at the initial instantiation of the class via the color_updates parameter, but this method allows the colors to be updated after the initial instantiation and will re-instantiate the class with the new colors
Parameters
color_updates(dict): A dictionary where the keys correspond to the name of the feature that's color is to be updated (seecani_color_features()method for a list of these names). The default is an empty dictionary
Returns
Nothing, but the class is re-instantiated with the updated colors:
update_rink_params
HockeyRink.update_rink_params(rink_param_updates = {}, *args, **kwargs)
Update the rink's defining parameters.
This method should primarily be used in cases when plotting a league not currently supported by sportypy
Parameters
rink_updates(dict): A dictionary where the keys correspond to the name of the parameter of the rink that is to be updated (seecani_change_dimensions()method for a list of these parameters). The default is an empty dictionary
Returns
Nothing, but the class is re-instantiated with the updated parameters:
reset_colors
HockeyRink.reset_colors()
Reset the features of the rink to their default color set.
The colors can be passed at the initial instantiation of the class via the color_updates parameter, and through the update_colors() method, these can be changed. This method allows the colors to be reset to their default values after experiencing such a change
reset_rink_params
HockeyRink.reset_rink_params()
Reset the features of the rink to their default parameterizations.
The rink parameters can be passed at the initial instantiation of the class via the rink_updates parameter, and through the update_rink_params() method, these can be changed. This method allows the feature parameterization to be reset to their default values after experiencing such a change