naturtag.metadata.inat_metadata module#

Tools to translate iNaturalist observations and taxa into image metadata

naturtag.metadata.inat_metadata.get_ids_from_url(url)#

If a URL is provided containing an ID, return the taxon or observation ID.

Return type

tuple[Optional[int], Optional[int]]

Returns

(observation_id, taxon_id)

naturtag.metadata.inat_metadata.get_inat_metadata(observation_id=None, taxon_id=None, common_names=False, hierarchical=False, metadata=None)#

Create or update image metadata based on an iNaturalist observation and/or taxon

Return type

Optional[MetaMetadata]

naturtag.metadata.inat_metadata.get_observed_taxa(username, include_casual=False, **kwargs)#

Get counts of taxa observed by the user, ordered by number of observations descending

Return type

TaxonCounts

naturtag.metadata.inat_metadata.refresh_tags(image_paths, recursive=False, settings=None)#

Refresh metadata for previously tagged images

Example

>>> # Refresh previously tagged images with latest observation and taxonomy metadata
>>> from naturtag import refresh_tags
>>> refresh_tags(['~/observations/'], recursive=True)
Parameters
  • image_paths (Iterable[Union[Path, str]]) – Paths to images to tag

  • recursive (bool) – Recursively search subdirectories for valid image files

  • settings (Optional[Settings]) – Settings for metadata types to generate

naturtag.metadata.inat_metadata.strip_url(value)#

If a URL is provided containing an ID, return just the ID

Return type

Optional[int]

naturtag.metadata.inat_metadata.tag_images(image_paths, observation_id=None, taxon_id=None, recursive=False, settings=None)#

Get taxonomy tags from an iNaturalist observation or taxon, and write them to local image metadata.

Examples

>>> # Tag images with full observation metadata:
>>> from naturtag import tag_images
>>> tag_images(['img1.jpg', 'img2.jpg'], observation_id=1234)
>>> # Tag images with taxonomy metadata only
>>> tag_images(['img1.jpg', 'img2.jpg'], taxon_id=1234)
>>> # Glob patterns are also supported
>>> tag_images(['~/observations/*.jpg'], taxon_id=1234)
Parameters
  • image_paths (Iterable[Union[Path, str]]) – Paths to images to tag

  • observation_id (Optional[int]) – ID of an iNaturalist observation

  • taxon_id (Optional[int]) – ID of an iNaturalist species or other taxon

  • recursive (bool) – Recursively search subdirectories for valid image files

  • settings (Optional[Settings]) – Settings for metadata types to generate

Return type

list[MetaMetadata]

Returns

Updated image metadata for each image