HinetPy.utils module
Utility functions.
- HinetPy.utils.split_integer(number: int, maxn: int) list[int]
Split an integer into evenly sized chunks.
- 参数:
number -- An interger that to be split into chunks.
maxn -- The maximum number in each chunk.
- 返回:
List of integers.
- 返回类型:
chunks
示例
>>> 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.
- 参数:
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.
- 返回:
True if the point is inside the box region.
- 返回类型:
示例
>>> 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.
- 参数:
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.
- 返回:
True if the point is inside the circular region.
- 返回类型:
示例
>>> point_inside_circular(30, 50, 30, 52, 0, 5) True
- HinetPy.utils.to_datetime(value: str | datetime | date) datetime
Convert a datetime from
str
todatetime.datetime
in a hard way.- 参数:
value -- A
datetime.datetime
object or a datetime string.- 返回:
A datetime as
datetime.datetime
.- 返回类型:
datetime
示例
>>> to_datetime("201001010000") datetime.datetime(2010, 1, 1, 0, 0) >>> to_datetime("2010-01-01T03:45") datetime.datetime(2010, 1, 1, 3, 45)