Skip to content

Commit 88fda35

Browse files
authored
Merge pull request FlexTRKR#118 from WACCEM/fix_generic_quicklook
Updated quicklook plotting scripts
2 parents f6c5e9e + 656575f commit 88fda35

5 files changed

Lines changed: 136 additions & 13 deletions
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
###############################################################################################
3+
# This script plots MCS tracking animations
4+
###############################################################################################
5+
6+
# Specify start/end datetime
7+
start_date='2020-06-21T00'
8+
end_date='2020-06-24T00'
9+
# Define domain map extent
10+
lon_min=-20.0
11+
lon_max=40.0
12+
lat_min=-5.0
13+
lat_max=25.0
14+
# Run in parallel
15+
run_parallel=1
16+
# Tracking config file
17+
config_file='/global/homes/f/feng045/program/PyFLEXTRKR-dev/config/config_mcs_tbpf_scream_healpix9.yml'
18+
# Quicklook/animation output directories
19+
quicklook_dir='/pscratch/sd/w/wcmca1/scream-cess-healpix/mcs_tracking_hp9/quicklooks/'
20+
animation_dir='/pscratch/sd/w/wcmca1/scream-cess-healpix/mcs_tracking_hp9/animation/'
21+
animation_filename=${animation_dir}mcs_tbpf_${start_date}_${end_date}.mp4
22+
# Tracking pixel-level time format
23+
time_format='yyyymodd_hhmmss'
24+
# Plotting code
25+
code_name='/global/homes/f/feng045/program/PyFLEXTRKR-dev/Analysis/plot_subset_tbpf_mcs_tracks_1panel_demo.py'
26+
27+
# Make quicklook plots
28+
echo 'Making quicklook plots ...'
29+
python ${code_name} -s ${start_date} -e ${end_date} -c ${config_file} \
30+
--extent ${extent} ${lon_min} ${lon_max} ${lat_min} ${lat_max} \
31+
--subset 1 \
32+
--time_format ${time_format} \
33+
-p ${run_parallel} \
34+
--output ${quicklook_dir}
35+
echo 'View quicklook plots here: '${quicklook_dir}
36+
37+
# Make animation using ffmpeg
38+
mkdir -p ${animation_dir}
39+
echo 'Making animations from quicklook plots ...'
40+
ffmpeg -framerate 2 -pattern_type glob -i ${quicklook_dir}'*.png' -c:v libx264 -r 10 -crf 20 -pix_fmt yuv420p \
41+
-y ${animation_filename}
42+
echo 'View animation here: '${animation_filename}
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@
66
# Specify start/end datetime
77
start_date='2019-01-20T00'
88
end_date='2019-01-23T00'
9+
# Define domain map extent
10+
lon_min=90.0
11+
lon_max=140.0
12+
lat_min=-10.0
13+
lat_max=10.0
14+
# Panel orientation (horizontal:up/down, vertical:left/right)
915
orientation='horizontal'
16+
# Run in parallel
1017
run_parallel=1
1118
# Tracking config file
1219
config_file='/global/homes/f/feng045/program/pyflex_config/config/config_imerg_mcs_tbpf_2019.yml'
@@ -20,10 +27,9 @@ time_format='yyyymodd_hhmm'
2027
code_name='/global/homes/f/feng045/program/PyFLEXTRKR-dev/Analysis/plot_subset_tbpf_mcs_tracks_demo.py'
2128

2229
# Make quicklook plots
23-
# --extent specifies subset region: minlon maxlon minlat maxlat (cannot have decimals yet)
2430
echo 'Making quicklook plots ...'
2531
python ${code_name} -s ${start_date} -e ${end_date} -c ${config_file} \
26-
--extent ${extent} 90 140 -10 10 \
32+
--extent ${extent} ${lon_min} ${lon_max} ${lat_min} ${lat_max} \
2733
--subset 1 \
2834
--time_format ${time_format} \
2935
-o ${orientation} \
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
###############################################################################################
3+
# This script plots MCS tracking animations
4+
###############################################################################################
5+
6+
# Specify start/end datetime
7+
start_date='2004-06-27T00'
8+
end_date='2004-06-27T11'
9+
# Define domain map extent
10+
lon_min=-110
11+
lon_max=95
12+
lat_min=20
13+
lat_max=40
14+
# Run in parallel
15+
run_parallel=0
16+
# Tracking config file
17+
config_file='/global/homes/f/feng045/program/PyFLEXTRKR-dev/config/config_gridrad_mcs_2004.yml'
18+
# Quicklook/animation output directories
19+
quicklook_dir='/pscratch/sd/f/feng045/usa/gridrad_v3/v3_final/quicklook_test/2004/'
20+
animation_dir='/pscratch/sd/f/feng045/usa/gridrad_v3/v3_final/quicklook_test/'
21+
animation_filename=${animation_dir}mcs_tbdbz_${start_date}_${end_date}.mp4
22+
# Tracking pixel-level time format
23+
time_format='yyyymodd_hhmmss'
24+
# Plotting code
25+
code_name='/global/homes/f/feng045/program/PyFLEXTRKR-dev/Analysis/plot_subset_tbze_mcs_tracks_1panel_demo.py'
26+
27+
# Make quicklook plots
28+
echo 'Making quicklook plots ...'
29+
python ${code_name} -s ${start_date} -e ${end_date} -c ${config_file} \
30+
--extent ${extent} ${lon_min} ${lon_max} ${lat_min} ${lat_max} \
31+
--subset 1 \
32+
--time_format ${time_format} \
33+
-p ${run_parallel} \
34+
--output ${quicklook_dir}
35+
echo 'View quicklook plots here: '${quicklook_dir}
36+
37+
# # Make animation using ffmpeg
38+
# mkdir -p ${animation_dir}
39+
# echo 'Making animations from quicklook plots ...'
40+
# ffmpeg -framerate 2 -pattern_type glob -i ${quicklook_dir}'*.png' -c:v libx264 -r 10 -crf 20 -pix_fmt yuv420p \
41+
# -y ${animation_filename}
42+
# echo 'View animation here: '${animation_filename}

