xml_common.utils package#

CamelCase Enum#

This implementation of the Enum Python Class supports the conversation from EML types to Python Enum.

class xml_common.utils.enum.CamelCaseEnum(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)#

Bases: Enum

Enum class that allow conversion and retrieval using camel case name.

classmethod get_enum(name: str) CamelCaseEnum#

Obtain the Enum from the string with the name in camel case.

Parameters:
namestr

Camel case name.

Returns:
CamelCaseEnum

Instance of CamelCaseEnum.

Raises:
ValueError

Not a valid name.

to_camel_case()#

Converts name to camel case (eg: camelCase).

Returns:
str

Name of role in camel case.

Language Class#

Language type for various EML objects.

class xml_common.utils.language.Language(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)#

Bases: Enum

The language of the resource.

Attributes:
ESPstr

Spanish language

ENGstr

English language

ENG = 'English'#
ESP = 'Spanish'#
static get_language(abbreviation: str) Language#

Defined Values#

These are helpful predefined types.

class xml_common.utils.length_unit.LengthUnit(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)#

Bases: CamelCaseEnum

The list of units which are of length type, or have a parentSI of meter SI.

Attributes:
METERfloat

International meter.

NANOMETERfloat

International nanometer.

MICROMETERfloat

International micrometer.

MICRONfloat

Non International System of Units (SI) name of micrometer.

MILLIMETERfloat

International millimeter.

CENTIMETERfloat

International centimeter.

DECIMETERfloat

International decimeter.

DEKAMETERfloat

International dekameter.

HECTOMETERfloat

International hectometer.

KILOMETERfloat

International kilometer.

MEGAMETERfloat

International megameter.

ANGSTROMfloat

Ångström metric unit.

INCHfloat

British imperial and United States customary inch.

FOOT_USfloat

United States foot.

FOOTfloat

International foot.

FOOT_GOLD_COASTfloat

Gold Coast foot.

FATHOMfloat

A measure (especially of depth) of six feet.

NAUTICALMILEfloat

Nautical mile.

YARDfloat

International yard.

YARD_INDIANfloat

Indian yard.

LINK_CLARKEfloat

Link (Clarke’s ratio).

YARD_SEARSfloat

Yard (Sears).

MILEfloat

International mile.

ANGSTROM = 1e-10#
CENTIMETER = 0.01#
DECIMETER = 0.1#
DEKAMETER = 10.0#
FATHOM = 1.8288#
FOOT = 0.3048#
FOOT_GOLD_COAST = 0.3047997101815088#
FOOT_US = 0.3048006096012192#
HECTOMETER = 100.0#
INCH = 0.0254#
KILOMETER = 1000.0#
MEGAMETER = 1000000.0#
METER = 1.0#
MICROMETER = 1e-06#
MICRON = 1e-06#
MILE = 1609.347218694438#
MILLIMETER = 0.001#
NANOMETER = 1e-09#
NAUTICALMILE = 1852#
YARD = 0.9144#
YARD_INDIAN = 0.9143985307444408#
YARD_SEARS = 0.9143984146160287#
property valid_name: str#

Generate the valid name of the unit.

Returns:
str

Name of the unit.

class xml_common.utils.establishment_means.EstablishmentMeans(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)#

Bases: CamelCaseEnum

Terms intended to be used as a controlled value for Darwin Core terms with local name establishmentMeans.

For details and rationale, see Groom et al. 2019. Improving Darwin Core for research and management of alien species. https://doi.org/10.3897/biss.3.38084

Attributes:
NATIVEint

A taxon occurring within its natural range.

NATIVE_REINTRODUCEDint

A taxon re-established by direct introduction into its natural range, but from where it had become extinct.

INTRODUCEDint

Establishment of a taxon by human agency into an area that is not part of its natural range.

INTRODUCED_ASSISTED_COLONISATIONint

Establishment of a taxon specifically with the intention of creating a self-sustaining wild population.

VAGRANTint

The temporary occurrence of a taxon far outside its natural or migratory range.

UNCERTAINint

The origin of the occurrence of the taxon in an area is obscure.

