nilomr/pykanto

Error when assigning cluster IDs

Closed this issue · 0 comments

Hi Nilo!

I'm working on analyzing some pre-segmented birdsong syllables in pykanto, and I'm hitting an error when I run dataset.cluster_ids(). Do you know what the issue might be? Here's the error:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
File ~/anaconda3/envs/pykanto-env/lib/python3.9/site-packages/pandas/core/indexes/base.py:3805, in Index.get_loc(self, key)
   [3804](https://file+.vscode-resource.vscode-cdn.net/Users/masonyoungblood/Desktop/~/anaconda3/envs/pykanto-env/lib/python3.9/site-packages/pandas/core/indexes/base.py:3804) try:
-> [3805](https://file+.vscode-resource.vscode-cdn.net/Users/masonyoungblood/Desktop/~/anaconda3/envs/pykanto-env/lib/python3.9/site-packages/pandas/core/indexes/base.py:3805)     return self._engine.get_loc(casted_key)
   [3806](https://file+.vscode-resource.vscode-cdn.net/Users/masonyoungblood/Desktop/~/anaconda3/envs/pykanto-env/lib/python3.9/site-packages/pandas/core/indexes/base.py:3806) except KeyError as err:

File index.pyx:167, in pandas._libs.index.IndexEngine.get_loc()

File index.pyx:196, in pandas._libs.index.IndexEngine.get_loc()

File pandas/_libs/hashtable_class_helper.pxi:7081, in pandas._libs.hashtable.PyObjectHashTable.get_item()

File pandas/_libs/hashtable_class_helper.pxi:7089, in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'ID'

The above exception was the direct cause of the following exception:

KeyError                                  Traceback (most recent call last)
Cell In[97], [line 1](vscode-notebook-cell:?execution_count=97&line=1)
----> [1](vscode-notebook-cell:?execution_count=97&line=1) dataset.cluster_ids()

File ~/anaconda3/envs/pykanto-env/lib/python3.9/site-packages/pykanto/utils/compute.py:107, in timing.<locals>.wrap(*args, **kwargs)
    [104](https://file+.vscode-resource.vscode-cdn.net/Users/masonyoungblood/Desktop/~/anaconda3/envs/pykanto-env/lib/python3.9/site-packages/pykanto/utils/compute.py:104) @wraps(f)
...
   [3815](https://file+.vscode-resource.vscode-cdn.net/Users/masonyoungblood/Desktop/~/anaconda3/envs/pykanto-env/lib/python3.9/site-packages/pandas/core/indexes/base.py:3815)     #  InvalidIndexError. Otherwise we fall through and re-raise
   [3816](https://file+.vscode-resource.vscode-cdn.net/Users/masonyoungblood/Desktop/~/anaconda3/envs/pykanto-env/lib/python3.9/site-packages/pandas/core/indexes/base.py:3816)     #  the TypeError.
   [3817](https://file+.vscode-resource.vscode-cdn.net/Users/masonyoungblood/Desktop/~/anaconda3/envs/pykanto-env/lib/python3.9/site-packages/pandas/core/indexes/base.py:3817)     self._check_indexing_error(key)

KeyError: 'ID'

In case it's an issue with the "ID" field in my JSON files (which I'm making from scratch to match the examples in the repository), here's an example of what one looks like (many fields are random btw):

{
 "species":"Kauai Oo",
 "ID":"kauai",
 "label":"",
 "recorder":"",
 "recordist":"Mason Youngblood",
 "source_datetime":"2014-09-22 23:15:00",
 "datetime":"2014-09-22 23:15:00",
 "date":"2014-09-22",
 "time":"23:15:00",
 "timezone":"UTC",
 "sample_rate": 22050,
 "length_s": 0.345986394557823,
 "lower_freq": 0,
 "upper_freq": 11025,
 "max_amplitude": 1,
 "min_amplitude": -0.974272191524506,
 "bit_depth": 32,
 "tech_comment":"...",
 "source_wav":"/Users/masonyoungblood/Documents/Work/Fall 2023/Song Extinction/pykanto/data/raw/KAUAI/451.wav",
 "wav_file":"/Users/masonyoungblood/Documents/Work/Fall 2023/Song Extinction/pykanto/data/segmented/kauai/WAV/451.wav"
}

Let me know if any other details would be helpful, and thanks in advance! :)