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

Use ruff in pre-commit #40

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 10 additions & 17 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand All @@ -10,30 +10,23 @@ repos:
# - id: check-added-large-files
- id: debug-statements
- id: mixed-line-ending
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 22.12.0
hooks:
- id: black
- repo: https://github.com/keewis/blackdoc
rev: v0.3.8
hooks:
- id: blackdoc
additional_dependencies: [black==22.3.0]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.3
rev: v0.8.3
hooks:
# Run the linter
- id: ruff
args: [--fix, --show-fixes]
# Run the formatter
- id: ruff-format

- repo: https://github.com/executablebooks/mdformat
rev: 0.7.17
rev: 0.7.19
hooks:
- id: mdformat

- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.11.0
rev: v2.14.0
hooks:
- id: pretty-format-yaml
args: [--autofix, --preserve-quotes]
Expand Down
26 changes: 12 additions & 14 deletions docs/examples/ads.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@
"date = \"2024-02-18\"\n",
"\n",
"data = earthkit.data.from_source(\n",
" 'ads',\n",
" 'cams-europe-air-quality-forecasts',\n",
" \"ads\",\n",
" \"cams-europe-air-quality-forecasts\",\n",
" {\n",
" 'model': 'ensemble',\n",
" 'date': f'{date}/{date}',\n",
" 'variable': 'carbon_monoxide',\n",
" 'level': '0',\n",
" 'type': 'forecast',\n",
" 'time': '00:00',\n",
" 'leadtime_hour': '96',\n",
" \"model\": \"ensemble\",\n",
" \"date\": f\"{date}/{date}\",\n",
" \"variable\": \"carbon_monoxide\",\n",
" \"level\": \"0\",\n",
" \"type\": \"forecast\",\n",
" \"time\": \"00:00\",\n",
" \"leadtime_hour\": \"96\",\n",
" },\n",
")"
]
Expand Down Expand Up @@ -510,10 +510,7 @@
"]\n",
"\n",
"style = earthkit.plots.styles.Style(\n",
" levels=LEVELS,\n",
" ticks=LEVELS,\n",
" colors=COLORS,\n",
" units=\"µg m^-3\"\n",
" levels=LEVELS, ticks=LEVELS, colors=COLORS, units=\"µg m^-3\"\n",
")"
]
},
Expand Down Expand Up @@ -545,7 +542,8 @@
"chart.title(\n",
" \"{base_time:%A %-d %B %Y %HUTC} CAMS Forecast T+{lead_time} VT: {valid_time:%A %-d %B %Y %HUTC}\\n\"\n",
" \"Model: ENSEMBLE Height level: Surface Parameter: Carbon monoxide ({units})\",\n",
" horizontalalignment=\"left\", x=0,\n",
" horizontalalignment=\"left\",\n",
" x=0,\n",
")\n",
"chart.gridlines(linestyle=\"--\", xstep=5, ystep=5)\n",
"\n",
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/gallery/domains/cartopy-crs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
}
],
"source": [
"import earthkit.plots\n",
"import cartopy.crs as ccrs\n",
"\n",
"import earthkit.plots\n",
"\n",
"my_map = earthkit.plots.Map(crs=ccrs.Robinson())\n",
"\n",
"my_map.land()\n",
Expand Down
56 changes: 29 additions & 27 deletions docs/examples/gallery/domains/domain-union.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,32 @@
"import earthkit.plots\n",
"\n",
"EU_COUNTRIES = [\n",
" 'Austria',\n",
" 'Belgium',\n",
" 'Bulgaria',\n",
" 'Croatia',\n",
" 'Cyprus',\n",
" 'Czech Republic',\n",
" 'Denmark',\n",
" 'Estonia',\n",
" 'Finland',\n",
" 'France',\n",
" 'Germany',\n",
" 'Greece',\n",
" 'Hungary',\n",
" 'Ireland',\n",
" 'Italy',\n",
" 'Latvia',\n",
" 'Lithuania',\n",
" 'Luxembourg',\n",
" 'Netherlands',\n",
" 'Poland',\n",
" 'Portugal',\n",
" 'Romania',\n",
" 'Slovakia',\n",
" 'Slovenia',\n",
" 'Spain',\n",
" 'Sweden',\n",
" \"Austria\",\n",
" \"Belgium\",\n",
" \"Bulgaria\",\n",
" \"Croatia\",\n",
" \"Cyprus\",\n",
" \"Czech Republic\",\n",
" \"Denmark\",\n",
" \"Estonia\",\n",
" \"Finland\",\n",
" \"France\",\n",
" \"Germany\",\n",
" \"Greece\",\n",
" \"Hungary\",\n",
" \"Ireland\",\n",
" \"Italy\",\n",
" \"Latvia\",\n",
" \"Lithuania\",\n",
" \"Luxembourg\",\n",
" \"Netherlands\",\n",
" \"Poland\",\n",
" \"Portugal\",\n",
" \"Romania\",\n",
" \"Slovakia\",\n",
" \"Slovenia\",\n",
" \"Spain\",\n",
" \"Sweden\",\n",
"]\n",
"\n",
"EU = earthkit.plots.geo.domains.union(EU_COUNTRIES, name=\"European Union\")\n",
Expand All @@ -56,7 +56,9 @@
"eu_map.countries(edgecolor=\"white\")\n",
"\n",
"# We can reuse the same list of EU countries to show a subset of country polygons\n",
"eu_map.countries(include=EU_COUNTRIES, facecolor=\"#6c9dc6\", edgecolor=\"white\", labels=True)\n",
"eu_map.countries(\n",
" include=EU_COUNTRIES, facecolor=\"#6c9dc6\", edgecolor=\"white\", labels=True\n",
")\n",
"\n",
"eu_map.gridlines()\n",
"eu_map.title(\"{domain}\")\n",
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/gallery/grid-types/healpix-interpolated.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@
}
],
"source": [
"import numpy as np\n",
"\n",
"import earthkit.data\n",
"import earthkit.plots\n",
"import numpy as np\n",
"\n",
"data = earthkit.data.from_source(\"sample\", \"healpix-h128-nested-2t.grib\")\n",
"\n",
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/gallery/grid-types/healpix-pixels.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
}
],
"source": [
"import numpy as np\n",
"\n",
"import earthkit.data\n",
"import earthkit.plots\n",
"import numpy as np\n",
"\n",
"data = earthkit.data.from_source(\"sample\", \"healpix-h128-nested-2t.grib\")\n",
"\n",
Expand Down
7 changes: 5 additions & 2 deletions docs/examples/gallery/grid-types/healpix-point-cloud.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,18 @@
}
],
"source": [
"import numpy as np\n",
"\n",
"import earthkit.data\n",
"import earthkit.plots\n",
"import numpy as np\n",
"\n",
"data = earthkit.data.from_source(\"sample\", \"healpix-h128-ring-2t.grib\")\n",
"\n",
"chart = earthkit.plots.Map(domain=[\"France\", \"Spain\"])\n",
"\n",
"chart.point_cloud(data, levels=np.arange(0, 20, 0.5), colors=\"Spectral_r\", units=\"celsius\")\n",
"chart.point_cloud(\n",
" data, levels=np.arange(0, 20, 0.5), colors=\"Spectral_r\", units=\"celsius\"\n",
")\n",
"\n",
"chart.title()\n",
"chart.legend()\n",
Expand Down
7 changes: 3 additions & 4 deletions docs/examples/gallery/gridded-data/el-nino.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
"id": "633a5450",
"metadata": {},
"outputs": [],
"source": [
"from datetime import datetime"
]
"source": []
},
{
"cell_type": "code",
Expand Down Expand Up @@ -57,7 +55,8 @@
],
"source": [
"data = earthkit.data.from_source(\n",
" \"cds\", \"reanalysis-era5-single-levels-monthly-means\",\n",
" \"cds\",\n",
" \"reanalysis-era5-single-levels-monthly-means\",\n",
" {\n",
" \"product_type\": \"monthly_averaged_reanalysis\",\n",
" \"variable\": \"sea_surface_temperature\",\n",
Expand Down
10 changes: 7 additions & 3 deletions docs/examples/gallery/gridded-data/hatched-shading.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@
}
],
"source": [
"data = earthkit.data.from_source(\"url\", \"https://get.ecmwf.int/repository/test-data/metview/gallery/efi.grib\")\n",
"data = earthkit.data.from_source(\n",
" \"url\", \"https://get.ecmwf.int/repository/test-data/metview/gallery/efi.grib\"\n",
")\n",
"data.ls()"
]
},
Expand All @@ -151,7 +153,7 @@
"from earthkit.plots.styles import Hatched\n",
"\n",
"LEVELS = [0.6, 0.8, 1.0]\n",
"HATCHES = [\".\"*5, \"o\"*5]\n",
"HATCHES = [\".\" * 5, \"o\" * 5]\n",
"\n",
"fgi_style = Hatched(\n",
" colors=\"magenta\",\n",
Expand Down Expand Up @@ -196,7 +198,9 @@
"chart.borders()\n",
"chart.gridlines()\n",
"\n",
"chart.figure.title(\"EFI (Extreme Forecast Index) at {time:%H:%M} on {time:%Y-%m-%d} (T+{lead_time})\")\n",
"chart.figure.title(\n",
" \"EFI (Extreme Forecast Index) at {time:%H:%M} on {time:%Y-%m-%d} (T+{lead_time})\"\n",
")\n",
"\n",
"chart.legend(label=\"{variable_name!l}\", location=[\"top left\", \"top right\"], ncols=2)\n",
"\n",
Expand Down
6 changes: 4 additions & 2 deletions docs/examples/gallery/gridded-data/model-orography.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@
}
],
"source": [
"data = earthkit.data.from_source(\"url\", \"https://get.ecmwf.int/repository/test-data/metview/gallery/model_orog.grib\")\n",
"data = earthkit.data.from_source(\n",
" \"url\", \"https://get.ecmwf.int/repository/test-data/metview/gallery/model_orog.grib\"\n",
")\n",
"data.ls()"
]
},
Expand Down Expand Up @@ -140,7 +142,7 @@
" levels=levels,\n",
" extend=\"both\",\n",
" colors=\"terrain\",\n",
" scale_factor=1/9.81,\n",
" scale_factor=1 / 9.81,\n",
")"
]
},
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/gallery/gridded-data/numpy-arrays.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
}
],
"source": [
"import earthkit.plots\n",
"import numpy as np\n",
"\n",
"import earthkit.plots\n",
"\n",
"chart = earthkit.plots.Map()\n",
"\n",
"chart.plot(\n",
Expand Down
19 changes: 9 additions & 10 deletions docs/examples/gallery/gridded-data/temperature-and-pressure.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,20 @@
"source": [
"import earthkit.data\n",
"import earthkit.plots\n",
"import cartopy.crs as ccrs\n",
"\n",
"temperature, pressure = earthkit.data.from_source(\n",
" 'cds',\n",
" 'reanalysis-era5-single-levels',\n",
" \"cds\",\n",
" \"reanalysis-era5-single-levels\",\n",
" {\n",
" 'product_type': 'reanalysis',\n",
" 'variable': [\n",
" '2m_temperature',\n",
" \"product_type\": \"reanalysis\",\n",
" \"variable\": [\n",
" \"2m_temperature\",\n",
" \"mean_sea_level_pressure\",\n",
" ],\n",
" 'year': '1985',\n",
" 'month': '12',\n",
" 'day': '25',\n",
" 'time': '12:00',\n",
" \"year\": \"1985\",\n",
" \"month\": \"12\",\n",
" \"day\": \"25\",\n",
" \"time\": \"12:00\",\n",
" },\n",
")"
]
Expand Down
16 changes: 8 additions & 8 deletions docs/examples/gallery/gridded-data/time-zones.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
],
"source": [
"data = earthkit.data.from_source(\n",
" 'cds',\n",
" 'reanalysis-era5-single-levels',\n",
" \"cds\",\n",
" \"reanalysis-era5-single-levels\",\n",
" {\n",
" 'product_type': 'reanalysis',\n",
" 'variable': '2m_temperature',\n",
" 'year': '2024',\n",
" 'month': '05',\n",
" 'day': '04',\n",
" 'time': '12:00',\n",
" \"product_type\": \"reanalysis\",\n",
" \"variable\": \"2m_temperature\",\n",
" \"year\": \"2024\",\n",
" \"month\": \"05\",\n",
" \"day\": \"04\",\n",
" \"time\": \"12:00\",\n",
" },\n",
")"
]
Expand Down
6 changes: 2 additions & 4 deletions docs/examples/gallery/gridded-data/unstructured-grids.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@
"metadata": {},
"outputs": [],
"source": [
"import earthkit.plots\n",
"\n",
"import numpy as np\n",
"import cartopy.crs as ccrs\n",
"from scipy.interpolate import griddata"
"\n",
"import earthkit.plots"
]
},
{
Expand Down
Loading
Loading