Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update notebooks #203

Merged
merged 11 commits into from
Oct 17, 2024
33 changes: 6 additions & 27 deletions notebooks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(self, start_date=datetime(2018, 1, 1), end_date=datetime(2023, 12,
continuous_update=False,
readout=True,
behaviour="drag",
layout={"width": "80%", "height": "100px", "margin": "0 auto 0 auto"},
layout={"width": "90%", "height": "100px", "margin": "0 auto 0 auto"},
style={
"handle_color": "dodgerblue",
},
Expand Down Expand Up @@ -83,34 +83,13 @@ def show_slider(self):
"""
)

# Generate a list of dates for the ticks every 3 months
tick_dates = pd.date_range(
self.start_date, self.end_date + pd.DateOffset(months=3), freq="5ME"
)

# Create a list of tick labels in the format "Aug 2023"
tick_labels = [date.strftime("%b<br>%Y") for date in tick_dates]

# Calculate the positions of the ticks to align them with the slider
total_days = (self.end_date - self.start_date).days
tick_positions = [
((date - self.start_date).days / total_days * 100) for date in tick_dates
]

# Create a text widget to display the tick labels with calculated positions
tick_widget_html = "<div style='text-align: center; font-size: 12px; position: relative; width: 86%; height: 20px; margin-top: -20px;'>"
for label, position in zip(tick_labels, tick_positions):
tick_widget_html += f"<div style='position: absolute; left: {position}%; transform: translateX(-50%);'>{label}</div>"
tick_widget_html += "</div>"

tick_widget = widgets.HTML(
value=tick_widget_html, layout={"width": "80%", "margin": "0 auto 0 auto"}
)

# Arrange the text widget, interval slider, and tick widget using VBox
vbox_with_ticks = widgets.VBox(
[descr_widget, self.interval_slider, tick_widget],
layout={"height": "200px"},
[
descr_widget,
self.interval_slider,
],
layout={"height": "150px"},
)

display(vbox_with_ticks)
Expand Down
30 changes: 25 additions & 5 deletions notebooks/worldcereal_v1_demo_custom_cropland.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"source": [
"### Before you start\n",
"\n",
"In order to run WorldCereal crop mapping jobs from this notebook, you need to create an account on the Copernicus Data Space Ecosystem (CDSE) registering [here](https://dataspace.copernicus.eu/). This is free of charge and will grant you a number of free openEO processing credits to continue this demo."
"In order to run WorldCereal crop mapping jobs from this notebook, you need to create an account on the [Copernicus Data Space Ecosystem](https://dataspace.copernicus.eu/).\n",
"This is free of charge and will grant you a number of free openEO processing credits to continue this demo."
]
},
{
Expand Down Expand Up @@ -100,7 +101,7 @@
"polygon = map.get_polygon_latlon()\n",
"\n",
"# Query our public database of training data\n",
"public_df = query_public_extractions(polygon, filter_cropland=False)\n",
"public_df = query_public_extractions(polygon, filter_cropland=False, buffer=250000)\n",
"public_df.year.value_counts()"
]
},
Expand Down Expand Up @@ -285,9 +286,8 @@
"import os\n",
"from pathlib import Path\n",
"\n",
"# Specify the local directory where the resulting maps should be downloaded to.\n",
"run = get_input(\"model run\")\n",
"output_dir = Path(os.getcwd()) / f'CROPLAND_{modelname}_{run}'\n",
"# The output directory is named after the model\n",
"output_dir = Path(os.getcwd()) / f'CROPLAND_{modelname}'\n",
"print(f\"Output directory: {output_dir}\")"
]
},
Expand Down Expand Up @@ -329,6 +329,26 @@
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# The results contain the openeo job id...\n",
"print(f\"Job id: {job_results.job_id}\")\n",
"print(f\"Location of metadata: {job_results.metadata}\")\n",
"#... a list of products that were downloaded...\n",
"print(f\"Products: {job_results.products.keys()}\")\n",
"# ... for each product:\n",
"print('-- For each product --')\n",
"print(f\"Type: {job_results.products['cropland']['type']}\")\n",
"print(f\"Temporal extent: {job_results.products['cropland']['temporal_extent']}\")\n",
"print(f\"Look-up table: {job_results.products['cropland']['lut']}\")\n",
"print(f\"URL: {job_results.products['cropland']['url']}\")\n",
"print(f\"Local path: {job_results.products['cropland']['path']}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
Loading
Loading