{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"%pylab inline --no-import-all \nfrom pathlib import Path ","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-06-11T11:49:35.915754Z","iopub.execute_input":"2022-06-11T11:49:35.916394Z","iopub.status.idle":"2022-06-11T11:49:35.949718Z","shell.execute_reply.started":"2022-06-11T11:49:35.916263Z","shell.execute_reply":"2022-06-11T11:49:35.948687Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Data_path = Path(\"../input/geolifeclef-2022-lifeclef-2022-fgvc9\")","metadata":{"execution":{"iopub.status.busy":"2022-06-11T11:49:35.951635Z","iopub.execute_input":"2022-06-11T11:49:35.951981Z","iopub.status.idle":"2022-06-11T11:49:35.957177Z","shell.execute_reply.started":"2022-06-11T11:49:35.951944Z","shell.execute_reply":"2022-06-11T11:49:35.956092Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ls -L $Data_path","metadata":{"execution":{"iopub.status.busy":"2022-06-11T11:49:35.958572Z","iopub.execute_input":"2022-06-11T11:49:35.959101Z","iopub.status.idle":"2022-06-11T11:49:36.732004Z","shell.execute_reply.started":"2022-06-11T11:49:35.959064Z","shell.execute_reply":"2022-06-11T11:49:36.730929Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ls $Data_path/observations","metadata":{"execution":{"iopub.status.busy":"2022-06-11T11:49:36.733201Z","iopub.execute_input":"2022-06-11T11:49:36.733751Z","iopub.status.idle":"2022-06-11T11:49:37.552692Z","shell.execute_reply.started":"2022-06-11T11:49:36.733690Z","shell.execute_reply":"2022-06-11T11:49:37.551722Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd \n","metadata":{"execution":{"iopub.status.busy":"2022-06-11T11:49:37.554840Z","iopub.execute_input":"2022-06-11T11:49:37.555399Z","iopub.status.idle":"2022-06-11T11:49:37.565157Z","shell.execute_reply.started":"2022-06-11T11:49:37.555346Z","shell.execute_reply":"2022-06-11T11:49:37.562853Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_obs_us = pd.read_csv(Data_path/ \"observations\"/ \"observations_us_train.csv\",sep=\";\",index_col=\"observation_id\")\ndf_obs_fr = pd.read_csv(Data_path/ \"observations\"/ \"observations_fr_train.csv\",sep=\";\",index_col=\"observation_id\")\n\ndf_obs= pd.concat((df_obs_us,df_obs_fr))\n\nprint(\"Number of observation for training: {}\".format(len(df_obs)))\n\ndf_obs.head()","metadata":{"execution":{"iopub.status.busy":"2022-06-11T11:49:37.568734Z","iopub.execute_input":"2022-06-11T11:49:37.569699Z","iopub.status.idle":"2022-06-11T11:49:40.100733Z","shell.execute_reply.started":"2022-06-11T11:49:37.569646Z","shell.execute_reply":"2022-06-11T11:49:40.099525Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_obs_fr_test= pd.read_csv(Data_path/\"observations\"/\"observations_fr_test.csv\",sep=\";\",index_col=\"observation_id\")\ndf_obs_us_test= pd.read_csv(Data_path/\"observations\"/ \"observations_us_test.csv\",sep=\";\",index_col=\"observation_id\")\n\ndf_obs_test=pd.concat((df_obs_fr_test,df_obs_us_test))\n\nprint(\"Number of observation in test set:{}\".format(len(df_obs_test)))\n\ndf_obs_test.head()","metadata":{"execution":{"iopub.status.busy":"2022-06-11T11:49:40.102050Z","iopub.execute_input":"2022-06-11T11:49:40.102388Z","iopub.status.idle":"2022-06-11T11:49:40.176694Z","shell.execute_reply.started":"2022-06-11T11:49:40.102356Z","shell.execute_reply":"2022-06-11T11:49:40.175502Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!rm -rf GLC\n!git clone https://github.com/maximiliense/GLC","metadata":{"execution":{"iopub.status.busy":"2022-06-11T11:49:40.178448Z","iopub.execute_input":"2022-06-11T11:49:40.179064Z","iopub.status.idle":"2022-06-11T11:49:43.606281Z","shell.execute_reply.started":"2022-06-11T11:49:40.179016Z","shell.execute_reply":"2022-06-11T11:49:43.605327Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from GLC.plotting import plot_map\n\n\ndef plot_observations_distribution(ax, df_obs, df_obs_test=None, **kwargs):\n    default_kwargs = {\n        \"zorder\": 1,\n        \"alpha\": 0.1,\n        \"s\": 0.5\n    }\n    default_kwargs.update(kwargs)\n    kwargs = default_kwargs\n    \n    ax.scatter(df_obs.longitude, df_obs.latitude, color=\"blue\", **kwargs)\n    \n    if df_obs_test is not None:\n        ax.scatter(df_obs_test.longitude, df_obs_test.latitude, color=\"red\", **kwargs)\n\n\nfig = plt.figure(figsize=(10, 5.5))\nax = plot_map(region=\"us\")\nplot_observations_distribution(ax, df_obs_us, df_obs_us_test)\nax.set_title(\"Observations distribution (US)\")\n\n# fig.savefig(\"../input/geolifeclef-2022-lifeclef-2022-fgvc9/observations/images/observations_distribution_US.png\", bbox_inches=\"tight\", dpi=100, facecolor=\"white\")\n\n\nfig = plt.figure(figsize=(8, 8))\nax = plot_map(region=\"fr\")\nplot_observations_distribution(ax, df_obs_fr, df_obs_fr_test)\nax.set_title(\"Observations distribution (France)\")\n\n# fig.savefig(\"../input/geolifeclef-2022-lifeclef-2022-fgvc9/observations/observations_distribution_FR.png\", bbox_inches=\"tight\", dpi=100, facecolor=\"white\")","metadata":{"execution":{"iopub.status.busy":"2022-06-11T11:49:43.607554Z","iopub.execute_input":"2022-06-11T11:49:43.609065Z","iopub.status.idle":"2022-06-11T11:49:56.218567Z","shell.execute_reply.started":"2022-06-11T11:49:43.609012Z","shell.execute_reply":"2022-06-11T11:49:56.217604Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def select_samples_around_point(df_obs,lon_min,lon_max,lat_min,lat_max):\n    ind= ((lon_min<=df_obs.longitude) & (lon_max>= df_obs.longitude)\n         & (lat_min<= df_obs.latitude) & (lat_max>= df_obs.latitude))\n    return df_obs[ind]\n\nextent= [3, 4.5, 43.25, 44.25]\n\nfig= plt.figure(figsize=(9.5,7))\nax= plot_map(extent=extent)\n\nplt.show(ax)","metadata":{"execution":{"iopub.status.busy":"2022-06-11T11:49:56.219777Z","iopub.execute_input":"2022-06-11T11:49:56.220444Z","iopub.status.idle":"2022-06-11T11:49:56.667617Z","shell.execute_reply.started":"2022-06-11T11:49:56.220411Z","shell.execute_reply":"2022-06-11T11:49:56.666239Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# df_obs_zoom= select_samples_around_point(df_obs_fr,*extent)\n# df_obs_zoom_test= select_samples_around_point(df_obs_fr_test, *extent)\n\n# kwargs = {\n#     \"alpha\": 0.2,\n#     \"s\": 5,\n# }\n\n# plot_observations_distribution(ax, df_obs_zoom, df_obs_zoom_test, **kwargs)\n# ax.set_title(\"Observations distribution around Montpellier, France\")\n\ndf_obs_zoom = select_samples_around_point(df_obs_fr, *extent)\ndf_obs_zoom_test = select_samples_around_point(df_obs_fr_test, *extent)\n\nkwargs = {\n    \"alpha\": 0.2,\n    \"s\": 5,\n}\nplot_observations_distribution(ax,df_obs_zoom, df_obs_zoom_test, **kwargs)\nax.set_title(\"Observations distribution around Montpellier, France\")\n","metadata":{"execution":{"iopub.status.busy":"2022-06-11T11:49:56.668800Z","iopub.execute_input":"2022-06-11T11:49:56.669270Z","iopub.status.idle":"2022-06-11T11:49:56.703459Z","shell.execute_reply.started":"2022-06-11T11:49:56.669238Z","shell.execute_reply":"2022-06-11T11:49:56.702267Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def select_samples_around_point(df_obs, lon_min, lon_max, lat_min, lat_max):\n    ind = (\n        (lon_min <= df_obs.longitude) & (df_obs.longitude <= lon_max)\n        & (lat_min <= df_obs.latitude) & (df_obs.latitude <= lat_max)\n    )\n    return df_obs[ind]\n\n\nextent = [3, 4.5, 43.25, 44.25]\n\nfig = plt.figure(figsize=(9.5, 7))\nax = plot_map(extent=extent)\n\ndf_obs_zoom = select_samples_around_point(df_obs_fr, *extent)\ndf_obs_zoom_test = select_samples_around_point(df_obs_fr_test, *extent)\n\nkwargs = {\n    \"alpha\": 0.2,\n    \"s\": 5,\n}\nplot_observations_distribution(ax, df_obs_zoom, df_obs_zoom_test, **kwargs)\nax.set_title(\"Observations distribution around Montpellier, France\")\n\n# fig.savefig(\"../images/train_test_split.png\", bbox_inches=\"tight\", dpi=100, facecolor=\"white\")","metadata":{"execution":{"iopub.status.busy":"2022-06-11T11:49:56.704720Z","iopub.execute_input":"2022-06-11T11:49:56.705222Z","iopub.status.idle":"2022-06-11T11:49:57.281874Z","shell.execute_reply.started":"2022-06-11T11:49:56.705192Z","shell.execute_reply":"2022-06-11T11:49:57.281038Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"species_value_counts = df_obs[\"species_id\"].value_counts()\n\nprint(\"Total number of species: {}\".format(len(species_value_counts)))\n\n\nfig = plt.figure()\nax = fig.gca()\n\nx = np.arange(len(species_value_counts))\nax.plot(x, species_value_counts)\n\nax.set_yscale(\"log\")\n\nax.set_xlabel(\"ranked species\")\nax.set_ylabel(\"number of observations per species\")\nax.set_title(\"Species observations distribution\")\n\nax.grid()\nax.autoscale(tight=True)\nax.set_ylim(bottom=1)","metadata":{"execution":{"iopub.status.busy":"2022-06-11T11:49:57.282871Z","iopub.execute_input":"2022-06-11T11:49:57.283132Z","iopub.status.idle":"2022-06-11T11:49:57.989442Z","shell.execute_reply.started":"2022-06-11T11:49:57.283106Z","shell.execute_reply":"2022-06-11T11:49:57.988520Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_species= pd.read_csv(\"../input/geolifeclef-2022-lifeclef-2022-fgvc9/metadata/species_details.csv\",sep=\";\")\n\nprint(\"total_number_of_species:{}\".format(len(df_species)))\nprint(\"\\nNumber of species in each kingdom\")\nprint(df_species.GBIF_kingdom_name.value_counts())\n\ndf_species.head()\n      ","metadata":{"execution":{"iopub.status.busy":"2022-06-11T11:55:56.999851Z","iopub.execute_input":"2022-06-11T11:55:57.000274Z","iopub.status.idle":"2022-06-11T11:55:57.050610Z","shell.execute_reply.started":"2022-06-11T11:55:57.000241Z","shell.execute_reply":"2022-06-11T11:55:57.049646Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}