Skip to content

Commit

Permalink
Add nbQa precommit
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiggi committed May 21, 2024
1 parent 6104794 commit eea01c0
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 50 deletions.
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,10 @@ repos:
hooks:
- id: nbstripout
args: ["--keep-output"]

- repo: https://github.com/nbQA-dev/nbQA
rev: 1.8.5
hooks:
- id: nbqa-black
- id: nbqa-ruff
args: ["--fix", "--ignore=E402,B018"]
13 changes: 5 additions & 8 deletions tutorials/tutorial_01_DataDownload.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,10 @@
"metadata": {},
"outputs": [],
"source": [
"\n",
"username = \"<your PPS username>\" # likely your mail\n",
"password = \"<your PPS password>\" # likely your mail\n",
"username = \"<your PPS username>\" # likely your mail\n",
"password = \"<your PPS password>\" # likely your mail\n",
"base_dir = \"<path/to/directory/GPM\" # path to the directory where to download the data\n",
"gpm.define_configs(username_pps=username,\n",
" password_pps=password,\n",
" base_dir=base_dir)\n",
"gpm.define_configs(username_pps=username, password_pps=password, base_dir=base_dir)\n",
"\n",
"# You can check that the config file has been correctly created with:\n",
"configs = gpm.read_configs()\n",
Expand Down Expand Up @@ -224,7 +221,7 @@
}
],
"source": [
"gpm.available_products(product_types=\"NRT\") # near-real-time products"
"gpm.available_products(product_types=\"NRT\") # near-real-time products"
]
},
{
Expand All @@ -251,7 +248,7 @@
"end_time = datetime.datetime.strptime(\"2019-07-13 13:00:00\", \"%Y-%m-%d %H:%M:%S\")\n",
"# Specify the product and product type\n",
"product = \"IMERG-FR\" # 'IMERG-ER' 'IMERG-LR'\n",
"product_type = \"RS\" # \"NRT\"\n",
"product_type = \"RS\" # \"NRT\"\n",
"# Specify the version\n",
"version = 6"
]
Expand Down
28 changes: 14 additions & 14 deletions tutorials/tutorial_02_IMERG.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
"\n",
"# Specify the product and product type\n",
"product = \"IMERG-FR\" # 'IMERG-ER' 'IMERG-LR'\n",
"product_type = \"RS\" # \"NRT\"\n",
"product_type = \"RS\" # \"NRT\"\n",
"\n",
"# Specify the version\n",
"version = 7"
Expand Down Expand Up @@ -171,7 +171,7 @@
" verbose=True,\n",
" progress_bar=True,\n",
" check_integrity=False,\n",
")\n"
")"
]
},
{
Expand Down Expand Up @@ -3022,7 +3022,7 @@
"da = ds[variable]\n",
"print(\"xr.Dataset gpm methods:\", dir(ds.gpm))\n",
"print(\"\")\n",
"print(\"xr.DataArray gpm methods:\", dir(da.gpm))\n"
"print(\"xr.DataArray gpm methods:\", dir(da.gpm))"
]
},
{
Expand Down Expand Up @@ -3791,7 +3791,7 @@
}
],
"source": [
"ds[variable].isel(time=0).gpm.plot_map() # With cartopy"
"ds[variable].isel(time=0).gpm.plot_map() # With cartopy"
]
},
{
Expand Down Expand Up @@ -3862,7 +3862,7 @@
}
],
"source": [
"ds[variable].isel(time=slice(0,4)).gpm.plot_map(col=\"time\", col_wrap=2)"
"ds[variable].isel(time=slice(0, 4)).gpm.plot_map(col=\"time\", col_wrap=2)"
]
},
{
Expand Down Expand Up @@ -3893,7 +3893,7 @@
}
],
"source": [
"ds[variable].isel(time=slice(0,4)).gpm.plot_image(col=\"time\", col_wrap=2)"
"ds[variable].isel(time=slice(0, 4)).gpm.plot_image(col=\"time\", col_wrap=2)"
]
},
{
Expand Down Expand Up @@ -3996,7 +3996,7 @@
"da = ds[variable].isel(time=0)\n",
"p = da.gpm.plot_map()\n",
"p.axes.set_extent(extent)\n",
"p.axes.set_title(label=title)\n"
"p.axes.set_title(label=title)"
]
},
{
Expand Down Expand Up @@ -4136,7 +4136,7 @@
}
],
"source": [
"plot_kwargs, cbar_kwargs = gpm.get_plot_kwargs(\"IMERG_Solid\")\n",
"plot_kwargs, cbar_kwargs = gpm.get_plot_kwargs(\"IMERG_Solid\")\n",
"da.gpm.plot_map(cbar_kwargs=cbar_kwargs, **plot_kwargs)"
]
},
Expand Down Expand Up @@ -4168,7 +4168,7 @@
}
],
"source": [
"plot_kwargs, cbar_kwargs = gpm.get_plot_kwargs(\"IMERG_Liquid\")\n",
"plot_kwargs, cbar_kwargs = gpm.get_plot_kwargs(\"IMERG_Liquid\")\n",
"da.gpm.plot_map(cbar_kwargs=cbar_kwargs, **plot_kwargs)"
]
},
Expand Down Expand Up @@ -4201,12 +4201,12 @@
"ds_single_timestep = ds.isel(time=0)\n",
"da_is_liquid = ds_single_timestep[\"probabilityLiquidPrecipitation\"] > 90\n",
"da_precip = ds_single_timestep[variable]\n",
"da_liquid = da_precip.where(da_is_liquid, 0) # set to 0 where is not True\n",
"da_solid = da_precip.where(~da_is_liquid, 0) # set to 0 where is True\n",
"da_liquid = da_precip.where(da_is_liquid, 0) # set to 0 where is not True\n",
"da_solid = da_precip.where(~da_is_liquid, 0) # set to 0 where is True\n",
"\n",
"plot_kwargs, cbar_kwargs = gpm.get_plot_kwargs(\"IMERG_Liquid\")\n",
"plot_kwargs, cbar_kwargs = gpm.get_plot_kwargs(\"IMERG_Liquid\")\n",
"p = da_liquid.gpm.plot_map(cbar_kwargs=cbar_kwargs, **plot_kwargs, add_colorbar=False)\n",
"plot_kwargs, cbar_kwargs = gpm.get_plot_kwargs(\"IMERG_Solid\")\n",
"plot_kwargs, cbar_kwargs = gpm.get_plot_kwargs(\"IMERG_Solid\")\n",
"p = da_solid.gpm.plot_map(ax=p.axes, cbar_kwargs=cbar_kwargs, **plot_kwargs, add_colorbar=False)\n",
"_ = p.axes.set_title(label=da_solid.gpm.title())"
]
Expand Down Expand Up @@ -4258,7 +4258,7 @@
"# Crop by extent\n",
"extent = get_country_extent(\"United States\")\n",
"ds_us = ds.gpm.crop(extent=extent)\n",
"ds_us[variable].isel(time=0).gpm.plot_map()\n"
"ds_us[variable].isel(time=0).gpm.plot_map()"
]
},
{
Expand Down
22 changes: 11 additions & 11 deletions tutorials/tutorial_02_PMW_1C.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
"start_time = datetime.datetime.strptime(\"2020-08-02 12:00:00\", \"%Y-%m-%d %H:%M:%S\")\n",
"end_time = datetime.datetime.strptime(\"2020-08-03 12:00:00\", \"%Y-%m-%d %H:%M:%S\")\n",
"# Specify the product and product type\n",
"product = \"1C-MHS-METOPB\" # 1C-GMI, 1C-SSMIS-F17, ...\n",
"product = \"1C-MHS-METOPB\" # 1C-GMI, 1C-SSMIS-F17, ...\n",
"product_type = \"RS\"\n",
"# Specify the version\n",
"version = 7"
Expand Down Expand Up @@ -163,7 +163,7 @@
" verbose=True,\n",
" progress_bar=True,\n",
" check_integrity=False,\n",
")\n"
")"
]
},
{
Expand Down Expand Up @@ -3616,7 +3616,7 @@
"source": [
"# List some variables of interest\n",
"variables = [\n",
" \"Tc\", # \"Tb\" if PMW 1B product\n",
" \"Tc\", # \"Tb\" if PMW 1B product\n",
"]\n",
"# Load the dataset\n",
"ds = gpm.open_dataset(\n",
Expand Down Expand Up @@ -4243,7 +4243,7 @@
}
],
"source": [
"variable = \"Tc\" # \"Tb\" if PMW 1B product\n",
"variable = \"Tc\" # \"Tb\" if PMW 1B product\n",
"da = ds[variable]\n",
"da"
]
Expand Down Expand Up @@ -4593,11 +4593,11 @@
}
],
"source": [
"variable = \"Tc\" # \"Tb\" if PMW 1B product\n",
"variable = \"Tc\" # \"Tb\" if PMW 1B product\n",
"da = ds[variable]\n",
"print(\"xr.Dataset gpm methods:\", dir(ds.gpm))\n",
"print(\"\")\n",
"print(\"xr.DataArray gpm methods:\", dir(da.gpm))\n"
"print(\"xr.DataArray gpm methods:\", dir(da.gpm))"
]
},
{
Expand Down Expand Up @@ -5357,7 +5357,7 @@
}
],
"source": [
"ds.gpm.is_spatial_2d # because the xarray.Dataset also contains the channel dimension !"
"ds.gpm.is_spatial_2d # because the xarray.Dataset also contains the channel dimension !"
]
},
{
Expand Down Expand Up @@ -5435,7 +5435,7 @@
}
],
"source": [
"da = ds[variable].isel(pmw_frequency=0).isel(along_track=slice(0,8000))\n",
"da = ds[variable].isel(pmw_frequency=0).isel(along_track=slice(0, 8000))\n",
"da.gpm.plot_map()"
]
},
Expand Down Expand Up @@ -5706,15 +5706,15 @@
"da = ds[variable].isel(pmw_frequency=0, along_track=slice(0, 8000))\n",
"\n",
"# Crop by extent\n",
"extent = (-172, -67, 19, 72) # (xmin, xmax, ymin, ymax)\n",
"extent = (-172, -67, 19, 72) # (xmin, xmax, ymin, ymax)\n",
"list_isel_dict = da.gpm.get_crop_slices_by_extent(extent)\n",
"print(list_isel_dict)\n",
"for isel_dict in list_isel_dict:\n",
" da_subset = da.isel(isel_dict)\n",
" slice_title = da_subset.gpm.title(add_timestep=True)\n",
" p = da_subset.gpm.plot_map()\n",
" p.axes.set_extent(extent)\n",
" p.axes.set_title(label=slice_title)\n"
" p.axes.set_title(label=slice_title)"
]
},
{
Expand Down Expand Up @@ -5834,7 +5834,7 @@
" slice_title = da_subset.gpm.title(add_timestep=True)\n",
" p = da_subset.gpm.plot_map()\n",
" p.axes.set_extent(extent)\n",
" p.axes.set_title(label=slice_title)\n"
" p.axes.set_title(label=slice_title)"
]
}
],
Expand Down
16 changes: 8 additions & 8 deletions tutorials/tutorial_02_PMW_2A.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@
"start_time = datetime.datetime.strptime(\"2020-08-01 12:00:00\", \"%Y-%m-%d %H:%M:%S\")\n",
"end_time = datetime.datetime.strptime(\"2020-08-02 12:00:00\", \"%Y-%m-%d %H:%M:%S\")\n",
"# Specify the product and product type\n",
"product = \"2A-MHS-METOPB\" # \"2A-GMI\", \"2A-SSMIS-F17\", ...\n",
"product = \"2A-MHS-METOPB\" # \"2A-GMI\", \"2A-SSMIS-F17\", ...\n",
"product_type = \"RS\"\n",
"# Specify the version\n",
"version = 5 # 7"
"version = 5 # 7"
]
},
{
Expand Down Expand Up @@ -5927,7 +5927,7 @@
"source": [
"# List some variables of interest\n",
"variables = [\n",
" \"surfacePrecipitation\",\n",
" \"surfacePrecipitation\",\n",
" \"rainWaterPath\",\n",
" \"iceWaterPath\",\n",
" \"cloudWaterPath\",\n",
Expand Down Expand Up @@ -6676,7 +6676,7 @@
"da = ds[variable]\n",
"print(\"xr.Dataset gpm methods:\", dir(ds.gpm))\n",
"print(\"\")\n",
"print(\"xr.DataArray gpm methods:\", dir(da.gpm))\n"
"print(\"xr.DataArray gpm methods:\", dir(da.gpm))"
]
},
{
Expand Down Expand Up @@ -6895,7 +6895,7 @@
}
],
"source": [
"da = ds[variable].isel(along_track=slice(0,8000))\n",
"da = ds[variable].isel(along_track=slice(0, 8000))\n",
"da.gpm.plot_map()"
]
},
Expand Down Expand Up @@ -7156,15 +7156,15 @@
"da = ds[variable].isel(along_track=slice(0, 8000))\n",
"\n",
"# Crop by extent\n",
"extent = (-172, -67, 19, 72) # (xmin, xmax, ymin, ymax)\n",
"extent = (-172, -67, 19, 72) # (xmin, xmax, ymin, ymax)\n",
"list_isel_dict = da.gpm.get_crop_slices_by_extent(extent)\n",
"print(list_isel_dict)\n",
"for isel_dict in list_isel_dict:\n",
" da_subset = da.isel(isel_dict)\n",
" slice_title = da_subset.gpm.title(add_timestep=True)\n",
" p = da_subset.gpm.plot_map()\n",
" p.axes.set_extent(extent)\n",
" p.axes.set_title(label=slice_title)\n"
" p.axes.set_title(label=slice_title)"
]
},
{
Expand Down Expand Up @@ -7284,7 +7284,7 @@
" slice_title = da_subset.gpm.title(add_timestep=True)\n",
" p = da_subset.gpm.plot_map()\n",
" p.axes.set_extent(extent)\n",
" p.axes.set_title(label=slice_title)\n"
" p.axes.set_title(label=slice_title)"
]
}
],
Expand Down
18 changes: 9 additions & 9 deletions tutorials/tutorial_02_RADAR_2A.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
"start_time = datetime.datetime.strptime(\"2020-07-05 02:00:00\", \"%Y-%m-%d %H:%M:%S\")\n",
"end_time = datetime.datetime.strptime(\"2020-07-05 06:00:00\", \"%Y-%m-%d %H:%M:%S\")\n",
"# Specify the product and product type\n",
"product = \"2A-DPR\" # 2A-PR\n",
"product = \"2A-DPR\" # 2A-PR\n",
"product_type = \"RS\"\n",
"# Specify the version\n",
"version = 7"
Expand Down Expand Up @@ -146,7 +146,7 @@
" verbose=True,\n",
" progress_bar=True,\n",
" check_integrity=False,\n",
")\n"
")"
]
},
{
Expand Down Expand Up @@ -22458,7 +22458,7 @@
"da = ds[variable]\n",
"print(\"xr.Dataset gpm methods:\", dir(ds.gpm))\n",
"print(\"\")\n",
"print(\"xr.DataArray gpm methods:\", dir(da.gpm))\n"
"print(\"xr.DataArray gpm methods:\", dir(da.gpm))"
]
},
{
Expand Down Expand Up @@ -23210,7 +23210,7 @@
}
],
"source": [
"ds.gpm.is_spatial_2d # because the xarray.Dataset also contains the range and frequency dimensions !"
"ds.gpm.is_spatial_2d # because the xarray.Dataset also contains the range and frequency dimensions !"
]
},
{
Expand Down Expand Up @@ -23340,7 +23340,7 @@
}
],
"source": [
"ds[variable].isel(along_track=slice(500,1200)).gpm.plot_map()"
"ds[variable].isel(along_track=slice(500, 1200)).gpm.plot_map()"
]
},
{
Expand Down Expand Up @@ -23642,7 +23642,7 @@
}
],
"source": [
"plot_kwargs, cbar_kwargs = gpm.get_plot_kwargs(\"IMERG_Liquid\")\n",
"plot_kwargs, cbar_kwargs = gpm.get_plot_kwargs(\"IMERG_Liquid\")\n",
"da.isel(along_track=slice(500, 1000)).gpm.plot_map(cbar_kwargs=cbar_kwargs, **plot_kwargs)"
]
},
Expand Down Expand Up @@ -23709,15 +23709,15 @@
],
"source": [
"# Crop by extent\n",
"extent = (-172, -67, 19, 72) # (xmin, xmax, ymin, ymax)\n",
"extent = (-172, -67, 19, 72) # (xmin, xmax, ymin, ymax)\n",
"list_isel_dict = ds.gpm.get_crop_slices_by_extent(extent)\n",
"print(list_isel_dict)\n",
"for isel_dict in list_isel_dict:\n",
" da_subset = ds[variable].isel(isel_dict)\n",
" slice_title = da_subset.gpm.title(add_timestep=True)\n",
" p = da_subset.gpm.plot_map()\n",
" p.axes.set_extent(extent)\n",
" p.axes.set_title(label=slice_title)\n"
" p.axes.set_title(label=slice_title)"
]
},
{
Expand Down Expand Up @@ -23847,7 +23847,7 @@
" slice_title = da_subset.gpm.title(add_timestep=True)\n",
" p = da_subset.gpm.plot_map()\n",
" p.axes.set_extent(extent)\n",
" p.axes.set_title(label=slice_title)\n"
" p.axes.set_title(label=slice_title)"
]
},
{
Expand Down

0 comments on commit eea01c0

Please sign in to comment.