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.
 

132 lines
3.3 KiB

{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"%matplotlib notebook\n",
"%matplotlib notebook\n",
"\n",
"import cartopy.crs as ccrs\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import h5py as h5py\n",
"import cartopy.feature as cfeature\n",
"from cartopy.io.shapereader import Reader\n",
"from cartopy.feature import ShapelyFeature\n",
"from osgeo import gdal, osr\n",
"\n",
"projection = ccrs.PlateCarree()\n",
"\n",
"extent = [-44.996, -44.009, -2.805, -1.809]\n",
"\n",
"fig = plt.figure(dpi=150)\n",
"\n",
"ax = plt.axes(projection = projection)\n",
"\n",
"ax.gridlines()\n",
"ax.add_feature(cfeature.STATES.with_scale('10m'))\n",
"\n",
"ax.set_extent(extent, crs=ccrs.PlateCarree())\n",
"\n",
"ax.plot(-44.243317, -2.565823, 'bo', markersize=7, color='red', transform=ccrs.Geodetic())\n",
"ax.text(-44.23, -2.54, 'São Luíz', color='black', size=10, transform=ccrs.Geodetic())\n",
"\n",
"plt.title('January 2019 Monthly Average Rain Rate')\n",
"\n",
"font = {'weight' : 'bold', 'size' : 5}\n",
"\n",
"plt.rc('font', **font)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fname = './resources/T23MNT_20190525T132241_TCI_60m.jp2'\n",
"\n",
"img = plt.imread(fname)\n",
"\n",
"ax.imshow(img, extent=extent, origin='upper', transform=ccrs.PlateCarree(), zorder=0)\n",
"\n",
"ax.set_extent(extent, crs=ccrs.PlateCarree())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"hdf5 = '/notebooks/resources/3B-MO.MS.MRG.3IMERG.20190101-S000000-E235959.01.V06A.HDF5'\n",
"dataset = h5py.File(hdf5,'r')\n",
"\n",
"precip = dataset['Grid/precipitation'][:]\n",
"precip = np.transpose(precip[0])\n",
"\n",
"theLats = dataset['Grid/lat'][:]\n",
"theLons = dataset['Grid/lon'][:]\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"clevs = np.arange(0,0.1,0.01)\n",
"\n",
"x, y = np.float32(np.meshgrid(theLons, theLats))\n",
"\n",
"masked_array = np.ma.masked_where(precip < 0,precip)\n",
"\n",
"cmap = 'nipy_spectral'\n",
"\n",
"cs = ax.contourf(x, y, precip, clevs, transform=ccrs.PlateCarree(), cmap=cmap)\n",
"\n",
"ax.set_extent(extent, crs=ccrs.PlateCarree())\n",
"\n",
"plt.xlim(-44.996, -44.009)\n",
"plt.ylim(-2.805, -1.809)"
]
},
{
"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)"
]
}
],
"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
}