Skip to content
This repository was archived by the owner on Sep 11, 2023. It is now read-only.

Commit 3a3f2e6

Browse files
authored
Update to reusable workflows (#289)
* Update to reusable workflows * Only check nowcasting_dataset for linting * Run isort * Update pre-commit to new standards
1 parent 392db62 commit 3a3f2e6

File tree

73 files changed

+250
-307
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+250
-307
lines changed

.github/workflows/linters.yaml

+4-19
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,7 @@ name: Lint Python
33
on: [push]
44

55
jobs:
6-
build:
7-
runs-on: ubuntu-latest
8-
strategy:
9-
matrix:
10-
python-version: [3.9]
11-
12-
steps:
13-
- uses: actions/checkout@v2
14-
- name: Set up Python ${{ matrix.python-version }}
15-
uses: actions/setup-python@v2
16-
with:
17-
python-version: ${{ matrix.python-version }}
18-
- name: Install dependencies
19-
run: |
20-
python -m pip install --upgrade pip
21-
pip install pydocstyle
22-
- name: Docstyle linting
23-
run: |
24-
pydocstyle --convention=google --add-ignore=D200,D202,D210,D212,D415 nowcasting_dataset
6+
call-run-python-linters:
7+
uses: openclimatefix/.github/.github/workflows/python-lint.yml@main
8+
with:
9+
folder: "nowcasting_dataset"

.github/workflows/python-app.yml

-34
This file was deleted.

.github/workflows/release.yaml

+4-54
Original file line numberDiff line numberDiff line change
@@ -4,57 +4,7 @@ on:
44
branches:
55
- main
66
jobs:
7-
build:
8-
runs-on: ubuntu-latest
9-
outputs:
10-
new_tag: ${{ steps.bumper.outputs.new_ver }}
11-
steps:
12-
- uses: actions/checkout@v2
13-
- name: Bump version
14-
id: bumper
15-
uses: jaumann/[email protected]
16-
env:
17-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18-
- name: Push changes
19-
uses: ad-m/github-push-action@master
20-
with:
21-
github_token: ${{ secrets.GITHUB_TOKEN }}
22-
tags: true
23-
- name: Set up Python
24-
uses: actions/setup-python@v2
25-
with:
26-
python-version: "3.x"
27-
- name: Install dependencies
28-
run: |
29-
python -m pip install --upgrade pip
30-
pip install build
31-
- name: Build package
32-
run: python -m build
33-
- name: Publish package
34-
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
35-
with:
36-
user: __token__
37-
password: ${{ secrets.PYPI_API_TOKEN }}
38-
39-
release:
40-
needs: [build]
41-
runs-on: ubuntu-latest
42-
steps:
43-
- run: echo ${{needs.build.outputs.new_tag}}
44-
- name: Changelog
45-
uses: scottbrenner/generate-changelog-action@master
46-
id: Changelog
47-
env:
48-
REPO: ${{ github.repository }}
49-
- name: Create Release
50-
id: create_release
51-
uses: actions/create-release@latest
52-
env:
53-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54-
with:
55-
tag_name: v${{ needs.build.outputs.new_tag }}
56-
release_name: v${{ needs.build.outputs.new_tag }}
57-
body: |
58-
${{ steps.Changelog.outputs.changelog }}
59-
draft: false
60-
prerelease: false
7+
call-run-python-release:
8+
uses: openclimatefix/.github/.github/workflows/python-release.yml@main
9+
secrets:
10+
token: ${{ secrets.PYPI_API_TOKEN }}

.github/workflows/workflows.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
name: Python package
2+
3+
on: [push]
4+
jobs:
5+
call-run-python-tests:
6+
uses: openclimatefix/.github/.github/workflows/python-test.yml@main

.pre-commit-config.yaml

+21-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,27 @@ repos:
1212
- id: debug-statements
1313
- id: detect-private-key
1414

15-
# python code formatting
15+
# python code formatting/linting
16+
- repo: https://github.com/PyCQA/pydocstyle
17+
rev: 6.1.1
18+
hooks:
19+
- id: pydocstyle
20+
args:
21+
[
22+
--convention=google,
23+
"--add-ignore=D200,D202,D210,D212,D415",
24+
"nowcasting_dataset",
25+
]
26+
- repo: https://github.com/PyCQA/flake8
27+
rev: 4.0.1
28+
hooks:
29+
- id: flake8
30+
args: [--max-line-length, "100", --extend-ignore=E203]
31+
- repo: https://github.com/PyCQA/isort
32+
rev: 5.9.3
33+
hooks:
34+
- id: isort
35+
args: [--profile, black, --line-length, "100"]
1636
- repo: https://github.com/psf/black
1737
rev: 20.8b1
1838
hooks:

notebooks/2021-08/2021-08-25/video.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import os
2-
from nowcasting_dataset.dataset import NetCDFDataset, SAT_MEAN, SAT_STD
3-
import plotly.graph_objects as go
4-
import plotly
5-
import pandas as pd
2+
3+
import cv2
64
import numpy as np
5+
import pandas as pd
6+
import plotly
77
import plotly.graph_objects as go
8-
import cv2
8+
9+
from nowcasting_dataset.dataset import SAT_MEAN, SAT_STD, NetCDFDataset
910

1011
DATA_PATH = "gs://solar-pv-nowcasting-data/prepared_ML_training_data/v4/"
1112
TEMP_PATH = ""
@@ -40,6 +41,7 @@
4041

4142
# get satellite image, currently from https://github.com/openclimatefix/py-staticmaps
4243
import staticmaps
44+
4345
from nowcasting_dataset.geospatial import osgb_to_lat_lon
4446

4547
bottom_left = osgb_to_lat_lon(x=x_min, y=y_min)

notebooks/2021-08/2021-08-26/video.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import os
2-
from nowcasting_dataset.dataset import NetCDFDataset, SAT_MEAN, SAT_STD
3-
import plotly.graph_objects as go
4-
import plotly
5-
import pandas as pd
2+
3+
import cv2
64
import numpy as np
7-
import plotly.graph_objects as go
8-
from plotly.subplots import make_subplots
5+
import pandas as pd
6+
import plotly
97
import plotly.express as px
10-
import cv2
8+
import plotly.graph_objects as go
119

1210
# get satellite image, currently from https://github.com/openclimatefix/py-staticmaps
1311
import staticmaps
14-
from nowcasting_dataset.geospatial import osgb_to_lat_lon
12+
from plotly.subplots import make_subplots
1513

14+
from nowcasting_dataset.dataset import SAT_MEAN, SAT_STD, NetCDFDataset
15+
from nowcasting_dataset.geospatial import osgb_to_lat_lon
1616

1717
##############
1818
# Setup data generator

notebooks/2021-09/2021-09-06/gsp.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
from urllib.request import urlopen
3+
34
import geopandas as gpd
45
import plotly.graph_objects as go
56

notebooks/2021-09/2021-09-07/gsp.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import itertools
12
import json
23
from urllib.request import urlopen
4+
35
import geopandas as gpd
4-
import plotly.graph_objects as go
56
import numpy as np
6-
import itertools
7+
import plotly.graph_objects as go
78

89
WGS84_CRS = "EPSG:4326"
910

notebooks/2021-09/2021-09-08/dan.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import gcsfs
22
import xarray as xr
3-
filename = 'gs://solar-pv-nowcasting-data/satellite/EUMETSAT/SEVIRI_RSS/OSGB36/all_zarr_int16_single_timestep.zarr/'
3+
4+
filename = "gs://solar-pv-nowcasting-data/satellite/EUMETSAT/SEVIRI_RSS/OSGB36/all_zarr_int16_single_timestep.zarr/"
45
# filename2 = 'gs://solar-pv-nowcasting-data/prepared_ML_training_data/testing.zarr'
5-
ds = xr.open_dataset(filename, engine='zarr')
6+
ds = xr.open_dataset(filename, engine="zarr")

notebooks/2021-09/2021-09-13/remove_hash.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from nowcasting_dataset.filesystem.gcp import get_all_filenames_in_path, rename_file
21
import random
32

3+
from nowcasting_dataset.filesystem.gcp import get_all_filenames_in_path, rename_file
44

55
# batch files are save with hash id and then batch and we want to remove the hashing
66
# {xxxxxx}_{batch_idx}.nc is the format of the file

notebooks/2021-09/2021-09-14/gsp_centroid.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
import json
2+
3+
import plotly.graph_objects as go
4+
15
from nowcasting_dataset.data_sources.gsp.eso import (
26
get_gsp_metadata_from_eso,
37
get_gsp_shape_from_eso,
48
)
5-
import plotly.graph_objects as go
6-
import json
79
from nowcasting_dataset.geospatial import WGS84_CRS
810

9-
1011
# load data
1112
shape_data_raw = get_gsp_metadata_from_eso()
1213
shape_data_raw = shape_data_raw.to_crs(WGS84_CRS)

notebooks/2021-09/2021-09-14/gsp_duplicated.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1+
import json
2+
3+
import plotly.graph_objects as go
4+
15
from nowcasting_dataset.data_sources.gsp.eso import (
26
get_gsp_metadata_from_eso,
37
get_gsp_shape_from_eso,
48
)
5-
import plotly.graph_objects as go
6-
import json
7-
89

910
# Seem to have 2 different GSP shape files, #Hams Hall, Melksham, Iron Acton, Axminster
1011
s = get_gsp_shape_from_eso(join_duplicates=False)
11-
duplicated_raw = s[s['RegionID'].duplicated(keep=False)]
12+
duplicated_raw = s[s["RegionID"].duplicated(keep=False)]
1213
duplicated_raw["Amount"] = range(0, len(duplicated_raw))
1314

14-
for i in range(0,8,2):
15+
for i in range(0, 8, 2):
1516

1617
# just select the first one
17-
duplicated = duplicated_raw.iloc[i: i + 2]
18+
duplicated = duplicated_raw.iloc[i : i + 2]
1819
shapes_dict = json.loads(duplicated["geometry"].to_json())
19-
region_name = duplicated['RegionName'].iloc[0]
20+
region_name = duplicated["RegionName"].iloc[0]
2021

2122
# plot to check it looks right
2223
fig = go.Figure()
@@ -37,5 +38,3 @@
3738
# fig.show(renderer="browser")
3839
fig.write_html(f"images/duplicated_{region_name}.html")
3940
fig.write_image(f"images/duplicated_{region_name}.png")
40-
41-

notebooks/2021-09/2021-09-28/get_raw_sun_data.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@
1212
logging.getLogger().setLevel(logging.DEBUG)
1313
logging.getLogger("urllib3").setLevel(logging.WARNING)
1414

15+
import os
1516
from datetime import datetime
1617
from pathlib import Path
17-
import pandas as pd
18+
1819
import numpy as np
19-
import os
20+
import pandas as pd
21+
2022
import nowcasting_dataset
2123
from nowcasting_dataset.data_sources.gsp.eso import get_gsp_metadata_from_eso
2224
from nowcasting_dataset.data_sources.sun.raw_data_load_save import (
23-
save_to_zarr,
2425
get_azimuth_and_elevation,
26+
save_to_zarr,
2527
)
2628

2729
# set up

notebooks/2021-09/2021-09-29/gsp_duplicated.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
import json
2+
3+
import plotly.graph_objects as go
4+
15
from nowcasting_dataset.data_sources.gsp.eso import (
26
get_gsp_metadata_from_eso,
37
get_gsp_shape_from_eso,
48
)
5-
import plotly.graph_objects as go
6-
import json
7-
89
from nowcasting_dataset.geospatial import WGS84_CRS
910

10-
1111
# Seem to have 2 different GSP shape files, #Hams Hall, Melksham, Iron Acton, Axminster
1212
s = get_gsp_shape_from_eso(join_duplicates=False)
1313
s = s.to_crs(WGS84_CRS)

notebooks/2021-09/2021-09-29/video.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# Idea is to make a GSP video using Sheffield solar data for one day
2+
import json
3+
import logging
4+
from datetime import datetime
5+
26
import pandas as pd
7+
import plotly.graph_objects as go
38

4-
from nowcasting_dataset.data_sources.gsp.pvlive import load_pv_gsp_raw_data_from_pvlive
59
from nowcasting_dataset.data_sources.gsp.eso import get_gsp_metadata_from_eso
6-
from datetime import datetime
10+
from nowcasting_dataset.data_sources.gsp.pvlive import load_pv_gsp_raw_data_from_pvlive
711
from nowcasting_dataset.geospatial import WGS84_CRS
8-
import logging
9-
import plotly.graph_objects as go
10-
import json
1112

1213
logging.basicConfig()
1314
logging.getLogger().setLevel(logging.DEBUG)

notebooks/2021-10/2021-10-01/pydantic.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
from pydantic import BaseModel, Field, validator
21
from typing import Union
2+
33
import numpy as np
4-
import xarray as xr
54
import torch
6-
from nowcasting_dataset.config.model import Configuration
5+
import xarray as xr
6+
from pydantic import BaseModel, Field, validator
77

8+
from nowcasting_dataset.config.model import Configuration
89

910
Array = Union[xr.DataArray, np.ndarray, torch.Tensor]
1011

notebooks/2021-10/2021-10-08/xr_compression.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import numpy as np
44
import xarray as xr
5+
56
from nowcasting_dataset.utils import coord_to_range
67

78

0 commit comments

Comments
 (0)