In the cells below, set log_path
to a valid path and your choice of filename. The results of your lasso operations will be saved here.
Set results_dir
and the path to the grid_files
in the next line to match the dates for the case you're analyzing. the wildcard match to flash_extent and the nc_field below it are set to look at the 2D flash extent density grids, which is probably what you want.
To use the tool, run all the cells. An interactive lasso widget that pops up. Use the frame slider to scroll through each time in the gridded data. Ckick the "Draw Lasso" button to practice drawing a lasso around a storm of interest.
Once you have practiced, check the box to log lassos. When checked, any lassos drawn will be saved to the lasso log file.
Recommended best practice is to start at the first frame, define a cell, advance to the next frame, and then define another cell. If you skip a few frames, that's ok; in the analysis code that uses the lasso log file, the first lasso you defined persists until a new one is available.
You can watch the lasso log file fill up by doing tail -f lasso_log_filename
in a separate terminal window.
When you're done, just quit the notebook.
In [1]:
import os, glob
import tables, pandas
import numpy as np
import warnings
# warnings.filterwarnings('ignore')
warnings.filterwarnings('ignore', category=DeprecationWarning, module='.*/IPython/.*')
In [2]:
%matplotlib qt4
import matplotlib.pyplot as plt
In [3]:
log_path = './DemoNCGridLassoLog.txt'
In [4]:
from lmatools.grid.grid_collection import LMAgridFileCollection
results_dir = "flashsort"
nc_filenames=glob.glob(os.path.join(results_dir, "grid_files/2014/May/26/*_flash_extent.nc"))
nc_field = 'flash_extent'
# print nc_filenames
NCs = LMAgridFileCollection(nc_filenames, nc_field, x_name='longitude', y_name='latitude')
geosys, mapproj = NCs.get_projection()
In [5]:
# This cell is not necessary for the lasso analysis, but shows how
# one might overlay additional data on the plot in order to guide
# the lasso analyses - in this case, which cell was being sampled by
# two radars scanning in RHI mode?
ka1_loc = -102.13410, 33.30546, 1004.0
ka2_loc = -102.09339, 33.40950, 1018.0
ka1_az = 180. + 163. - 360.0
ka2_az = 0. + 249.
radar_dist = 20.0e3
ka1_dx = radar_dist * np.cos(np.deg2rad(90.0-ka1_az))
ka1_dy = radar_dist * np.sin(np.deg2rad(90.0-ka1_az))
ka2_dx = radar_dist * np.cos(np.deg2rad(90.0-ka2_az))
ka2_dy = radar_dist * np.sin(np.deg2rad(90.0-ka2_az))
ka1_xyz = mapproj.fromECEF(*geosys.toECEF(*ka1_loc))
ka2_xyz = mapproj.fromECEF(*geosys.toECEF(*ka2_loc))
ka1_radial = [[ka1_xyz[0], ka1_xyz[0]+ka1_dx],
[ka1_xyz[1], ka1_xyz[1]+ka1_dy]
]
ka2_radial = [[ka2_xyz[0], ka2_xyz[0]+ka2_dx],
[ka2_xyz[1], ka2_xyz[1]+ka2_dy]
]
def plot_ka(lasso_widget, ax):
ax.plot(ka1_radial[0], ka1_radial[1], 'k')
ax.annotate('Ka1', xy=(ka1_radial[0][0], ka1_radial[1][0]))
ax.plot(ka2_radial[0], ka2_radial[1], 'k')
ax.annotate('Ka2', xy=(ka2_radial[0][0], ka2_radial[1][0]))
ax.axis((-75e3, 0e3, -75e3, 0e3))
ax.tick_params(axis='both', labelsize=12)
In [ ]:
In [6]:
# from ipywidgets import interactive
from IPython.display import display
In [7]:
from GridLassoTools import NCgridLasso, NCgridLassoWidgets
nclasso = NCgridLasso(NCs, log_path=log_path)
widget = NCgridLassoWidgets(nclasso) #, overplot_func = plot_ka)
display(widget.container)
In [ ]: