Set the location of where this repository is housed


In [9]:
import sys
sys.path.append("C:/Users/ahaberlie/Documents/GitHub/MCS/")

Download classified slices from May-September in 2015

Download data.tar.gz from https://tiny.cc/ + the full manuscript ID for part 1 (case sensitive), and untar and ungzip this into the directory "MCS/mcs" and make sure the output folder is "data" and it has a folder named "slice_data". Examine the code to see the proper location if you are getting an error (i.e., "../data/slice_data/")


In [1]:
import pandas as pd

df = pd.DataFrame.from_csv("../data/slice_data/labeled_slices_020618.csv")

df = df[df.major_axis_length >= 100]

df


C:\Users\ahaberlie\Anaconda3\envs\py35\lib\site-packages\ipykernel_launcher.py:3: FutureWarning: from_csv is deprecated. Please use read_csv(...) instead. Note that some of the default arguments are different, so please refer to the documentation for from_csv when changing your function calls
  This is separate from the ipykernel package so we can avoid doing imports until
Out[1]:
Unnamed: 0.1 datetime Unnamed: 0.1.1 area conv_buffer convection_area convection_stratiform_ratio convex_area eccentricity filename ... minor_axis_length solidity strat_buffer xmax xmin ymax ymin CRSR SSR mcs_proba
0 0 2015-05-01 00:00:00 0 14720.0 6 2908.0 0.197554 20616.0 0.843152 100_6_48/slices/5/BREF_150501_0000_00000.png ... 107.991190 0.714009 48 2717 2609 734 669 6 48 0.439753
1 1 2015-05-01 00:00:00 1 11428.0 6 2808.0 0.245712 15652.0 0.862554 100_6_48/slices/5/BREF_150501_0000_00001.png ... 94.269337 0.730130 48 2729 2665 1005 912 6 48 0.286128
2 2 2015-05-01 00:15:00 2 11172.0 6 2352.0 0.210526 15196.0 0.859877 100_6_48/slices/5/BREF_150501_0015_00000.png ... 92.654812 0.735193 48 2730 2671 1007 916 6 48 0.255566
3 3 2015-05-01 01:45:00 3 3044.0 6 660.0 0.216820 5052.0 0.984759 100_6_48/slices/5/BREF_150501_0145_00000.png ... 30.203461 0.602534 48 1563 1492 638 595 6 48 0.001463
4 4 2015-05-01 03:45:00 4 11004.0 6 1300.0 0.118139 15480.0 0.688608 100_6_48/slices/5/BREF_150501_0345_00000.png ... 111.893932 0.710853 48 2904 2827 886 813 6 48 0.186368
5 5 2015-05-01 06:30:00 5 6156.0 6 1368.0 0.222222 8708.0 0.974867 100_6_48/slices/5/BREF_150501_0630_00000.png ... 44.107213 0.706936 48 1617 1524 580 537 6 48 0.015263
6 6 2015-05-01 06:45:00 6 5924.0 6 1084.0 0.182984 8236.0 0.973157 100_6_48/slices/5/BREF_150501_0645_00000.png ... 44.502831 0.719281 48 1624 1535 581 538 6 48 0.008078
7 7 2015-05-01 09:00:00 7 11488.0 6 1708.0 0.148677 15756.0 0.692926 100_6_48/slices/5/BREF_150501_0900_00000.png ... 112.262872 0.729119 48 2663 2573 948 887 6 48 0.161678
8 8 2015-05-01 11:00:00 8 4376.0 6 1920.0 0.438757 7900.0 0.988881 100_6_48/slices/5/BREF_150501_1100_00000.png ... 38.909910 0.553924 48 762 711 854 733 6 48 0.027735
9 9 2015-05-01 18:00:00 9 5912.0 6 1288.0 0.217862 9524.0 0.941335 100_6_48/slices/5/BREF_150501_1800_00000.png ... 62.935261 0.620748 48 2810 2724 1007 966 6 48 0.005032
10 10 2015-05-01 18:15:00 10 5824.0 6 1128.0 0.193681 9052.0 0.952374 100_6_48/slices/5/BREF_150501_1815_00000.png ... 57.816851 0.643394 48 2811 2726 1010 972 6 48 0.001484
11 11 2015-05-01 22:00:00 11 6000.0 6 1416.0 0.236000 8664.0 0.929029 100_6_48/slices/5/BREF_150501_2200_00000.png ... 61.839257 0.692521 48 1360 1285 757 709 6 48 0.004954
12 12 2015-05-01 23:15:00 12 5736.0 6 1684.0 0.293584 9260.0 0.919861 100_6_48/slices/5/BREF_150501_2315_00000.png ... 66.146729 0.619438 48 1395 1313 875 832 6 48 0.000665
13 13 2015-05-01 23:45:00 13 6572.0 6 1092.0 0.166159 10092.0 0.925780 100_6_48/slices/5/BREF_150501_2345_00000.png ... 68.541401 0.651209 48 1417 1329 880 835 6 48 0.002662
14 14 2015-05-02 00:00:00 14 7884.0 6 880.0 0.111618 11832.0 0.850167 100_6_48/slices/5/BREF_150502_0000_00000.png ... 89.293447 0.666329 48 1423 1336 880 830 6 48 0.031005
15 15 2015-05-02 03:00:00 15 9152.0 6 1116.0 0.121941 12436.0 0.745360 100_6_48/slices/5/BREF_150502_0300_00000.png ... 95.864780 0.735928 48 1492 1424 739 684 6 48 0.142304
16 16 2015-05-02 03:15:00 16 6980.0 6 1204.0 0.172493 10024.0 0.754818 100_6_48/slices/5/BREF_150502_0315_00000.png ... 85.369966 0.696329 48 1494 1424 737 692 6 48 0.029634
17 17 2015-05-02 09:00:00 17 5988.0 6 1104.0 0.184369 11292.0 0.718411 100_6_48/slices/5/BREF_150502_0900_00000.png ... 95.947116 0.530287 48 1632 1570 640 573 6 48 0.032700
18 18 2015-05-02 16:30:00 18 17868.0 6 2800.0 0.156705 20628.0 0.845018 100_6_48/slices/5/BREF_150502_1630_00000.png ... 114.397497 0.866201 48 1917 1817 732 655 6 48 0.622041
19 19 2015-05-02 16:45:00 19 19408.0 6 3064.0 0.157873 22816.0 0.830072 100_6_48/slices/5/BREF_150502_1645_00000.png ... 123.500565 0.850631 48 1926 1825 739 654 6 48 0.718974
20 20 2015-05-02 17:15:00 20 20196.0 6 3020.0 0.149535 26348.0 0.792871 100_6_48/slices/5/BREF_150502_1715_00000.png ... 137.115038 0.766510 48 1946 1836 738 655 6 48 0.585049
21 21 2015-05-02 21:30:00 21 10056.0 6 1212.0 0.120525 17164.0 0.871769 100_6_48/slices/5/BREF_150502_2130_00000.png ... 95.181155 0.585877 48 1715 1625 346 276 6 48 0.592313
22 22 2015-05-02 21:45:00 22 9720.0 6 1120.0 0.115226 14892.0 0.917187 100_6_48/slices/5/BREF_150502_2145_00000.png ... 79.954950 0.652699 48 1718 1631 353 279 6 48 0.229855
23 23 2015-05-03 01:15:00 23 6444.0 6 2044.0 0.317194 9072.0 0.724118 100_6_48/slices/5/BREF_150503_0115_00000.png ... 83.121839 0.710317 48 1693 1644 672 612 6 48 0.019877
24 24 2015-05-03 01:30:00 24 9216.0 6 3360.0 0.364583 12428.0 0.482022 100_6_48/slices/5/BREF_150503_0130_00000.png ... 111.119470 0.741551 48 1700 1626 670 610 6 48 0.239009
25 25 2015-05-03 02:00:00 25 9100.0 6 2752.0 0.302418 12008.0 0.745095 100_6_48/slices/5/BREF_150503_0200_00000.png ... 96.134901 0.757828 48 1738 1655 665 613 6 48 0.056577
26 26 2015-05-03 02:15:00 26 11212.0 6 3212.0 0.286479 14644.0 0.791929 100_6_48/slices/5/BREF_150503_0215_00000.png ... 100.667555 0.765638 48 1747 1661 665 607 6 48 0.425646
27 27 2015-05-03 02:30:00 27 11044.0 6 3040.0 0.275263 14136.0 0.825280 100_6_48/slices/5/BREF_150503_0230_00000.png ... 94.350435 0.781268 48 1753 1667 667 613 6 48 0.271779
28 28 2015-05-03 03:00:00 28 9248.0 6 2068.0 0.223616 13400.0 0.866425 100_6_48/slices/5/BREF_150503_0300_00000.png ... 83.035660 0.690149 48 1737 1657 674 617 6 48 0.156168
29 29 2015-05-03 03:15:00 29 17012.0 6 3444.0 0.202445 24600.0 0.831158 100_6_48/slices/5/BREF_150503_0315_00000.png ... 117.590997 0.691545 48 1775 1664 679 611 6 48 0.839199
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
774851 774851 2016-09-30 22:30:00 39178 4132.0 48 1048.0 0.253630 7216.0 0.973665 100_48_192/slices/9/BREF_160930_2230_00000.png ... 41.075092 0.572616 192 2308 2211 774 739 48 192 0.001223
774852 774852 2016-09-30 22:30:00 39179 9280.0 48 1548.0 0.166810 16920.0 0.789887 100_48_192/slices/9/BREF_160930_2230_00001.png ... 104.367922 0.548463 192 2235 2167 845 757 48 192 0.318765
774853 774853 2016-09-30 22:30:00 39180 2028.0 48 436.0 0.214990 5080.0 0.772928 100_48_192/slices/9/BREF_160930_2230_00002.png ... 69.263584 0.399213 192 2200 2147 905 867 48 192 0.001619
774854 774854 2016-09-30 22:30:00 39181 29484.0 48 3556.0 0.120608 57192.0 0.865076 100_48_192/slices/9/BREF_160930_2230_00003.png ... 187.622756 0.515527 192 2905 2796 1140 948 48 192 0.991624
774855 774855 2016-09-30 22:30:00 39182 4408.0 48 1100.0 0.249546 12156.0 0.909557 100_48_192/slices/9/BREF_160930_2230_00004.png ... 80.773236 0.362619 192 1057 968 1159 1112 48 192 0.000645
774856 774856 2016-09-30 22:30:00 39183 21092.0 48 4624.0 0.219230 75828.0 0.614789 100_48_192/slices/9/BREF_160930_2230_00005.png ... 285.766745 0.278156 192 2667 2506 1505 1311 48 192 0.775934
774857 774857 2016-09-30 22:30:00 39184 34072.0 48 3380.0 0.099202 78340.0 0.828350 100_48_192/slices/9/BREF_160930_2230_00006.png ... 214.244794 0.434925 192 2612 2473 1731 1532 48 192 0.947928
774858 774858 2016-09-30 22:45:00 39195 4404.0 48 1060.0 0.240690 8308.0 0.969396 100_48_192/slices/9/BREF_160930_2245_00000.png ... 46.427709 0.530091 192 2306 2208 787 741 48 192 0.004809
774859 774859 2016-09-30 22:45:00 39196 9836.0 48 1600.0 0.162668 18160.0 0.782482 100_48_192/slices/9/BREF_160930_2245_00001.png ... 105.660187 0.541630 192 2230 2164 847 758 48 192 0.222746
774860 774860 2016-09-30 22:45:00 39197 25680.0 48 2712.0 0.105607 46244.0 0.797871 100_48_192/slices/9/BREF_160930_2245_00002.png ... 182.935539 0.555315 192 2908 2804 1106 944 48 192 0.955308
774861 774861 2016-09-30 22:45:00 39198 15240.0 48 4364.0 0.286352 49860.0 0.906532 100_48_192/slices/9/BREF_160930_2245_00003.png ... 164.800114 0.305656 192 2610 2509 1506 1311 48 192 0.150407
774862 774862 2016-09-30 22:45:00 39199 26580.0 48 4684.0 0.176223 76124.0 0.960815 100_48_192/slices/9/BREF_160930_2245_00004.png ... 165.828327 0.349167 192 2667 2482 1640 1415 48 192 0.942897
774863 774863 2016-09-30 22:45:00 39200 27684.0 48 1544.0 0.055772 45768.0 0.830385 100_48_192/slices/9/BREF_160930_2245_00005.png ... 171.883337 0.604877 192 2609 2437 1739 1641 48 192 0.927930
774864 774864 2016-09-30 23:00:00 39213 18716.0 48 3188.0 0.170336 59988.0 0.785601 100_48_192/slices/9/BREF_160930_2300_00000.png ... 230.326655 0.311996 192 2321 2108 850 740 48 192 0.346658
774865 774865 2016-09-30 23:00:00 39214 30644.0 48 3224.0 0.105208 58812.0 0.863115 100_48_192/slices/9/BREF_160930_2300_00001.png ... 186.408220 0.521050 192 2912 2805 1137 941 48 192 0.987845
774866 774866 2016-09-30 23:00:00 39215 19320.0 48 3840.0 0.198758 67320.0 0.773235 100_48_192/slices/9/BREF_160930_2300_00002.png ... 243.391750 0.286988 192 2667 2510 1482 1308 48 192 0.513317
774867 774867 2016-09-30 23:00:00 39216 46072.0 48 4780.0 0.103751 105808.0 0.694140 100_48_192/slices/9/BREF_160930_2300_00003.png ... 311.553547 0.435430 192 2607 2410 1730 1547 48 192 0.777402
774868 774868 2016-09-30 23:15:00 39229 28028.0 48 3360.0 0.119880 48828.0 0.877086 100_48_192/slices/9/BREF_160930_2315_00000.png ... 162.036533 0.574015 192 2910 2820 1117 942 48 192 0.974511
774869 774869 2016-09-30 23:15:00 39230 14320.0 48 4924.0 0.343855 53780.0 0.897444 100_48_192/slices/9/BREF_160930_2315_00001.png ... 184.183174 0.266270 192 2614 2509 1507 1305 48 192 0.130096
774870 774870 2016-09-30 23:15:00 39231 33472.0 48 4056.0 0.121176 65204.0 0.855743 100_48_192/slices/9/BREF_160930_2315_00002.png ... 191.142283 0.513343 192 2600 2476 1728 1552 48 192 0.997774
774871 774871 2016-09-30 23:30:00 39242 4196.0 48 708.0 0.168732 10284.0 0.901621 100_48_192/slices/9/BREF_160930_2330_00000.png ... 71.348656 0.408012 192 2573 2497 774 725 48 192 0.001641
774872 774872 2016-09-30 23:30:00 39243 11908.0 48 4356.0 0.365805 39028.0 0.971733 100_48_192/slices/9/BREF_160930_2330_00001.png ... 108.746950 0.305114 192 2593 2511 1508 1303 48 192 0.136694
774873 774873 2016-09-30 23:30:00 39244 31224.0 48 3928.0 0.125801 61436.0 0.879015 100_48_192/slices/9/BREF_160930_2330_00002.png ... 180.651726 0.508236 192 2601 2482 1728 1553 48 192 0.973965
774874 774874 2016-09-30 23:30:00 39245 10420.0 48 1192.0 0.114395 21060.0 0.722626 100_48_192/slices/9/BREF_160930_2330_00003.png ... 127.210687 0.494777 192 2490 2415 1715 1613 48 192 0.118923
774875 774875 2016-09-30 23:45:00 39255 13032.0 48 544.0 0.041743 23832.0 0.880615 100_48_192/slices/9/BREF_160930_2345_00000.png ... 112.575935 0.546828 192 280 162 413 333 48 192 0.070911
774876 774876 2016-09-30 23:45:00 39256 4736.0 48 676.0 0.142736 9136.0 0.934412 100_48_192/slices/9/BREF_160930_2345_00001.png ... 61.719561 0.518389 192 2575 2536 856 772 48 192 0.002340
774877 774877 2016-09-30 23:45:00 39257 31468.0 48 4336.0 0.137791 61268.0 0.863851 100_48_192/slices/9/BREF_160930_2345_00002.png ... 182.470166 0.513612 192 2935 2819 1141 937 48 192 0.995925
774878 774878 2016-09-30 23:45:00 39258 7560.0 48 3180.0 0.420635 14508.0 0.926158 100_48_192/slices/9/BREF_160930_2345_00003.png ... 74.045321 0.521092 192 2597 2549 1404 1301 48 192 0.002198
774879 774879 2016-09-30 23:45:00 39259 4056.0 48 1188.0 0.292899 12152.0 0.976478 100_48_192/slices/9/BREF_160930_2345_00004.png ... 53.258745 0.333772 192 2547 2507 1511 1397 48 192 0.001148
774880 774880 2016-09-30 23:45:00 39260 35568.0 48 5256.0 0.147773 85488.0 0.537661 100_48_192/slices/9/BREF_160930_2345_00005.png ... 314.622862 0.416058 192 2608 2414 1729 1544 48 192 0.721294

