From 1c986de9dfebcd3eaa57d2612e697401b457adf7 Mon Sep 17 00:00:00 2001 From: Bob Yantosca Date: Thu, 25 Jan 2024 10:27:07 -0500 Subject: [PATCH 1/3] Add create_test_plot script; can check if GCPy is installed properly gcpy/examples/plotting/create_test_plot.py - Script to create a dummy plot that renders to the screen. Useful for checking if "import gcpy" works properly. gcpy/examples/plotting/__init__.py - Added create_test_plot.py CHANGELOG.md - Updated accordingly Signed-off-by: Bob Yantosca --- CHANGELOG.md | 5 ++ gcpy/examples/plotting/__init__.py | 1 + gcpy/examples/plotting/create_test_plot.py | 55 ++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100755 gcpy/examples/plotting/create_test_plot.py diff --git a/CHANGELOG.md b/CHANGELOG.md index d6258b7e..86335626 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to GCPy will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] - TBD +### Added +- Example script `create_test_plot.py`, which can be used to check that GCPy has been installed properly + + ## [1.4.1] - 2023-12-08 ### Fixed - Now use the proper default value for the `--weightsdir` argument to `gcpy/file_regrid.py` diff --git a/gcpy/examples/plotting/__init__.py b/gcpy/examples/plotting/__init__.py index b9f7dd64..7aa3eac5 100644 --- a/gcpy/examples/plotting/__init__.py +++ b/gcpy/examples/plotting/__init__.py @@ -1,5 +1,6 @@ """ GCPy import script """ +from .create_test_plot import * from .plot_single_panel import * from .plot_comparisons import * diff --git a/gcpy/examples/plotting/create_test_plot.py b/gcpy/examples/plotting/create_test_plot.py new file mode 100755 index 00000000..848677ff --- /dev/null +++ b/gcpy/examples/plotting/create_test_plot.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python + +""" +Creates a dummy xarray DataArray object for testing the single_panel +plotting routine. This script can be a useful check to see whether the +GCPy mamba/conda environment has been successfully installed. +""" + +import numpy as np +import xarray as xr +import matplotlib.pyplot as plt +import gcpy + + +def main(): + """ + Main program: Creates a dummy plot + """ + + # Get X and Y coordinate arrays + n_lat = 181 + n_lon = 361 + lat_vals = np.linspace(-90, 90, n_lat) + lon_vals = np.linspace(-180, 180, n_lon) + + # Create a dummy numpy array for plotting + # Populate it with the distance from the center of the plot + data = np.zeros([n_lat, n_lon]) + for lat in range(n_lat): + for lon in range(n_lon): + data[lat, lon] = np.sqrt(lon_vals[lon]**2 + lat_vals[lat]**2) + + # Create a Dataarray from the numpy array + darr = xr.DataArray( + data=data, + dims=["lat", "lon"], + coords=dict( + lat=("lat", lat_vals), + lon=("lon", lon_vals), + ), + ) + + # Create a plot + gcpy.plot.single_panel( + darr, + plot_type="single_level", + title="Test plot to check GCPy import", + extent=[-180, 180, -90, 90], + comap=plt.get_cmap("RdBu_r") + ) + plt.show() + + +if __name__ == '__main__': + main() From 730cb82f51d6ce430dd0f6f7046222f14b527f94 Mon Sep 17 00:00:00 2001 From: Bob Yantosca Date: Thu, 25 Jan 2024 11:23:35 -0500 Subject: [PATCH 2/3] Add GitHub action "build-gcpy-environment" .github/workflows/build-gcpy-environment.yml - Added this configuration file for the "build-gcpy-environment" GitHub action. This runs on pushes or PRs made to the main or dev branches. The PR will use setup-micromamba to build the gcpy environment, import gcpy, and call a simple plotting script. CHANGELOG.md - Updated accordingly Signed-off-by: Bob Yantosca --- .github/workflows/build-gcpy-environment.yml | 34 ++++++++++++++++++++ CHANGELOG.md | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/build-gcpy-environment.yml diff --git a/.github/workflows/build-gcpy-environment.yml b/.github/workflows/build-gcpy-environment.yml new file mode 100644 index 00000000..33bd0063 --- /dev/null +++ b/.github/workflows/build-gcpy-environment.yml @@ -0,0 +1,34 @@ +--- +# +# GitHub action to build the GCPy environment with micromamba +# See: https://github.com/marketplace/actions/setup-micromamba +# +name: build-gcpy-environment + +on: + push: + branches: [ "main", "dev" ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ "main", "dev" ] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.9"] + steps: + - uses: mamba-org/setup-micromamba@v1 + with: + micromamba-version: 'latest' + environment-file: docs/source/environment.yml + init-shell: bash + cache-environment: true + post-cleanup: 'all' + - name: Import gcpy in micromamba environment (bash) + run: python -c "import numpy" + shell: bash -el {0} + - name: Run custom command in micromamba environment + run: python -m gcpy.examples.plotting.create_test_plot + shell: micromamba-shell {0} diff --git a/CHANGELOG.md b/CHANGELOG.md index 86335626..7c68b041 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## [Unreleased] - TBD ### Added - Example script `create_test_plot.py`, which can be used to check that GCPy has been installed properly - +- GitHub action `build-gcpy-environment` which tests installation of the mamba environment specified in in `docs/source/environment.yml` ## [1.4.1] - 2023-12-08 ### Fixed From 5afddd3a2d9dd3793ab6df7689ed5d272f5b2e67 Mon Sep 17 00:00:00 2001 From: Bob Yantosca Date: Thu, 25 Jan 2024 13:11:55 -0500 Subject: [PATCH 3/3] Add GitHub action to build the GCPy python environment .github/workflows/build-gcpy-environment.yml - Add configuration file to trigger a GitHub action on pushes to main,dev or PRs to main,dev. CHANGELOG.md - Updated accordingly Signed-off-by: Bob Yantosca --- .github/workflows/build-gcpy-environment.yml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-gcpy-environment.yml b/.github/workflows/build-gcpy-environment.yml index 33bd0063..35b8fb19 100644 --- a/.github/workflows/build-gcpy-environment.yml +++ b/.github/workflows/build-gcpy-environment.yml @@ -19,16 +19,21 @@ jobs: matrix: python-version: ["3.9"] steps: - - uses: mamba-org/setup-micromamba@v1 + - name: Checkout the GCPy repository + uses: actions/checkout@v2 + - name: Create the GCPy environment + uses: mamba-org/setup-micromamba@v1 with: micromamba-version: 'latest' - environment-file: docs/source/environment.yml + environment-file: environment.yml + environment-name: gcpy-test-env init-shell: bash cache-environment: true + generate-run-shell: true post-cleanup: 'all' - - name: Import gcpy in micromamba environment (bash) - run: python -c "import numpy" - shell: bash -el {0} - - name: Run custom command in micromamba environment + - name: Test if "import gcpy" works + run: python -c "import gcpy" + shell: micromamba-shell {0} + - name: Test if we can create a plot run: python -m gcpy.examples.plotting.create_test_plot shell: micromamba-shell {0}