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)#
Bases:
EnumEnum 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)#
Bases:
EnumThe language of the resource.
- Attributes:
- ENGstr
English language.
- JPNstr
Japanese language.
- SPAstr
Spanish language.
- ITAstr
Italian language.
- RUSstr
Russian language.
- POLstr
Polish language.
- FINstr
Finnish language.
- PORstr
Portuguese language.
- CATstr
Catalan language.
- TURstr
Turkish language.
- NORstr
Norwegian language.
- SWEstr
Swedish language.
- NOBstr
Bokmål, Norwegian language.
- NNOstr
Norwegian Nynorsk language.
- COSstr
Corsican language.
- HUNstr
Hungarian language.
- AFRstr
Afrikaans language.
- HRVstr
Croatian language.
- SLVstr
Slovenian language.
- GLGstr
Galician language.
- GLAstr
Gaelic language.
- DANstr
Danish language.
- ESTstr
Estonian language.
- ARAstr
Arabic language.
- SCOstr
Scots language.
- HEBstr
Hebrew language.
- SRPstr
Serbian language.
- MLTstr
Maltese language.
- MLGstr
Malagasy language.
- VIEstr
Vietnamese language.
- WOLstr
Wolof language.
- HAWstr
Hawaiian language.
- TGLstr
Tagalog language.
- ROMstr
Romany language.
- PAPstr
Papiamento language.
- KORstr
Korean language.
- FAOstr
Faroese language.
- SMOstr
Samoan language.
- SOMstr
Somali language.
- KHMstr
Central Khmer language.
- TELstr
Telugu language.
- TAMstr
Tamil language.
- INDstr
Indonesian language.
- TAHstr
Tahitian language.
- NIUstr
Niuean language.
- SWAstr
Swahili language.
- SRNstr
Sranan Tongo language.
- DIVstr
Divehi language.
- TKLstr
Tokelau language.
- MALstr
Malayalam language.
- THAstr
Thai language.
- JAVstr
Javanese language.
- MARstr
Marathi language.
- GUJstr
Gujarati language.
- BIKstr
Bikol language.
- TSIstr
Tsimshian language.
- TONstr
Tonga (Tonga Islands) language.
- FIJstr
Fijian language.
- PAUstr
Palauan language.
- ACEstr
Achinese language.
- PAGstr
Pangasinan language.
- ILOstr
Iloko language.
- WARstr
Waray language.
- SNDstr
Sindhi language.
- PAMstr
Pampanga language.
- CEBstr
Cebuano language.
- KANstr
Kannada language.
- HAIstr
Haida language.
- SINstr
Sinhala language.
- FONstr
Fon language.
- FANstr
Fang language.
- MAHstr
Marshallese language.
- TVLstr
Tuvalu language.
- BULstr
Bulgarian language.
- KALstr
Kalaallisut language.
- GLVstr
Manx language.
- IKUstr
Inuktitut language.
- BENstr
Bengali language.
- HILstr
Hiligaynon language.
- MENstr
Mende language.
- CHAstr
Chamorro language.
- LITstr
Lithuanian language.
- LAVstr
Latvian language.
- KIRstr
Kirghiz language.
- AMHstr
Amharic language.
- UKRstr
Ukrainian language.
- VENstr
Venda language.
- KASstr
Kashmiri language.
- RAPstr
Rapanui language.
- NEPstr
Nepali language.
- KOKstr
Konkani language.
- CREstr
Cree language.
- KOSstr
Kosraean language.
- SUSstr
Susu language.
- EWEstr
Ewe language.
- ORIstr
Oriya language.
- EPOstr
Esperanto language.
- DEUstr
German language.
- NLDstr
Dutch language.
- FRAstr
French language.
- ELLstr
Greek, Modern (1453-) language.
- CESstr
Czech language.
- SQIstr
Albanian language.
- KATstr
Georgian language.
- ZHOstr
Chinese language.
- EUSstr
Basque language.
- RONstr
Romanian language.
- SLKstr
Slovak language.
- ISLstr
Icelandic language.
- MRIstr
Maori language.
- CYMstr
Welsh language.
- MSAstr
Malay language.
- FASstr
Persian language.
- MYAstr
Burmese language.
- MKDstr
Macedonian language.
- MEYstr
Hassaniyya language.
- CMNstr
Mandarin Chinese language.
- DNJstr
Dan language.
- BCNstr
Bali (Nigeria) language.
- VIFstr
Vili language.
- NLGstr
Gela language.
- CALstr
Carolinian language.
- UNDstr
Undetermined code for unknown languages.
- ACE = 'Achinese'#
- AFR = 'Afrikaans'#
- AMH = 'Amharic'#
- ARA = 'Arabic'#
- BCN = 'Bali (Nigeria)'#
- BEN = 'Bengali'#
- BIK = 'Bikol'#
- BUL = 'Bulgarian'#
- CAL = 'Carolinian'#
- CAT = 'Catalan'#
- CEB = 'Cebuano'#
- CES = 'Czech'#
- CHA = 'Chamorro'#
- CMN = 'Mandarin Chinese'#
- COS = 'Corsican'#
- CRE = 'Cree'#
- CYM = 'Welsh'#
- DAN = 'Danish'#
- DEU = 'German'#
- DIV = 'Divehi'#
- DNJ = 'Dan'#
- ELL = 'Greek, Modern (1453-)'#
- ENG = 'English'#
- EPO = 'Esperanto'#
- EST = 'Estonian'#
- EUS = 'Basque'#
- EWE = 'Ewe'#
- FAN = 'Fang'#
- FAO = 'Faroese'#
- FAS = 'Persian'#
- FIJ = 'Fijian'#
- FIN = 'Finnish'#
- FON = 'Fon'#
- FRA = 'French'#
- GLA = 'Gaelic'#
- GLG = 'Galician'#
- GLV = 'Manx'#
- GUJ = 'Gujarati'#
- HAI = 'Haida'#
- HAW = 'Hawaiian'#
- HEB = 'Hebrew'#
- HIL = 'Hiligaynon'#
- HRV = 'Croatian'#
- HUN = 'Hungarian'#
- IKU = 'Inuktitut'#
- ILO = 'Iloko'#
- IND = 'Indonesian'#
- ISL = 'Icelandic'#
- ITA = 'Italian'#
- JAV = 'Javanese'#
- JPN = 'Japanese'#
- KAL = 'Kalaallisut'#
- KAN = 'Kannada'#
- KAS = 'Kashmiri'#
- KAT = 'Georgian'#
- KHM = 'Central Khmer'#
- KIR = 'Kirghiz'#
- KOK = 'Konkani'#
- KOR = 'Korean'#
- KOS = 'Kosraean'#
- LAV = 'Latvian'#
- LIT = 'Lithuanian'#
- MAH = 'Marshallese'#
- MAL = 'Malayalam'#
- MAR = 'Marathi'#
- MEN = 'Mende'#
- MEY = 'Hassaniyya'#
- MKD = 'Macedonian'#
- MLG = 'Malagasy'#
- MLT = 'Maltese'#
- MRI = 'Maori'#
- MSA = 'Malay'#
- MYA = 'Burmese'#
- NEP = 'Nepali'#
- NIU = 'Niuean'#
- NLD = 'Dutch'#
- NLG = 'Gela'#
- NNO = 'Norwegian Nynorsk'#
- NOB = 'Bokmål, Norwegian'#
- NOR = 'Norwegian'#
- ORI = 'Oriya'#
- PAG = 'Pangasinan'#
- PAM = 'Pampanga'#
- PAP = 'Papiamento'#
- PAU = 'Palauan'#
- POL = 'Polish'#
- POR = 'Portuguese'#
- RAP = 'Rapanui'#
- ROM = 'Romany'#
- RON = 'Romanian'#
- RUS = 'Russian'#
- SCO = 'Scots'#
- SIN = 'Sinhala'#
- SLK = 'Slovak'#
- SLV = 'Slovenian'#
- SMO = 'Samoan'#
- SND = 'Sindhi'#
- SOM = 'Somali'#
- SPA = 'Spanish'#
- SQI = 'Albanian'#
- SRN = 'Sranan Tongo'#
- SRP = 'Serbian'#
- SUS = 'Susu'#
- SWA = 'Swahili'#
- SWE = 'Swedish'#
- TAH = 'Tahitian'#
- TAM = 'Tamil'#
- TEL = 'Telugu'#
- TGL = 'Tagalog'#
- THA = 'Thai'#
- TKL = 'Tokelau'#
- TON = 'Tonga (Tonga Islands)'#
- TSI = 'Tsimshian'#
- TUR = 'Turkish'#
- TVL = 'Tuvalu'#
- UKR = 'Ukrainian'#
- UND = 'Undetermined'#
- VEN = 'Venda'#
- VIE = 'Vietnamese'#
- VIF = 'Vili'#
- WAR = 'Waray'#
- WOL = 'Wolof'#
- ZHO = 'Chinese'#
- property two_letters#
Defined Values#
These are helpful predefined types.
- class xml_common.utils.length_unit.LengthUnit(value)#
Bases:
CamelCaseEnumThe 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#
- LINK_CLARKE = 0.2011661949#
- 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)#
Bases:
CamelCaseEnumTerms 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_sql(value: Any, a_type: TypeAlias) Any#
Format a value to the SQL equivalent.
- Parameters:
- valueAny
Value to be formatted.
- a_typeTypeAlias
The type of the value.
- Returns:
- Any
Value formatted.
- 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.
- 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:
objectOptional TQDM progress bar. Support all method in case tqdm is not installed.
Methods
close()Close tqdm progress bar.
reset(**kwargs)Reset tqdm progress bar.
set_descriptor(**kwargs)Set descriptor for tqdm progress bar.
set_postfix(**kwargs)Set postfix for tqdm progress bar.
update(**kwargs)Update tqdm progress bar.
- close() None#
Close tqdm progress bar.
- Other Parameters:
- See tqdm documentation.
See also
- reset(**kwargs) None#
Reset tqdm progress bar.
- Other Parameters:
- See tqdm documentation.
See also
- set_descriptor(**kwargs) None#
Set descriptor for tqdm progress bar.
- Other Parameters:
- See tqdm documentation.
See also
- set_postfix(**kwargs) None#
Set postfix for tqdm progress bar.
- Other Parameters:
- See tqdm documentation.
See also
- update(**kwargs) None#
Update tqdm progress bar.
- Other Parameters:
- See tqdm documentation.
See also
- xml_common.utils.iteratate.get_optional_iterator(**kwargs) T#
Get optional bar progress with or without iterator.
- Parameters:
- See tqdm documentation.
- Returns:
- tqdm
Instance of tqdm in case library is installed.
See also
- xml_common.utils.iteratate.is_notebook() bool#
Check if it is running in a terminal or in a notebook (or interactive Python).
- Returns:
- bool
True if it is running in an IPython, False otherwise.
- xml_common.utils.iteratate.iterate_with_bar(iterator: Iterable[T], **kwargs) T#
Get a tqdm instance iterator or just the iterator.
- Parameters:
- iteratorIterable
Python object to be iterated.
- Returns:
- tqdm
Instance of tqdm in case library is installed.
- Other Parameters:
- See tqdm documentation.
See also
GPolygon#
GPolygon support functions.
- class xml_common.utils.gpolygon.GPolygon(outer: GRing, exclusion: List[GRing] = None)#
Bases:
objectThis 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:
- class xml_common.utils.gpolygon.GRing(*points: Tuple[float, float])#
Bases:
objectA set of ordered pairs of floating-point numbers.
- Parameters:
- pointsTuple[float, float]
Points to generate a ring, minimum 3 points with latitude and longitude.