Skip to content
Draft
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
74 changes: 27 additions & 47 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,63 +1,43 @@
default_language_version:
python: python3
default_stages:
- pre-commit
- pre-push
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
rev: v6.0.0
hooks:
- id: trailing-whitespace # Trailing whitespace checker
- id: end-of-file-fixer # Ensure files end in a newline
- id: check-json
- id: check-yaml # Check YAML files for syntax errors only
args: [--unsafe, --allow-multiple-documents]
- id: check-toml
# - id: check-added-large-files
- id: debug-statements # Check for debugger imports and py37+ breakpoint()
- id: detect-private-key
- id: check-ast
- id: end-of-file-fixer
- id: mixed-line-ending
- id: no-commit-to-branch # Prevent committing to main / master
- id: check-merge-conflict # Check for files that contain merge conflict
exclude: /README\.rst$|^docs/.*\.rst$
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
args:
- -l 120
- --force-single-line-imports
- --profile black
- repo: https://github.com/psf/black
rev: 24.8.0
hooks:
- id: black
args: [--line-length=120]
- repo: https://github.com/keewis/blackdoc
rev: v0.3.8
hooks:
- id: blackdoc
additional_dependencies: [black==23.3.0]
exclude: xr_engine_profile_rst\.py
args: [--fix=lf]
- id: trailing-whitespace
- id: check-case-conflict
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.9
rev: v0.15.4
hooks:
- id: ruff
- id: ruff-check
exclude: '(dev/.*|.*_)\.py$'
args:
- --line-length=120
- --fix
- --exit-non-zero-on-fix
- --preview
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.14
hooks:
- id: mdformat
exclude: cruft-update-template.md
- id: ruff-format
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.11.0
rev: v2.16.0
hooks:
- id: pretty-format-yaml
args: [--autofix, --preserve-quotes]
- repo: https://github.com/sphinx-contrib/sphinx-lint
rev: v1.0.0
hooks:
- id: sphinx-lint
- repo: https://github.com/tox-dev/pyproject-fmt
rev: "v2.8.0"
hooks:
- id: pyproject-fmt
- id: pretty-format-toml
args: [--autofix]
- repo: local
hooks:
- id: forbid-to-commit
name: Don't commit rej files
entry: |
Cannot commit .rej files. These indicate merge conflicts that arise during automated template updates.
Fix the merge conflicts manually and remove the .rej files.
language: fail
files: '.*\.rej$'
18 changes: 10 additions & 8 deletions docs/tutorials/01_grib_file.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
"outputs": [],
"source": [
"import io\n",
"\n",
"import matplotlib.pyplot as plt\n",
"\n",
"from earthkit import data, regrid\n",
"\n",
"fs = data.from_source(\"file\", \"tz_1000.grib\")"
Expand All @@ -57,7 +59,7 @@
"outputs": [],
"source": [
"# define the interpolation job\n",
"job = regrid.Job(grid='0.2/0.2', area='70/-30/20/70')"
"job = regrid.Job(grid=\"0.2/0.2\", area=\"70/-30/20/70\")"
]
},
{
Expand All @@ -73,27 +75,27 @@
"# note: sel() first iterates through the messages and returns a\n",
"# view to the ones matching the conditions\n",
"for f in fs.sel(param=\"t\", level=1000):\n",
" # interpolate - \n",
" # interpolate -\n",
" # the input is a GRIB message in memory\n",
" # the output is a GRIB message in memory stored in a BytesIO object\n",
" d = f.message()\n",
" data_in = regrid.GribMemoryInput(d)\n",
" data_out = io.BytesIO()\n",
" job.execute(data_in, data_out)\n",
" \n",
"\n",
" # load the resulting GRIB message\n",
" g = data.from_source(\"memory\", data_out.getvalue())[0]\n",
" \n",
"\n",
" if res is None:\n",
" # start accumulation\n",
" res = g.to_numpy()\n",
" \n",
"\n",
" # get metadata for plotting\n",
" lat, lon = g.data(\"lat\",\"lon\")\n",
" lat, lon = g.data(\"lat\", \"lon\")\n",
" else:\n",
" # accumulation\n",
" res += g.to_numpy()\n",
" \n",
"\n",
" num += 1"
]
},
Expand Down Expand Up @@ -133,7 +135,7 @@
}
],
"source": [
"res /= num \n",
"res /= num\n",
"print(f\"num={num}\")\n",
"print(res)"
]
Expand Down
38 changes: 20 additions & 18 deletions docs/tutorials/02_grib_fdb.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
"outputs": [],
"source": [
"import io\n",
"\n",
"import matplotlib.pyplot as plt\n",
"import pyfdb\n",
"\n",
"from earthkit import data, regrid"
]
},
Expand Down Expand Up @@ -64,16 +66,16 @@
"source": [
"# date must be adjusted since FDB only stores recent dates\n",
"request = {\n",
" 'class': 'od',\n",
" 'expver': '0001',\n",
" 'stream': 'oper',\n",
" 'date': '20230219',\n",
" 'time': '0000',\n",
" 'domain': 'g',\n",
" 'type': 'fc',\n",
" 'levtype': 'sfc',\n",
" 'step': list(range(0,48,3)),\n",
" 'param': 167\n",
" \"class\": \"od\",\n",
" \"expver\": \"0001\",\n",
" \"stream\": \"oper\",\n",
" \"date\": \"20230219\",\n",
" \"time\": \"0000\",\n",
" \"domain\": \"g\",\n",
" \"type\": \"fc\",\n",
" \"levtype\": \"sfc\",\n",
" \"step\": list(range(0, 48, 3)),\n",
" \"param\": 167,\n",
"}\n",
"\n",
"# Must be set correctly\n",
Expand Down Expand Up @@ -117,34 +119,34 @@
"outputs": [],
"source": [
"# define the interpolation job\n",
"job = regrid.Job(grid='0.2/0.2', area='70/-30/20/70')\n",
"job = regrid.Job(grid=\"0.2/0.2\", area=\"70/-30/20/70\")\n",
"\n",
"res = None\n",
"num = 0\n",
"\n",
"# iterating through the GRIB fields from the stream\n",
"for f in fs:\n",
" # interpolate - \n",
" # interpolate -\n",
" # the input is a GRIB message in memory\n",
" # the output is a GRIB message in memory stored in a BytesIO object \n",
" # the output is a GRIB message in memory stored in a BytesIO object\n",
" d = f.message()\n",
" data_in = regrid.GribMemoryInput(d)\n",
" data_out = io.BytesIO()\n",
" job.execute(data_in, data_out)\n",
" \n",
"\n",
" # load the resulting GRIB message\n",
" g = data.from_source(\"memory\", data_out.getvalue())[0]\n",
" \n",
"\n",
" if res is None:\n",
" # start accumulation\n",
" res = g.to_numpy()\n",
" \n",
"\n",
" # get metadata for plotting\n",
" lat, lon = g.data(\"lat\", \"lon\")\n",
" else:\n",
" # accumulation\n",
" res += g.to_numpy()\n",
" \n",
"\n",
" num += 1"
]
},
Expand Down Expand Up @@ -173,7 +175,7 @@
}
],
"source": [
"res /= num \n",
"res /= num\n",
"print(f\"num={num}\")\n",
"print(res)"
]
Expand Down
Loading
Loading