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.
 

212 lines
4.7 KiB

{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"from matplotlib import cm\n",
"import numpy as np\n",
"import h5py as h5py\n",
"import cartopy.crs as ccrs\n",
"import cartopy.feature as cfeature\n",
"from cartopy.io.shapereader import Reader\n",
"from cartopy.feature import ShapelyFeature"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# hdf5 = '/notebooks/resources/3B-MO.MS.MRG.3IMERG.20150801-S000000-E235959.08.V03D.HDF5'\n",
"# hdf5 = '/notebooks/resources/3B-MO.MS.MRG.3IMERG.20150801-S000000-E235959.08.V06A.HDF5'\n",
"hdf5 = '/notebooks/resources/3B-MO.MS.MRG.3IMERG.20190101-S000000-E235959.01.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": {
"scrolled": false
},
"outputs": [],
"source": [
"# Plot the figure, define the geographic bounds\n",
"fig = plt.figure(dpi=150)\n",
"# fig = plt.figure(figsize=(5,3))\n",
"\n",
"latcorners = ([-60,60])\n",
"\n",
"loncorners = ([-180,180])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ax = plt.axes(projection=ccrs.PlateCarree())\n",
"ax.coastlines()\n",
"ax.add_feature(cfeature.BORDERS)\n",
"# ax.add_feature(cfeature.STATES.with_scale('10m'))"
]
},
{
"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": [
"cmap = 'nipy_spectral'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"# Plot the data\n",
"\n",
"cs = ax.contourf(x,y,precip,clevs,transform=ccrs.PlateCarree(),cmap=cmap)"
]
},
{
"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' : 3}\n",
"\n",
"plt.rc('font', **font)\n",
"\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sm = plt.cm.ScalarMappable(cmap=cmap,norm=plt.Normalize(0,1))\n",
"sm._A = []\n",
"plt.colorbar(sm, ax=ax, label='mm/h', shrink=0.5)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# ax.set_extent([-180, 180, -90, 90])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# fname = r'./layers/POLYGON.shp'\n",
"\n",
"# # ax = plt.axes(projection=ccrs.Robinson())\n",
"# shape_feature = ShapelyFeature(Reader(fname).geometries(),\n",
"# ccrs.PlateCarree(), edgecolor='black')\n",
"# ax.add_feature(shape_feature)"
]
},
{
"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
}