Create a pathmap for Hurricane Sandy

Source: Internet
Author: User
Tags timedelta

Author: vamei Source: http://www.cnblogs.com/vamei welcome reprint, please also keep this statement. Thank you!

 

Hurricane Sandy swept across eastern United States and logged in near New York, taking 113 lives away and causing $50 billion in losses, sandy is also listed as the most expensive hurricane in American history. Today, we use the matplotlib and basemap packages of Python we have introduced to create a path map for Sandy and reconstruct the entire development process of Sandy. ,

The following is a GIF image that is made into an animation effect (because the blog Park does not allow uploading images of more than 2 MB, the resolution is limited, but you can always make a high-resolution animation .)

I add a shadow to the picture to show the night time. As you can see, after Sandy was formed, it first lingers near Panama, then passes through Cuba, and is forced to hurricane-2 in this process. Then Sandy crossed the East Coast of the United States, then suddenly turned to the west, went straight to New York, and on the afternoon of the 29 th in New York South login.

 

Download: Data File

The unit of wind (maximum wind speed) in the data file is knot, the unit of pressure (pressure) is MB, and the time is the world.

Python source code for creating a path chart

View code

 # Written by vamei  From Datetime Import  Datetime, timedelta  Import  Re  Import  Numpy as NP  Import  Matplotlibmatplotlib. rcparams [  '  Text. Color  ' ] = '  White  ' Matplotlib. rcparams [  '  Xtick. Color  ' ] = '  White  '  Matplotlib. rcparams [  '  Ytick. Color  ' ] = '  White  '  From Mpl_toolkits.basemap Import Basemap  Import  Matplotlib. pyplot as pltfont = '  Monospace  '  #  This function is to plot the base map  Def Plotbase (FIG, dT = None): m = Basemap (projection = '  Merc  '  , Lon_0 = 0, lat_0 = 0, lat_ts =0, llcrnrlat = 0, urcrnrlat = 50 , Llcrnrlon =-100, urcrnrlon =-50 , Resolution = '  L  '  ) M. drawcountries (linewidth = 1, color = '  K  '  ) M. drawmapscale ( -90, 5,-90, 5, 1000, barstyle = '  Fancy '  ) M. bluemarble (Scale = 1 )  #  Get position of NYC, longbench-74.0064, latitude 40.7142 X, Y = m (-74.0064, 40.7142 )  #  Plot NYC M. Scatter (X, Y, S = 100, marker = '  *  ' , Color = '  0.5  ' , Alpha = 1) PLT. Text (x, y,  '  NYC  ' , Fontsize = '  15  '  )  If DT Is   Not None: M. NIGHTSHADE (DT, alpha = 0.3 )  Return  M  #  Hurricane category colors Color_dict = { '  Tropical Depression  ' : '  # Aef100  ' , '  Tropical Storm  ' : '  # Ffd600  ' , '  Hurricane-1  ' : ' # Ff6440  ' , '  Hurricane-2  ' : '  #8506a9  '  }  #  Read data file, unzip from track.zip to get track. dat Fn = '  Track. dat  '  REC = { ' Lat  ' : [], '  Lon  ' : [], '  Wind  ' : [], '  Press  ' : [], '  DT  ' : [], '  Cat  ' : []}  For I, line In  Enumerate (file (FN )):  If I = 0: Continue    #  Jump over the first line      #  Replace multiple whitespaces with a single whitespace Line = Re. sub (R "  \ S +  " , '   ' , Line) pieces = Line. Split ( "   "  )  #  Retrieve Information REC [ '  Lat  '  ]. Append (float (pieces [0]) Rec [  '  Lon  ' ]. Append (float (pieces [1 ]) Rec [  ' Wind  ' ]. Append (float (pieces [3 ]) Rec [  '  Press  ' ]. Append (float (pieces [4 ]) Rec [  '  Cat  ' ]. Append (( "   " . Join (pieces [5 :]). Strip () Time = Pieces [2 ] Time ="  2012/  " + Time rec [  '  DT  ' ]. Append (datetime. strptime (time, "  % Y/% m/% d/% Hz  "  ))  #  Plot the track and the else N = Len (REC [ '  Lat  ' ])  For Idx In  Range (n): dt = Rec [ '  DT  '  ] [Idx]  #  Adjust Time Zone according to NYC Lt = DT-timedelta (hours = 5 ) Lon = Rec [ '  Lon  '  ] [Idx] lat = Rec [ '  Lat  '  ] [Idx] Wind = Rec [ '  Wind  '  ] [Idx] Press = Rec [ '  Press  '  ] [Idx] Cat = Rec [ '  Cat  '  ] [Idx] fig = PLT. Figure () m = Plotbase (FIG, DT)  #  From Lon, lat to pixels X, Y = M (Lon, Lat)  #  Plot track      For I In  Range (idx): A0, B0 = M (REC [ '  Lon  ' ] [I], REC [ ' Lat  '  ] [I]) A1, B1 = M (REC [ '  Lon  ' ] [I + 1], REC [ '  Lat  ' ] [I + 1 ]) M. Plot (A0, A1), (B0, B1), linewidth = 2.5 , Color = Color_dict [Rec [ '  Cat  ' ] [I + 1])  #  Plot Sandy's current position M. Scatter (X, Y, S = 100, c = color_dict [Cat], alpha = 0.8 )  #  Annotate Current Position  PLT. annotate (CAT, XY = (X, y), xytext = (-5,-30 ), Textcoords = '  Offset points  ' , HA = '  Right ' , VA = '  Bottom  '  , BBox = Dict (boxstyle = '  Round, pad = 0.5  ' , Fc = color_dict [Cat], alpha = 0.8 ), Arrowprops = Dict (arrowstyle = '  ->  ' , Connectionstyle = '  Arc3, Rad = 0 '  ) Tx, ty = M (-98, 40 ) PLT. Text (TX, Ty, LT. strftime (  "  Hurricane Sandy \ n \ nnyc LT: \ n % Y-% m-% d % H: 00: 00 \ ndata Source: NOAA \ nby vamei  "  ), Family = Font, HA = '  Left  '  )  #  Add a small axes to show pressure A = fig. add_axes ([0.6, 0.2,. 15,. 1]) A. set_ylim (( 950,1000 ) A. set_xlim (( -10, 70 ) A. set_yticks ([ 900,1050 ]) A. set_xticks ([0, 60 ]) A. set_title (  "  Center pressure (MB)  " , Fontsize = 10 ) A. Plot (REC [  '  Press  '  ]) A. axvline (x = Idx, color ='  R  '  )  #  Add a small axes to show wind A = fig. add_axes ([0.6, 0.4,. 15,. 1 ]) A. set_ylim (0, 100 ) A. set_xlim (( -10, 70 ) A. set_yticks ([0, 100 ]) A. set_xticks ([0, 60 ]) A. set_title (  "  Max Wind (knots)  " , Fontsize = 10 ) A. Plot (REC [  '  Wind  '  ]) A. axvline (x = Idx, color = '  R  '  ) Fig. savefig ((  '  10904d.png  ' % Idx) PLT. Close () 

 

A satellite map of Sandy is shown below, showing Sandy's amazing size (from NASA's GOES satellite)

 

Major and minor disasters brought about by Sandy:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.