Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mp changes to ds_plots.py #1

Merged
merged 2 commits into from
Nov 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions plotting_script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import xarray as xr
import matplotlib.pyplot as plt
import numpy as np
import cartopy.crs as ccrs
from cartopy.util import add_cyclic_point

import sys
sys.path.insert(0, '/scratch/mp586/git_repos/ACDC/tools')
from ds_plots import *
from netCDF4 import Dataset

# load dataset 1
nc = Dataset('/scratch/mp586/git_repos/ACDC/Data/monthlyclimo_'+input('Which experiment ? ')+'.nc')
lats = nc.variables['lat'][:]
lons = nc.variables['lon'][:]

P = xr.DataArray(nc.variables['precipitation'][:])*86400

mmap(np.asarray(P.mean('dim_0')),lats,lons,show = 'Yes')

17 changes: 15 additions & 2 deletions tools/ds_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ def hmap(mapdata,lat,cmap=None,clim=None,title=None,
def mmap(mapdata,lat,lon,title=None,cb_ttl=None,cmap=None,clim=None,
filepath=None,show=None,sigmask=None,p=None,
do_zonal=None,newfig=True,
outside_color = None, outside_val = None):
outside_color = None, outside_val=None,
use_pcolor=False):
# Make a map (robinson projection) of mapdata over lat/lon
# Inputs
# mapdata : 2D field to be plotted
Expand All @@ -122,7 +123,14 @@ def mmap(mapdata,lat,lon,title=None,cb_ttl=None,cmap=None,clim=None,
# cb_ttl : colorbar title
# cmap : special colormap
# clim : colorbar limits, as a 2 element array
# use_pcolor: default is to use contourf. Set True for pcolormesh

# mp added a few lines to convert potential xarray inputs to numpy arrays
# so that add_cyclic_point works
lon = np.asarray(lon)
lat = np.asarray(lat)
mapdata = np.asarray(mapdata)

if newfig:
if do_zonal==1:
# make 2 subplots, one for map, one for zonal average next to it
Expand All @@ -140,7 +148,12 @@ def mmap(mapdata,lat,lon,title=None,cb_ttl=None,cmap=None,clim=None,
cyclic_data, cyclic_lons = add_cyclic_point(mapdata,coord=lon)

# Make the plot
cs = plt.pcolormesh(cyclic_lons,lat,cyclic_data,transform=ccrs.PlateCarree())
# Default: contourf
if not use_pcolor:
cs = plt.contourf(cyclic_lons,lat,cyclic_data,transform=ccrs.PlateCarree())
else:
cs = plt.pcolormesh(cyclic_lons,lat,cyclic_data,transform=ccrs.PlateCarree())


# set colormap
if cmap:
Expand Down