Skip to content

Commit a39f48a

Browse files
committed
Diagnose age across members
1 parent b571a81 commit a39f48a

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

scripts/diagnose_cyclo_Gammas.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ def CMIP6_member(member):
7373

7474
# Members to loop through
7575

76+
77+
# Create directory on scratch to save the data
78+
scratchdatadir = '/scratch/xv83/TMIP/data'
79+
80+
# Depends on time window
81+
start_time, end_time = time_window_strings(year_start, num_years)
82+
start_time_str = f'Jan{start_time}'
83+
end_time_str = f'Dec{end_time}'
84+
85+
86+
7687
def inputdirfun(member):
7788
return f'{scratchdatadir}/{model}/{experiment}/{CMIP6_member(member)}/{start_time_str}-{end_time_str}/cyclo{lumpby}'
7889

@@ -83,8 +94,12 @@ def isvalidmember(member):
8394
return os.path.isfile(inputfilepathfun(member))
8495

8596
members = [m for m in range(1, 41) if isvalidmember(m)]
97+
98+
# # For debugging only
99+
# members = members[0:2]
100+
86101
paths = [inputfilepathfun(m) for m in members]
87-
members_axis = pd.Index(members, name="members")
102+
members_axis = pd.Index(members, name="member")
88103

89104

90105
# function to open all files and combine them
@@ -93,11 +108,11 @@ def open_my_dataset(paths):
93108
ds = xr.open_mfdataset(
94109
paths,
95110
chunks={'Ti':-1, 'lev':-1}, # TODO these dim names likely won't work for my Gammas
96-
concat_dim=members_axis, # TODO these dim names likely won't work for my Gammas
111+
concat_dim=[members_axis], # TODO these dim names likely won't work for my Gammas
97112
compat='override',
98113
preprocess=None,
99114
engine='netcdf4',
100-
data_vars='minimal',
115+
# data_vars='minimal', # <- cannot have this option otherwise only one member is loaded it seems
101116
coords='minimal',
102117
combine='nested',
103118
parallel=True,
@@ -109,29 +124,19 @@ def open_my_dataset(paths):
109124

110125

111126

112-
# Create directory on scratch to save the data
113-
scratchdatadir = '/scratch/xv83/TMIP/data'
114-
115-
# Depends on time window
116-
start_time, end_time = time_window_strings(year_start, num_years)
117-
start_time_str = f'Jan{start_time}'
118-
end_time_str = f'Dec{end_time}'
119-
120-
121127

122128
outputdir = f'{scratchdatadir}/{model}/{experiment}/all_members/{start_time_str}-{end_time_str}/cyclo{lumpby}'
123129
print("Creating directory: ", outputdir)
124130
os.makedirs(outputdir, exist_ok=True)
125-
print(" averaging data from: ", inputdir)
126131
print(" to be saved in: ", outputdir)
127132

128133
print("Starting client")
129134

130135
# This `if` statement is required in scripts (not required in Jupyter)
131136
if __name__ == '__main__':
132-
client = Client(n_workers=44, threads_per_worker=1)
137+
client = Client(n_workers=40, threads_per_worker=1)
133138

134-
age_ds = open_my_dataset(paths[0:2])
139+
age_ds = open_my_dataset(paths)
135140
print("\nage_ds: ", age_ds)
136141
age = age_ds.age
137142
print("\nage: ", age)

0 commit comments

Comments
 (0)