Package: pyethnobiology
pyethnobiologyEthnobiological data assessment toolIntroductionThis tool is designed to help researchers analyze their ethnobiological data. It is based on theethnobotanyRpackage with some modifications. Also, for further information on the methods used in this tool, please refer to the ethnobotanyR package.Scientific explanations of the indices used in this tool can be found in thedocumentation of the ethnobotanyR package.InstallationTo install this package, you can use the following code:pipinstallpyethnobiologyWe recommend use virtualenv to install this package.Getting startedImporting the packageimportpandasaspdfrompyethnobiologyimportpyethnobiologyAccepted data formatsThis package accepts data in the following formats:A data frame with the following columns: informant, taxon, uses. The use columns must be binary (0 or 1). For example:informantsp_nameUse_1Use_2Use_3Use_4Use_5inform_asp_a00011inform_asp_b00000inform_asp_c00100inform_asp_d00000inform_bsp_a01001A data frame with the following columns: informant, taxon, use. The use column must be a string. For example:informantsp_nameailments_treatedinform_asp_aUse_3inform_asp_aUse_8inform_asp_aUse_9inform_asp_cUse_6inform_asp_cUse_7inform_bsp_dUse_3inform_bsp_dUse_6inform_bsp_dUse_7inform_bsp_dUse_8Literature data is optional for Jaccard index calculation. If there is a multiple literatures, they must be separated by a semicolon. For example:informantsp_nameailments_treatedliteratureinform_asp_aUse_31inform_asp_aUse_81;2inform_asp_aUse_91;3;5inform_asp_cUse_62inform_asp_cUse_71;7inform_bsp_dUse_33To use this package, you can use the following code:Load data from csv, excel or txt file# You can define your separator, for example: sep=";" or sep="\t". By default, the separator is ",".data=pd.read_csv("{path}/data.csv")# or pd.read_excel("data.xlsx") or pd.read_csv("data.txt")Load rda (R Data) filedata="{path}/data.rda"Define the columnsIf uses are binary values in your data (first example in accepted data formats), you don't need to define the use column. But if uses are strings (second example in accepted data formats), you have to define the use column. For example:# if uses are binary valuesinformant_column="informant"taxon_column="sp_name"convert_use_data=True# if uses are stringsinformant_column="informant"taxon_column="sp_name"use_column="ailments_treated"# if you have literature datainformant_column="informant"taxon_column="sp_name"use_column="ailments_treated"literature_column="literature"Create an instance of the classpye=pyethnobiology(data,informant_column,taxon_column,convert_use_data)You can also define the use column and literature column in the class instance. For example:pye=pyethnobiology(data,informant_column="informant",taxon_column="sp_name",use_column="ailments_treated")Indice calculationsUse Report (UR) per speciespye.UR().calculate()Out[1]:sp_nameUR0sp_c521sp_a432sp_d433sp_b36Cultural Importance (CI) indexpye.CI().calculate()Out[1]:sp_nameCI0sp_c2.601sp_a2.152sp_d2.153sp_b1.80Frequency of Citation (FC) per speciespye.FC().calculate()Out[1]:sp_nameFC0sp_c171sp_a152sp_b123sp_d12Number of Uses (NU) per speciespye.NU().calculate()Out[1]:sp_nameNU0sp_c81sp_d82sp_a73sp_b7Relative Frequency of Citation (RFC) indexpye.RFC().calculate()Out[1]:sp_nameRFC0sp_c0.851sp_a0.752sp_b0.603sp_d0.60Relative Importance (RI) indexpye.RI().calculate()Out[1]:sp_nameRI0sp_c1.0000001sp_a0.8786762sp_d0.8529413sp_b0.790441Use Value (UV) indexpye.UV().calculate()Out[1]:sp_nameUV0sp_c2.601sp_a2.152sp_d2.153sp_b1.80Cultural Value (CV) for ethnospeciespye.CV().calculate()Out[1]:sp_nameCV0sp_c1.768002sp_a1.128751sp_d1.032003sp_b0.75600Fidelity Level (FL) per speciespye.FL().calculate()Out[1]:sp_nameailments_treatedFL1sp_aUse_1020.0000002sp_aUse_253.3333333sp_aUse_360.0000005sp_aUse_533.3333336sp_aUse_646.6666678sp_aUse_840.0000009sp_aUse_933.33333310sp_bUse_150.00000013sp_bUse_341.66666714sp_bUse_433.33333315sp_bUse_533.33333316sp_bUse_641.66666717sp_bUse_758.33333319sp_bUse_941.66666720sp_cUse_152.94117621sp_cUse_1035.29411822sp_cUse_241.17647124sp_cUse_435.29411825sp_cUse_517.64705926sp_cUse_623.52941227sp_cUse_729.41176528sp_cUse_870.58823530sp_dUse_141.66666732sp_dUse_225.00000033sp_dUse_358.33333335sp_dUse_58.33333336sp_dUse_641.66666737sp_dUse_766.66666738sp_dUse_875.00000039sp_dUse_941.666667Informant Consensus Factor (FIC)Informant Consensus Factor (FIC) operates like a consensus barometer, assessing the agreement among individuals. It boils down to a simple equation:where Nur is the number of use reports for a particular use category and Nt is the number of taxa used for that category. The FIC ranges from 0 to 1, with 0 indicating no agreement among informants and 1 indicating that all informants agree on the taxa to be used for a particular category (Heinrich et al., 1998;Güzel et al., 2015).pye.FIC().calculate()Out[1]:ailments_treatedFIC0Use_80.9230771Use_30.9000002Use_70.8947373Use_10.8947374Use_40.8888895Use_20.8823536Use_100.8750007Use_90.8571438Use_60.8500009Use_50.750000Jaccard similarity indexJaccard similarity index is a measure of similarity between two sets of data. The higher the Jaccard index, the more similar the two samples are. You can calculate the Jaccard index for all studies or for each study. For example:pye.jaccard()Out[1]:studysimilarity020.480000130.480000250.480000360.440000410.400000540.360000670.360000790.2000008100.035714980.000000Mean similarity of all studies:pye.jaccard()['similarity'].mean()Out[1]:0.32357142857142857# Round to 2 decimal placespye.jaccard()['similarity'].mean().round(2)Out[1]:0.32VisualizationRadial plotYou can plot all indices in a radial plotexcept Fidelity Level (FL). For example:#Use Report (UR) per speciespye.UR().plot_radial()Customization of the radial plotYou can customize the radial plot. For example:#Use Report (UR) per speciespye.UR().plot_radial(filename="UR.png",# You can define the saving filename. It is default to "UR.png" for UR index.dpi=300,# You can define the dpi. It is default to 300.num_row=10,# It is default to 10 which is the first 10 rows of the data.ytick_position="onbar",# You can define the ytick position. It is default to "onbar".colors=None,# You can define the colors. It is default to None.show_colorbar=True# You can define if you want to show the colorbar. It is default to True.)num_rowmeans the number of species you want to plot. For example, if you want to plot the first 5 species of the data, you can use the following code:#Use Report (UR) per speciespye.UR().plot_radial(num_row=5)You can change the colors of the radial plot. It takes the range of two colors. For example:#Use Report (UR) per speciespye.UR().plot_radial(colors=["#ECF4D6","#265073"])# [minimum value color, maximum value color]You can also use multiple configurations. For example:#Use Report (UR) per speciespye.UR().plot_radial(filename="UR_conf.png",dpi=300,num_row=5,ytick_position="onbar",# on_linecolors=["#ECF4D6","#265073"],show_colorbar=False)HeatmapYou can only plot the Fidelity Level (FL) index in a heatmap. For example:#Fidelity Level (FL) per speciespye.FL().plot_heatmap()Customization of the heatmapYou can customize the heatmap. For example:#Fidelity Level (FL) per speciespye.FL().plot_heatmap(filename="FL.png",# You can define the saving filename. It is default to "FL.png"cmap="coolwarm",# You can define the cmap. It is default to "coolwarm".show_colorbar=True,# You can define if you want to show the colorbar. It is default to True.colorbar_shrink=0.50,# You can define the colorbar shrink. It is default to 0.50.plot_width=10,# You can define the plot width. It is default to 10.plot_height=8,# You can define the plot height. It is default to 8.dpi=300,# You can define the dpi. It is default to 300.fillna_zero=True# You can define if you want to fill the NaN values with 0. It is default to True.))Supported cmaps:https://matplotlib.org/stable/tutorials/colors/colormaps.html#Fidelity Level (FL) per speciespye.FL().plot_heatmap(filename="FL_reds.png",cmap="Reds")Chord plotYou can plot all data with the Chord plot. It is diagram of ethnobiological uses and species. For example:pye.plot_chord()Customization of the Chord plotYou can customize the Chord plot. For example:pye.plot_chord(filename="chord_plot.png",# You can define the saving filename. It is default to "chord_plot.png"dpi=300,# You can define the dpi. It is default to 300.by="taxon",# You can define the by. It is default to "taxon". Other option is "informant".colors=None,# You can define the colors. It is default to None.min_info_count=0,# You can define the minimum information count for filter data. It is default to 0.get_first=None# You can define the number of first data. It is default to None.)You can change the colors of the Chord plot.
Supported cmaps:https://matplotlib.org/stable/tutorials/colors/colormaps.htmlpye.plot_chord(colors="Dark2")You can also use multiple configurations. For example:pye.plot_chord(filename="chord_plot_conf.png",dpi=300,by="informant",colors="tab20b",min_info_count=5,get_first=10)