-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels not returned for Plant Phenology annotation #433
Comments
Interesting, it looks like the response format has changed within the last year or so. Previously, pyinaturalist/test/sample_data/get_observation_with_ofvs.json Lines 7 to 16 in 7e3f345
But I just checked that same observation, and it looks like it now contains labels and other details you could previously only get from It would be fairly simple to include that info in |
This is mostly done, but a few more changes are needed. I noticed that these annotation details are available from |
@nigelcharman I ended up adding a separate function for this, Changes for this are available in the latest pre-release. Usage example: >>> from pyinaturalist import *
>>> observation_json = get_observations_by_id(141964204)
>>> observation = Observation.from_json(observation_json['results'][0])
>>> a = observation.annotations[0]
>>> a
Annotation(term='Plant Phenology', value='No Evidence of Flowering') I added some less verbose properties to get labels only: >>> a.term
'Plant Phenology'
>>> a.value
'No Evidence of Flowering', To see full controlled term details: >>> a.controlled_attribute
ControlledTerm(
id=12,
is_value=False,
multivalued=True,
label='Plant Phenology',
ontology_uri='',
uri='',
uuid='e997f5f1-1e22-4f1e-bb51-425d70d07b1a',
taxon_ids=[47126],
values=[
ControlledTermValue(id=13),
ControlledTermValue(id=14),
ControlledTermValue(id=15),
ControlledTermValue(id=21),
],
)
>>> a.controlled_value
ControlledTermValue(
id=21,
blocking=True,
label='No Evidence of Flowering',
ontology_uri='',
uri='',
uuid='943f8dac-764a-4736-86b5-2f419bbd368b',
taxon_ids=[47125],
) |
By the way, if you mainly want to work with model objects instead of JSON, you may want to give the API client class a try (#217). It's not fully documented yet, but will be soon. Here's an example of getting an observation by ID: from pyinaturalist import *
client = iNatClient()
observation = client.observations.from_ids(141964204).one()
# Shorter syntax for getting a single record by ID:
observation = client.observations(141964204) Or multiple observations by ID: observations = client.observations.from_ids(141964204, 12345).all() Or by other search criteria: observations = client.observations.search(user_login='my_username', taxon_name='Danaus plexippus').all() |
Thanks for the changes @JWCook! I do normally want to search for observations (by taxon and place) rather than getting them by id. With the I'm not tied to JSON, so could definitely try out the model object approach and see if it gives us what we need. |
Not yet, but that would be doable. I could add an option to use the main observation search endpoint, and make a separate request to fill in the missing annotation details using the controlled terms endpoint. Generally I'd like the basic API functions (like I'll make a separate issue for that. |
The problem
I'm hoping to get the labels for annotations, but am only seeing the IDs
Expected behavior
I can see the labels
Plant Phenology
andNo Evidence of Flowering
rather than just12
and21
Steps to reproduce the behavior
is returning:
Term: 12, Value: 21
I've checked that these ids map to the labels
Plant Phenology
andNo Evidence of Flowering
at https://api.inaturalist.org/v1/docs/#!/Controlled_Terms/get_controlled_termsWorkarounds
Not that I know of
Environment
MacOS 12.6.1
Python 3.9.13
Pyinaturalist latest as at 21 Nov 2022 (
pip install -U --pre pyinaturalist
)3.9
]0.13
ormain
branch]The text was updated successfully, but these errors were encountered: