Browse Source

gin commit from PF2DSLKM

New files: 20
Moritz-Alexander-Kern 1 year ago
parent
commit
946a706c14
20 changed files with 711 additions and 0 deletions
  1. 62 0
      unittest/phase_analysis/weighted_phase_lag_index/README.md
  2. 103 0
      unittest/phase_analysis/weighted_phase_lag_index/data/wpli_ground_truth/LICENSE.txt
  3. 1 0
      unittest/phase_analysis/weighted_phase_lag_index/data/wpli_ground_truth/ground_truth_WPLI_from_ft_connectivity_wpli_with_artificial_LFPs.csv
  4. 1 0
      unittest/phase_analysis/weighted_phase_lag_index/data/wpli_ground_truth/ground_truth_WPLI_from_ft_connectivity_wpli_with_real_LFPs_R2G.csv
  5. 103 0
      unittest/phase_analysis/weighted_phase_lag_index/data/wpli_real_data/LICENSE.txt
  6. 57 0
      unittest/phase_analysis/weighted_phase_lag_index/data/wpli_real_data/README.md
  7. BIN
      unittest/phase_analysis/weighted_phase_lag_index/data/wpli_real_data/i140703-001_ch01_slice_TS_ON_to_GO_ON_correct_trials.mat
  8. BIN
      unittest/phase_analysis/weighted_phase_lag_index/data/wpli_real_data/i140703-001_ch02_slice_TS_ON_to_GO_ON_correct_trials.mat
  9. BIN
      unittest/phase_analysis/weighted_phase_lag_index/data/wpli_real_data/i140703-001_ch03_slice_TS_ON_to_GO_ON_correct_trials.mat
  10. BIN
      unittest/phase_analysis/weighted_phase_lag_index/data/wpli_real_data/i140703-001_cross_spectrum_of_channel_1_and_2_of_slice_TS_ON_to_GO_ON_corect_trials.mat
  11. 103 0
      unittest/phase_analysis/weighted_phase_lag_index/data/wpli_specific_artificial_dataset/LICENSE.txt
  12. BIN
      unittest/phase_analysis/weighted_phase_lag_index/data/wpli_specific_artificial_dataset/artificial_LFPs_1.mat
  13. BIN
      unittest/phase_analysis/weighted_phase_lag_index/data/wpli_specific_artificial_dataset/artificial_LFPs_2.mat
  14. BIN
      unittest/phase_analysis/weighted_phase_lag_index/data/wpli_specific_artificial_dataset/cross_spectrum_of_artificial_LFPs_1_and_2.mat
  15. 26 0
      unittest/phase_analysis/weighted_phase_lag_index/src/LICENSE.txt
  16. 29 0
      unittest/phase_analysis/weighted_phase_lag_index/src/call_script_routines_for_WPLI.py
  17. 97 0
      unittest/phase_analysis/weighted_phase_lag_index/src/generate_artificial_datasets_for_ground_truth_of_wpli.py
  18. 80 0
      unittest/phase_analysis/weighted_phase_lag_index/src/multielectrode_grasp_i140703_001_cutting_script_TS_ON_to_GO_ON.py
  19. 14 0
      unittest/phase_analysis/weighted_phase_lag_index/src/requirements.txt
  20. 35 0
      unittest/phase_analysis/weighted_phase_lag_index/src/wpli_get_ground_truth_via_ft_connectivity_wpli.m

+ 62 - 0
unittest/phase_analysis/weighted_phase_lag_index/README.md

