You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

233 lines
5.7 KiB

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"ename": "ImportError",
"evalue": "No module named 'mpl_toolkits.basemap'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mImportError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-1-986bd408e0b7>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mnumpy\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mh5py\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mh5py\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m \u001b[0;32mfrom\u001b[0m \u001b[0mmpl_toolkits\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbasemap\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mBasemap\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcm\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mImportError\u001b[0m: No module named 'mpl_toolkits.basemap'"
]
}
],
"source": [
"%matplotlib inline\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import h5py as h5py\n",
"from mpl_toolkits.basemap import Basemap, cm"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# hdf5 = '/notebooks/3B-MO.MS.MRG.3IMERG.20150801-S000000-E235959.08.V03D.HDF5'\n",
"# hdf5 = '/notebooks/3B-MO.MS.MRG.3IMERG.20150801-S000000-E235959.08.V06A.HDF5'\n",
"hdf5 = '/notebooks/3B-MO.MS.MRG.3IMERG.20190101-S000000-E235959.08.V06A.HDF5'\n",
"dataset = h5py.File(hdf5,'r') # Change this to the proper path"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"precip = dataset['Grid/precipitation'][:]\n",
"\n",
"precip = np.transpose(precip[0])\n",
"\n",
" \n",
"\n",
"theLats= dataset['Grid/lat'][:]\n",
"\n",
"theLons = dataset['Grid/lon'][:]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Plot the figure, define the geographic bounds\n",
"\n",
"fig = plt.figure(dpi=300)\n",
"\n",
"latcorners = ([-60,60])\n",
"\n",
"loncorners = ([-180,180])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"m = Basemap(\n",
" projection='cyl',\n",
" llcrnrlat=latcorners[0],\n",
" urcrnrlat=latcorners[1],\n",
" llcrnrlon=loncorners[0],\n",
" urcrnrlon=loncorners[1])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"# Draw coastlines, state and country boundaries, edge of map.\n",
"\n",
"m.drawcoastlines()\n",
"\n",
"m.drawstates()\n",
"\n",
"m.drawcountries()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Draw filled contours.\n",
"\n",
"clevs = np.arange(0,1.26,0.125)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Define the latitude and longitude data\n",
"\n",
"x, y = np.float32(np.meshgrid(theLons, theLats))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Mask the values less than 0 because there is no data to plot.\n",
"\n",
"masked_array = np.ma.masked_where(precip < 0,precip)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Plot every masked value as white\n",
"\n",
"cmap = cm.GMT_drywet\n",
"\n",
"cmap.set_bad('w',1.)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"# Plot the data\n",
"\n",
"cs = m.contourf(x,y,precip,clevs,cmap=cmap,latlon=True)\n",
"\n",
"\n",
"\n",
"parallels = np.arange(-60.,61,20.)\n",
"\n",
"m.drawparallels(parallels,labels=[True,False,True,False])\n",
"\n",
"meridians = np.arange(-180.,180.,60.)\n",
"\n",
"m.drawmeridians(meridians,labels=[False,False,False,True])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Set the title and fonts\n",
"\n",
"plt.title('August 2015 Monthly Average Rain Rate')\n",
"\n",
"font = {'weight' : 'bold', 'size' : 6}\n",
"\n",
"plt.rc('font', **font)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Add colorbar\n",
"\n",
"cbar = m.colorbar(cs,location='right',pad=\"5%\")\n",
"\n",
"cbar.set_label('mm/h')\n",
"\n",
"# plt.show()\n",
"\n",
"plt.savefig('testIMERGmap.png',dpi=200)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}