Skip to content

Commit

Permalink
Save plots to file, & add image-creation workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
garyo committed Feb 8, 2024
1 parent 2e80ab3 commit 11bb4d0
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 5 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/make-images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Create Images and Upload to Imgur

on:
workflow_dispatch:
schedule:
- cron: '0 12 * * *'
jobs:
upload-image:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Generate
run: |
python sea-surface-temps.py --mode map --dataset sst --days-ago 1 --out sst-map.png
python sea-surface-temps.py --mode map --dataset anom --days-ago 1 --out sst-anom-map.png
python sea-surface-temps.py --mode all --dataset sst --out sst-all.png
python sea-surface-temps.py --mode all --dataset anom --out sst-all-anom.png
- name: Upload images to Imgur
env:
IMGUR_CLIENT_ID: ${{ secrets.IMGUR_CLIENT_ID }}
run: |
curl --request POST \
--url https://api.imgur.com/3/image \
--header "Authorization: Client-ID $IMGUR_CLIENT_ID" \
--form image=@"./sst-map.png"
curl --request POST \
--url https://api.imgur.com/3/image \
--header "Authorization: Client-ID $IMGUR_CLIENT_ID" \
--form image=@"./sst-anom-map.png"
curl --request POST \
--url https://api.imgur.com/3/image \
--header "Authorization: Client-ID $IMGUR_CLIENT_ID" \
--form image=@"./sst-all.png"
curl --request POST \
--url https://api.imgur.com/3/image \
--header "Authorization: Client-ID $IMGUR_CLIENT_ID" \
--form image=@"./sst-all-anom.png"
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sst-data-cache.json

16 changes: 12 additions & 4 deletions sea-surface-temps.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,7 @@ def plot_globe_dataset(data, hdf, vmin, vmax, cmap, title):
plt.colorbar(c, orientation='horizontal', pad=0.05)

plt.title(title)
plt.savefig('/tmp/sst-map.png', dpi=300)
plt.show()
return plt

def process_date(args):
if args.days_ago:
Expand Down Expand Up @@ -204,6 +203,11 @@ def process_date(args):
[0.8, "yellow"], [0.9, "red"],
[1.0, "darkred"]])
plot_globe_dataset(data, hdf, 0, 30, sst_cmap, f'{date}\nSea Surface Temp, °C')
if args.out:
plt.savefig(args.out, dpi=300)
else:
plt.show()


def process_all(args):
def get_data(temp_data, dataset_name):
Expand Down Expand Up @@ -261,8 +265,10 @@ def plot_fig(temps, title):
plt.text(0, 0,
msg,
ha="left", va="top", transform=plt.gca().transAxes, fontsize=9)
plt.savefig('/tmp/sst.png', dpi=300)
plt.show()
if args.out:
plt.savefig(args.out, dpi=300)
else:
plt.show()

temp_data = {} # indexed by year and then day of year (0-based)
type = 'anom' # 'anom' or 'sst'
Expand Down Expand Up @@ -300,6 +306,8 @@ class CustomFormatter(argparse.ArgumentDefaultsHelpFormatter,
parser.add_argument('--days-ago', type=int,
default=0,
help="""Days ago (before today), for map mode""")
parser.add_argument('--out', '-o', type=pathlib.Path,
help="""Output image to this path""")
parser.add_argument('--cache-file', type=pathlib.Path,
default='./sst-data-cache.json',
help="""Cache file to speed up future runs""")
Expand Down
1 change: 1 addition & 0 deletions sst-data-cache.json

Large diffs are not rendered by default.

0 comments on commit 11bb4d0

Please sign in to comment.