Analysis/plot_subset_generic_tracks_demo.py

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@
3535
warnings.filterwarnings("ignore")
3636
from pyflextrkr.ft_utilities import load_config, subset_files_timerange
3737

38+
#-----------------------------------------------------------------------
39+
def four_floats(value):
40+
# Split string by ' '
41+
values = value.split(' ')
42+
if len(values) != 4:
43+
raise argparse.ArgumentError
44+
# Convert list to array and type to float
45+
values = np.array(values).astype(float)
46+
return values
47+
3848
#-----------------------------------------------------------------------
3949
def parse_cmd_args():
4050
# Define and retrieve the command-line arguments...
@@ -45,7 +55,8 @@ def parse_cmd_args():
4555
parser.add_argument("-e", "--end", help="last time in time series to plot, format=YYYY-mm-ddTHH:MM:SS", required=True)
4656
parser.add_argument("-c", "--config", help="yaml config file for tracking", required=True)
4757
parser.add_argument("-p", "--parallel", help="flag to run in parallel (0:serial, 1:parallel)", type=int, default=0)
48-
parser.add_argument("--extent", nargs='+', help="map extent (lonmin, lonmax, latmin, latmax)", type=float, default=None)
58+
# parser.add_argument("--extent", nargs='+', help="map extent (lonmin, lonmax, latmin, latmax)", type=float, default=None)
59+
parser.add_argument("--extent", help="map extent (lonmin lonmax latmin latmax)", type=four_floats, action='store', default=None)
4960
parser.add_argument("--subset", help="flag to subset data (0:no, 1:yes)", type=int, default=0)
5061
parser.add_argument("--figsize", nargs='+', help="figure size (width, height) in inches", type=float, default=[8,7])
5162
parser.add_argument("--output", help="ouput directory", default=None)
@@ -195,9 +206,9 @@ def plot_map(pixel_dict, plot_info, map_info, track_dict):
195206
yy = pixel_dict['latitude']
196207
fvar = pixel_dict['fvar']
197208
tn_perim = pixel_dict['tn_perim']
198-
lon_tn = pixel_dict['lon_tn']
199-
lat_tn = pixel_dict['lat_tn']
200-
tracknumbers = pixel_dict['tracknumber_unique']
209+
# lon_tn = pixel_dict['lon_tn']
210+
# lat_tn = pixel_dict['lat_tn']
211+
# tracknumbers = pixel_dict['tracknumber_unique']
201212
# Get track data from dictionary
202213
ntracks = track_dict['ntracks']
203214
lifetime = track_dict['lifetime']
@@ -219,7 +230,6 @@ def plot_map(pixel_dict, plot_info, map_info, track_dict):
219230
trackpath_color = plot_info['trackpath_color']
220231
map_edgecolor = plot_info['map_edgecolor']
221232
map_resolution = plot_info['map_resolution']
222-
# map_central_lon = plot_info['map_central_lon']
223233
timestr = plot_info['timestr']
224234
figname = plot_info['figname']
225235
figsize = plot_info['figsize']
@@ -232,6 +242,9 @@ def plot_map(pixel_dict, plot_info, map_info, track_dict):
232242
draw_border = map_info.get('draw_border', False)
233243
draw_state = map_info.get('draw_state', False)
234244

245+
# Time difference matching pixel-time and track time
246+
dt_match = 1 # [min]
247+
235248
# Marker style for track center
236249
marker_style = dict(edgecolor=trackpath_color, facecolor=trackpath_color, linestyle='-', marker='o')
237250