1515944 rows × 28 columns

Calculate basic stats on slices organized by perturbation


In [6]:
import numpy as np

table9 = {'Year':[],
          'CRSR':[],
          'SSR':[],
          'Count_0.00':[],
          'Area_0.00':[],
          'Count_0.50':[],
          'Area_0.50':[],
          'Count_0.90':[],
          'Area_0.90':[],
          'Count_0.95':[],
          'Area_0.95':[]}


for year in [2015, 2016]:
    for crsr in [6, 12, 24, 48]:
        for ssr in [48, 96, 192]:

            table9['Year'].append(year)
            table9['CRSR'].append(crsr)
            table9['SSR'].append(ssr)
            

            t_df = df[(df.CRSR==crsr) & (df.SSR==ssr) & (pd.to_datetime(df.datetime).dt.year==year)]

            for p, ps in zip([0.0, 0.5, 0.9, 0.95], ['0.00', '0.50', '0.90', '0.95']):

                t_df1 = t_df[t_df.mcs_proba >= p]

                table9['Count_' + ps].append(len(t_df1))
                table9['Area_' + ps].append(np.sum(t_df1.area)/10**9)

df1 = pd.DataFrame.from_dict(table9)

df1[['Year','CRSR','SSR','Count_0.00','Area_0.00',
     'Count_0.50','Area_0.50','Count_0.90',
     'Area_0.90','Count_0.95','Area_0.95']]


