<jupyter_start><jupyter_text>1. Setup your EC2 instance ![](img/instance.png)  2. Setup your JupyterHub ![](img/jupyterhub.png)  3. Setup the server ![](img/terminal.png)  4. Get the data what we wrangled in our first milestone.<jupyter_code>import re
import os
import glob
import zipfile
import requests
from urllib.request import urlretrieve
import json
import pandas as pd
# Necessary metadata
article_id = 14226968  # this is the unique identifier of the article on figshare
url = f"https://api.figshare.com/v2/articles/{article_id}"
headers = {"Content-Type": "application/json"}
output_directory = "/srv/data/my_shared_data_folder/"

response = requests.request("GET", url, headers=headers)
data = json.loads(response.text)  # this contains all the articles data, feel free to check it out
files = data["files"]             # this is just the data about the files, which is what we want
files
files_to_dl = ["combined_model_data_parti.parquet.zip"]  ## Please download the partitioned 
for file in files:
    if file["name"] in files_to_dl:
        os.makedirs(output_directory, exist_ok=True)
        urlretrieve(file["download_url"], output_directory + file["name"])
with zipfile.ZipFile(os.path.join(output_directory, "combined_model_data_parti.parquet.zip"), 'r') as f:
    f.extractall(output_directory)<jupyter_output><empty_output><jupyter_text>5. Setup your S3 bucket and move data ![](img/s3.png)  6. Wrangle the data in preparation for machine learning<jupyter_code>#6.1
df = pd.read_parquet("s3://mds-s3-student55/combined_model_data_parti.parquet/", storage_options=aws_credentials)
print(df.head(), end="\n\n")
print(df.shape)
df_true = pd.read_csv("s3://mds-s3-student55/observed_daily_rainfall_SYD.csv"),
                      storage_options=aws_credentials,
                      parse_dates=True,
                     index_col="time")\
            .rename(columns = {"rain (mm/day)": "observed rainfall"})

print(df_true.head(), end="\n\n")
print(df_true.shape)
#6.2
syd_lat = -33.86
syd_lon = 151.21
syd_df = df.query("@syd_lat > lat_min & @syd_lat < lat_max & @syd_lon > lon_min & @syd_lon < lon_max")\
        .drop(["lat_min", "lat_max", "lon_min", "lon_max"], axis=1)\
        .set_index("time")
syd_df.index = syd_df.index.date

# #6.3
syd_df.to_csv("s3://mds-s3-student55/output/ml_data_SYD.csv", storage_options=aws_credentials)
print(syd_df.head(), end="\n\n")
print(syd_df.shape)<jupyter_output>rain (mm/day)       model
1889-01-01       0.040427  ACCESS-CM2
1889-01-02       0.073777  ACCESS-CM2
1889-01-03       0.232656  ACCESS-CM2
1889-01-04       0.911319  ACCESS-CM2
1889-01-05       0.698013  ACCESS-CM2

(1150049, 2)<jupyter_text>Screenshot of the saved file ![](img/s3_2.png)<jupyter_code>syd_df = syd_df.reset_index().pivot(index='index', values = 'rain (mm/day)', columns='model')
syd_df.index = pd.to_datetime(syd_df.index)
syd_df.index.name = "time"

df_final = syd_df.merge(df_true, on="time")
print(df_final.shape)
df_final.head()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13754152823920265, 'fraction_numerical': 0.045182724252491695, 'mean_word_length': 4.2547993019197206, 'pattern_counts': {'":': 2, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '475519', 'license': 'MIT', 'n_tokens_mistral': 1203, 'n_tokens_neox': 1106, 'n_words': 229, 'path': 'notebooks/milestone_2.ipynb', 'repo_name': 'UBC-MDS/525-Group19', 'size': '3010'}