<jupyter_start><jupyter_text>Using the IceNet API for historic forecastsThis notebook will explain how to retrieve historic `IceNet` data from the public API and display it locally.<jupyter_code># Import required modules
import datetime
import requests
import geopandas as gpd
import matplotlib.pyplot as plt
# Set the base URL for API requests
api_base_url = "https://app-icenetgeoapi-pygeoapi.azurewebsites.net/"<jupyter_output><empty_output><jupyter_text>Let's see how the prediction for a particular cell changes over time. First, let's identify a cell in the Bering Sea (close to 53, -170).<jupyter_code>response = requests.get(f"{api_base_url}/collections/north_forecasts_historic/items?bbox=-170.1,52.9,-169.9,53.1")
cell_id = response.json()["features"][0]["properties"]["cell_id"]
print(cell_id)
# Retrieve the cell
response = requests.get(f"{api_base_url}/collections/north_cells/items?cell_id={cell_id}")
geodata = gpd.GeoDataFrame.from_features(response.json(), crs="EPSG:4326")
# Let's take a look at where this is on a world map
world = gpd.read_file(gpd.datasets.get_path("naturalearth_lowres"))

fig, axes = plt.subplots(1, figsize=(12, 10))
axes.set(xlim=(-180, -160), ylim=(45, 60))
world.plot(ax=axes, color="lightgray")
geodata.plot(ax=axes)<jupyter_output><empty_output><jupyter_text>Now let's pick our target date - we'll use today.<jupyter_code># Set the target date
target_date = datetime.datetime.today().date()
print(target_date)<jupyter_output>2022-02-18<jupyter_text>We'll use the following options in our query:- `cell_id` set to the `cell_id` we identified above- `date_forecast_for` set to our `target_date`- `sortby` set to `date_forecast_generated` so that we get results in ascending order of date- `limit` set to 1000 so that we get all available forecasts<jupyter_code>response = requests.get(f"{api_base_url}/collections/north_forecasts_historic/items?cell_id={cell_id}&date_forecast_for={target_date}&sortby=date_forecast_generated&limit=1000")<jupyter_output><empty_output><jupyter_text>Load data and plot itLet's load our data into `GeoPandas` and look at it<jupyter_code># Look at the first few rows of data
geodata = gpd.GeoDataFrame.from_features(response.json(), crs="EPSG:4326")
geodata.head()<jupyter_output><empty_output><jupyter_text>And now let's plot it with `matplotlib`<jupyter_code># Plot the data
fig, axes = plt.subplots(1, figsize=(12,10))
plt.errorbar(
    geodata["date_forecast_generated"],
    geodata["sea_ice_concentration_mean"],
    yerr=geodata["sea_ice_concentration_stddev"],
    marker="*",
    linestyle="None"
)
plt.xticks(rotation=90)
plt.tight_layout()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12094951017332328, 'fraction_numerical': 0.024868123587038434, 'mean_word_length': 7.401898734177215, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '643134', 'license': 'MIT', 'n_tokens_mistral': 999, 'n_tokens_neox': 926, 'n_words': 217, 'path': 'examples/api-usage-historic-forecasts.ipynb', 'repo_name': 'alan-turing-institute/IceNetOGCAPI', 'size': '2654'}