from pathlib import Path
from karmapi import base, show

from IPython import display

tankrain = Path('~/karmapi/tankrain/2016/10/13').expanduser()

%load_ext autoreload
%autoreload 2

cd ~/karmapi

"""
Explanation: The star of Nicole
Hurricane Nicole hit Bermuda on Thursday 13th October, 2016 as a category 3 storm.
A hundred miles away it was a category 4 storm.
A number of factors helped spare Bermuda:


the storm was experiencing increasing wind sheer as it passed


the moon was full, but high tide was a few hours before the eye passed.


the windfield was very smooth, strong winds but steadily in the same direction.


the star of Niclole?????


Two years ago, almost to the day (October 11th, 2014) Bermuda was hit by hurricane Fay.  A borderline category 1 storm.  Fay did significantly more damage than Nicole.
Fay was full of intense vortices.
From wikipedia:
    L.F. Wade International Airport reported 10-minute sustained winds of 61 mph (98 km/h), with gusts to 82
    mph (132 km/h). Several stations at higher elevations recorded gusts in excess of 115 mph (185 km/h),
    reaching 123 mph (198 km/h) at Commissioner's Point, about 150 ft (46 m)

For Nicole, Commissioner's point recorded a peak gust of 136mph.
The Bermuda Weather rainfall radar was again an invaluable resource to help follow the storm.  It gives an almost real time picture of the rainfall and the movement of the storm.
Below are some images and animations using the Bermuda Weather radar data.
These images were saved during the storm using the karmapi utility, tankrain.
End of explanation
"""


show.show(tankrain / 'parish_1154.png')

"""
Explanation: Power lost at 11.54Z
In Southampton, we lost power around 9am.  Winds were force 9 per the Parish map, with heavy rain.
The eye was still a distance away.
End of explanation
"""


display.HTML('<img src="nicole_wide.gif">')

"""
Explanation: 250km radar
Below is an animation of the 250km radar
End of explanation
"""


display.HTML('<img src="nicole_local.gif">')

"""
Explanation: local view
End of explanation
"""



display.HTML('<img src="nicole_parish.gif">')

"""
Explanation: Parish view
The Parish view also has wind barbs.  These are the three black arrows.  The number of barbs tells you the Beaufort force (I think).  A full barb counts two, a half is just one.   \
In the animation, the winds start around force 5 and it ends around force 9 when the power went out.
The arrows also show the wind direction, so you can see the contrast between the movement of the storm towards the north east and the direction of the wind, from the South East at Bermuda Weather Station, St Davids.
At North Rock and in the sound the wind is more easterly.
End of explanation
"""


show.show(tankrain / 'parish_0448.png')

"""
Explanation: The Star of Nicole
Watching these aminations you may see a star like pattern, centred on St Davids.
This is visible in all three animations.
This parish image at 0448Z shows a very clear hexagonal pattern centred just at the edge of the coast of St David's.
This pattern is present throughout the storm.
It does seem that Bermuda's topography (including the reefs), orientation relative to the storm helped this structure form.
It may even have helped a smooth the airflow over the island through the storm and reduced rainfall somewhat too.
End of explanation
"""


paths = {}
for version in ['wide', 'local', 'parish']:
    paths[version] = tankrain.glob('*{}*'.format(version))

parish = sorted(paths['parish'])
wide = sorted(paths['wide'])
local = sorted(paths['local'])

after = wide[-10:] + local[-12:] + parish[-8:]

mafter = show.movie([show.load(x) for x in after], duration=1.0)

cd -

mafter_path = Path('nicole_after.gif')

mafter_path.write_bytes(mafter)

display.HTML('<img src="nicole_after.gif">')

"""
Explanation: The Star
It looks very like three waves, running in different directions:\


the direction the storm is moving


the direction of the ground level wind


a line between the two.


Nicole was a long lived and very organised storm.  I would expect there were very high seas beneath the storm, moving in harmony with the sea level winds, the winds will have a wave like motion too, and be full of rain and water vapour.
Bermuda is surrounded by reefs which give great protection to the island.  Taller, longer period waves are broken into smaller, but still formidable waves.
As it passed Bermuda it was experiencing wind sheer: the higher level winds in a different direction, and intermediate levels at intermediate angles.
Nicole's encounter with Bermuda must have been like a jet of water from a hosepipe hitting a rock.  At the same time, the ocean is hitting a rock, just a few miles offshore.
Another notable thing in the eye of the storm was the roar from the ocean and its interaction with the airflow.
It would be interesting to analyse the spectrum of any sound recordings.
The eye and beyond
When the eye arrived I was able to tether a mobile phone and got a few more images before the radar itself went out.
This was just as St Davids was starting to pass through the back of the eye wall.
End of explanation
"""