INTRODUCED = 3#
INTRODUCED_ASSISTED_COLONISATION = 4#
NATIVE = 1#
NATIVE_REINTRODUCED = 2#
UNCERTAIN = 6#
VAGRANT = 5#
get_iri() str#

Generate the Term IRI (Internationalized Resource Identifier) of the Establishment Means.

Returns:
str

Term IRI.

Type Function#

Functions for type conversion, from XML defined to Python data types.

xml_common.utils.type_functions.format_datetime(value: str) datetime | None#

Convert value in a datetime object.

Parameters:
valuestr

Value to be parsed in a datetime object.

Returns:
datatime

Datetime object from value.

xml_common.utils.type_functions.format_to_type(value: str, a_type: TypeAlias, address_value: bool = True) Any#

Convert the string value according to the type given.

Parameters:
valuestr

A value to be converted.

a_typeTypeAlias

The type to convert the value.

address_valuebool, optional

If the conversion gives ValueError, whether return None.

Returns:
Any

The value as a TypeAlias.

Raises:
TypeError

When the Type alias is not supported or value cannot be converted in that particular Type.

xml_common.utils.type_functions.format_union(value: str, types: TypeAlias) Any#

Convert the string value to any of the types given inside the union.

Parameters:
valuestr

A value to be converted.

typesTypeAlias

A Union Type with various option of types.

Returns:
Any

Value in one of the type listed inside the types parameter.

Raises:
TypeError

When the value cannot be converted in any of Types given.

xml_common.utils.type_functions.type_to_pl(a_type: TypeAlias, lazy: bool = False) TypeAlias#

Equivalent to a_type in the polars dtype.

Parameters:
a_typeTypeAlias

Any available type.

lazybool

When used to inference the types in lazy mode.

Returns:
TypeAlias

polars dtype.

xml_common.utils.type_functions.type_to_sql(a_type: TypeAlias) str#

Equivalent to a_type in the polars dtype.

Parameters:
a_typeTypeAlias

Any available type.

lazybool

When used to inference the types in lazy mode.

Returns:
TypeAlias

polars dtype.

xml_common.utils.type_functions.unformat_datetime(value: datetime) str#

Convert a datetime value in an encoded string.

Parameters:
valuedatetime

Value to be encoded as a string.

Returns:
str

Encoded Datetime object.

xml_common.utils.type_functions.unformat_type(value: Any, a_type: TypeAlias) str#

Convert a value to a string according to the type given.

Parameters:
valueAny

A value in a_type format.

a_typeTypeAlias

The type of the value given.

Returns:
str

Encoded value

Iteration#

Iteration functions.

OptionalTqdm support having tqdm installed or not.

class xml_common.utils.iteratate.OptionalTqdm(**kwargs)#

Bases: object

Methods

close

reset

set_descriptor

set_postfix

update

close() None#
reset(**kwargs) None#
set_descriptor(**kwargs) None#
set_postfix(**kwargs) None#
update(**kwargs) None#
xml_common.utils.iteratate.iterate_with_bar(iterator: Iterable[T], **kwargs) T#

GPolygon#

GPolygon support functions.

class xml_common.utils.gpolygon.GPolygon(outer: GRing, exclusion: List[GRing] = None)#

Bases: object

This construct creates a spatial ring with a hollow center.

Parameters:
outerGRing

The outer containment loop of a datasetGPolygon.

exclusionList[GRing], optional

Exclusion G-Ring, the closed non-intersecting boundary of a void area (or hole in an interior area).

Attributes:
exclusion

List[GRing]: Exclusion G-Ring.

outer

GRing: The outer containment loop of a datasetGPolygon.

property exclusion: List[GRing]#

List[GRing]: Exclusion G-Ring.

property outer: GRing#

GRing: The outer containment loop of a datasetGPolygon.

class xml_common.utils.gpolygon.GRing(*points: Tuple[float, float])#

Bases: object

A set of ordered pairs of floating-point numbers.

Parameters:
pointsTuple[float, float]

Points to generate a ring, minimum 3 points with latitude and longitude.