Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

POF Plotter

Importing all the necessary python libraries

import matplotlib
import matplotlib.pyplot as plt
from matplotlib import colors
from matplotlib import cm
from matplotlib.colors import Normalize
import numpy as np
import xarray as xr
import matplotlib as mpl
from cartopy import config
import cartopy.crs as ccrs
import cartopy as cart
import sys
import datetime
from matplotlib.colors import ListedColormap,LinearSegmentedColormap

Open Prediction Netcdf

year=2019
month=12


fire= xr.open_dataset(f"./outputs/POF_prediction_{year}_{month:02d}.nc")
fire = fire.assign_coords(longitude=((fire.longitude + 360) % 360)).sortby('longitude')
lats = fire.latitude.values
lons = fire.longitude.values
fire

Define a subregion to plot

lat1 = -10
lat2 = -45
lon1 = 110
lon2 = 155

sub_ds = fire.sel(
    latitude=slice(lat1, lat2), 
    longitude=slice(lon1, lon2)
)
# x1 = (np.argmin(np.abs(lons - lon1)))
# x2 = (np.argmin(np.abs(lons - lon2)))
# y1 = (np.argmin(np.abs(lats - lat1)))
# y2 = (np.argmin(np.abs(lats - lat2)))

# sub_lons = lons[x1:x2]
# sub_lats = lats[y2:y1]
# print(y2)
# print(y1)
# print(sub_lats)
sub_ds

Create colour pallete

cols = ['#4a5a60','#edcc00','#edcc00','#e57d0f','#e57d0f','#e57d0f','#e57d0f','#e57d0f','#e57d0f','#e21819','#e21819','#e21819','#e21819','#e21819','#000000','#000000']
test = ListedColormap(cols)

Define levels

index=0 # Which index to plot (1st of the month)

fires = sub_ds.fire_probability[index].values
plot_title = f"Probability of Fire Forecast for {sub_ds.time.values[index].strftime('%d %B %Y') }"

fires[fires>0.006]=0.006 # 1km

levels = np.arange(16)/2500 # 1km

print(np.shape(fires))
print(np.nanmax(fire.fire_probability.values))
print(np.nanmin(fire.fire_probability.values))
print(np.nanmean(fire.fire_probability.values))

Plot

ax = plt.axes(projection=ccrs.PlateCarree())
ax.coastlines(linewidth=1)

fig = ax.contourf(sub_ds.longitude, sub_ds.latitude, fires,levels=levels,vmin=0,vmax=0.006,transform=ccrs.PlateCarree(),cmap=test)

ax.add_feature(cart.feature.OCEAN,zorder=1,edgecolor='k',color='white')
ax.add_feature(cart.feature.BORDERS,linewidth=0.5,color='white')
ax.add_feature(cart.feature.LAKES,color='white', edgecolor='k', linewidth=0.2, zorder=2)

states_provinces = cart.feature.NaturalEarthFeature(
        category='cultural',
        name='admin_1_states_provinces_lines',
        scale='50m',
        edgecolor='black'
)

for spine in ax.spines.values():
   spine.set_visible(False)

cbar = plt.colorbar(fig,ticks=[0.0002,0.0008,0.0022,0.0044,0.0056],fraction=0.025, pad=0.04)
cbar.ax.set_yticklabels(['Low', 'Medium','High', 'Very High', 'Extreme'])

plt.title(plot_title, fontsize=16)

plt.tight_layout()

plt.savefig('./outputs/My_PoF_Plot.png', dpi=300)