Skip to content

Commit b45ee22

Browse files
author
R Bailey
committed
L5 script now writes real-time L1 data from NOAA to pickle file (last three months are kept), so that there is always data available for a 27-day recurrence model.
1 parent 0ca5fb3 commit b45ee22

2 files changed

Lines changed: 31 additions & 10 deletions

File tree

predstorm/data.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2378,9 +2378,9 @@ def merge_Data(satdata1, satdata2, keys=None):
23782378
raise Exception("Dataset1 contains key ({}) not available in Dataset2!".format(k))
23792379

23802380
# Find num of points for addition:
2381-
if (satdata1.h['SamplingRate'] - 1./24.) < 0.0001:
2381+
if np.abs((satdata1.h['SamplingRate'] - 1./24.)) < 0.0001:
23822382
timestep = 1./24.
2383-
elif (satdata1.h['SamplingRate'] - 1./24./60.) < 0.0001:
2383+
elif np.abs((satdata1.h['SamplingRate'] - 1./24./60.)) < 0.0001:
23842384
timestep = 1./24./60.
23852385
else:
23862386
timestep = satdata1.h['SamplingRate']
@@ -2398,16 +2398,21 @@ def merge_Data(satdata1, satdata2, keys=None):
23982398

23992399
MergedData = SatData(datadict, source=satdata1.source+'+'+satdata2.source)
24002400
tf = "%Y-%m-%d %H:%M:%S"
2401-
MergedData.h['DataSource'] = '{} ({} - {}) & {} ({} - {})'.format(satdata1.h['DataSource'],
2402-
datetime.strftime(num2date(satdata1['time'][0]), tf),
2403-
datetime.strftime(num2date(satdata1['time'][-1]), tf),
2404-
satdata2.h['DataSource'],
2405-
datetime.strftime(num2date(new_time[0]), tf),
2406-
datetime.strftime(num2date(new_time[-1]), tf))
2401+
if satdata1.h['DataSource'] == satdata2.h['DataSource']:
2402+
MergedData.h['DataSource'] = satdata1.h['DataSource']
2403+
MergedData.h['Instruments'] = satdata1.h['Instruments']
2404+
MergedData.h['FileVersion'] = satdata1.h['FileVersion']
2405+
else:
2406+
MergedData.h['DataSource'] = '{} ({} - {}) & {} ({} - {})'.format(satdata1.h['DataSource'],
2407+
datetime.strftime(num2date(satdata1['time'][0]), tf),
2408+
datetime.strftime(num2date(satdata1['time'][-1]), tf),
2409+
satdata2.h['DataSource'],
2410+
datetime.strftime(num2date(new_time[0]), tf),
2411+
datetime.strftime(num2date(new_time[-1]), tf))
2412+
MergedData.h['Instruments'] = satdata1.h['Instruments'] + satdata2.h['Instruments']
2413+
MergedData.h['FileVersion'] = {**satdata1.h['FileVersion'], **satdata2.h['FileVersion']}
24072414
MergedData.h['SamplingRate'] = timestep
24082415
MergedData.h['ReferenceFrame'] = satdata1.h['ReferenceFrame']
2409-
MergedData.h['Instruments'] = satdata1.h['Instruments'] + satdata2.h['Instruments']
2410-
MergedData.h['FileVersion'] = {**satdata1.h['FileVersion'], **satdata2.h['FileVersion']}
24112416

24122417
logger.info("merge_Data: Finished merging data.")
24132418

predstorm_l5.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,22 @@ def main():
158158
timenow = dism['time'][-1]
159159
# Get UTC time now
160160
timeutc = date2num(timestamp)
161+
# Save to pickle file for recurrence model:
162+
rec_dism = copy.deepcopy(dism)
163+
# Cut by three days so data is always 3 days old at least, in case it's updated
164+
rec_dism.cut(endtime=num2date(timenow-3))
165+
rec_model_path = 'recurrence_l1_27days.pickle'
166+
if not os.path.exists(rec_model_path):
167+
with open(rec_model_path, 'wb') as f:
168+
pickle.dump(rec_dism, f)
169+
with open(rec_model_path, 'rb') as f:
170+
rec_27days = pickle.load(f)
171+
if rec_dism['time'][-1] > rec_27days['time'][-1]:
172+
rec_dism.cut(starttime=num2date(rec_27days['time'][-1]))
173+
rec_new = ps.merge_Data(rec_27days, rec_dism)
174+
rec_new.cut(starttime=num2date(timenow-90)) # don't keep more than three months
175+
with open(rec_model_path, 'wb') as f:
176+
pickle.dump(rec_new, f)
161177
elif run_mode == 'historic':
162178
timestamp = historic_date
163179
if (datetime.utcnow() - historic_date).days < (7.-plot_past_days):

0 commit comments

Comments
 (0)