Skip to content

Commit bfc6ce5

Browse files
committed
regression analysis of arts calibration
1 parent e465ec6 commit bfc6ce5

File tree

8 files changed

+332
-217
lines changed

8 files changed

+332
-217
lines changed

config_ipns.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
date: '20240929'
1+
date: '20240928'
22
flightletter: a
33
flightname: HALO-{date}{flightletter}
44
iwv: ipns://latest.orcestra-campaign.org/products/HALO/iwv/HALO-{date}{flightletter}.zarr

flights.csv

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
,flightletter,location
2+
20240809,a,transfer
3+
20240811,a,sal
4+
20240813,a,sal
5+
20240816,a,sal
6+
20240818,a,sal
7+
20240821,a,sal
8+
20240822,a,sal
9+
20240825,a,sal
10+
20240827,a,sal
11+
20240829,a,sal
12+
20240831,a,sal
13+
20240903,a,sal
14+
20240906,a,transfer
15+
20240907,a,barbados
16+
20240909,a,barbados
17+
20240912,a,barbados
18+
20240914,a,barbados
19+
20240916,a,barbados
20+
20240919,a,barbados
21+
20240921,a,barbados
22+
20240923,a,barbados
23+
20240924,a,barbados
24+
20240926,a,barbados
25+
20240928,a,barbados
26+
20240929,a,transfer
27+
20241105,a,op
28+
20241107,a,op
29+
20241110,a,op
30+
20241112,b,op
31+
20241114,b,op
32+
20241116,a,op
33+
20241119,a,op

scripts/arts_calibration/arts_bt_calculation.py

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -154,41 +154,15 @@ def calc_arts_bts(date, flightletter):
154154
TBs_hamp.to_csv(f"Data/arts_calibration/{cfg['flightname']}/TBs_hamp.csv")
155155

156156

157-
# %% call function
158-
dates = [
159-
"20240811",
160-
"20240813",
161-
"20240816",
162-
"20240818",
163-
"20240821",
164-
"20240822",
165-
"20240825",
166-
"20240827",
167-
"20240829",
168-
"20240831",
169-
"20240903",
170-
"20240906",
171-
"20240907",
172-
"20240909",
173-
"20240912",
174-
"20240914",
175-
"20240916",
176-
"20240919",
177-
"20240921",
178-
"20240923",
179-
"20240924",
180-
"20240926",
181-
"20240928",
182-
"20240929",
183-
]
157+
# %% loop over flights
184158

185-
flightletters = {}
186-
for date in dates:
187-
flightletters[date] = "a"
159+
flights = pd.read_csv("flights.csv", index_col=0)
160+
flights_processed = flights[
161+
(flights["location"] == "sal") | (flights["location"] == "barbados")
162+
]
188163

189-
# %%
190-
for date in dates:
191-
calc_arts_bts(date, flightletters[date])
164+
for date in flights_processed.index:
165+
calc_arts_bts(str(date), flights_processed.loc[date]["flightletter"])
192166

193167

194168
# %%
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# %%
2+
import numpy as np
3+
from scipy.stats import linregress
4+
import pandas as pd
5+
import xarray as xr
6+
from src import readwrite_functions as rwfuncs
7+
from src.plots_functions import plot_regression
8+
9+
# %% Read csv BTs
10+
11+
flights = pd.read_csv("flights.csv", index_col=0)
12+
flights_processed = flights[
13+
(flights["location"] == "sal") | (flights["location"] == "barbados")
14+
]
15+
16+
TB_arts_list = []
17+
TB_hamp_list = []
18+
for date in flights_processed.index:
19+
TB_arts_list.append(
20+
pd.read_csv(f"Data/arts_calibration/HALO-{date}a/TBs_arts.csv", index_col=0)
21+
)
22+
TB_hamp_list.append(
23+
pd.read_csv(f"Data/arts_calibration/HALO-{date}a/TBs_hamp.csv", index_col=0)
24+
)
25+
26+
# load dropsonde data
27+
configfile = "config_ipns.yaml"
28+
cfg = rwfuncs.extract_config_params(configfile)
29+
ds_dropsonde = xr.open_dataset(cfg["path_dropsondes"], engine="zarr")
30+
31+
# restructure data
32+
TB_arts = pd.concat(TB_arts_list, axis=1)
33+
TB_hamp = pd.concat(TB_hamp_list, axis=1)
34+
launch_time = ds_dropsonde.sel(sonde_id=TB_arts.columns).launch_time.values
35+
TB_arts.columns = launch_time
36+
TB_hamp.columns = launch_time
37+
TB_arts = TB_arts.T.dropna()
38+
TB_hamp = TB_hamp.T.dropna()
39+
40+
# %% drop extreme outliers
41+
TB_arts_std = TB_arts.std("index")
42+
TB_hamp_std = TB_hamp.std("index")
43+
TB_arts_med = TB_arts.median("index")
44+
TB_hamp_med = TB_hamp.median("index")
45+
TB_arts = TB_arts.where((TB_arts - TB_arts_med).abs() < 3 * TB_arts_std)
46+
TB_hamp = TB_hamp.where((TB_hamp - TB_hamp_med).abs() < 3 * TB_hamp_std)
47+
48+
# %% count NaN values
49+
mask_arts = ((TB_arts - TB_arts_med).abs() < 2 * TB_arts_std).mean("index")
50+
mask_hamp = ((TB_hamp - TB_hamp_med).abs() < 2 * TB_hamp_std).mean("index")
51+
mask_arts
52+
53+
# %%
54+
mask_hamp
55+
56+
57+
# %%
58+
multi_index = pd.MultiIndex.from_product(
59+
[TB_arts.columns, ["slope", "intercept"]], names=["frequency", "parameter"]
60+
)
61+
regression_coeffs = pd.DataFrame(
62+
index=np.unique(TB_arts.index.date), columns=multi_index
63+
)
64+
65+
for date in flights_processed.index:
66+
date = pd.to_datetime(date, format="%Y%m%d").date()
67+
TB_arts_day = TB_arts.loc[TB_arts.index.date == date]
68+
TB_hamp_day = TB_hamp.loc[TB_hamp.index.date == date]
69+
70+
for f in TB_arts_day.columns:
71+
# Flatten the arrays and filter out NaN values
72+
x = TB_hamp_day[f].values.flatten()
73+
y = TB_arts_day[f].values.flatten()
74+
mask = ~np.isnan(x) & ~np.isnan(y)
75+
x = x[mask]
76+
y = y[mask]
77+
78+
if len(x) > 0 and len(y) > 0: # Ensure there are values left after filtering
79+
regression = linregress(x, y)
80+
regression_coeffs.loc[date, (f, "slope")] = regression.slope
81+
regression_coeffs.loc[date, (f, "intercept")] = regression.intercept
82+
83+
# %% plot regressions
84+
plot_regression(regression_coeffs, TB_arts, TB_hamp, date)
85+
86+
# %%

scripts/process_data.py

Lines changed: 0 additions & 183 deletions
This file was deleted.

0 commit comments

Comments
 (0)