-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]>
- Loading branch information
Showing
3 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |