-
Notifications
You must be signed in to change notification settings - Fork 0
/
SSC_test.py
115 lines (74 loc) · 3.17 KB
/
SSC_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
'''----------------------------------------------------------------------------
License:
This program is free software: you can redistribute it and/or modify
it. This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
If you use this software (or a part of it) in your research, please cite
the authors. For more information how to cite this work properly please
visit the official webside. THANKS!
https://ssc.shef.ac.uk
----------------------------------------------------------------------------'''
from timeit import default_timer as timer
from engine.logger import get_log
from datetime import timedelta
import engine.download as get
import engine.running as run
import multiprocessing
import datetime
import random
import sys
__author__ = ["Gyenge, Norbert"]
__email__ = ["[email protected]"]
def ssc(log, live):
"""
"""
# Starting date
sd = datetime.datetime(2012, 6, 1)
if live:
ed = datetime.today()
else:
ed = datetime.datetime(2020, 6, 1)
while sd <= ed:
#Measure the running time
start = timer()
try:
# Module 1: Download and load observation data from JSOC
full_disk = get.get_data(date_of_obs=sd, lag=live)
# Module 2: Downloading and processing Sharp data
sharp = get.get_sharp(date_of_obs=sd, lag=live)
# Skip if no ShARP data, no sunspot group observed
if sharp and full_disk:
# Start parallel threads, number of threads depends on the architecture
for obs in full_disk:
# Save threads in array
threads=[]
# Module 3: Sunspot data based on continuum and magnetogram
thread = multiprocessing.Process(target=run.start, args=(obs, sharp, ))
thread.start()
# Start threads
threads.append(thread)
# Syncronise threads
for thread in threads:
thread.join()
else:
log.warning('Observation is not available.')
except:
if "KeyboardInterrupt()" not in str(sys.exc_info()):
#Error logged
log.warning("An error has occurred. Details in the error log file.")
else:
#Manual abort
log.warning("SSC has been aborted.")
break
finally:
# Increase variable sd my 1 hour
sd += datetime.timedelta(hours=1)
# Time logged
log.info('Next Observation: ' + sd.strftime("%m/%d/%Y, %H:%M:%S") +
' Running time: ' + str(timedelta(seconds=timer()-start)))
if __name__ == '__main__':
# STEP 2: Lag-time. The downloaded observations cannot be real-time because
# the JSOC and the ShARC services need time for publising data The lag-time
# defines a period of time between the present and the observations.
ssc(log=get_log(), live=False)