Skip to content

Commit

Permalink
Merge PR #286 (Add GitHub action to build GCPy env)
Browse files Browse the repository at this point in the history
This merge brings PR #286 (Add GitHub action to build GCPy environment
and test installation, by @yantosca) into the GCPy 1.4.2 development
stream.

This adds a GitHub action to check if the GCPy environment (as specified
in the "environment.yml" file) will build properly, and if the "import gcpy"
command works.

Signed-off-by: Bob Yantosca <[email protected]>
  • Loading branch information
yantosca committed Jan 25, 2024
2 parents a056352 + 5afddd3 commit 1fb87e4
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/build-gcpy-environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
#
# 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:
- 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: environment.yml
environment-name: gcpy-test-env
init-shell: bash
cache-environment: true
generate-run-shell: true
post-cleanup: 'all'
- 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}
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
- 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
- Now use the proper default value for the `--weightsdir` argument to `gcpy/file_regrid.py`
Expand Down
1 change: 1 addition & 0 deletions gcpy/examples/plotting/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
GCPy import script
"""
from .create_test_plot import *
from .plot_single_panel import *
from .plot_comparisons import *
55 changes: 55 additions & 0 deletions gcpy/examples/plotting/create_test_plot.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 1fb87e4

Please sign in to comment.