Out[6]:
Year CRSR SSR Count_0.00 Area_0.00 Count_0.50 Area_0.50 Count_0.90 Area_0.90 Count_0.95 Area_0.95
0 2015 6 48 43443 0.788927 20830 0.608636 12471 0.466669 10677 0.422930
1 2015 6 96 41120 1.102817 25177 0.957453 18361 0.809222 15984 0.736414
2 2015 6 192 39666 1.435475 25379 1.233574 19339 1.015065 16685 0.898451
3 2015 12 48 54008 0.933895 23447 0.701829 14519 0.550038 12539 0.501463
4 2015 12 96 51318 1.273715 28153 1.080014 20333 0.909633 17578 0.821768
5 2015 12 192 49827 1.615311 28393 1.351061 21112 1.089727 17830 0.949747
6 2015 24 48 70443 1.153159 26825 0.837808 17231 0.672647 14923 0.613455
7 2015 24 96 67312 1.518513 31642 1.240211 22705 1.035736 19188 0.919815
8 2015 24 192 65756 1.864746 31940 1.491493 23014 1.176112 18838 1.001645
9 2015 48 48 89371 1.455718 30204 1.034556 20417 0.841607 16914 0.737666
10 2015 48 96 85780 1.849242 34998 1.458195 24725 1.174097 19852 1.002725
11 2015 48 192 84198 2.197667 34975 1.661132 24243 1.253401 18711 1.021451
12 2016 6 48 44997 0.827754 21914 0.644812 13277 0.498470 11392 0.453614
13 2016 6 96 42489 1.155696 26348 1.013325 19442 0.864694 16963 0.786362
14 2016 6 192 41115 1.493506 26664 1.292487 20582 1.089392 17904 0.976745
15 2016 12 48 56113 0.974865 24657 0.738912 15270 0.580279 13264 0.531467
16 2016 12 96 53298 1.327213 29354 1.131494 21467 0.960423 18608 0.870685
17 2016 12 192 51854 1.671297 29765 1.404148 22322 1.163211 19133 1.033484
18 2016 24 48 73595 1.202363 27967 0.874547 17996 0.702160 15621 0.641864
19 2016 24 96 70355 1.580935 33077 1.293339 23718 1.082567 20219 0.970076
20 2016 24 192 68894 1.929108 33569 1.550477 24378 1.253788 20182 1.087123
21 2016 48 48 93199 1.511315 31493 1.073158 21181 0.866889 17613 0.760249
22 2016 48 96 89674 1.918107 36772 1.509932 25952 1.219863 20901 1.047677
23 2016 48 192 88119 2.267671 37069 1.735049 25970 1.341341 20252 1.114819

