Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow member_id to be optional #54

Merged
merged 4 commits into from
Jul 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions ecgtools/parsers/cesm.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ def _join(a):
return ''.join(a)

data = list(str(date))
if len(data) == 10:

if len(data) == 16:
return f'{_join(data[:4])}-{_join(data[5:7])}-{_join(data[8:10])}'
elif len(data) == 10:
return f'{_join(data[:4])}-{_join(data[4:6])}-{_join(data[6:8])}T{_join(data[8:])}'
elif len(data) == 8:
return f'{_join(data[:4])}-{_join(data[4:6])}-{_join(data[6:])}'
Expand Down Expand Up @@ -114,8 +117,14 @@ def parse_cesm_history(file, user_streams_dict={}):
info['component'] = stream.component
info['stream'] = stream.name
z = file.stem.split(extracted_stream)
info['case'] = z[0].strip('.')
info['date'] = z[-1].strip('.')
info['case'] = z[0].strip('.')

try:
info['member_id'] = info['case'].split('.')[-1]

except:
info['member_id'] = None
break
with xr.open_dataset(file, chunks={}, decode_times=False) as ds:
try:
Expand Down Expand Up @@ -178,7 +187,12 @@ def parse_cesm_timeseries(file, user_streams_dict={}):
continue

info['case'] = z[0].strip('.')
info['member_id'] = int(info['case'].split('.')[-1])

try:
info['member_id'] = info['case'].split('.')[-1]

except:
info['member_id'] = None

# Use the last part to get variable and time info
date_and_variable = z[-1].split('.')
Expand Down Expand Up @@ -248,7 +262,7 @@ def parse_smyle(file):
inits = z[0].split('-')
init_year = int(inits[0])
init_month = int(inits[1])
member_id = int(z[-1])
member_id = z[-1]
x = case.split(z[0])[0].strip('.').split('.')
experiment = x[-2]
grid = x[-1]
Expand Down