@@ -0,0 +1,62 @@
+# Weighted Phase Lag Index  
+###### see [\[1\]](https://pubmed.ncbi.nlm.nih.gov/21276857/) for further information about the measure
+
+This license [CC BY 4.0](ground_truth_wpli/LICENSE.txt) covers the artificial 
+LFP-data and calculated ground truth data.  \
+This license [BSD-3](scripts/LICENSE.txt) covers the provided script codes. 
+
+## Description
+
+This folder contains subfolders for:
+* 1. the WPLI related artificial LFP datasets in 'wpli_specific_artificial_data'
+* 2. the ground truth data calculated by 'ft_connectivity_wpli' function from 
+     MATLAB package FieldTrip (see 
+     [\[2\]](https://pubmed.ncbi.nlm.nih.gov/21253357/) ) in 'ground_truth_wpli' 
+* 3. the scripts used for calculating the ground truth, slicing the 
+     [R2G-data](../../../dataset-4/R2G_slices) and creating the artificial 
+     LFP-data in 'scripts'.
+
+NOTE: *.mat files can't contain units, there for we provide the units explicitly
+
+The _artificial_LFPs_{i}.mat_ files in 'wpli_specific_artificial_data' contain 
+the artificial LFP-signals with the fields: 
+* 'lfp_matrix': multi-trial LFP-data with shape (150(trials) x 2500(samples); 
+  implicit unit: uV)
+* 'times':  time-vector (1 (aligned trials) x 2500 (time-points); 
+  implicit unit: msec)
+* 'sf': sampling frequency of the recording (1000; implicit unit: Hz)
+
+There is also a _cross_spectrum_of_artificial_LFPs_1_and_2.mat_ file containing 
+the cross-spectrum of signal 1 and 2 with the fields:
+* 'cross_spectrum_matrix': multi-trial cross-spectrum with shape 
+  (150(trials) x 1251(cross-spectrum))
+* 'frequencies': positive, real-valued frequencies with shape 
+  (1 (aligned trials) x 1251 (frequency); implicit unit: Hz)  
+
+The *.csv files in 'ground_truth_wpli' contain the function-dependent ground truths calculated by  
+the reference implementation:
+* data-shapes:
+  
+  * real data: 1 (aligned trials) x 1051 (WPLI values)
+  * artificial data: 1 (aligned trials) x 1251 (WPLI values)
+   
+
+* For WPLI the reference implementation is ft_connectivity_wpli() from the MATLAB
+package 'FieldTrip' (see [\[1\]](https://pubmed.ncbi.nlm.nih.gov/21276857/) for 
+  the reference method publication and 
+  [\[2\]](https://pubmed.ncbi.nlm.nih.gov/21253357/) for the toolbox publication). \
+Used versions of MATLAB & FieldTrip:\
+    MATLAB          Version 9.9         (2020b)\
+    FieldTrip       fieldtrip-20210128 
+  
+## References
+1. Vinck, Martin et al. “An improved index of phase-synchronization for 
+   electrophysiological data in the presence of volume-conduction, noise and 
+   sample-size bias.” NeuroImage vol. 55,4 (2011): 1548-65. 
+   doi:10.1016/j.neuroimage.2011.01.055
+2.  Oostenveld, R., Fries, P., Maris, E., Schoffelen, JM (2011). 
+    FieldTrip: Open Source Software for Advanced Analysis of MEG, EEG, and 
+    Invasive Electrophysiological Data. 
+    Computational Intelligence and Neuroscience, 
+    Volume 2011 (2011), Article ID 156869, doi:10.1155/2011/156869
+    

+ 103 - 0
unittest/phase_analysis/weighted_phase_lag_index/data/wpli_ground_truth/LICENSE.txt

@@ -0,0 +1,103 @@
+Creative Commons Attribution-ShareAlike 4.0 International Public License
+
+By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution-ShareAlike 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions.
+
+Section 1 – Definitions.
+
+    Adapted Material means material subject to Copyright and Similar Rights that is derived from or based upon the Licensed Material and in which the Licensed Material is translated, altered, arranged, transformed, or otherwise modified in a manner requiring permission under the Copyright and Similar Rights held by the Licensor. For purposes of this Public License, where the Licensed Material is a musical work, performance, or sound recording, Adapted Material is always produced where the Licensed Material is synched in timed relation with a moving image.
+    Adapter's License means the license You apply to Your Copyright and Similar Rights in Your contributions to Adapted Material in accordance with the terms and conditions of this Public License.
+    BY-SA Compatible License means a license listed at creativecommons.org/compatiblelicenses, approved by Creative Commons as essentially the equivalent of this Public License.
+    Copyright and Similar Rights means copyright and/or similar rights closely related to copyright including, without limitation, performance, broadcast, sound recording, and Sui Generis Database Rights, without regard to how the rights are labeled or categorized. For purposes of this Public License, the rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights.
+    Effective Technological Measures means those measures that, in the absence of proper authority, may not be circumvented under laws fulfilling obligations under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, and/or similar international agreements.
+    Exceptions and Limitations means fair use, fair dealing, and/or any other exception or limitation to Copyright and Similar Rights that applies to Your use of the Licensed Material.
+    License Elements means the license attributes listed in the name of a Creative Commons Public License. The License Elements of this Public License are Attribution and ShareAlike.
+    Licensed Material means the artistic or literary work, database, or other material to which the Licensor applied this Public License.
+    Licensed Rights means the rights granted to You subject to the terms and conditions of this Public License, which are limited to all Copyright and Similar Rights that apply to Your use of the Licensed Material and that the Licensor has authority to license.
+    Licensor means the individual(s) or entity(ies) granting rights under this Public License.
+    Share means to provide material to the public by any means or process that requires permission under the Licensed Rights, such as reproduction, public display, public performance, distribution, dissemination, communication, or importation, and to make material available to the public including in ways that members of the public may access the material from a place and at a time individually chosen by them.
+    Sui Generis Database Rights means rights other than copyright resulting from Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, as amended and/or succeeded, as well as other essentially equivalent rights anywhere in the world.
+    You means the individual or entity exercising the Licensed Rights under this Public License. Your has a corresponding meaning.
+
+Section 2 – Scope.
+
+    License grant.
+        Subject to the terms and conditions of this Public License, the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, irrevocable license to exercise the Licensed Rights in the Licensed Material to:
+            reproduce and Share the Licensed Material, in whole or in part; and
+            produce, reproduce, and Share Adapted Material.
+        Exceptions and Limitations. For the avoidance of doubt, where Exceptions and Limitations apply to Your use, this Public License does not apply, and You do not need to comply with its terms and conditions.
+        Term. The term of this Public License is specified in Section 6(a).
+        Media and formats; technical modifications allowed. The Licensor authorizes You to exercise the Licensed Rights in all media and formats whether now known or hereafter created, and to make technical modifications necessary to do so. The Licensor waives and/or agrees not to assert any right or authority to forbid You from making technical modifications necessary to exercise the Licensed Rights, including technical modifications necessary to circumvent Effective Technological Measures. For purposes of this Public License, simply making modifications authorized by this Section 2(a)(4) never produces Adapted Material.
+        Downstream recipients.
+            Offer from the Licensor – Licensed Material. Every recipient of the Licensed Material automatically receives an offer from the Licensor to exercise the Licensed Rights under the terms and conditions of this Public License.
+            Additional offer from the Licensor – Adapted Material. Every recipient of Adapted Material from You automatically receives an offer from the Licensor to exercise the Licensed Rights in the Adapted Material under the conditions of the Adapter’s License You apply.
+            No downstream restrictions. You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, the Licensed Material if doing so restricts exercise of the Licensed Rights by any recipient of the Licensed Material.
+        No endorsement. Nothing in this Public License constitutes or may be construed as permission to assert or imply that You are, or that Your use of the Licensed Material is, connected with, or sponsored, endorsed, or granted official status by, the Licensor or others designated to receive attribution as provided in Section 3(a)(1)(A)(i).
+
+    Other rights.
+        Moral rights, such as the right of integrity, are not licensed under this Public License, nor are publicity, privacy, and/or other similar personality rights; however, to the extent possible, the Licensor waives and/or agrees not to assert any such rights held by the Licensor to the limited extent necessary to allow You to exercise the Licensed Rights, but not otherwise.
+        Patent and trademark rights are not licensed under this Public License.
+        To the extent possible, the Licensor waives any right to collect royalties from You for the exercise of the Licensed Rights, whether directly or through a collecting society under any voluntary or waivable statutory or compulsory licensing scheme. In all other cases the Licensor expressly reserves any right to collect such royalties.
+
+Section 3 – License Conditions.
+
+Your exercise of the Licensed Rights is expressly made subject to the following conditions.
+
+    Attribution.
+
+        If You Share the Licensed Material (including in modified form), You must:
+            retain the following if it is supplied by the Licensor with the Licensed Material:
+                identification of the creator(s) of the Licensed Material and any others designated to receive attribution, in any reasonable manner requested by the Licensor (including by pseudonym if designated);
+                a copyright notice;
+                a notice that refers to this Public License;
+                a notice that refers to the disclaimer of warranties;
+                a URI or hyperlink to the Licensed Material to the extent reasonably practicable;
+            indicate if You modified the Licensed Material and retain an indication of any previous modifications; and
+            indicate the Licensed Material is licensed under this Public License, and include the text of, or the URI or hyperlink to, this Public License.
+        You may satisfy the conditions in Section 3(a)(1) in any reasonable manner based on the medium, means, and context in which You Share the Licensed Material. For example, it may be reasonable to satisfy the conditions by providing a URI or hyperlink to a resource that includes the required information.
+        If requested by the Licensor, You must remove any of the information required by Section 3(a)(1)(A) to the extent reasonably practicable.
+    ShareAlike.
+
+    In addition to the conditions in Section 3(a), if You Share Adapted Material You produce, the following conditions also apply.
+        The Adapter’s License You apply must be a Creative Commons license with the same License Elements, this version or later, or a BY-SA Compatible License.
+        You must include the text of, or the URI or hyperlink to, the Adapter's License You apply. You may satisfy this condition in any reasonable manner based on the medium, means, and context in which You Share Adapted Material.
+        You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, Adapted Material that restrict exercise of the rights granted under the Adapter's License You apply.
+
+Section 4 – Sui Generis Database Rights.
+
+Where the Licensed Rights include Sui Generis Database Rights that apply to Your use of the Licensed Material:
+
+    for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, reuse, reproduce, and Share all or a substantial portion of the contents of the database;
+    if You include all or a substantial portion of the database contents in a database in which You have Sui Generis Database Rights, then the database in which You have Sui Generis Database Rights (but not its individual contents) is Adapted Material, including for purposes of Section 3(b); and
+    You must comply with the conditions in Section 3(a) if You Share all or a substantial portion of the contents of the database.
+
+For the avoidance of doubt, this Section 4 supplements and does not replace Your obligations under this Public License where the Licensed Rights include other Copyright and Similar Rights.
+
+Section 5 – Disclaimer of Warranties and Limitation of Liability.
+
+    Unless otherwise separately undertaken by the Licensor, to the extent possible, the Licensor offers the Licensed Material as-is and as-available, and makes no representations or warranties of any kind concerning the Licensed Material, whether express, implied, statutory, or other. This includes, without limitation, warranties of title, merchantability, fitness for a particular purpose, non-infringement, absence of latent or other defects, accuracy, or the presence or absence of errors, whether or not known or discoverable. Where disclaimers of warranties are not allowed in full or in part, this disclaimer may not apply to You.
+    To the extent possible, in no event will the Licensor be liable to You on any legal theory (including, without limitation, negligence) or otherwise for any direct, special, indirect, incidental, consequential, punitive, exemplary, or other losses, costs, expenses, or damages arising out of this Public License or use of the Licensed Material, even if the Licensor has been advised of the possibility of such losses, costs, expenses, or damages. Where a limitation of liability is not allowed in full or in part, this limitation may not apply to You.
+
+    The disclaimer of warranties and limitation of liability provided above shall be interpreted in a manner that, to the extent possible, most closely approximates an absolute disclaimer and waiver of all liability.
+
+Section 6 – Term and Termination.
+
+    This Public License applies for the term of the Copyright and Similar Rights licensed here. However, if You fail to comply with this Public License, then Your rights under this Public License terminate automatically.
+
+    Where Your right to use the Licensed Material has terminated under Section 6(a), it reinstates:
+        automatically as of the date the violation is cured, provided it is cured within 30 days of Your discovery of the violation; or
+        upon express reinstatement by the Licensor.
+    For the avoidance of doubt, this Section 6(b) does not affect any right the Licensor may have to seek remedies for Your violations of this Public License.
+    For the avoidance of doubt, the Licensor may also offer the Licensed Material under separate terms or conditions or stop distributing the Licensed Material at any time; however, doing so will not terminate this Public License.
+    Sections 1, 5, 6, 7, and 8 survive termination of this Public License.
+
+Section 7 – Other Terms and Conditions.
+
+    The Licensor shall not be bound by any additional or different terms or conditions communicated by You unless expressly agreed.
+    Any arrangements, understandings, or agreements regarding the Licensed Material not stated herein are separate from and independent of the terms and conditions of this Public License.
+
+Section 8 – Interpretation.
+
+    For the avoidance of doubt, this Public License does not, and shall not be interpreted to, reduce, limit, restrict, or impose conditions on any use of the Licensed Material that could lawfully be made without permission under this Public License.
+    To the extent possible, if any provision of this Public License is deemed unenforceable, it shall be automatically reformed to the minimum extent necessary to make it enforceable. If the provision cannot be reformed, it shall be severed from this Public License without affecting the enforceability of the remaining terms and conditions.
+    No term or condition of this Public License will be waived and no failure to comply consented to unless expressly agreed to by the Licensor.
+    Nothing in this Public License constitutes or may be interpreted as a limitation upon, or waiver of, any privileges and immunities that apply to the Licensor or You, including from the legal processes of any jurisdiction or authority.

File diff suppressed because it is too large
+ 1 - 0
unittest/phase_analysis/weighted_phase_lag_index/data/wpli_ground_truth/ground_truth_WPLI_from_ft_connectivity_wpli_with_artificial_LFPs.csv


File diff suppressed because it is too large
+ 1 - 0
unittest/phase_analysis/weighted_phase_lag_index/data/wpli_ground_truth/ground_truth_WPLI_from_ft_connectivity_wpli_with_real_LFPs_R2G.csv


+ 103 - 0
unittest/phase_analysis/weighted_phase_lag_index/data/wpli_real_data/LICENSE.txt

@@ -0,0 +1,103 @@
+Creative Commons Attribution-ShareAlike 4.0 International Public License
+
+By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution-ShareAlike 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions.
+
+Section 1 – Definitions.
+
+    Adapted Material means material subject to Copyright and Similar Rights that is derived from or based upon the Licensed Material and in which the Licensed Material is translated, altered, arranged, transformed, or otherwise modified in a manner requiring permission under the Copyright and Similar Rights held by the Licensor. For purposes of this Public License, where the Licensed Material is a musical work, performance, or sound recording, Adapted Material is always produced where the Licensed Material is synched in timed relation with a moving image.
+    Adapter's License means the license You apply to Your Copyright and Similar Rights in Your contributions to Adapted Material in accordance with the terms and conditions of this Public License.
+    BY-SA Compatible License means a license listed at creativecommons.org/compatiblelicenses, approved by Creative Commons as essentially the equivalent of this Public License.
+    Copyright and Similar Rights means copyright and/or similar rights closely related to copyright including, without limitation, performance, broadcast, sound recording, and Sui Generis Database Rights, without regard to how the rights are labeled or categorized. For purposes of this Public License, the rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights.
+    Effective Technological Measures means those measures that, in the absence of proper authority, may not be circumvented under laws fulfilling obligations under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, and/or similar international agreements.
+    Exceptions and Limitations means fair use, fair dealing, and/or any other exception or limitation to Copyright and Similar Rights that applies to Your use of the Licensed Material.
+    License Elements means the license attributes listed in the name of a Creative Commons Public License. The License Elements of this Public License are Attribution and ShareAlike.
+    Licensed Material means the artistic or literary work, database, or other material to which the Licensor applied this Public License.
+    Licensed Rights means the rights granted to You subject to the terms and conditions of this Public License, which are limited to all Copyright and Similar Rights that apply to Your use of the Licensed Material and that the Licensor has authority to license.
+    Licensor means the individual(s) or entity(ies) granting rights under this Public License.
+    Share means to provide material to the public by any means or process that requires permission under the Licensed Rights, such as reproduction, public display, public performance, distribution, dissemination, communication, or importation, and to make material available to the public including in ways that members of the public may access the material from a place and at a time individually chosen by them.
+    Sui Generis Database Rights means rights other than copyright resulting from Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, as amended and/or succeeded, as well as other essentially equivalent rights anywhere in the world.
+    You means the individual or entity exercising the Licensed Rights under this Public License. Your has a corresponding meaning.
+
+Section 2 – Scope.
+
+    License grant.
+        Subject to the terms and conditions of this Public License, the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, irrevocable license to exercise the Licensed Rights in the Licensed Material to:
+            reproduce and Share the Licensed Material, in whole or in part; and
+            produce, reproduce, and Share Adapted Material.
+        Exceptions and Limitations. For the avoidance of doubt, where Exceptions and Limitations apply to Your use, this Public License does not apply, and You do not need to comply with its terms and conditions.
+        Term. The term of this Public License is specified in Section 6(a).
+        Media and formats; technical modifications allowed. The Licensor authorizes You to exercise the Licensed Rights in all media and formats whether now known or hereafter created, and to make technical modifications necessary to do so. The Licensor waives and/or agrees not to assert any right or authority to forbid You from making technical modifications necessary to exercise the Licensed Rights, including technical modifications necessary to circumvent Effective Technological Measures. For purposes of this Public License, simply making modifications authorized by this Section 2(a)(4) never produces Adapted Material.
+        Downstream recipients.
+            Offer from the Licensor – Licensed Material. Every recipient of the Licensed Material automatically receives an offer from the Licensor to exercise the Licensed Rights under the terms and conditions of this Public License.
+            Additional offer from the Licensor – Adapted Material. Every recipient of Adapted Material from You automatically receives an offer from the Licensor to exercise the Licensed Rights in the Adapted Material under the conditions of the Adapter’s License You apply.
+            No downstream restrictions. You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, the Licensed Material if doing so restricts exercise of the Licensed Rights by any recipient of the Licensed Material.
+        No endorsement. Nothing in this Public License constitutes or may be construed as permission to assert or imply that You are, or that Your use of the Licensed Material is, connected with, or sponsored, endorsed, or granted official status by, the Licensor or others designated to receive attribution as provided in Section 3(a)(1)(A)(i).
+
+    Other rights.
+        Moral rights, such as the right of integrity, are not licensed under this Public License, nor are publicity, privacy, and/or other similar personality rights; however, to the extent possible, the Licensor waives and/or agrees not to assert any such rights held by the Licensor to the limited extent necessary to allow You to exercise the Licensed Rights, but not otherwise.
+        Patent and trademark rights are not licensed under this Public License.
+        To the extent possible, the Licensor waives any right to collect royalties from You for the exercise of the Licensed Rights, whether directly or through a collecting society under any voluntary or waivable statutory or compulsory licensing scheme. In all other cases the Licensor expressly reserves any right to collect such royalties.
+
+Section 3 – License Conditions.
+
+Your exercise of the Licensed Rights is expressly made subject to the following conditions.
+
+    Attribution.
+
+        If You Share the Licensed Material (including in modified form), You must:
+            retain the following if it is supplied by the Licensor with the Licensed Material:
+                identification of the creator(s) of the Licensed Material and any others designated to receive attribution, in any reasonable manner requested by the Licensor (including by pseudonym if designated);
+                a copyright notice;
+                a notice that refers to this Public License;
+                a notice that refers to the disclaimer of warranties;
+                a URI or hyperlink to the Licensed Material to the extent reasonably practicable;
+            indicate if You modified the Licensed Material and retain an indication of any previous modifications; and
+            indicate the Licensed Material is licensed under this Public License, and include the text of, or the URI or hyperlink to, this Public License.
+        You may satisfy the conditions in Section 3(a)(1) in any reasonable manner based on the medium, means, and context in which You Share the Licensed Material. For example, it may be reasonable to satisfy the conditions by providing a URI or hyperlink to a resource that includes the required information.
+        If requested by the Licensor, You must remove any of the information required by Section 3(a)(1)(A) to the extent reasonably practicable.
+    ShareAlike.
+
+    In addition to the conditions in Section 3(a), if You Share Adapted Material You produce, the following conditions also apply.
+        The Adapter’s License You apply must be a Creative Commons license with the same License Elements, this version or later, or a BY-SA Compatible License.
+        You must include the text of, or the URI or hyperlink to, the Adapter's License You apply. You may satisfy this condition in any reasonable manner based on the medium, means, and context in which You Share Adapted Material.
+        You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, Adapted Material that restrict exercise of the rights granted under the Adapter's License You apply.
+
+Section 4 – Sui Generis Database Rights.
+
+Where the Licensed Rights include Sui Generis Database Rights that apply to Your use of the Licensed Material:
+
+    for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, reuse, reproduce, and Share all or a substantial portion of the contents of the database;
+    if You include all or a substantial portion of the database contents in a database in which You have Sui Generis Database Rights, then the database in which You have Sui Generis Database Rights (but not its individual contents) is Adapted Material, including for purposes of Section 3(b); and
+    You must comply with the conditions in Section 3(a) if You Share all or a substantial portion of the contents of the database.
+
+For the avoidance of doubt, this Section 4 supplements and does not replace Your obligations under this Public License where the Licensed Rights include other Copyright and Similar Rights.
+
+Section 5 – Disclaimer of Warranties and Limitation of Liability.
+
+    Unless otherwise separately undertaken by the Licensor, to the extent possible, the Licensor offers the Licensed Material as-is and as-available, and makes no representations or warranties of any kind concerning the Licensed Material, whether express, implied, statutory, or other. This includes, without limitation, warranties of title, merchantability, fitness for a particular purpose, non-infringement, absence of latent or other defects, accuracy, or the presence or absence of errors, whether or not known or discoverable. Where disclaimers of warranties are not allowed in full or in part, this disclaimer may not apply to You.
+    To the extent possible, in no event will the Licensor be liable to You on any legal theory (including, without limitation, negligence) or otherwise for any direct, special, indirect, incidental, consequential, punitive, exemplary, or other losses, costs, expenses, or damages arising out of this Public License or use of the Licensed Material, even if the Licensor has been advised of the possibility of such losses, costs, expenses, or damages. Where a limitation of liability is not allowed in full or in part, this limitation may not apply to You.
+
+    The disclaimer of warranties and limitation of liability provided above shall be interpreted in a manner that, to the extent possible, most closely approximates an absolute disclaimer and waiver of all liability.
+
+Section 6 – Term and Termination.
+
+    This Public License applies for the term of the Copyright and Similar Rights licensed here. However, if You fail to comply with this Public License, then Your rights under this Public License terminate automatically.
+
+    Where Your right to use the Licensed Material has terminated under Section 6(a), it reinstates:
+        automatically as of the date the violation is cured, provided it is cured within 30 days of Your discovery of the violation; or
+        upon express reinstatement by the Licensor.
+    For the avoidance of doubt, this Section 6(b) does not affect any right the Licensor may have to seek remedies for Your violations of this Public License.
+    For the avoidance of doubt, the Licensor may also offer the Licensed Material under separate terms or conditions or stop distributing the Licensed Material at any time; however, doing so will not terminate this Public License.
+    Sections 1, 5, 6, 7, and 8 survive termination of this Public License.
+
+Section 7 – Other Terms and Conditions.
+
+    The Licensor shall not be bound by any additional or different terms or conditions communicated by You unless expressly agreed.
+    Any arrangements, understandings, or agreements regarding the Licensed Material not stated herein are separate from and independent of the terms and conditions of this Public License.
+
+Section 8 – Interpretation.
+
+    For the avoidance of doubt, this Public License does not, and shall not be interpreted to, reduce, limit, restrict, or impose conditions on any use of the Licensed Material that could lawfully be made without permission under this Public License.
+    To the extent possible, if any provision of this Public License is deemed unenforceable, it shall be automatically reformed to the minimum extent necessary to make it enforceable. If the provision cannot be reformed, it shall be severed from this Public License without affecting the enforceability of the remaining terms and conditions.
+    No term or condition of this Public License will be waived and no failure to comply consented to unless expressly agreed to by the Licensor.
+    Nothing in this Public License constitutes or may be interpreted as a limitation upon, or waiver of, any privileges and immunities that apply to the Licensor or You, including from the legal processes of any jurisdiction or authority.

+ 57 - 0
unittest/phase_analysis/weighted_phase_lag_index/data/wpli_real_data/README.md

@@ -0,0 +1,57 @@
+# REACH-TO-GRASP Data
+
+This dataset is covered by this license: 
+[CC BY 4.0](LICENSE.txt)
+
+## Description
+
+This folder contains in the subfolder 'R2G_slices' the event-related LFP-cutouts 
+from the G-Node GIN repository 
+'Massively parallel multi-electrode recordings of macaque motor cortex during an
+instructed delayed reach-to-grasp task' 
+[R2G-repository](https://doi.gin.g-node.org/10.12751/g-node.f83565/) [1].
+
+The dataset is used for ground truth consistency checks of 
+phase-analysis functions like 'Weighted Phase Lag Index' (WPLI) in 
+[Elephant](https://github.com/NeuralEnsemble/elephant) [2].
+
+The slicing of this LFP recording was performed by the following steps:
+1. data-set i140703-001 was loaded and read with ReachGraspIO provided by [1].
+2. got start event 'TS_ON' for all correct trials 
+3. created the wanted epochs from start event 'TS_ON' to approximately 'GO_ON' 
+   with length 2.1 sec
+4. performed cut_segment_by_epoch()
+5. kept just the data of 3 channels
+6. rearranged sliced LFP-data to have the shape (trial x time) and saved it 
+   as *.mat file
+7. calculated cross-spectrum of channel 1 & 2 and saved it as *.mat file 
+
+NOTE: *.mat files can't contain units, there for we provide the units explicitly 
+
+The _i140703-001_ch0i_slice_TS_ON_to_GO_ON_correct_trials.mat_ 
+files contain the LFP-signal-recordings of a single channel, from
+event TS_ON to approximately GO_ON for all correct trials, with the fields: 
+* 'lfp_matrix': multi-trial LFP-data with shape (142 (trials) x 2100 (samples); 
+  implicit unit: uV)
+* 'times':  time-vector (1 (aligned trials) x 2100 (time points); implicit unit: 
+  msec)
+* 'sf': sampling frequency of the recording (1000; implicit unit: Hz)
+
+There is also a 
+_i140703-001_cross_spectrum_of_channel_1_and_2_of_slice_TS_ON_to_GO_ON_corect_trials.mat_ 
+file containing the cross-spectrum of channel 1 and 2 with
+the fields:
+* 'cross_spectrum_matrix': multi-trial cross-spectrum with shape 
+  (142 (trials) x 1051 (cross-spectrum))
+* 'frequencies': positive, real-valued frequencies with shape 
+  (1 (aligned trials) x 1051 (frequency); implicit unit: Hz)  
+  
+
+## References 
+1. Brochier T, Zehl L, Hao Y, Duret M, Sprenger J, Denker M, Grün S, 
+   Riehle A (2017) Massively parallel multi-electrode recordings of macaque 
+   motor cortex during an instructed delayed reach-to-grasp task. 
+   doi:10.12751/g-node.f83565
+2. Denker M, Yegenoglu A, Grün S (2018) Collaborative HPC-enabled workflows 
+   on the HBP Collaboratory using the Elephant framework. 
+   Neuroinformatics 2018, P19. doi:10.12751/incf.ni2018.0019   

BIN
unittest/phase_analysis/weighted_phase_lag_index/data/wpli_real_data/i140703-001_ch01_slice_TS_ON_to_GO_ON_correct_trials.mat


BIN
unittest/phase_analysis/weighted_phase_lag_index/data/wpli_real_data/i140703-001_ch02_slice_TS_ON_to_GO_ON_correct_trials.mat


BIN
unittest/phase_analysis/weighted_phase_lag_index/data/wpli_real_data/i140703-001_ch03_slice_TS_ON_to_GO_ON_correct_trials.mat


BIN
unittest/phase_analysis/weighted_phase_lag_index/data/wpli_real_data/i140703-001_cross_spectrum_of_channel_1_and_2_of_slice_TS_ON_to_GO_ON_corect_trials.mat


+ 103 - 0
unittest/phase_analysis/weighted_phase_lag_index/data/wpli_specific_artificial_dataset/LICENSE.txt

@@ -0,0 +1,103 @@
+Creative Commons Attribution-ShareAlike 4.0 International Public License
+
+By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution-ShareAlike 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions.
+
+Section 1 – Definitions.
+
+    Adapted Material means material subject to Copyright and Similar Rights that is derived from or based upon the Licensed Material and in which the Licensed Material is translated, altered, arranged, transformed, or otherwise modified in a manner requiring permission under the Copyright and Similar Rights held by the Licensor. For purposes of this Public License, where the Licensed Material is a musical work, performance, or sound recording, Adapted Material is always produced where the Licensed Material is synched in timed relation with a moving image.
+    Adapter's License means the license You apply to Your Copyright and Similar Rights in Your contributions to Adapted Material in accordance with the terms and conditions of this Public License.
+    BY-SA Compatible License means a license listed at creativecommons.org/compatiblelicenses, approved by Creative Commons as essentially the equivalent of this Public License.
+    Copyright and Similar Rights means copyright and/or similar rights closely related to copyright including, without limitation, performance, broadcast, sound recording, and Sui Generis Database Rights, without regard to how the rights are labeled or categorized. For purposes of this Public License, the rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights.
+    Effective Technological Measures means those measures that, in the absence of proper authority, may not be circumvented under laws fulfilling obligations under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, and/or similar international agreements.
+    Exceptions and Limitations means fair use, fair dealing, and/or any other exception or limitation to Copyright and Similar Rights that applies to Your use of the Licensed Material.
+    License Elements means the license attributes listed in the name of a Creative Commons Public License. The License Elements of this Public License are Attribution and ShareAlike.
+    Licensed Material means the artistic or literary work, database, or other material to which the Licensor applied this Public License.
+    Licensed Rights means the rights granted to You subject to the terms and conditions of this Public License, which are limited to all Copyright and Similar Rights that apply to Your use of the Licensed Material and that the Licensor has authority to license.
+    Licensor means the individual(s) or entity(ies) granting rights under this Public License.
+    Share means to provide material to the public by any means or process that requires permission under the Licensed Rights, such as reproduction, public display, public performance, distribution, dissemination, communication, or importation, and to make material available to the public including in ways that members of the public may access the material from a place and at a time individually chosen by them.
+    Sui Generis Database Rights means rights other than copyright resulting from Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, as amended and/or succeeded, as well as other essentially equivalent rights anywhere in the world.
+    You means the individual or entity exercising the Licensed Rights under this Public License. Your has a corresponding meaning.
+
+Section 2 – Scope.
+
+    License grant.
+        Subject to the terms and conditions of this Public License, the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, irrevocable license to exercise the Licensed Rights in the Licensed Material to:
+            reproduce and Share the Licensed Material, in whole or in part; and
+            produce, reproduce, and Share Adapted Material.
+        Exceptions and Limitations. For the avoidance of doubt, where Exceptions and Limitations apply to Your use, this Public License does not apply, and You do not need to comply with its terms and conditions.
+        Term. The term of this Public License is specified in Section 6(a).
+        Media and formats; technical modifications allowed. The Licensor authorizes You to exercise the Licensed Rights in all media and formats whether now known or hereafter created, and to make technical modifications necessary to do so. The Licensor waives and/or agrees not to assert any right or authority to forbid You from making technical modifications necessary to exercise the Licensed Rights, including technical modifications necessary to circumvent Effective Technological Measures. For purposes of this Public License, simply making modifications authorized by this Section 2(a)(4) never produces Adapted Material.
+        Downstream recipients.
+            Offer from the Licensor – Licensed Material. Every recipient of the Licensed Material automatically receives an offer from the Licensor to exercise the Licensed Rights under the terms and conditions of this Public License.
+            Additional offer from the Licensor – Adapted Material. Every recipient of Adapted Material from You automatically receives an offer from the Licensor to exercise the Licensed Rights in the Adapted Material under the conditions of the Adapter’s License You apply.
+            No downstream restrictions. You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, the Licensed Material if doing so restricts exercise of the Licensed Rights by any recipient of the Licensed Material.
+        No endorsement. Nothing in this Public License constitutes or may be construed as permission to assert or imply that You are, or that Your use of the Licensed Material is, connected with, or sponsored, endorsed, or granted official status by, the Licensor or others designated to receive attribution as provided in Section 3(a)(1)(A)(i).
+
+    Other rights.
+        Moral rights, such as the right of integrity, are not licensed under this Public License, nor are publicity, privacy, and/or other similar personality rights; however, to the extent possible, the Licensor waives and/or agrees not to assert any such rights held by the Licensor to the limited extent necessary to allow You to exercise the Licensed Rights, but not otherwise.
+        Patent and trademark rights are not licensed under this Public License.
+        To the extent possible, the Licensor waives any right to collect royalties from You for the exercise of the Licensed Rights, whether directly or through a collecting society under any voluntary or waivable statutory or compulsory licensing scheme. In all other cases the Licensor expressly reserves any right to collect such royalties.
+
+Section 3 – License Conditions.
+
+Your exercise of the Licensed Rights is expressly made subject to the following conditions.
+
+    Attribution.
+
+        If You Share the Licensed Material (including in modified form), You must:
+            retain the following if it is supplied by the Licensor with the Licensed Material:
+                identification of the creator(s) of the Licensed Material and any others designated to receive attribution, in any reasonable manner requested by the Licensor (including by pseudonym if designated);
+                a copyright notice;
+                a notice that refers to this Public License;
+                a notice that refers to the disclaimer of warranties;
+                a URI or hyperlink to the Licensed Material to the extent reasonably practicable;
+            indicate if You modified the Licensed Material and retain an indication of any previous modifications; and
+            indicate the Licensed Material is licensed under this Public License, and include the text of, or the URI or hyperlink to, this Public License.
+        You may satisfy the conditions in Section 3(a)(1) in any reasonable manner based on the medium, means, and context in which You Share the Licensed Material. For example, it may be reasonable to satisfy the conditions by providing a URI or hyperlink to a resource that includes the required information.
+        If requested by the Licensor, You must remove any of the information required by Section 3(a)(1)(A) to the extent reasonably practicable.
+    ShareAlike.
+
+    In addition to the conditions in Section 3(a), if You Share Adapted Material You produce, the following conditions also apply.
+        The Adapter’s License You apply must be a Creative Commons license with the same License Elements, this version or later, or a BY-SA Compatible License.
+        You must include the text of, or the URI or hyperlink to, the Adapter's License You apply. You may satisfy this condition in any reasonable manner based on the medium, means, and context in which You Share Adapted Material.
+        You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, Adapted Material that restrict exercise of the rights granted under the Adapter's License You apply.
+
+Section 4 – Sui Generis Database Rights.
+
+Where the Licensed Rights include Sui Generis Database Rights that apply to Your use of the Licensed Material:
+
+    for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, reuse, reproduce, and Share all or a substantial portion of the contents of the database;
+    if You include all or a substantial portion of the database contents in a database in which You have Sui Generis Database Rights, then the database in which You have Sui Generis Database Rights (but not its individual contents) is Adapted Material, including for purposes of Section 3(b); and
+    You must comply with the conditions in Section 3(a) if You Share all or a substantial portion of the contents of the database.
+
+For the avoidance of doubt, this Section 4 supplements and does not replace Your obligations under this Public License where the Licensed Rights include other Copyright and Similar Rights.
+
+Section 5 – Disclaimer of Warranties and Limitation of Liability.
+
+    Unless otherwise separately undertaken by the Licensor, to the extent possible, the Licensor offers the Licensed Material as-is and as-available, and makes no representations or warranties of any kind concerning the Licensed Material, whether express, implied, statutory, or other. This includes, without limitation, warranties of title, merchantability, fitness for a particular purpose, non-infringement, absence of latent or other defects, accuracy, or the presence or absence of errors, whether or not known or discoverable. Where disclaimers of warranties are not allowed in full or in part, this disclaimer may not apply to You.
+    To the extent possible, in no event will the Licensor be liable to You on any legal theory (including, without limitation, negligence) or otherwise for any direct, special, indirect, incidental, consequential, punitive, exemplary, or other losses, costs, expenses, or damages arising out of this Public License or use of the Licensed Material, even if the Licensor has been advised of the possibility of such losses, costs, expenses, or damages. Where a limitation of liability is not allowed in full or in part, this limitation may not apply to You.
+
+    The disclaimer of warranties and limitation of liability provided above shall be interpreted in a manner that, to the extent possible, most closely approximates an absolute disclaimer and waiver of all liability.
+
+Section 6 – Term and Termination.
+
+    This Public License applies for the term of the Copyright and Similar Rights licensed here. However, if You fail to comply with this Public License, then Your rights under this Public License terminate automatically.
+
+    Where Your right to use the Licensed Material has terminated under Section 6(a), it reinstates:
+        automatically as of the date the violation is cured, provided it is cured within 30 days of Your discovery of the violation; or
+        upon express reinstatement by the Licensor.
+    For the avoidance of doubt, this Section 6(b) does not affect any right the Licensor may have to seek remedies for Your violations of this Public License.
+    For the avoidance of doubt, the Licensor may also offer the Licensed Material under separate terms or conditions or stop distributing the Licensed Material at any time; however, doing so will not terminate this Public License.
+    Sections 1, 5, 6, 7, and 8 survive termination of this Public License.
+
+Section 7 – Other Terms and Conditions.
+
+    The Licensor shall not be bound by any additional or different terms or conditions communicated by You unless expressly agreed.
+    Any arrangements, understandings, or agreements regarding the Licensed Material not stated herein are separate from and independent of the terms and conditions of this Public License.
+
+Section 8 – Interpretation.
+
+    For the avoidance of doubt, this Public License does not, and shall not be interpreted to, reduce, limit, restrict, or impose conditions on any use of the Licensed Material that could lawfully be made without permission under this Public License.
+    To the extent possible, if any provision of this Public License is deemed unenforceable, it shall be automatically reformed to the minimum extent necessary to make it enforceable. If the provision cannot be reformed, it shall be severed from this Public License without affecting the enforceability of the remaining terms and conditions.
+    No term or condition of this Public License will be waived and no failure to comply consented to unless expressly agreed to by the Licensor.
+    Nothing in this Public License constitutes or may be interpreted as a limitation upon, or waiver of, any privileges and immunities that apply to the Licensor or You, including from the legal processes of any jurisdiction or authority.

BIN
unittest/phase_analysis/weighted_phase_lag_index/data/wpli_specific_artificial_dataset/artificial_LFPs_1.mat


BIN
unittest/phase_analysis/weighted_phase_lag_index/data/wpli_specific_artificial_dataset/artificial_LFPs_2.mat


BIN
unittest/phase_analysis/weighted_phase_lag_index/data/wpli_specific_artificial_dataset/cross_spectrum_of_artificial_LFPs_1_and_2.mat


+ 26 - 0
unittest/phase_analysis/weighted_phase_lag_index/src/LICENSE.txt

@@ -0,0 +1,26 @@
+Copyright (c) 2021, Institute of Neuroscience and Medicine (INM-6),
+Forschungszentrum Juelich, Germany
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this
+list of conditions and the following disclaimer.
+* Redistributions in binary form must reproduce the above copyright notice,
+this list of conditions and the following disclaimer in the documentation
+and/or other materials provided with the distribution.
+* Neither the names of the copyright holders nor the names of the contributors
+may be used to endorse or promote products derived from this software without
+specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+ 29 - 0
unittest/phase_analysis/weighted_phase_lag_index/src/call_script_routines_for_WPLI.py

@@ -0,0 +1,29 @@
+import subprocess
+import generate_artificial_datasets_for_ground_truth_of_wpli
+import multielectrode_grasp_i140703_001_cutting_script_TS_ON_to_GO_ON
+
+
+def main():
+    # run cutting script for multielectrode_grasp_i140703_001 data
+    print("Start multielectrode_grasp_i140703_001_cutting_script_TS_ON_to_GO_ON\n")
+    multielectrode_grasp_i140703_001_cutting_script_TS_ON_to_GO_ON.main()
+    print("Finished multielectrode_grasp_i140703_001_cutting_script_TS_ON_to_GO_ON\n")
+
+    # run generation-script for artificial-data
+    print("Start artifical data generation\n")
+    generate_artificial_datasets_for_ground_truth_of_wpli.main()
+    print("Finished artifical data generation\n")
+
+    # run MATLAB-scripts
+    run_matlab_1 = 'matlab -batch "wpli_get_ground_truth_via_ft_connectivity_wpli ARTIFICIAL"'
+    run_matlab_2 = 'matlab -batch "wpli_get_ground_truth_via_ft_connectivity_wpli REAL"'
+    print("Start MATLAB-script for ground truth via ft_connectivity_wpli with ARTIFICIAL data\n")
+    subprocess.run(run_matlab_1, shell=True, check=True)
+    print("Finished MATLAB-script for ground truth via ft_connectivity_wpli with ARTIFICIAL data\n")
+    print("Start MATLAB-script for ground truth via ft_connectivity_wpli with REAL data\n")
+    subprocess.run(run_matlab_2, shell=True, check=True)
+    print("Finished MATLAB-script for ground truth via ft_connectivity_wpli with REAL data\n")
+
+
+if __name__ == '__main__':
+    main()

+ 97 - 0
unittest/phase_analysis/weighted_phase_lag_index/src/generate_artificial_datasets_for_ground_truth_of_wpli.py

@@ -0,0 +1,97 @@
+import numpy as np
+from scipy.io import savemat
+import quantities as pq
+
+
+def _generate_datasets_for_ground_truth_testing(ntrial=150, tlength=2.5,
+                                                srate=1000):
+    """
+    Generates simple sinusoidal, artificial LFP-datasets.
+
+    This function simulates the recording of two LFP-signals over several
+    trials, for a certain duration of time and with a specified sampling
+    rate. These datasets will be used to calculate WPLI-ground-truth
+    with the MATlAB package FieldTrip and its function
+    ft_connectivity_wpli(), its wrapper ft_connectivityanalysis() and
+    with MNEs spectral_connectivity(). The last two use both multitaper
+    for FFT, therefore just certain frequencies will be compared.
+
+    Parameters
+    ----------
+    ntrial: int
+        Number of trials in the datasets.
+    tlength: float
+        Time length of the datasets in seconds.
+    srate: float
+        Sampling rate used to 'record' the signals in Hz.
+
+    Returns
+    -------
+    None
+
+    Notes
+    -----
+    Used versions of MATLAB & FieldTrip:
+    MATLAB          Version 9.9         (2020b)
+    FieldTrip       fieldtrip-20210128
+
+    Instead of using the ft_connectivityanalysis() wrapper function, which
+    expects preprocessed data, the ft_connectivity_wpli() is called
+    directly. That's because the preprocessing functions of FieldTrip have
+    no 'conventional' Fourier-Transformation (FFT) method, but among
+    others a multitaper-FFT. Because this python-version of WPLI doesn't
+    use multitaper, but conventional FFT, the utilized MATLAB script also
+    uses the conventional FFT to preprocess the data and calculate the
+    cross-spectrum, which will then be passed to the ft_connectivity_wpli.
+
+    """
+    np.random.seed(73)
+
+    times = np.arange(0, tlength, 1 / srate)
+
+    # lfps_1 & 2 will be used for
+    # 1) calculating ground-truth with FieldTrips' ft_connectivity_wpli
+    lfps_1 = [np.cos(2 * 16 * np.pi * times + np.pi / 2) +
+              np.cos(2 * 36 * np.pi * times + np.pi / 2) +
+              np.cos(2 * 52 * np.pi * times) +
+              np.cos(2 * 100 * np.pi * times) +
+              np.cos(2 * 70 * np.pi * times + np.pi / 2 + np.pi * (i % 2)) +
+              np.random.normal(loc=0.0, scale=1, size=len(times))
+              for i in range(ntrial)]
+    lfps_1 = np.stack(lfps_1, axis=0) * pq.uV
+
+    lfps_2 = [np.cos(2 * 16 * np.pi * times) +
+              np.cos(2 * 36 * np.pi * times) +
+              np.cos(2 * 52 * np.pi * times + np.pi / 2) +
+              np.cos(2 * 100 * np.pi * times + np.pi / 2) +
+              np.cos(2 * 70 * np.pi * times) +
+              np.random.normal(loc=0.0, scale=1, size=len(times))
+              for _ in range(ntrial)]
+    lfps_2 = np.stack(lfps_2, axis=0) * pq.uV
+
+    # save artificial LFP-dataset to .mat files
+    mdic_1 = {"lfp_matrix": lfps_1, "time": times, "sf": srate}
+    mdic_2 = {"lfp_matrix": lfps_2, "time": times, "sf": srate}
+    filename1_artificial = "../wpli_specific_artificial_dataset/artificial_LFPs_1.mat"
+    filename2_artificial = "../wpli_specific_artificial_dataset/artificial_LFPs_2.mat"
+    savemat(filename1_artificial, mdic_1)
+    savemat(filename2_artificial, mdic_2)
+
+    # save cross-spectrum of those two LFP-matrices
+    fft1 = np.fft.rfft(lfps_1)
+    fft2 = np.fft.rfft(lfps_2)
+    window_length = np.shape(lfps_1)[1]
+    freq = np.fft.rfftfreq(window_length, d=1./srate)
+    cs = fft1 * np.conjugate(fft2)
+    cs_dict = {"cross_spectrum_matrix": cs, "frequencies": freq}
+    cs_fname = "../wpli_specific_artificial_dataset/cross_spectrum_of_artificial_LFPs_1_and_2.mat"
+    savemat(cs_fname, cs_dict)
+
+
+def main():
+    """Run generation function."""
+    _generate_datasets_for_ground_truth_testing()
+
+
+if __name__ == '__main__':
+    main()

+ 80 - 0
unittest/phase_analysis/weighted_phase_lag_index/src/multielectrode_grasp_i140703_001_cutting_script_TS_ON_to_GO_ON.py

@@ -0,0 +1,80 @@
+from neo.utils import get_events
+import quantities as pq
+from scipy.io import savemat
+import numpy as np
+from pathlib import Path
+
+# from multielectrode_grasp G-Node Gin repository
+# used version from branch 'master':
+# commit "placeholder-hash"
+# TODO: update commit after 'elephant-data' PR-'enh/neo09-2' is merged into master
+import reachgraspio.reachgraspio as rg
+
+
+def main():
+    # # load & read dataset for i140703-001
+    multielectrode_grasp_path = "/home/kramer/datasets/multielectrode_grasp/" \
+                                "datasets"
+    # Todo: before commiting use THIS generic path to multielectrode_grasp:
+    # multielectrode_grasp_path = "GNode-GIN/multielectrode_grasp/datasets"
+    session_name = Path(multielectrode_grasp_path, "i140703-001")
+    session = rg.ReachGraspIO(session_name.__str__(),
+                              odml_directory=multielectrode_grasp_path)
+    
+    # channels to slice from
+    channels = [1, 2, 3]
+
+    # read block in lazy-mode for updated reachgraspio
+    data_block = session.read_block(lazy=True, correct_filter_shifts=True)
+
+    # get the TrialStart(TS)-Events for correct trials
+    correct_trial_start_events = get_events(
+        data_block, name='TrialEvents', trial_event_labels='TS-ON',
+        performance_in_trial=session.performance_codes['correct_trial'])[0]
+
+    # create time-slices of length 2.1sec
+    neural_signals = data_block.filter(targdict={'neural_signal': True})[0]
+    neural_signals = [neural_signals.time_slice(i, i + 2.102 * pq.s)
+                      for i in correct_trial_start_events]
+    # reset t_start to 0sec
+    neural_signals = [neural_signals[i].time_shift(-neural_signals[i].times[0])
+                      for i in range(len(neural_signals))]
+    times = neural_signals[0].times[:2100]
+    srate = neural_signals[0].sampling_rate
+    # transpose matrix to get shape trials x samples
+    neural_signals = [neural_signals[i].transpose()
+                      for i in range(len(neural_signals))]
+
+    # create for each channel a dictionary with the fields:
+    # 'lfp_matrix', 'time' and 'sf' and save them as *.mat files
+    dataset_4_path = "../../../../dataset-4"
+    channel_dicts = {}
+    fname_dict = {}
+
+    for i in channels:
+        ch_id = i
+        channel_dicts[f"mdic_{ch_id}"] = {
+            "lfp_matrix": np.array(
+                [neural_signals[j][i-1][:2100].squeeze()
+                 # python-indexing!: first channel has index 0 -> i-1 needed
+                    for j in range(len(neural_signals))]),
+            "time": times,
+            "sf": srate}
+        fname_dict[f"fname{ch_id}"] = \
+            f"i140703-001_ch0{ch_id}_slice_TS_ON_to_GO_ON_correct_trials.mat"
+        savemat(Path(dataset_4_path, fname_dict[f"fname{ch_id}"]),
+                channel_dicts[f"mdic_{ch_id}"])
+
+    fft1 = np.fft.rfft(channel_dicts["mdic_1"]['lfp_matrix'])
+    fft2 = np.fft.rfft(channel_dicts["mdic_2"]['lfp_matrix'])
+    window_length = np.shape(channel_dicts["mdic_1"]['lfp_matrix'])[1]
+    freq = np.fft.rfftfreq(window_length, d=1./srate)
+    cs = fft1 * np.conjugate(fft2)
+    cs_dict = {"cross_spectrum_matrix": cs, "frequencies": freq}
+    cs_fname = "i140703-001_cross_spectrum_of_channel_1_and_2_of_slice_" \
+               "TS_ON_to_GO_ON_corect_trials.mat"
+    savemat(Path(dataset_4_path, cs_fname), cs_dict)
+
+
+if __name__ == '__main__':
+    main()

+ 14 - 0
unittest/phase_analysis/weighted_phase_lag_index/src/requirements.txt

@@ -0,0 +1,14 @@
+# G-Node GIN multielectrode_grasp repository for the reachgraspio.py module from master branch
+# git+https://gin.g-node.org/INT/multielectrode_grasp.git@synced/enh/neo09-2#egg=multielectro_grasp
+
+# versions currently used
+python==3.9
+neo==0.9.0
+odml==1.5.1
+numpy==1.20.3
+quantities==0.12.4
+scipy==1.6.2
+
+# Used versions of MATLAB & FieldTrip:
+# MATLAB Version 9.9 (2020b)
+# FieldTrip fieldtrip-20210128

+ 35 - 0
unittest/phase_analysis/weighted_phase_lag_index/src/wpli_get_ground_truth_via_ft_connectivity_wpli.m

@@ -0,0 +1,35 @@
+%% use FieldTrips' ft_connectivity_wpli() to calculate WPLI ground-truth
+
+function wpli_get_ground_truth_via_ft_connectivity_wpli(data_type)
+    addpath '/path/to/FieldTrip_toolbox'
+
+    if strcmpi(data_type, "REAL")
+        % cutted REAL DATA from multielectrode_grasp GIN-repository 
+        cs_dataset = load('../../../../dataset-4/i140703-001_cross_spectrum_of_channel_1_and_2_of_slice_TS_ON_to_GO_ON_corect_trials.mat');
+        cs = cs_dataset.cross_spectrum_matrix;
+    elseif strcmpi(data_type, "ARTIFICIAL")
+        % ARTIFICIAL DATA
+        cs_dataset =load('../wpli_specific_artificial_dataset/cross_spectrum_of_artificial_LFPs_1_and_2.mat');
+        cs = cs_dataset.cross_spectrum_matrix;
+    else
+        throw(ValueError("'REAL' and 'ARTIFICIAL' are accepted types"));
+    end
+
+    % reshape cross-spectrum, to meet expected input-shape
+    % of ft_connectivity_wpli() 
+    siz_2 = size(cs)
+    trials = siz_2(1)
+    freq_points = siz_2(2)
+    cs = reshape(cs, [trials, 1, freq_points]);
+
+    [wpli_1, v, n] = ft_connectivity_wpli(cs, 'feedback', 'text', 'dojack', 0, 'debias', 0);
+
+    if strcmpi(data_type, "REAL")
+        wpli_1 = abs(wpli_1); 
+        writematrix(wpli_1, '../ground_truth_wpli/ground_truth_WPLI_from_ft_connectivity_wpli_with_real_LFPs_R2G.csv'); 
+    else
+        writematrix(wpli_1, '../ground_truth_wpli/ground_truth_WPLI_from_ft_connectivity_wpli_with_artificial_LFPs.csv');
+    end
+    
+    exit;
+end