Show spatial occurrence of slices broken down by perturbation

Download occurrence_maps.tar.gz from http://tiny.cc/ + the full manuscript identification code/number for Part 1.

Untar file into MCS/mcs/data/slice_data/occurrence_maps/


In [21]:
import pickle
import matplotlib.pyplot as plt
from scipy.ndimage.filters import gaussian_filter
from mcs.utils.mapping_help import get_NOWrad_conus_lon_lat
import cartopy
import cartopy.crs as ccrs
import cartopy.io.shapereader as shpreader
from matplotlib.colors import BoundaryNorm
from matplotlib.ticker import MaxNLocator
from string import ascii_lowercase

import numpy as np

%matplotlib inline
plt.rcParams['figure.figsize'] = 20, 20

from_proj = ccrs.PlateCarree()
to_proj = ccrs.AlbersEqualArea(central_longitude=-100.0000, central_latitude=38.0000)

lons, lats = get_NOWrad_conus_lon_lat()

lons, lats = np.meshgrid(lons, lats)

splot = 1

year = 2015

data_dir = "../data/slice_data/occurrence_maps/"

for crsr in [6, 12, 24, 48]:
    for ssr in [48, 96, 192]:
        
        ax = plt.subplot(4, 3, splot, projection=to_proj)
        ax.set_extent([-105, -75, 25, 48])
        shapename = 'admin_1_states_provinces_lakes_shp'
        states_shp = shpreader.natural_earth(resolution='50m',
                                             category='cultural', name=shapename)

        for state, info in zip(shpreader.Reader(states_shp).geometries(), 
                               shpreader.Reader(states_shp).records()):
            if info.attributes['admin'] == 'United States of America':

                ax.add_geometries([state], ccrs.PlateCarree(),
                                  facecolor='None', edgecolor='k')
        
        pdict = {'p0.00':None, 'p0.50': None, 'p0.90': None, 'p0.95': None}
        
        for p, ps in zip([0.0, 0.5, 0.9, 0.95], ['0.00', '0.50', '0.90', '0.95']):
            
            fn = str(year) + "_" + str(crsr).zfill(2) + "_" + str(ssr) + "_p" + str(100*p) + ".pkl"
            prom = pickle.load(open( data_dir + str(year) + "/" + fn, "rb"))

            pdict["p" + ps] = prom

        cmap = plt.cm.Greys
        classes = list(range(0, 225, 40))
        norm = BoundaryNorm(classes, ncolors=cmap.N, clip=True)

        #Since each count is a 15 minute window, divide by 4 to get number of hours
        m50_ = gaussian_filter(pdict['p0.50']/4, 30)

        mmp = ax.pcolormesh(lons, lats, m50_, transform=from_proj, norm=norm, cmap=cmap)
        
        plt.colorbar(mmp, ax=ax, shrink=0.4, pad=0.01)

        m0_ = gaussian_filter(pdict['p0.00']/4, 30)
        m95_ = gaussian_filter(pdict['p0.95']/4, 30)

        l1 = ax.contour(lons, lats, m0_, levels=[40], colors=['k',], 
                          transform=from_proj, linestyles='dashed', linewidths=1)

        l3 = ax.contour(lons, lats, m95_, levels=[40], colors=['k',], 
                          transform=from_proj, linewidths=2)
        
        ax.set_title(ascii_lowercase[splot-1] + ".")
        
        splot += 1


