dopefishh / pympi

A python module for processing ELAN and Praat annotation files
MIT License
93 stars 39 forks source link

copy tier within the same file #24

Closed Cogitarian closed 4 years ago

Cogitarian commented 4 years ago

Expected behaviour I need to copy (duplicate) tier in one file or from one file to another and I don't understand the syntax: how copy function is supposed to work?

Actual behaviour I'd like to copy tier and change its name within one file. Next, I'd like to loop it over tens of other ear files. I thought copy_tier would work, but it doesn't. I've tried to copy tier from one object to another, but then got errors (see screenshot).

System information

Additional context Add any other context about the problem here.

dopefishh commented 4 years ago

I cannot open your screenshot (I have to login), can you copy paste the errors in the issue?

Cogitarian commented 4 years ago

Sure, I'd happy to:

eafexp1.copy_tier(eafexp1,"lh_Activation_R2") Traceback (most recent call last): File "", line 1, in File "/Users/cogitarian/PycharmProjects/PYMPI/venv/lib/python3.7/site-packages/pympi/Elan.py", line 432, in copy_tier tier_dict=self.get_parameters_for_tier(tier_name)) File "/Users/cogitarian/PycharmProjects/PYMPI/venv/lib/python3.7/site-packages/pympi/Elan.py", line 871, in get_parameters_for_tier return self.tiers[id_tier][2] KeyError: 'lh_Activation_R2' eafexp.copy_tier(eafexp1,"lh_Activation_R2") Traceback (most recent call last): File "", line 1, in File "/Users/cogitarian/PycharmProjects/PYMPI/venv/lib/python3.7/site-packages/pympi/Elan.py", line 432, in copy_tier tier_dict=self.get_parameters_for_tier(tier_name)) File "/Users/cogitarian/PycharmProjects/PYMPI/venv/lib/python3.7/site-packages/pympi/Elan.py", line 871, in get_parameters_for_tier return self.tiers[id_tier][2] KeyError: 'lh_Activation_R2' eafexp.copy_tier(eafexp,"lh_Activation_R2") Traceback (most recent call last): File "", line 1, in File "/Users/cogitarian/PycharmProjects/PYMPI/venv/lib/python3.7/site-packages/pympi/Elan.py", line 432, in copy_tier tier_dict=self.get_parameters_for_tier(tier_name)) File "/Users/cogitarian/PycharmProjects/PYMPI/venv/lib/python3.7/site-packages/pympi/Elan.py", line 871, in get_parameters_for_tier return self.tiers[id_tier][2]

dopefishh commented 4 years ago

Are you sure there is a tier with that exact name in the original object? Can you maybe attach the elan file and the script as well.

Cogitarian commented 4 years ago

Right, it works between different files, but not within one file, perhaps because elan does not accept two tiers with the same name. I guess the solution would be to copy the tier a temporary file and after changing its name copy it again into original file. I'll try that later. Any other solutions?

Cogitarian commented 4 years ago

OK, here is new function to duplicate tiers within the same eaf file. Unfortunately the result is a tier with duplicated annotations and I have no idea why this happens, as you can't do that in elan manually. I'm sure there is a bug in my function or there is room for improvement. Any ideas?

Here are two files: temporary.eaf is a file with just one empty tier and it is used to make a temporary copy of a tier from the annotated.eaf. The new file is here. I hope you can run the code to reproduce the bug seen on this screenshot.

Cogitarian commented 4 years ago

OK, I've solved it with another elan object. The function doesn't look pretty but it works for me.

dopefishh commented 4 years ago

Good to hear that the problem is solved. Small note, initializing an EAF object without filename is fine as well. This will just create an empty EAF file.

hoikiki commented 2 years ago

OK, here is new function to duplicate tiers within the same eaf file. Unfortunately the result is a tier with duplicated annotations and I have no idea why this happens, as you can't do that in elan manually. I'm sure there is a bug in my function or there is room for improvement. Any ideas?

Here are two files: temporary.eaf is a file with just one empty tier and it is used to make a temporary copy of a tier from the annotated.eaf. The new file is here. I hope you can run the code to reproduce the bug seen on this screenshot.

The URL was not found. I get stuck with duplicate tiers within the same eaf file. Thank you!