import matplotlib.pyplot as plt
import xarray as xr
import pandas as pd
data = xr.open_dataset('aux_data/structure_data_flux_10/structure_remaped_l1_20210923.nc')
target_struc = data.center_time.where(
data.center_time==pd.to_datetime("20210923 10:48:03.556000000"),
drop=True
).struc_id
sel_struc = data.sel(struc_id=target_struc)
print(f"struc_id {target_struc.values}")
struc_id [208.]
plt.figure(figsize=(15,8))
sel_struc.labelled_structures_remaped_struc.plot()
plt.title(f'{pd.to_datetime(sel_struc.center_time.values[0,0]).strftime("%Y%m%d %H:%M:%S")}')
plt.xlim(-1300, 1300)
plt.show()
plt.figure(figsize=(15,8))
sel_struc.vertical_wind_speed_10_anom_remaped_struc.plot(vmin=-0.5, vmax=0.5, cmap='coolwarm')
plt.title(f'{pd.to_datetime(sel_struc.center_time.values[0,0]).strftime("%Y%m%d %H:%M:%S")}',)
plt.xlim(-1300, 1300)
plt.show()
sel_struc = data.sel(struc_id=[202])
plt.figure(figsize=(15,8))
sel_struc.labelled_structures_remaped_struc.plot()
plt.title(f'{pd.to_datetime(sel_struc.center_time.values[0,0]).strftime("%Y%m%d %H:%M:%S")}')
plt.xlim(-1300, 1300)
plt.show()
plt.figure(figsize=(15,8))
sel_struc.vertical_wind_speed_10_anom_remaped_struc.plot(vmin=-0.5, vmax=0.5, cmap='coolwarm')
plt.title(f'{pd.to_datetime(sel_struc.center_time.values[0,0]).strftime("%Y%m%d %H:%M:%S")}',)
plt.xlim(-1300, 1300)
plt.show()
struc_ds=sel_struc.copy()
tmp_struc = struc_ds.labelled_structures_remaped_struc.sel(struc_id=int(struc_ds.struc_id))
tmp_struc = tmp_struc.where(tmp_struc == struc_ds.struc_id.sel(struc_id=int(struc_ds.struc_id)))
tmp_time_2d = tmp_struc/tmp_struc * struc_ds.time
tmp_time_2d_width = tmp_time_2d.copy()
tmp_range_2d = (tmp_struc/tmp_struc).T * struc_ds.norm_range
## for structure width
tmp_time_2d_width = tmp_time_2d_width.where(tmp_range_2d<=1.2)
min_time_width = tmp_time_2d_width.min() # left edge time
max_time_width = tmp_time_2d_width.max() # right edge time
struc_widith = (max_time_width - min_time_width).expand_dims('struc_id')
struc_widith.name = 'struc_widith'
plt.figure(figsize=(15,8))
struc_ds.labelled_structures_remaped_struc.plot()
plt.title(f'{pd.to_datetime(struc_ds.center_time.values[0,0]).strftime("%Y%m%d %H:%M:%S")}')
plt.vlines(min_time_width, 0, 1.5, colors='k', ls='--')
plt.vlines(min_time_width+struc_widith, 0, 1.5, colors='k', ls='--')
plt.xlim(-1300, 1300)
plt.show()