leaf_engine.adapt.utilities

Attributes

r_earth

Functions

cartesian(a, b, **kwargs)

create_dest_address(row[, use_zip])

create_origin_address(row[, use_zip])

dow_days(days)

fill_nan(num, fill)

haversine(a, b)

Computes the great circle distance between two points.

haversine_lanes(a, b)

Computes the great circle distance between the origin and destination of

lane_ships_per_period(ships, period[, start, end, label])

Find the number of shipments on each lane per period.

scalar_haversine(a, b)

Computes the great circle distance between two points.

Module Contents

leaf_engine.adapt.utilities.cartesian(a, b, **kwargs)
leaf_engine.adapt.utilities.create_dest_address(row, use_zip=True)
leaf_engine.adapt.utilities.create_origin_address(row, use_zip=True)
leaf_engine.adapt.utilities.dow_days(days)
leaf_engine.adapt.utilities.fill_nan(num, fill)
leaf_engine.adapt.utilities.haversine(a, b)

Computes the great circle distance between two points.

Parameters:
  • a – np.array([(lon,lat) … (lon,lat)])

  • b – np.array([(lon,lat) … (lon,lat)])

Returns:

Distance in miles between a,b

leaf_engine.adapt.utilities.haversine_lanes(a, b)

Computes the great circle distance between the origin and destination of two lanes.

Parameters:
  • a – lane 1 with origin and destination lon and lat

  • b – lane 2 with origin and destination lon and lat

Returns:

Distance in miles between origin and destination of the two lanes

leaf_engine.adapt.utilities.lane_ships_per_period(ships, period, start='', end='', label='left')

Find the number of shipments on each lane per period.

Parameters:
  • ships – a dataframe of shipment data containing columns named lane_id, shipments, period

  • period – pandas offset alias for the period over which to group shipments (e.g., ‘B’ for business day, ‘W’ for week)

  • start – start date for the period index. Will only be used if both start and end are provided.

  • end – end date for the period index. Will only be used if both start and end are provided.

  • label – ‘right’ or ‘left’ to indicate whether the period index will be labeled with the start or end of the period. ‘left’ is the start of the period, ‘right’ is the end of the period. The default is ‘left’.

Returns:

Dataframe of the shipment volume per period for each lane.

leaf_engine.adapt.utilities.scalar_haversine(a, b)

Computes the great circle distance between two points.

Parameters:
  • a – [lon,lat]

  • b – [lon,lat]

Returns:

Distance in miles between a,b

leaf_engine.adapt.utilities.r_earth = 3961