Spatial occurrence (hours, shaded) of slices with an MCS probability of 0.5 or higher in 2015 during the months of May through September for varying convective region and stratiform search radii. The solid line denotes the 40-hour isopleth for slices with an MCS probability of 0.95 or higher, and the dotted line denotes the 40-hour isopleth for all qualifying slices. The convective region search radii (CRSR) are: 6 km (a, b, c), 12 km (d, e, f), 24 km (g, h, i), and 48 km (j, k, l). The stratiform search radii (SSR) are: 48 km (a, d, g, j), 96 km (b, e, h, k), and 192 km (c, f, i, l).


In [22]:
import pickle
import matplotlib.pyplot as plt
from scipy.ndimage.filters import gaussian_filter
from mcs.utils.mapping_help import get_NOWrad_conus_lon_lat
import cartopy
import cartopy.crs as ccrs
import cartopy.io.shapereader as shpreader
from matplotlib.colors import BoundaryNorm
from matplotlib.ticker import MaxNLocator
from string import ascii_lowercase

import numpy as np

%matplotlib inline
plt.rcParams['figure.figsize'] = 20, 20

from_proj = ccrs.PlateCarree()
to_proj = ccrs.AlbersEqualArea(central_longitude=-100.0000, central_latitude=38.0000)

lons, lats = get_NOWrad_conus_lon_lat()

