HinetPy.utils module

Utility functions.

HinetPy.utils.split_integer(number, maxn)

Split an integer into evenly sized chunks.

Parameters
  • number (int) – An interger that to be split into chunks.

  • maxn (int) – The maximum number in each chunk.

Returns

List of integers.

Return type

list

Examples

>>> split_integer(12, 3)
[3, 3, 3, 3]
>>> split_integer(15, 4)
[4, 4, 4, 3]
HinetPy.utils.point_inside_box(latitude, longitude, minlatitude=None, maxlatitude=None, minlongitude=None, maxlongitude=None)

Check if a point is inside a box region.

Parameters
  • latitude (float) – Latitude of the point.

  • longitude (float) – Longitude of the point.

  • minlatitude (float) – Minimum latitude of the box region.

  • maxlatitude (float) – Maximum latitude of the box region.

  • minlongitude (float) – Minimum longitude of the box region.

  • maxlongitude (float) – Maximum longitude of the box region.

Returns

True if the point is inside the box region.

Return type

bool

Examples

>>> point_inside_box(40, 130)
True
>>> point_inside_box(40, 130, 0, 50, 100, 150)
True
>>> point_inside_box(40, 130, 0, 30, 100, 150)
False
>>> point_inside_box(40, -130, maxlongitude=150)
False
>>> point_inside_box(40, -130, maxlongitude=300)
True
HinetPy.utils.haversine(lat1, lon1, lat2, lon2)

Calculate the great circle distance between two points on the earth (specified in decimal degrees) using haversine formula.

Reference: https://stackoverflow.com/a/4913653/7770208.

>>> haversine(40, 130, 50, 140)
12.224069629545902
>>> haversine(-20, 50, 30, 70)
53.57930271469817
HinetPy.utils.point_inside_circular(lat1, lon1, lat2, lon2, minradius=None, maxradius=None)

Check if a point is inside a circular region.

Parameters
  • lat1 (float) – Latitude of the point.

  • lon1 (float) – Longitude of the point.

  • lat2 (float) – Latitude of center of the circular region.

  • lon2 (float) – Longitude of center of the circular region.

  • minradius (float) – Minimum radius in degrees of the circular region.

  • maxradius (float) – Maximum radius in degrees of the circular region.

Returns

True if the point is inside the circular region.

Return type

bool

Examples

>>> point_inside_circular(30, 50, 30, 52, 0, 5)
True
HinetPy.utils.to_datetime(value)

Convert a datetime from str to datetime.datetime in a hard way.

Parameters

value (str) – A datetime as a string.

Returns

A datetime as datetime.datetime.

Return type

datetime.datetime

Examples

>>> to_datetime("201001010000")
datetime.datetime(2010, 1, 1, 0, 0)
>>> to_datetime("2010-01-01T03:45")
datetime.datetime(2010, 1, 1, 3, 45)
HinetPy.utils.check_cmd_exists(cmd)

Check if a command exists in PATH and is executable.

Parameters

cmd (str) – Name of the command.

Returns

True is the command exists in PATH is executable.

Return type

bool

HinetPy.utils.check_package_release()

Check whether HinetPy has a new release.

Returns

True if HinetPy has a new release.

Return type

bool