HinetPy.utils module

Utility functions.

HinetPy.utils.split_integer(number: int, maxn: int) list[int]

Split an integer into evenly sized chunks.

Parameters:
  • number – An interger that to be split into chunks.

  • maxn – The maximum number in each chunk.

Returns:

List of integers.

Return type:

chunks

Examples

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

Check if a point is inside a box region.

Parameters:
  • latitude – Latitude of the point.

  • longitude – Longitude of the point.

  • minlatitude – Minimum latitude of the box region.

  • maxlatitude – Maximum latitude of the box region.

  • minlongitude – Minimum longitude of the box region.

  • maxlongitude – 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: float, lon1: float, lat2: float, lon2: float) float

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: float, lon1: float, lat2: float, lon2: float, minradius: float | None = None, maxradius: float | None = None) bool

Check if a point is inside a circular region.

Parameters:
  • lat1 – Latitude of the point.

  • lon1 – Longitude of the point.

  • lat2 – Latitude of center of the circular region.

  • lon2 – Longitude of center of the circular region.

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

  • maxradius – 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: str | datetime | date) datetime

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

Parameters:

value – A datetime.datetime object or a datetime string.

Returns:

A datetime as datetime.datetime.

Return type:

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: str) bool

Check if a command exists in PATH and is executable.

Parameters:

cmd – Name of the command.

Returns:

True is the command exists in PATH is executable.

Return type:

bool

HinetPy.utils.check_package_release() bool

Check whether HinetPy has a new release.

Returns:

True if HinetPy has a new release.

Return type:

bool