<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Overview
In this notebook, we simply plot the map Australia and look at how different organisms are spread and/or found in Australia.
Step1:  Authentication
In order to run this tutorial successfully, we need to be authenticated first. 
Depending on where we are running this notebook, the authentication steps may vary
Step2:  Configurations
Let's make sure we enter the name of our GCP project in the next cell.
Step3:  Also, let's select the country. In this notebook, we have selected Australia. For a more accurate mapping, we also select the region that contains Australia. This helps us exclude the entires with the country code AU, but with latitudes and longitudes that are not in this region.
Step5:  Data Preparation
Query the Data
Step6:  Check the Dataframe
Step7:  View the Map
<ASSISTANT_TASK:>
Python Code:
%%capture
# Installing the required libraries:
!pip install matplotlib pandas scikit-learn tensorflow pyarrow tqdm
!pip install google-cloud-bigquery google-cloud-bigquery-storage
!pip install flake8 pycodestyle pycodestyle_magic geopandas
# Python Builtin Libraries
# Third Party Libraries
import numpy as np
import geopandas
from google.cloud import bigquery
import matplotlib.pyplot as plt
# Configurations
%matplotlib inline
Explanation: Overview
In this notebook, we simply plot the map Australia and look at how different organisms are spread and/or found in Australia.
End of explanation
try:
    from google.colab import auth
    print("Authenticating in Colab")
    auth.authenticate_user()
    print("Authenticated")
except:  # noqa
    print("This notebook is not running on Colab.")
    print("Please make sure to follow the authentication steps.")
Explanation: Authentication
In order to run this tutorial successfully, we need to be authenticated first. 
Depending on where we are running this notebook, the authentication steps may vary:
| Runner      | Authentiction Steps |
| ----------- | ----------- |
| Local Computer      |  Use a service account, or run the following command: <br><br>gcloud auth login    |
| Colab   | Run the following python code and follow the instructions: <br><br>from google.colab import auth <br> auth.authenticate_user()    |
| Vertext AI (Workbench)   | Authentication is provided by Workbench       |
End of explanation
# ENTER THE GCP PROJECT HERE
gcp_project = "YOUR-GCP-PROJECT"
print(f"gcp_project is set to {gcp_project}")
Explanation: Configurations
Let's make sure we enter the name of our GCP project in the next cell.
End of explanation
# Select Coutry:
country_name = 'Australia'
country_code = 'AU'
TOP_LEFT = (-11, 110)
BOTTOM_RIGHT = (-40, 157)
Explanation: Also, let's select the country. In this notebook, we have selected Australia. For a more accurate mapping, we also select the region that contains Australia. This helps us exclude the entires with the country code AU, but with latitudes and longitudes that are not in this region.
End of explanation
query = f
SELECT kingdom, decimallatitude, decimallongitude
FROM
  `bigquery-public-data.gbif.occurrences` TABLESAMPLE SYSTEM (1 PERCENT)
WHERE
  decimallatitude IS NOT NULL
  AND decimallongitude IS NOT NULL
  AND decimallatitude BETWEEN {BOTTOM_RIGHT[0]} AND {TOP_LEFT[0]}
  AND decimallongitude BETWEEN {TOP_LEFT[1]} AND {BOTTOM_RIGHT[1]}
  AND countrycode = '{country_code}';
bqclient = bigquery.Client(project=gcp_project)
dataframe = bqclient.query(query).result().to_dataframe()
Explanation: Data Preparation
Query the Data
End of explanation
print(dataframe.shape)
dataframe.head()
Explanation: Check the Dataframe
End of explanation
# Using geopandas to extract the map of Australia:
world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))
country = world.loc[world['name'] == country_name]
# Using a subset of the entire dataframe to create the map:
subdataframe = dataframe.sample(n=10000)
labels, indices = np.unique(subdataframe['kingdom'].values, return_inverse=True)
ax = country['geometry'].plot(color='white', edgecolor='black', figsize=(18, 12))
scatter = ax.scatter(x=subdataframe['decimallongitude'],
                     y=subdataframe['decimallatitude'],
                     s=indices / 2.0 + 1.0,
                     c=indices,
                     cmap='Accent')
ax.legend(scatter.legend_elements()[0], labels, title='Kingdom', loc=1)
plt.show();
Explanation: View the Map
End of explanation
<END_TASK>