@@ -297,6 +310,7 @@ def plot_map(pixel_dict, plot_info, map_info, track_dict):
297310
for itrack in range(0, ntracks):
298311
# Get duration of the track
299312
ilifetime = lifetime.values[itrack]
313+
itracknum = lifetime.tracks.data[itrack]+1
300314
idur = (ilifetime / time_res).astype(int)
301315
# Get basetime of the track and the last time
302316
ibt = base_time.values[itrack,:idur]
@@ -322,10 +336,25 @@ def plot_map(pixel_dict, plot_info, map_info, track_dict):
322336
cl1 = ax1.scatter(meanlon.values[itrack,0], meanlat.values[itrack,0], s=marker_size*2,
323337
transform=data_proj, zorder=4, **marker_style)
324338

325-
# Overplot tracknumbers at current frame
326-
for ii in range(0, len(lon_tn)):
327-
ax1.text(lon_tn[ii]+0.02, lat_tn[ii]+0.02, f'{tracknumbers[ii]:.0f}', color='k', size=10,
328-
weight='bold', ha='left', va='center', transform=data_proj, zorder=4)
339+
# Find the closest time from track times
340+
idt = np.abs((ibt - pixel_bt).astype('timedelta64[m]'))
341+
idx_match = np.argmin(idt)
342+
idt_match = idt[idx_match]
343+
# Get center lat/lon from the matched tracks
344+
_ilon = meanlon.data[itrack,idx_match]
345+
_ilat = meanlat.data[itrack,idx_match]
346+
# Proceed if time difference is < dt_match
347+
if (idt_match < dt_match):
348+
# Overplot tracknumbers at current frame
349+
if (_ilon > map_extent[0]) & (_ilon < map_extent[1]) & \
350+
(_ilat > map_extent[2]) & (_ilat < map_extent[3]):
351+
ax1.text(_ilon+0.02, _ilat+0.02, f'{itracknum:.0f}', color='k', size=tracknumber_fontsize,
352+
ha='left', va='center', weight='bold', transform=data_proj, zorder=5)
353+
354+
# # Overplot tracknumbers at current frame
355+
# for ii in range(0, len(lon_tn)):
356+
# ax1.text(lon_tn[ii]+0.02, lat_tn[ii]+0.02, f'{tracknumbers[ii]:.0f}', color='k', size=10,
357+
# weight='bold', ha='left', va='center', transform=data_proj, zorder=4)
329358

330359
# Thread-safe figure output
331360
canvas = FigureCanvas(fig)
@@ -507,7 +536,6 @@ def work_for_time_loop(datafile, track_dict, map_info, plot_info, config):
507536
'trackpath_color': 'blueviolet', # track path color
508537
'map_edgecolor': 'gray', # background map edge color
509538
'map_resolution': '50m', # background map resolution ('110m', '50m', 10m')
510-
# 'map_central_lon': 180, # map projection central longitude (for global map)
511539
'figsize': figsize,
512540
'figbasename': figbasename,
513541
}

Analysis/plot_subset_tbze_mcs_tracks_1panel_demo.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def parse_cmd_args():
5656
parser.add_argument("--figbasename", help="output figure base name", default="")
5757
parser.add_argument("--trackstats_file", help="MCS track stats file name", default=None)
5858
parser.add_argument("--pixel_path", help="Pixel-level tracknumer mask files directory", default=None)
59+
parser.add_argument("--time_format", help="Pixel-level file datetime format", default=None)
5960
args = parser.parse_args()
6061

6162
# Put arguments in a dictionary
@@ -71,6 +72,7 @@ def parse_cmd_args():
7172
'figbasename': args.figbasename,
7273
'trackstats_file': args.trackstats_file,
7374
'pixeltracking_path': args.pixel_path,
75+
'time_format': args.time_format,
7476
}
7577

7678
return args_dict
@@ -509,6 +511,9 @@ def work_for_time_loop(datafile, track_dict, map_info, plot_info, config):
509511
figbasename = args_dict.get('figbasename')
510512
trackstats_file = args_dict.get('trackstats_file')
511513
pixeltracking_path = args_dict.get('pixeltracking_path')
514+
time_format = args_dict.get('time_format')
515+
516+
if time_format is None: time_format = "yyyymodd_hhmmss"
512517

513518
# Specify plotting info
514519
# Reflectivity color levels
@@ -613,7 +618,7 @@ def work_for_time_loop(datafile, track_dict, map_info, plot_info, config):
613618
pixeltracking_filebase,
614619
start_basetime,
615620
end_basetime,
616-
time_format="yyyymodd_hhmmss",
621+
time_format=time_format,
617622
)
618623
print(f'Number of pixel files: {len(datafiles)}')
619624

0 commit comments

Comments
 (0)