Skip to content

Commit

Permalink
Use extent param of get_data to do the cropping
Browse files Browse the repository at this point in the history
  • Loading branch information
amarandon committed Nov 22, 2024
1 parent 559aa0f commit dfcdbf0
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions docs/notebooks/tutos/tuto_cds.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "3ae7c8dec2b14dfb8713b9902b64edaf",
"model_id": "8eb68f6612d3446ca7338eb7ef1fc001",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -213,11 +213,23 @@
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"[Retry #1] Waiting 119.999952s until next download try for ordered product (retry every 2' for 20')"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"product = products_from_ads_req[0]\n",
"da = product.get_data(r\"\\.grib$\")"
"da = product.get_data(r\"\\.grib$\", extent={'lonmin': -12, 'latmin': 32, 'lonmax': 48, 'latmax': 72})"
]
},
{
Expand All @@ -231,30 +243,14 @@
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"import cartopy.crs as crs\n",
"import cartopy.feature as cfeature\n",
"\n",
"# europe crop\n",
"mask_lon = (da.x >= -12) & (da.x <= 48)\n",
"mask_lat = (da.y >= 32) & (da.y <= 72)\n",
"da_eu = da.where(mask_lon & mask_lat, drop=True)[0]\n",
"da_eu = da_eu"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<cartopy.mpl.gridliner.Gridliner at 0x741078c45fd0>"
"<cartopy.mpl.gridliner.Gridliner at 0x7c7390fad7f0>"
]
},
"execution_count": 7,
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
},
Expand All @@ -270,13 +266,16 @@
}
],
"source": [
"import cartopy.crs as crs\n",
"import cartopy.feature as cfeature\n",
"import matplotlib.pyplot as plt\n",
"\n",
"fig = plt.figure(figsize=(8,6))\n",
"\n",
"ax = fig.add_subplot(1,1,1, projection=crs.PlateCarree())\n",
"\n",
"da_eu.plot(ax=ax, transform=crs.PlateCarree())\n",
"band1 = da[0]\n",
"band1.plot(ax=ax, transform=crs.PlateCarree())\n",
"\n",
"ax.add_feature(cfeature.COASTLINE)\n",
"ax.gridlines(draw_labels=True)"
Expand Down

0 comments on commit dfcdbf0

Please sign in to comment.