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 linter #128

Merged
merged 10 commits into from
Mar 8, 2023
Merged
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
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
If you are opening an issue regarding an existing notebook/code or the webpage just ignore the instructions below.
If you want to suggest a notebook for the code gallery please answer these questions:

- [ ] What is language(s) for used in the example?
- [ ] Is it focused on a particular module/software or an IOOS data service?
- [ ] Can you provide a minimum example of the expected code and results in a notebook?
- \[ \] What is language(s) for used in the example?
- \[ \] Is it focused on a particular module/software or an IOOS data service?
- \[ \] Can you provide a minimum example of the expected code and results in a notebook?

Please provide a detailed description of the suggested example below:
6 changes: 3 additions & 3 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Thank you for send a Pull Request to our code gallery! When adding or updating a notebook please check if:

- [ ] The notebook has all the dependencies required to run in the IOOS env, if not please update the environment file.
- [ ] You added a title, description, and a line with `Created: YYYY-MM-DD` in the first cell.
- [ ] If you are updating a notebook add a line with `Updated: YYYY-MM-DD` below the created date.
- \[ \] The notebook has all the dependencies required to run in the IOOS env, if not please update the environment file.
- \[ \] You added a title, description, and a line with `Created: YYYY-MM-DD` in the first cell.
- \[ \] If you are updating a notebook add a line with `Updated: YYYY-MM-DD` below the created date.
27 changes: 20 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,9 @@ repos:
rev: v3.0.0-alpha.6
hooks:
- id: prettier
types_or: [html]
exclude: "_templates/layout.html"

- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
exclude: docs/source/conf.py
args: [--max-line-length=105]

- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
Expand All @@ -40,6 +34,25 @@ repos:
hooks:
- id: add-trailing-comma

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.254
hooks:
- id: ruff

- repo: https://github.com/nbQA-dev/nbQA
rev: 1.6.3
hooks:
# mdformat works on the CLI but not as pre-commit yet.
# Use `nbqa mdformat jupyterbook --nbqa-md` to run it locally.
# - id: mdformat
- id: nbqa-check-ast
- id: nbqa-black
- id: nbqa-ruff
args: [--fix, --extend-ignore=E402]
# Skipping b/c These notebooks mix R and Python and
# will return false positive for "F821 Undefined name.""
exclude: 2017-11-30-rerddap\.ipynb$|2018-02-20-obis.ipynb$

