diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c9ad9e9..961c5b9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 @@ -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] diff --git a/docs/examples/ads.ipynb b/docs/examples/ads.ipynb index c2c5bfc..b1b2a50 100644 --- a/docs/examples/ads.ipynb +++ b/docs/examples/ads.ipynb @@ -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", ")" ] @@ -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", ")" ] }, @@ -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", diff --git a/docs/examples/gallery/domains/cartopy-crs.ipynb b/docs/examples/gallery/domains/cartopy-crs.ipynb index 7375056..b5fa32c 100644 --- a/docs/examples/gallery/domains/cartopy-crs.ipynb +++ b/docs/examples/gallery/domains/cartopy-crs.ipynb @@ -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", diff --git a/docs/examples/gallery/domains/domain-union.ipynb b/docs/examples/gallery/domains/domain-union.ipynb index 8fcfa88..bdb7870 100644 --- a/docs/examples/gallery/domains/domain-union.ipynb +++ b/docs/examples/gallery/domains/domain-union.ipynb @@ -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", @@ -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", diff --git a/docs/examples/gallery/grid-types/healpix-interpolated.ipynb b/docs/examples/gallery/grid-types/healpix-interpolated.ipynb index a5a7862..dd44697 100644 --- a/docs/examples/gallery/grid-types/healpix-interpolated.ipynb +++ b/docs/examples/gallery/grid-types/healpix-interpolated.ipynb @@ -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", diff --git a/docs/examples/gallery/grid-types/healpix-pixels.ipynb b/docs/examples/gallery/grid-types/healpix-pixels.ipynb index 905ce2a..eae512f 100644 --- a/docs/examples/gallery/grid-types/healpix-pixels.ipynb +++ b/docs/examples/gallery/grid-types/healpix-pixels.ipynb @@ -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", diff --git a/docs/examples/gallery/grid-types/healpix-point-cloud.ipynb b/docs/examples/gallery/grid-types/healpix-point-cloud.ipynb index 9fc15ec..96b49b9 100644 --- a/docs/examples/gallery/grid-types/healpix-point-cloud.ipynb +++ b/docs/examples/gallery/grid-types/healpix-point-cloud.ipynb @@ -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", diff --git a/docs/examples/gallery/gridded-data/el-nino.ipynb b/docs/examples/gallery/gridded-data/el-nino.ipynb index c1de003..40d98e2 100644 --- a/docs/examples/gallery/gridded-data/el-nino.ipynb +++ b/docs/examples/gallery/gridded-data/el-nino.ipynb @@ -17,9 +17,7 @@ "id": "633a5450", "metadata": {}, "outputs": [], - "source": [ - "from datetime import datetime" - ] + "source": [] }, { "cell_type": "code", @@ -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", diff --git a/docs/examples/gallery/gridded-data/hatched-shading.ipynb b/docs/examples/gallery/gridded-data/hatched-shading.ipynb index 55543e1..e4dfcac 100644 --- a/docs/examples/gallery/gridded-data/hatched-shading.ipynb +++ b/docs/examples/gallery/gridded-data/hatched-shading.ipynb @@ -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()" ] }, @@ -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", @@ -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", diff --git a/docs/examples/gallery/gridded-data/model-orography.ipynb b/docs/examples/gallery/gridded-data/model-orography.ipynb index 3935b32..708ebdd 100644 --- a/docs/examples/gallery/gridded-data/model-orography.ipynb +++ b/docs/examples/gallery/gridded-data/model-orography.ipynb @@ -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()" ] }, @@ -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", ")" ] }, diff --git a/docs/examples/gallery/gridded-data/numpy-arrays.ipynb b/docs/examples/gallery/gridded-data/numpy-arrays.ipynb index 8160ef3..94ecfab 100644 --- a/docs/examples/gallery/gridded-data/numpy-arrays.ipynb +++ b/docs/examples/gallery/gridded-data/numpy-arrays.ipynb @@ -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", diff --git a/docs/examples/gallery/gridded-data/temperature-and-pressure.ipynb b/docs/examples/gallery/gridded-data/temperature-and-pressure.ipynb index 3e94c6e..993541b 100644 --- a/docs/examples/gallery/gridded-data/temperature-and-pressure.ipynb +++ b/docs/examples/gallery/gridded-data/temperature-and-pressure.ipynb @@ -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", ")" ] diff --git a/docs/examples/gallery/gridded-data/time-zones.ipynb b/docs/examples/gallery/gridded-data/time-zones.ipynb index 5dd5052..4372b38 100644 --- a/docs/examples/gallery/gridded-data/time-zones.ipynb +++ b/docs/examples/gallery/gridded-data/time-zones.ipynb @@ -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", ")" ] diff --git a/docs/examples/gallery/gridded-data/unstructured-grids.ipynb b/docs/examples/gallery/gridded-data/unstructured-grids.ipynb index 84624d0..eb288e4 100644 --- a/docs/examples/gallery/gridded-data/unstructured-grids.ipynb +++ b/docs/examples/gallery/gridded-data/unstructured-grids.ipynb @@ -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" ] }, { diff --git a/docs/examples/gallery/gridded-data/weather-forecast-steps.ipynb b/docs/examples/gallery/gridded-data/weather-forecast-steps.ipynb index 610b36b..bee7d64 100644 --- a/docs/examples/gallery/gridded-data/weather-forecast-steps.ipynb +++ b/docs/examples/gallery/gridded-data/weather-forecast-steps.ipynb @@ -7,10 +7,10 @@ "metadata": {}, "outputs": [], "source": [ - "import earthkit.data\n", - "import earthkit.plots\n", + "import matplotlib.pyplot as plt\n", "\n", - "import matplotlib.pyplot as plt" + "import earthkit.data\n", + "import earthkit.plots" ] }, { @@ -353,7 +353,10 @@ } ], "source": [ - "data = earthkit.data.from_source(\"url\", \"https://get.ecmwf.int/repository/test-data/metview/gallery/fc_msl_wg_joachim.grib\")\n", + "data = earthkit.data.from_source(\n", + " \"url\",\n", + " \"https://get.ecmwf.int/repository/test-data/metview/gallery/fc_msl_wg_joachim.grib\",\n", + ")\n", "data.ls()" ] }, @@ -385,7 +388,7 @@ "\n", "figure.add_map(0, 3)\n", "for i in range(8):\n", - " figure.add_map(1+i//4, i%4)\n", + " figure.add_map(1 + i // 4, i % 4)\n", "\n", "figure.contourf(data.sel(shortName=\"10fg6\"), style=gust_style)\n", "\n", @@ -399,7 +402,10 @@ "figure.subplot_titles(\"{time:%Y-%m-%d %H} UTC (+{lead_time}h)\")\n", "figure.title(\n", " \"ECMWF HRES Run: {base_time:%Y-%m-%d %H} UTC\\n{variable_name}\",\n", - " fontsize=14, horizontalalignment=\"left\", x=0, y=0.96,\n", + " fontsize=14,\n", + " horizontalalignment=\"left\",\n", + " x=0,\n", + " y=0.96,\n", ")\n", "\n", "figure.show()" diff --git a/docs/examples/gallery/hovmoeller/hovmoeller.ipynb b/docs/examples/gallery/hovmoeller/hovmoeller.ipynb index 5b94784..8e9eeaf 100644 --- a/docs/examples/gallery/hovmoeller/hovmoeller.ipynb +++ b/docs/examples/gallery/hovmoeller/hovmoeller.ipynb @@ -2920,7 +2920,10 @@ "hovmoeller = earthkit.plots.Subplot()\n", "\n", "hovmoeller.contourf(\n", - " da, z=\"fgdep\", levels=np.arange(-8.64, 0.17, 0.44), colors=\"Spectral_r\",\n", + " da,\n", + " z=\"fgdep\",\n", + " levels=np.arange(-8.64, 0.17, 0.44),\n", + " colors=\"Spectral_r\",\n", " ticks=np.arange(-8.64, 0.17, 0.44)[::2],\n", ")\n", "\n", diff --git a/docs/examples/gallery/interactive/meteogram.ipynb b/docs/examples/gallery/interactive/meteogram.ipynb index 70eb271..9dc3458 100644 --- a/docs/examples/gallery/interactive/meteogram.ipynb +++ b/docs/examples/gallery/interactive/meteogram.ipynb @@ -26,8 +26,8 @@ "metadata": {}, "outputs": [], "source": [ - "from earthkit.plots.interactive import Chart\n", - "import earthkit.data" + "import earthkit.data\n", + "from earthkit.plots.interactive import Chart" ] }, { @@ -73,7 +73,7 @@ "chart = Chart()\n", "chart.box(data)\n", "chart.title(\"ECMWF ensemble meteogram\")\n", - "chart.line(data,aggregation='mean', line_color='grey')\n", + "chart.line(data, aggregation=\"mean\", line_color=\"grey\")\n", "\n", "chart.show(renderer=\"png\") # Replace with chart.show() in an interactive session!" ] diff --git a/docs/examples/gallery/point-data/usa-temperature-obs.ipynb b/docs/examples/gallery/point-data/usa-temperature-obs.ipynb index 09e4f04..2a5f859 100644 --- a/docs/examples/gallery/point-data/usa-temperature-obs.ipynb +++ b/docs/examples/gallery/point-data/usa-temperature-obs.ipynb @@ -47,10 +47,7 @@ "outputs": [], "source": [ "style = earthkit.plots.styles.Style(\n", - " units=\"celsius\",\n", - " colors=\"Spectral_r\",\n", - " levels=range(0, 30, 2),\n", - " extend=\"both\"\n", + " units=\"celsius\", colors=\"Spectral_r\", levels=range(0, 30, 2), extend=\"both\"\n", ")" ] }, @@ -74,7 +71,14 @@ "source": [ "my_map = earthkit.plots.Map(domain=[-145, -70, 10, 75])\n", "\n", - "my_map.scatter(data.to_xarray(), x=\"longitude\", y=\"latitude\", z=\"temperature\", style=style, source_units=\"K\")\n", + "my_map.scatter(\n", + " data.to_xarray(),\n", + " x=\"longitude\",\n", + " y=\"latitude\",\n", + " z=\"temperature\",\n", + " style=style,\n", + " source_units=\"K\",\n", + ")\n", "\n", "my_map.ocean(zorder=0, color=\"lightgrey\")\n", "my_map.countries(zorder=0, facecolor=\"grey\", edgecolor=\"goldenrod\")\n", diff --git a/docs/examples/gallery/time-series/cmip6.ipynb b/docs/examples/gallery/time-series/cmip6.ipynb index 277e675..7bdd94f 100644 --- a/docs/examples/gallery/time-series/cmip6.ipynb +++ b/docs/examples/gallery/time-series/cmip6.ipynb @@ -16,11 +16,11 @@ } ], "source": [ - "import earthkit.data\n", - "import earthkit.plots\n", - "import earthkit.aggregate\n", + "import xarray as xr\n", "\n", - "import xarray as xr" + "import earthkit.aggregate\n", + "import earthkit.data\n", + "import earthkit.plots" ] }, { @@ -31,19 +31,19 @@ "outputs": [], "source": [ "MODELS = [\n", - " 'hadgem3_gc31_ll',\n", - " 'inm_cm5_0',\n", - " 'inm_cm4_8',\n", - " 'ipsl_cm6a_lr', \n", - " 'miroc_es2l',\n", - " 'mpi_esm1_2_lr',\n", + " \"hadgem3_gc31_ll\",\n", + " \"inm_cm5_0\",\n", + " \"inm_cm4_8\",\n", + " \"ipsl_cm6a_lr\",\n", + " \"miroc_es2l\",\n", + " \"mpi_esm1_2_lr\",\n", "]\n", "\n", "EXPERIMENTS = [\n", - " 'historical',\n", - " 'ssp126',\n", - " 'ssp245',\n", - " 'ssp585',\n", + " \"historical\",\n", + " \"ssp126\",\n", + " \"ssp245\",\n", + " \"ssp585\",\n", "]\n", "\n", "HISTORICAL_YEARS = [str(year) for year in range(1850, 2015)]\n", @@ -66,17 +66,19 @@ " data[experiment].append(\n", " earthkit.data.from_source(\n", " \"cds\",\n", - " 'projections-cmip6',\n", + " \"projections-cmip6\",\n", " {\n", - " 'format': 'zip',\n", - " 'temporal_resolution': 'monthly',\n", - " 'experiment': experiment,\n", - " 'variable': 'near_surface_air_temperature',\n", - " 'model': model,\n", - " 'year': years,\n", - " 'month': [f\"{month:02d}\" for month in range(1, 13)],\n", + " \"format\": \"zip\",\n", + " \"temporal_resolution\": \"monthly\",\n", + " \"experiment\": experiment,\n", + " \"variable\": \"near_surface_air_temperature\",\n", + " \"model\": model,\n", + " \"year\": years,\n", + " \"month\": [f\"{month:02d}\" for month in range(1, 13)],\n", " },\n", - " ).to_xarray().tas\n", + " )\n", + " .to_xarray()\n", + " .tas\n", " )" ] }, @@ -90,7 +92,9 @@ "timeseries = {}\n", "\n", "for experiment in EXPERIMENTS:\n", - " data[experiment] = [earthkit.aggregate.temporal.standardise_time(d) for d in data[experiment]]\n", + " data[experiment] = [\n", + " earthkit.aggregate.temporal.standardise_time(d) for d in data[experiment]\n", + " ]\n", " data[experiment] = xr.concat(data[experiment], dim=\"model\")\n", " yearly = earthkit.aggregate.temporal.resample(data[experiment], frequency=\"YE\")\n", " timeseries[experiment] = earthkit.aggregate.spatial.reduce(yearly)" @@ -117,7 +121,13 @@ "figure = earthkit.plots.Figure(size=(10, 4))\n", "subplot = figure.add_subplot()\n", "for experiment, color in zip(timeseries, [\"grey\", \"#EB702D\", \"green\", \"#545FA4\"]):\n", - " subplot.quantiles(timeseries[experiment], quantiles=[0.1, 0.5, 0.9], alpha=0.15, color=color, x=timeseries[experiment].isel(model=0).time)\n", + " subplot.quantiles(\n", + " timeseries[experiment],\n", + " quantiles=[0.1, 0.5, 0.9],\n", + " alpha=0.15,\n", + " color=color,\n", + " x=timeseries[experiment].isel(model=0).time,\n", + " )\n", "figure.title(\"CMIP6 annual global average temperature (1850 - 2100)\")\n", "\n", "subplot.ax.legend()\n", diff --git a/docs/examples/gallery/time-series/global-average-temperature.ipynb b/docs/examples/gallery/time-series/global-average-temperature.ipynb index 12c55bb..746908c 100644 --- a/docs/examples/gallery/time-series/global-average-temperature.ipynb +++ b/docs/examples/gallery/time-series/global-average-temperature.ipynb @@ -7,11 +7,13 @@ "metadata": {}, "outputs": [], "source": [ - "import earthkit.plots\n", - "import earthkit.data\n", - "import pandas as pd\n", "from datetime import datetime, timedelta\n", - "import numpy as np" + "\n", + "import numpy as np\n", + "import pandas as pd\n", + "\n", + "import earthkit.data\n", + "import earthkit.plots" ] }, { @@ -47,7 +49,10 @@ ], "source": [ "csv_file = \"era5_daily_series_2t_global.csv\"\n", - "data = earthkit.data.from_source(\"url\", \"https://sites.ecmwf.int/data/climatepulse/data/series/era5_daily_series_2t_global.csv\")\n", + "data = earthkit.data.from_source(\n", + " \"url\",\n", + " \"https://sites.ecmwf.int/data/climatepulse/data/series/era5_daily_series_2t_global.csv\",\n", + ")\n", "data.save(csv_file)\n", "df = pd.read_csv(csv_file, comment=\"#\", index_col=0, parse_dates=True).round(2)" ] @@ -61,7 +66,7 @@ "source": [ "start_year = 1940\n", "end_year = 2024\n", - "data_col = '2t'" + "data_col = \"2t\"" ] }, { @@ -126,9 +131,16 @@ " subplot.line(y=data, x=dates, linewidth=0.5, color=\"#e6e6e6\", label=\"1940-2022\")\n", " else:\n", " subplot.line(y=data, x=dates, linewidth=0.5, color=\"#e6e6e6\")\n", - "subplot.line(y=data_reference, x=dates, color=\"grey\", linestyle=\"--\", label=\"1991-2020 mean\")\n", + "subplot.line(\n", + " y=data_reference, x=dates, color=\"grey\", linestyle=\"--\", label=\"1991-2020 mean\"\n", + ")\n", "subplot.line(y=get_year_data(df, 2023), x=dates, color=\"orange\", label=\"2023\")\n", - "subplot.line(y=get_year_data(df, 2024), x=dates[:len(get_year_data(df, 2024))], color=C3S_RED, label=\"2024\")\n", + "subplot.line(\n", + " y=get_year_data(df, 2024),\n", + " x=dates[: len(get_year_data(df, 2024))],\n", + " color=C3S_RED,\n", + " label=\"2024\",\n", + ")\n", "\n", "subplot.ax.xaxis.set_ticklabels([])\n", "subplot.set_minor_xticks(\"M1\", format=\"%b\")\n", @@ -137,8 +149,7 @@ "\n", "subplot.ax.legend(ncol=4, loc=(0.15, 1.05), frameon=False)\n", "figure.fig.suptitle(\n", - " \"Global surface air temperature\\n\"\n", - " \"Daily average • Data ERA5 • Credit: C3S/ECMWF\"\n", + " \"Global surface air temperature\\n\" \"Daily average • Data ERA5 • Credit: C3S/ECMWF\"\n", ")\n", "\n", "figure.show()" diff --git a/docs/examples/gallery/vector-data/vorticity-and-wind.ipynb b/docs/examples/gallery/vector-data/vorticity-and-wind.ipynb index 19b6f10..cc9be1b 100644 --- a/docs/examples/gallery/vector-data/vorticity-and-wind.ipynb +++ b/docs/examples/gallery/vector-data/vorticity-and-wind.ipynb @@ -217,7 +217,7 @@ "PRESSURE = 700\n", "\n", "LEVELS = [1, 3, 5, 7, 9, 11, 13, 15, 20, 30, 50]\n", - "LEVELS = [0-level for level in LEVELS[::-1]] + [0] + LEVELS" + "LEVELS = [0 - level for level in LEVELS[::-1]] + [0] + LEVELS" ] }, { diff --git a/docs/examples/guide/02-components.ipynb b/docs/examples/guide/02-components.ipynb index cbc5876..3a610f5 100644 --- a/docs/examples/guide/02-components.ipynb +++ b/docs/examples/guide/02-components.ipynb @@ -58,8 +58,8 @@ "\n", "subplot = earthkit.plots.Subplot()\n", "subplot.line([1, 3, 2, 5, 4, 7])\n", - "subplot.line([i+1 for i in [1, 3, 2, 5, 4, 7]])\n", - "subplot.line([i+2 for i in [1, 3, 2, 5, 4, 7]])\n", + "subplot.line([i + 1 for i in [1, 3, 2, 5, 4, 7]])\n", + "subplot.line([i + 2 for i in [1, 3, 2, 5, 4, 7]])\n", "\n", "subplot.show()" ] diff --git a/docs/examples/guide/04-reusable-code.ipynb b/docs/examples/guide/04-reusable-code.ipynb index de369bf..99ee34f 100644 --- a/docs/examples/guide/04-reusable-code.ipynb +++ b/docs/examples/guide/04-reusable-code.ipynb @@ -44,19 +44,20 @@ "import earthkit.data\n", "import earthkit.plots\n", "\n", + "\n", "def my_plot(data, domain=None, units=None):\n", " chart = earthkit.plots.Map(domain=domain)\n", "\n", " chart.block(data, units=units)\n", " chart.coastlines()\n", " chart.gridlines()\n", - " \n", + "\n", " # The format keys between the curly braces will be populated from metadata\n", " chart.title(\"{variable_name} at {time:%H:%M on %-d %B %Y} over {domain}\")\n", - " \n", + "\n", " # You can also use metadata format strings in legend labels\n", " chart.legend(label=\"{variable_name} ({units})\")\n", - " \n", + "\n", " chart.show()" ] }, diff --git a/docs/examples/reduced_gg.ipynb b/docs/examples/reduced_gg.ipynb index cae3643..4226f10 100644 --- a/docs/examples/reduced_gg.ipynb +++ b/docs/examples/reduced_gg.ipynb @@ -47,7 +47,7 @@ "outputs": [], "source": [ "LEVELS = [1, 3, 5, 7, 9, 11, 13, 15, 20, 30, 50, 75, 100]\n", - "LEVELS = [0-level for level in LEVELS[::-1]] + [0] + LEVELS\n", + "LEVELS = [0 - level for level in LEVELS[::-1]] + [0] + LEVELS\n", "\n", "STYLE = earthkit.plots.styles.Style(\n", " units=\"celsius\",\n", diff --git a/docs/examples/sandbox.ipynb b/docs/examples/sandbox.ipynb index c6addd5..c5c1d94 100644 --- a/docs/examples/sandbox.ipynb +++ b/docs/examples/sandbox.ipynb @@ -19,15 +19,15 @@ "outputs": [], "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': '04',\n", - " 'day': '20',\n", - " 'time': '12:00',\n", + " \"product_type\": \"reanalysis\",\n", + " \"variable\": \"2m_temperature\",\n", + " \"year\": \"2024\",\n", + " \"month\": \"04\",\n", + " \"day\": \"20\",\n", + " \"time\": \"12:00\",\n", " },\n", ")\n", "\n", diff --git a/pyproject.toml b/pyproject.toml index 847c167..92ca02c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -57,17 +57,29 @@ urls.Repository = "https://github.com/ecmwf/earthkit-plots/" [tool.coverage.run] branch = "true" -[tool.isort] -profile = "black" +[tool.ruff.format] +docstring-code-format = true -[tool.pydocstyle] -add_ignore = [ +[tool.ruff.lint] +ignore = [ + "E501", "D1", "D200", "D205", "D400", - "D401" + "D401", + "D419" ] +select = [ + "F", # Pyflakes + "I", # Isort + "D", # Pydocstyle + "E", + "W" +] +unfixable = ["F401"] + +[tool.ruff.lint.pydocstyle] convention = "numpy" [tool.setuptools.packages.find] diff --git a/src/earthkit/plots/components/subplots.py b/src/earthkit/plots/components/subplots.py index 6ff4c7a..f1f6274 100644 --- a/src/earthkit/plots/components/subplots.py +++ b/src/earthkit/plots/components/subplots.py @@ -15,11 +15,11 @@ import warnings from itertools import cycle -import earthkit.data import matplotlib.dates as mdates import matplotlib.pyplot as plt import numpy as np +import earthkit.data from earthkit.plots import identifiers from earthkit.plots.components.layers import Layer from earthkit.plots.geo import grids diff --git a/src/earthkit/plots/geo/domains.py b/src/earthkit/plots/geo/domains.py index 4770b32..28facea 100644 --- a/src/earthkit/plots/geo/domains.py +++ b/src/earthkit/plots/geo/domains.py @@ -371,7 +371,6 @@ def extract( extra_values = [np.roll(v, roll_by, axis=1) for v in extra_values] if self.can_bbox: - try: import scipy.ndimage as sn except ImportError: diff --git a/src/earthkit/plots/geo/grids.py b/src/earthkit/plots/geo/grids.py index 85f0ef7..646481d 100644 --- a/src/earthkit/plots/geo/grids.py +++ b/src/earthkit/plots/geo/grids.py @@ -48,7 +48,6 @@ def is_structured(x, y, tol=1e-5): True if the data represents a structured grid, i.e., the spacing between consecutive points in both x and y is consistent. False otherwise. """ - x = np.asarray(x) y = np.asarray(y) diff --git a/src/earthkit/plots/interactive/inputs.py b/src/earthkit/plots/interactive/inputs.py index 37883a8..106cf7c 100644 --- a/src/earthkit/plots/interactive/inputs.py +++ b/src/earthkit/plots/interactive/inputs.py @@ -14,9 +14,9 @@ import warnings -import earthkit.data import numpy as np +import earthkit.data from earthkit.plots.interactive import times # from earthkit.plots.schemas import schema diff --git a/src/earthkit/plots/metadata/formatters.py b/src/earthkit/plots/metadata/formatters.py index ffc0f1a..225f3fe 100644 --- a/src/earthkit/plots/metadata/formatters.py +++ b/src/earthkit/plots/metadata/formatters.py @@ -15,10 +15,10 @@ import itertools import logging from string import Formatter -from zoneinfo import ZoneInfo import dateutil import numpy as np +from zoneinfo import ZoneInfo from earthkit.plots import metadata from earthkit.plots.schemas import schema diff --git a/src/earthkit/plots/schemas.py b/src/earthkit/plots/schemas.py index ac5fcd5..c034f35 100644 --- a/src/earthkit/plots/schemas.py +++ b/src/earthkit/plots/schemas.py @@ -174,7 +174,6 @@ def set(self, **kwargs): >>> schema.set(font="verdana") >>> with schema.set(font="comic sans"): ... print(schema.font) - ... comic sans >>> print(schema.font) verdana diff --git a/src/earthkit/plots/sources/__init__.py b/src/earthkit/plots/sources/__init__.py index 6366f89..6699386 100644 --- a/src/earthkit/plots/sources/__init__.py +++ b/src/earthkit/plots/sources/__init__.py @@ -13,7 +13,6 @@ # limitations under the License. import earthkit.data as ek_data - from earthkit.plots.sources.earthkit import EarthkitSource from earthkit.plots.sources.numpy import NumpySource from earthkit.plots.sources.xarray import XarraySource diff --git a/src/earthkit/plots/sources/single.py b/src/earthkit/plots/sources/single.py index 8a4a9f4..09bb6ca 100644 --- a/src/earthkit/plots/sources/single.py +++ b/src/earthkit/plots/sources/single.py @@ -16,7 +16,6 @@ from functools import cached_property import earthkit.data - from earthkit.plots.sources import gridspec _NO_EARTHKIT_REGRID = False diff --git a/src/earthkit/plots/styles/__init__.py b/src/earthkit/plots/styles/__init__.py index 9a2521c..90acbc5 100644 --- a/src/earthkit/plots/styles/__init__.py +++ b/src/earthkit/plots/styles/__init__.py @@ -790,7 +790,6 @@ def __init__( preferred_method="contour", **kwargs, ): - super().__init__(colors=colors, preferred_method=preferred_method, **kwargs) self._line_colors = line_colors self.labels = labels diff --git a/src/earthkit/plots/workflows.py b/src/earthkit/plots/workflows.py index 3a43e39..d0bdc96 100644 --- a/src/earthkit/plots/workflows.py +++ b/src/earthkit/plots/workflows.py @@ -1,7 +1,6 @@ import json import earthkit.data - import earthkit.plots