utils
canari_ml.utils
¶
canari_ml.utils.location_arg(argument)
¶
Parse a string argument as a location, expecting a pair of integers separated by a comma.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
argument
|
str
|
The string argument containing the location. |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, int]
|
Tuple of the x and y coordinates of the location. |
Raises:
| Type | Description |
|---|---|
ArgumentTypeError
|
If the argument cannot be parsed as a location. |
Source code in canari_ml/utils.py
canari_ml.utils.parse_location_or_region(argument, separator=',')
¶
Parse a string argument as a sequence of integers separated by a specified separator.
This function splits the input string using the given separator and attempts to convert each resulting substring into an integer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
argument
|
str
|
The string argument containing the sequence of integers. |
required |
separator
|
optional
|
The character used to separate the integers in the string. Defaults to ",". |
','
|
Returns:
| Type | Description |
|---|---|
tuple[int, int]
|
Tuple of parsed integers. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any substring cannot be converted into an integer. |
Source code in canari_ml/utils.py
canari_ml.utils.region_arg(argument)
¶
Parse a string argument as a region, expecting four integers separated by commas.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
argument
|
str
|
The string argument containing the region's coordinates. |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, int, int, int]
|
Tuple containing the x1, y1, x2, and y2 coordinates of the region. |
Raises:
| Type | Description |
|---|---|
ArgumentTypeError
|
If the argument cannot be parsed as a valid region. |
RuntimeError
|
If the provided coordinates do not form a valid rectangle. |
Source code in canari_ml/utils.py
canari_ml.utils.date_arg(string)
¶
Parse a string argument as a date in the format YYYY-MM-DD.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
string
|
str
|
The string argument containing the date. |
required |
Returns:
| Type | Description |
|---|---|
date
|
The parsed date. |
Raises:
| Type | Description |
|---|---|
ArgumentTypeError
|
If the argument cannot be parsed as a valid date. |