ci:
autofix_commit_msg: |
[pre-commit.ci] auto fixes from pre-commit.com hooks
Expand Down
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ If you would like to work on a notebook that has been proposed, follow these ste
1. Notebooks are kept in the [jupyterbook/content/code_gallery](https://github.com/ioos/ioos_code_lab/tree/main/jupyterbook/content/code_gallery) directory of this repository.
1. There are three directories where notebooks can be placed:
1. `data_access_notebooks` -
2. `data_analysis_and_visualization_notebooks` -
3. `data_management_notebooks` -
2. Typically, it's best to copy an existing (working) notebook to a new file. If you are creating a python notebook, copy one of the python notebooks. If you are creating an R notebook, copy one of the R notebooks, etc
3. Name the notebook following the convention `[date]-[short name].ipynb`. Where, `[date]` is the date (YYYY-MM-DD) you started the new notebook and `[short name]` is an abbreviation for what the notebook will cover. Look at the existing notebook filenames to get a sense of the short names used.
1. `data_analysis_and_visualization_notebooks` -
1. `data_management_notebooks` -
1. Typically, it's best to copy an existing (working) notebook to a new file. If you are creating a python notebook, copy one of the python notebooks. If you are creating an R notebook, copy one of the R notebooks, etc
1. Name the notebook following the convention `[date]-[short name].ipynb`. Where, `[date]` is the date (YYYY-MM-DD) you started the new notebook and `[short name]` is an abbreviation for what the notebook will cover. Look at the existing notebook filenames to get a sense of the short names used.
1. Edit the notebook following the [Jupyter Notebook documentation](https://jupyter-notebook.readthedocs.io/en/stable/notebook.html). The notebook should include the following information:
1. Descriptive title for what the notebook is doing.
1. A short summary providing context and expanding on the title.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ To suggest a notebook or ask questions please open an issue at: https://github.c

[![DOI](https://zenodo.org/badge/399546690.svg)](https://zenodo.org/badge/latestdoi/399546690)

---
______________________________________________________________________

## Build the JupyterBook locally

Expand All @@ -24,7 +24,7 @@ To suggest a notebook or ask questions please open an issue at: https://github.c
### Requirements:

- Git: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
- Jupyter{Book}: https://jupyterbook.org/intro.html
- Jupyter\{Book}: https://jupyterbook.org/intro.html
- Web Browser

### Installation
Expand Down
8 changes: 5 additions & 3 deletions jupyterbook/content/Video_Demo_Markdown/glos.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# GLOS Links

```{image} ../../images/GLOS.png
:alt: IOOS
:width: 150px
:align: center
---
alt: IOOS
width: 150px
align: center
---
```

- [How to use the GLOS data portal](https://www.youtube.com/playlist?list=PLEK-mxRrHSZ5LkSSUyYHEy4lEXnEdNJJc)
Expand Down
8 changes: 5 additions & 3 deletions jupyterbook/content/Video_Demo_Markdown/ioos.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# IOOS

```{image} ../../images/placeholder.png
:alt: IOOS
:width: 150px
:align: center
---
alt: IOOS
width: 150px
align: center
---
```

- [COMT Tutorial](https://www.youtube.com/watch?v=Dqc1C1HeemQ)
Expand Down
8 changes: 5 additions & 3 deletions jupyterbook/content/Video_Demo_Markdown/nanoos.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# NANOOS

```{image} ../../images/NANOOS.png
:alt: IOOS
:width: 150px
:align: center
---
alt: IOOS
width: 150px
align: center
---
```

- [NANOOS Visualization System](https://www.youtube.com/watch?v=MEVz0jOsqmI)
Expand Down
8 changes: 5 additions & 3 deletions jupyterbook/content/Video_Demo_Markdown/ooi.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# OOI Demonstration Videos

```{image} ../../images/OOI_Logo.png
:alt: IOOS
:width: 150px
:align: center
---
alt: IOOS
width: 150px
align: center
---
```

- [Demo of OOI ERDDAP endpoint](https://www.youtube.com/watch?v=tj4M9hodTG0)
8 changes: 5 additions & 3 deletions jupyterbook/content/Video_Demo_Markdown/python_dem.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Python Demonstration Videos

```{image} ../../images/python.png
:alt: IOOS
:width: 150px
:align: center
---
alt: IOOS
width: 150px
align: center
---
```

- [Catalog Driven Reproducible Workflows for Ocean-science](https://www.youtube.com/watch?v=05ax0lkQFrg)
Expand Down
4 changes: 1 addition & 3 deletions jupyterbook/content/code_gallery/data_access.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ Matlab, R, etc).

For more information on accessing IOOS data, see <https://ioos.noaa.gov/data/access-ioos-data/>.

---
______________________________________________________________________

## Chapter table of contents

```{tableofcontents}

```

---
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"source": [
"from erddapy import ERDDAP\n",
"\n",
"\n",
"e = ERDDAP(\n",
" server=\"https://opendap.co-ops.nos.noaa.gov/erddap\",\n",
" protocol=\"tabledap\",\n",
Expand All @@ -39,7 +38,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The geographical bounding box includes all the states in the [SECOORA](http://secoora.org/) region: Florida, Georgia, South and North Carolina. "
"The geographical bounding box includes all the states in the [SECOORA](http://secoora.org/) region: Florida, Georgia, South and North Carolina."
]
},
{
Expand Down Expand Up @@ -142,14 +141,15 @@
"source": [
"import folium\n",
"\n",
"\n",
"lon = (min_lon + max_lon) / 2\n",
"lat = (min_lat + max_lat) / 2\n",
"\n",
"m = folium.Map(location=[lat, lon], tiles=\"OpenStreetMap\", zoom_start=5)\n",
"\n",
"folium.Polygon([(min_lat,min_lon), (max_lat,min_lon), (max_lat,max_lon), (min_lat,max_lon)],\n",
" fill=True).add_to(m)\n",
"folium.Polygon(\n",
" [(min_lat, min_lon), (max_lat, min_lon), (max_lat, max_lon), (min_lat, max_lon)],\n",
" fill=True,\n",
").add_to(m)\n",
"\n",
"m"
]
Expand All @@ -158,7 +158,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Unfortunately, as you'll notice below, adding the bounding box as a constraint won't help because this ERDDAP server requires the `STATION_ID` number as a mandatory argument for the request. "
"Unfortunately, as you'll notice below, adding the bounding box as a constraint won't help because this ERDDAP server requires the `STATION_ID` number as a mandatory argument for the request."
]
},
{
Expand Down Expand Up @@ -225,7 +225,6 @@
"source": [
"import pandas as pd\n",
"\n",
"\n",
"df = pd.read_csv(e.get_search_url(response=\"csv\"))\n",
"df[\"Dataset ID\"]"
]
Expand Down Expand Up @@ -258,9 +257,7 @@
"\n",
"e.dataset_id = dataset_id\n",
"\n",
"variables = e.get_var_by_attr(\n",
" standard_name=std_name\n",
")\n",
"variables = e.get_var_by_attr(standard_name=std_name)\n",
"\n",
"print(f\"Found {','.join(variables)} variable(s) in the dataset.\")\n",
"\n",
Expand Down Expand Up @@ -399,7 +396,11 @@
}
],
"source": [
"print(station_id_info.loc[station_id_info[\"Attribute Name\"] == \"comment\"][\"Value\"].squeeze())"
"print(\n",
" station_id_info.loc[station_id_info[\"Attribute Name\"] == \"comment\"][\n",
" \"Value\"\n",
" ].squeeze()\n",
")"
]
},
{
Expand All @@ -425,10 +426,7 @@
")[[\"name\", \"ID\"]]\n",
"\n",
"\n",
"locations = pd.read_xml(\n",
" url,\n",
" xpath=\"//*[contains(name(),\\\"location\\\")]\"\n",
")\n",
"locations = pd.read_xml(url, xpath='//*[contains(name(),\"location\")]')\n",
"\n",
"df = pd.concat([names, locations], axis=1)"
]
Expand All @@ -455,15 +453,17 @@
],
"source": [
"mask = (\n",
" (df[\"lat\"] >= min_lat) &\n",
" (df[\"lat\"] <= max_lat) &\n",
" (df[\"long\"] >= min_lon) &\n",
" (df[\"long\"] <= max_lon)\n",
" (df[\"lat\"] >= min_lat)\n",
" & (df[\"lat\"] <= max_lat)\n",
" & (df[\"long\"] >= min_lon)\n",
" & (df[\"long\"] <= max_lon)\n",
")\n",
"\n",
"df = df[mask]\n",
"\n",
"print(f\"We filtered out all stations but those from {', '.join(filter(None, set(df['state'])))} states.\")"
"print(\n",
" f\"We filtered out all stations but those from {', '.join(filter(None, set(df['state'])))} states.\"\n",
")"
]
},
{
Expand Down Expand Up @@ -640,11 +640,12 @@
"import matplotlib\n",
"import matplotlib.pyplot as plt\n",
"\n",
"\n",
"station_ids = df.loc[df[\"state\"] == \"NC\"][\"ID\"]\n",
"\n",
"with matplotlib.style.context([\"seaborn-notebook\", \"seaborn-darkgrid\"]):\n",
" fix, axes = plt.subplots(nrows=len(station_ids), sharex=True, sharey=True, figsize=(11, 2.25 * 5))\n",
" fix, axes = plt.subplots(\n",
" nrows=len(station_ids), sharex=True, sharey=True, figsize=(11, 2.25 * 5)\n",
" )\n",
"\n",
" for k, station_id in enumerate(station_ids):\n",
" series = water_level[station_id]\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@
"metadata": {},
"outputs": [],
"source": [
"import xarray as xr\n",
"import cf_xarray\n",
"\n",
"print(cf_xarray.__version__)\n",
"import xarray as xr\n",
"\n",
"xr.set_options(keep_attrs=True)\n",
"ds = xr.open_dataset(url)"
Expand Down Expand Up @@ -619,7 +620,6 @@
"source": [
"import folium\n",
"\n",
"\n",
"tiles = (\n",
" \"http://services.arcgisonline.com/arcgis/rest/services/\"\n",
" \"World_Topo_Map/MapServer/MapServer/tile/{z}/{y}/{x}\"\n",
Expand Down Expand Up @@ -657,7 +657,6 @@
"import numpy as np\n",
"import numpy.ma as ma\n",
"\n",
"\n",
"# Find the deepest profile.\n",
"idx = np.nonzero(~ma.masked_invalid(temp[:, -1]).mask)[0][0]\n",
"\n",
Expand Down Expand Up @@ -691,7 +690,6 @@
"source": [
"import matplotlib.pyplot as plt\n",
"\n",
"\n",
"ncols = 3\n",
"fig, (ax0, ax1, ax2) = plt.subplots(\n",
" sharey=True, sharex=False, ncols=ncols, figsize=(3.25 * ncols, 5)\n",
Expand Down Expand Up @@ -749,9 +747,7 @@
" return np.r_[0, np.cumsum(dist)]\n",
"\n",
"\n",
"def plot_glider(\n",
" x, y, z, t, data, cmap=plt.cm.viridis, figsize=(11, 3.75)):\n",
"\n",
"def plot_glider(x, y, z, t, data, cmap=plt.cm.viridis, figsize=(11, 3.75)):\n",
" fig, ax = plt.subplots(figsize=figsize)\n",
" dist = distance(x, y, units=\"km\")\n",
" z = np.abs(z)\n",
Expand Down Expand Up @@ -818,7 +814,6 @@
"source": [
"from palettable import cmocean\n",
"\n",
"\n",
"haline = cmocean.sequential.Haline_20.mpl_colormap\n",
"thermal = cmocean.sequential.Thermal_20.mpl_colormap\n",
"dense = cmocean.sequential.Dense_20.mpl_colormap\n",
Expand Down Expand Up @@ -871,7 +866,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.4"
"version": "3.11.0"
}
},
"nbformat": 4,
Expand Down
Loading