Hockey#

Hockey is currently supported for the following leagues (in alphabetical order):

Extension of the BaseSurfacePlot class to create a hockey rink.

This is a second-level child class of the BaseSurface class, and as such will have access to its attributes and methods. sportypy will ship with pre- defined leagues that will have their own subclass, but a user can manually specify their own rink parameters to create a totally-customized rink. The rink’s features are parameterized by the basic dimensions of the rink, which comprise the attributes of the class.

@author: Ross Drucker

class sportypy.surfaces.hockey.HockeyRink(league_code='', rink_updates={}, color_updates={}, rotation=0.0, x_trans=0.0, y_trans=0.0, units='default', **added_features)#

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.

league_code#

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

Type:

str

rotation#

The angle (in degrees) through which to rotate the final plot. The default is 0.0

Type:

float

x_trans#

The amount that the x coordinates are to be shifted. By convention, the +``x`` axis extends from the center of the surface towards the right-hand goal when viewing the rink in TV view. The default is 0.0

Type:

float

y_trans#

The amount that the y coordinates are to be shifted. By convention, the +``y`` axis extends from the center of the surface towards the top of the rink when viewing the rink in TV view. The default is 0.0

Type:

float

rink_updates#

A dictionary of updated parameters to use for the hockey rink. The default is an empty dictionary

Type:

dict

color_updates#

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

Type:

dict

units#

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"

Type:

str

rink_params#

A dictionary containing the following parameters of the rink:

  • rink_lengthfloat

    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 point

  • rink_widthfloat

    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 ice

  • rink_unitsstr

    The units with which to draw the rink

  • corner_radiusfloat

    The radius of the circle that comprises the rink’s corners

  • board_thicknessfloat

    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 rink

  • referee_crease_radiusfloat

    The outer radius of the semi-circle that comprises the referee’s crease

  • nzone_lengthfloat

    The length of the neutral zone, measured from the interior edges of the zone lines (blue lines)

  • goal_line_to_boardsfloat

    The x position of the center of the right-hand goal line relative to the boards behind the right-hand goal

  • major_line_thicknessfloat

    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_thicknessfloat

    The thickness of the minor lines on the ice surface. Minor lines are those such as goal lines, hash marks, faceoff markings, or circle thicknesses

  • faceoff_circle_radiusfloat

    The radius of the faceoff circles, both center and non-center, on the ice

  • center_faceoff_spot_radiusfloat

    The radius of the center faceoff spot on the ice

  • center_faceoff_spot_gapfloat

    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 line

  • noncenter_faceoff_spot_radiusfloat

    The radius of the non-centered faceoff spots on the ice. These are in the defensive, neutral, and offensive zones

  • nzone_faceoff_spot_to_zone_linefloat

    The x position of the right-side faceoff spots in the neutral zone relative to the neutral-zone side of the zone (blue) line

  • odzone_faceoff_spot_to_boardsfloat

    The distance (in the x direction) from the end of the rink to the center of the defensive/offensive zone faceoff spot

  • noncenter_faceoff_spot_yfloat

    The y position of the upper faceoff spots in the defensive, neutral, and offensive zones on the ice

  • noncenter_faceoff_spot_gap_widthfloat

    The gap between the interior edge of a non-centered faceoff spot ring and the stripe running across it

  • hashmark_widthfloat

    The width of the hashmarks on the exterior of the defensive and offensive faceoff circles. Note that width refers to a distance solely in the y direction

  • hashmark_ext_spacingfloat

    The exterior horizontal spacing between the hashmarks on the exterior of the defensive and offensive faceoff circles. Note that this is solely in the x direction

  • faceoff_line_dist_xfloat

    The distance from the center of the defensive and offensive faceoff spot to the left-most edge of the upper-right faceoff line

  • faceoff_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 line

  • faceoff_line_lengthfloat

    The exterior length of the faceoff line

  • faceoff_line_widthfloat

    The exterior width of the faceoff line

  • has_trapezoidbool

    Indicator of whether or not the rink has a goalkeeper’s restricted area (trapezoid) behind each goal

  • short_base_widthfloat

    The exterior base-width of the trapezoid (should it exist) that lies along the goal line

  • long_base_widthfloat

    The exterior base-width of the trapezoid (should it exist) that lies along the boards

  • goal_crease_stylestr
    The style of goal crease to implement. Viable options are:
    • nhl98the current iteration of the NHL goal crease.

      This is what is used for most professional leagues

    • nhl92the 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-circle

    • ushl1the current iteration of a USA Hockey goal

      crease. This is what is currently used in the USHL (United States Hockey League)

  • goal_crease_radiusfloat

    The radius of the rounded portion of the goal crease, as taken from the center of the goal line

  • goal_crease_lengthfloat

    The distance from the center of the goal line to the start of the arc of the goal crease

  • goal_crease_widthfloat

    The exterior width of the goal crease

  • goal_crease_notch_dist_xfloat

    The distance from the center of the goal line to the notch (if one exists) in the goal crease

  • goal_crease_notch_widthfloat

    The width of the notch (if one exists) in the goal crease

  • goal_mouth_widthfloat

    The interior distance between the goalposts

  • goal_back_widthfloat

    The exterior distance between the widest part of the goal frame’s footprint

  • goal_depthfloat

    The depth of the goal frame from the center of the goal line to the exterior of the back pipe of the goal frame

  • goal_post_diameterfloat

    The diameter of the posts of the goal frame

  • goal_radiusfloat

    The interior radius of the goal frame

  • bench_lengthfloat

    The exterior length of a single team’s bench area

  • bench_depthfloat

    The interior depth off the boards of a single team’s bench area

  • bench_separationfloat

    The separation between the two teams’ bench areas

  • penalty_box_lengthfloat

    The interior length of a single penalty box

  • penalty_box_depthfloat

    The interior depth off of the boards of a single team’s penalty box

  • penalty_box_separationfloat

    The distance that separates each team’s penalty box area. This should be equivalent to the length of the off-ice officials’ box

Type:

dict

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

Return type:

Nothing, but a message will be printed out

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

Return type:

Nothing, but a message will be printed out

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 is None, this will display all leagues that do come shipped with sportypy. The default is None

Return type:

Nothing, but a message will be printed out

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. If None is 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 the x direction to be used. If a single float is provided, this will be used as the lower bound of the x coordinates to display and the upper bound will be the +``x`` end of the boards. If a tuple, the two values will be used to determine the bounds. If None, then the display_range will be used instead to set the bounds. The default is None

  • ylim (float or tuple of floats or None) – The display range in the y direction to be used. If a single float is provided, this will be used as the lower bound of the y coordinates to display and the upper bound will be the +``y`` side of the rink. If a tuple, the two values will be used to determine the bounds. If None, then the display_range will be used instead to set the bounds. The default is None

  • 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 of 0.0 will correspond to a TV view of the rink, where +``x`` is to the right and +``y`` is on top. The rotation occurs counter clockwise. The default is None

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()#

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

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 (see cani_color_features() method for a list of these names). The default is an empty dictionary

Return type:

Nothing, but the class is re-instantiated with the updated colors

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 (see cani_change_dimensions() method for a list of these parameters). The default is an empty dictionary

Return type:

Nothing, but the class is re-instantiated with the updated parameters