lons, lats = np.meshgrid(lons, lats)

splot = 1

year = 2016

data_dir = "../data/slice_data/occurrence_maps/"

for crsr in [6, 12, 24, 48]:
    for ssr in [48, 96, 192]:
        
        ax = plt.subplot(4, 3, splot, projection=to_proj)
        ax.set_extent([-105, -75, 25, 48])
        shapename = 'admin_1_states_provinces_lakes_shp'
        states_shp = shpreader.natural_earth(resolution='50m',
                                             category='cultural', name=shapename)

        for state, info in zip(shpreader.Reader(states_shp).geometries(), 
                               shpreader.Reader(states_shp).records()):
            if info.attributes['admin'] == 'United States of America':

                ax.add_geometries([state], ccrs.PlateCarree(),
                                  facecolor='None', edgecolor='k')
        
        pdict = {'p0.00':None, 'p0.50': None, 'p0.90': None, 'p0.95': None}
        
        for p, ps in zip([0.0, 0.5, 0.9, 0.95], ['0.00', '0.50', '0.90', '0.95']):
            
            fn = str(year) + "_" + str(crsr).zfill(2) + "_" + str(ssr) + "_p" + str(100*p) + ".pkl"
            prom = pickle.load(open( data_dir + str(year) + "/" + fn, "rb"))

            pdict["p" + ps] = prom

        cmap = plt.cm.Greys
        classes = list(range(0, 225, 40))
        norm = BoundaryNorm(classes, ncolors=cmap.N, clip=True)

        #Since each count is a 15 minute window, divide by 4 to get number of hours
        m50_ = gaussian_filter(pdict['p0.50']/4, 30)

        mmp = ax.pcolormesh(lons, lats, m50_, transform=from_proj, norm=norm, cmap=cmap)
        
        plt.colorbar(mmp, ax=ax, shrink=0.4, pad=0.01)

        m0_ = gaussian_filter(pdict['p0.00']/4, 30)
        m95_ = gaussian_filter(pdict['p0.95']/4, 30)

        l1 = ax.contour(lons, lats, m0_, levels=[40], colors=['k',], 
                          transform=from_proj, linestyles='dashed', linewidths=1)

        l3 = ax.contour(lons, lats, m95_, levels=[40], colors=['k',], 
                          transform=from_proj, linewidths=2)
        
        ax.set_title(ascii_lowercase[splot-1] + ".")
        
        splot += 1


Spatial occurrence (hours, shaded) of slices with an MCS probability of 0.5 or higher in 2016 during the months of May through September for varying convective region and stratiform search radii. The solid line denotes the 40-hour isopleth for slices with an MCS probability of 0.95 or higher, and the dotted line denotes the 40-hour isopleth for all qualifying slices. The convective region search radii (CRSR) are: 6 km (a, b, c), 12 km (d, e, f), 24 km (g, h, i), and 48 km (j, k, l). The stratiform search radii (SSR) are: 48 km (a, d, g, j), 96 km (b, e, h, k), and 192 km (c, f, i, l).