Skip to content

Commit bb4197e

Browse files
committed
improved plots
1 parent 27fa3b9 commit bb4197e

4 files changed

Lines changed: 144 additions & 27 deletions

File tree

‎fill-in.ipynb‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,7 +1982,7 @@
19821982
},
19831983
{
19841984
"cell_type": "code",
1985-
"execution_count": 94,
1985+
"execution_count": 96,
19861986
"id": "a10d439a",
19871987
"metadata": {},
19881988
"outputs": [
@@ -1992,25 +1992,25 @@
19921992
"text": [
19931993
"Interpolating specific humidity 'q' as well.\n",
19941994
"t -79.06939697265625 30.296119589309058\n",
1995-
"'calculate_pi' 0.03452 s \n",
1995+
"'calculate_pi' 0.03005 s \n",
19961996
"\n",
19971997
"t -79.06939697265625 30.296119589309058\n",
1998-
"'calculate_pi' 0.03012 s \n",
1998+
"'calculate_pi' 0.02750 s \n",
19991999
"\n",
20002000
"t -79.06939697265625 29.628082275390625\n",
2001-
"'calculate_pi' 0.03337 s \n",
2001+
"'calculate_pi' 0.03104 s \n",
20022002
"\n",
20032003
"t -79.06939697265625 25.721405029296875\n",
2004-
"'calculate_pi' 0.02879 s \n",
2004+
"'calculate_pi' 0.02786 s \n",
20052005
"\n",
20062006
"t -79.06939697265625 17.55535888671875\n",
2007-
"'calculate_pi' 0.02905 s \n",
2007+
"'calculate_pi' 0.02669 s \n",
20082008
"\n",
20092009
"t -79.06939697265625 30.296119589309065\n",
2010-
"'calculate_pi' 0.02621 s \n",
2010+
"'calculate_pi' 0.02583 s \n",
20112011
"\n",
20122012
"t -79.06939697265625 30.296119589309058\n",
2013-
"'calculate_pi' 0.03303 s \n",
2013+
"'calculate_pi' 0.03278 s \n",
20142014
"\n"
20152015
]
20162016
},
@@ -2031,7 +2031,7 @@
20312031
},
20322032
{
20332033
"cell_type": "code",
2034-
"execution_count": 93,
2034+
"execution_count": 95,
20352035
"id": "8483fb42",
20362036
"metadata": {},
20372037
"outputs": [
@@ -2041,25 +2041,25 @@
20412041
"text": [
20422042
"Interpolating specific humidity 'q' as well.\n",
20432043
"t -69.27500915527344 31.399871826171875\n",
2044-
"'calculate_pi' 0.07401 s \n",
2044+
"'calculate_pi' 0.04714 s \n",
20452045
"\n",
20462046
"t -69.27500915527344 31.399871826171875\n",
2047-
"'calculate_pi' 0.05028 s \n",
2047+
"'calculate_pi' 0.03215 s \n",
20482048
"\n",
20492049
"t -69.27500915527344 26.84356689453125\n",
2050-
"'calculate_pi' 0.04249 s \n",
2050+
"'calculate_pi' 0.03131 s \n",
20512051
"\n",
20522052
"t -69.27500915527344 23.313018798828125\n",
2053-
"'calculate_pi' 0.04869 s \n",
2053+
"'calculate_pi' 0.02618 s \n",
20542054
"\n",
20552055
"t -69.27500915527344 15.280517578125\n",
2056-
"'calculate_pi' 0.03119 s \n",
2056+
"'calculate_pi' 0.02575 s \n",
20572057
"\n",
20582058
"t -69.27500915527344 31.399871826171875\n",
2059-
"'calculate_pi' 0.03782 s \n",
2059+
"'calculate_pi' 0.03177 s \n",
20602060
"\n",
20612061
"t -69.27500915527344 31.399871826171875\n",
2062-
"'calculate_pi' 0.03270 s \n",
2062+
"'calculate_pi' 0.03051 s \n",
20632063
"\n"
20642064
]
20652065
},

‎tcpips/pi.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ def fix_profile(
124124
2. 'lapse_rate': Fills NaNs at the bottom of the profile by extrapolating
125125
downwards from the lowest valid data point using a dry adiabatic lapse rate.
126126
This is ideal for fixing missing surface-level pressure data.
127+
3. 'well_mixed': Fills NaNs at the bottom of the profile by assuming a well-mixed
128+
boundary layer. This method fills both temperature and specific humidity
129+
profiles consistently and is physically principled for tropical atmospheres.
127130
128131
Args:
129132
ds (xr.Dataset): Xarray dataset containing temperature 't' with a

‎w22/img/new_orleans_timeseries.pdf‎

-49.4 KB
Binary file not shown.

‎w22/plot.py‎

Lines changed: 125 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -402,14 +402,43 @@ def place_to_position(place: str) -> tuple:
402402

403403
def plot_spatials(
404404
axs: np.ndarray,
405-
places: str = "new_orleans",
406-
vars: Tuple[str, str] = ("vmax", "r0"),
405+
place: str = "new_orleans",
406+
vars: Tuple[str, str] = ("vmax_3", "r0_3", "rmax_3", "rmax_1"),
407+
labels: tuple = (
408+
"Potential intensity, $V_{p}$ [m s$^{-1}$]",
409+
"Corresponding potential outer size, $r_{a3}$ [km]",
410+
"Corresponding potential inner size, $r_{3}$ [km]",
411+
"Cat1 potential inner size, $r_{1}$ [km]",
412+
),
407413
pi_version: int = 4,
408414
trial=1,
409415
pressure_assumption="isothermal",
410416
) -> None:
411417
assert len(axs) == len(vars)
412418

419+
name = f"august_cmip6_pi{pi_version}_{pressure_assumption}_trial{trial}.nc"
420+
421+
if place in {"new_orleans", "galverston", "miami"}:
422+
name = "gom_" + name
423+
if place in {"shanghai", "hong_kong", "hanoi"}:
424+
name = "scs_" + name
425+
ds = xr.open_dataset(os.path.join(DATA_PATH, name))
426+
print("spatial ds", ds)
427+
428+
ds["lon"].attrs = {"units": "$^{\circ}E$", "long_name": "Longitude"}
429+
ds["lat"].attrs = {"units": "$^{\circ}N$", "long_name": "Latitude"}
430+
for i, var in enumerate(vars):
431+
if var in ds:
432+
if var in {"r0", "rmax", "rmax_1", "rmax_3", "r0_1", "r0_3"}:
433+
(ds[var] / 1000).plot(ax=axs[i], cbar_kwargs={"label": ""})
434+
else:
435+
ds[var].plot(ax=axs[i], cbar_kwargs={"label": ""})
436+
axs[i].set_title(labels[i])
437+
point = place_to_position(place)
438+
axs[i].scatter(*point, color="black", s=75, marker="x")
439+
if i != len(vars) - 1:
440+
axs[i].set_xlabel("")
441+
413442

414443
def plot_two_spatial(
415444
axs: np.ndarray,
@@ -553,7 +582,13 @@ def get_cmip6_timeseries(
553582

554583
def plot_timeserii(
555584
axs: np.ndarray,
556-
serii: tuple = ("vmax_3", "r0_3", "rmax_3", "rmax_1"),
585+
vars: tuple = ("vmax_3", "r0_3", "rmax_3", "rmax_1"),
586+
labels: tuple = (
587+
"Potential intensity, $V_{p}$ [m s$^{-1}$]",
588+
"PI potential outer size, $r_{a3}$ [km]",
589+
"PI potential inner size, $r_{3}$ [km]",
590+
"Cat1 potential inner size, $r_{1}$ [km]",
591+
),
557592
color: str = "black",
558593
member: int = 4,
559594
model: str = "CESM2",
@@ -563,24 +598,34 @@ def plot_timeserii(
563598
year_min: int = 2014,
564599
year_max: int = 2100,
565600
) -> None:
566-
assert len(axs) == len(serii)
601+
assert len(axs) == len(vars)
602+
assert len(labels) == len(vars)
567603
ds = get_cmip6_timeseries(
568604
place=place,
569605
pressure_assumption=pressure_assumption,
570606
member=member,
571607
model=model,
572608
pi_version=pi_version,
573609
)
574-
for i in range(len(serii)):
575-
axs[i].set_title(serii[i])
610+
for i in range(len(vars)):
611+
axs[i].set_title(vars[i])
612+
var_np = ds[vars[i]].values
613+
if vars[i] in {"r0", "rmax", "rmax_1", "rmax_3", "r0_1", "r0_3"}:
614+
var_np /= 1000
615+
576616
axs[i].plot(
577-
np.array([t.astype("datetime64[Y]").astype(int) + 1970 for t in ds.values]),
578-
ds[serii[i]].values,
617+
# np.array(
618+
# [t.astype("datetime64[Y]").astype(int) + 1970 for t in ds.time.values]
619+
# ),
620+
ds["time"].values,
621+
var_np,
579622
color=color,
580623
linewidth=0.5,
624+
alpha=0.5,
581625
)
626+
axs[i].set_title(labels[i])
582627
axs[i].set_xlabel("")
583-
if i == len(serii) - 1:
628+
if i == len(vars) - 1:
584629
axs[i].set_xlabel("Year")
585630
axs[i].set_xlim([1850, 2100])
586631
# vertical black line at year_min
@@ -839,6 +884,73 @@ def figure_two(place: str = "new_orleans") -> None:
839884
plt.close()
840885

841886

887+
def multipanel(
888+
place: str = "new_orleans",
889+
vars: Tuple[str] = ("vmax_3", "r0_3", "rmax_3", "rmax_1"),
890+
):
891+
"""Plot the multipanel figure for the CMIP6 timeseries.
892+
893+
Args:
894+
vars (tuple): The variables to plot (default is ("vmax_3", "r0_3", "rmax_3", "rmax_1")).
895+
"""
896+
plot_defaults()
897+
_, axs = plt.subplots(
898+
len(vars),
899+
2,
900+
figsize=get_dim(ratio=1.5),
901+
)
902+
members = [4, 10, 11]
903+
colors = ["orange", "green", "grey"]
904+
plot_spatials(axs[:, 0], place="new_orleans", vars=vars)
905+
for i, member in enumerate(members):
906+
plot_timeserii(
907+
axs[:, 1],
908+
vars=vars,
909+
color="orange",
910+
member=member,
911+
model="CESM2",
912+
pressure_assumption="isothermal",
913+
place="new_orleans",
914+
pi_version=4,
915+
year_min=2014,
916+
year_max=2100,
917+
)
918+
919+
members = ["r1i1p1f3", "r2i1p1f3", "r3i1p1f3"]
920+
for i, member in enumerate(members):
921+
plot_timeserii(
922+
axs[:, 1],
923+
vars=vars,
924+
color="green",
925+
member=member,
926+
model="HADGEM3-GC31-MM",
927+
pressure_assumption="isothermal",
928+
place="new_orleans",
929+
pi_version=4,
930+
year_min=2014,
931+
year_max=2100,
932+
)
933+
members = ["r1i1p1f1", "r2i1p1f1", "r3i1p1f1"]
934+
for i, member in enumerate(members):
935+
plot_timeserii(
936+
axs[:, 1],
937+
vars=vars,
938+
color="grey",
939+
member=member,
940+
model="MIROC6",
941+
pressure_assumption="isothermal",
942+
place="new_orleans",
943+
pi_version=4,
944+
year_min=2014,
945+
year_max=2100,
946+
)
947+
948+
label_subplots(axs)
949+
plt.savefig(os.path.join(FIGURE_PATH, f"{place}_multipanel.pdf"))
950+
plt.clf()
951+
plt.close()
952+
953+
842954
def temporal_relationship_data(place: str = "new_orleans", pi_version: int = 4) -> None:
843955
"""Get the temporal relationships data for the given place and potential intensity version.
844956
@@ -1131,8 +1243,8 @@ def _generate_header_map(columns: list[str]) -> dict[str, str]:
11311243
# python -m w22.plot
11321244
# plot_panels()
11331245
#
1134-
figure_two(place="new_orleans")
1135-
figure_two(place="hong_kong")
1246+
# figure_two(place="new_orleans")
1247+
# figure_two(place="hong_kong")
11361248
# temporal_relationship_data(place="new_orleans", pi_version=4)
11371249
# plot_seasonal_profiles()
11381250
# years = [2015, 2100]
@@ -1149,3 +1261,5 @@ def _generate_header_map(columns: list[str]) -> dict[str, str]:
11491261
# years=years,
11501262
# members=[4, 10],
11511263
# )
1264+
multipanel(place="new_orleans")
1265+
multipanel(place="hong_kong")

0 commit comments

Comments
 (0)