Skip to content

Commit c1d0244

Browse files
author
+Joseph Abbate
committed
move lib stuff to head so toksearch parallelization works; add script to dump info for experimental runs like textual summaries (since toksearch only works with shot data)
1 parent 5c0b4b0 commit c1d0244

19 files changed

+127
-31
lines changed
File renamed without changes.

configs/example.yaml

+9-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ data:
22
shots: data/shots.npy
33
tmin: 0
44
tmax: 6000
5-
time_step: 25
5+
time_step: 20
66
sql_sig_names: ['t_ip_flat','ip_flat_duration','topology','time_of_shot','run',
77
'poh','pech','pbeam','btor','btorsign','ip','ipsign', 'betanmax']
88
scalar_sig_names: ['vloop','ip','ipsiptargt','bt',
@@ -29,28 +29,30 @@ data:
2929
efit_types: ['EFIT01','EFIT02','EFIT_CAKE01','EFIT_CAKE02']
3030
include_psirz: False
3131
include_rhovn: True
32-
thomson_sig_names: [] #['density', 'temp']
32+
thomson_sig_names: ['density', 'temp']
3333
include_thomson_uncertainty: True
3434
include_rt_thomson: True
35-
cer_sig_names: [] #['temp','rot']
35+
cer_sig_names: ['temp','rot']
3636
cer_type: 'CERQUICK'
3737
cer_realtime_channels: True
38-
cer_rotation_units_of_khz: True
38+
cer_rotation_units_of_krad: True
3939
zipfit_sig_names: ['trotfit','edensfit','etempfit','itempfit'] #,'idensfit']
4040
#['ftscrot','ftscpsin','ftsc1vld','ftsspsin','ftssrot','etscr','etscrin','etscrout','etsct','etsctin']
4141
# ['etste', 'etsne','etscr','etsct',
4242
# 'etstein', 'etsnein','etscrin', 'etsctin','etsinq', 'etsinprs',
4343
# 'etsteout', 'etsneout', 'etsqout', 'etsprsout',
4444
# 'etste', 'etsne','etscr','etsct']
4545
pcs_sig_names: []
46-
include_radiation: False
46+
include_radiation: True
4747
include_full_ech_data: True
4848
include_full_nb_data: True
4949
include_gas_valve_info: True
50+
include_log_info: True
5051
num_x_points: 33
5152
trial_fits: [] #['spline_1d','linear_interp_1d','mtanh_1d', 'csaps_1d']
5253
logistics:
53-
output_file: '/mnt/beegfs/users/abbatej/example.h5'
54+
output_file: '/mnt/beegfs/users/abbatej/new_20ms_log_data/example.h5'
5455
overwrite_shots: True
5556
num_processes: 1
56-
max_shots_per_run: 5000
57+
max_shots_per_run: 1
58+
print_errors: False

dump_shots.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
# for getting all plasma shots past a certain shot number
77
if True:
8-
minimum_shot = 165400
9-
maximum_shot=174042
8+
minimum_shot = 140000 #2010-ish
9+
maximum_shot = 194528 #200000 #arbitrarily big
1010
query = """
1111
select shot
1212
from shots_type
File renamed without changes.

lib/mtanh_fit.py mtanh_fit.py

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

new_database_maker.py

+53-21
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import os
3232
import time
3333
from scipy import interpolate, stats
34-
sys.path.append(os.path.join(os.path.dirname(__file__),'lib'))
3534
from transport_helpers import my_interp, standardize_time, Timer
3635
import fit_functions
3736
from plot_tools import plot_comparison_over_time, plot_2d_comparison
@@ -156,6 +155,7 @@
156155
print(f'Starting shot {shots[0]}-{shots[-1]}')
157156
sys.stdout.flush()
158157

158+
print('Writing summary SQL signals')
159159
# pipeline for SQL signals
160160
if len(cfg['data']['sql_sig_names'])>0:
161161
conn = connect_d3drdb()
@@ -185,6 +185,7 @@
185185
else:
186186
final_data[shot][sig_name]=record[sig]
187187

188+
print('Writing gas SQL signals')
188189
# pipeline for GAS
189190
if cfg['data']['include_gas_valve_info']:
190191
gas_sigs=['gas','valve']
@@ -203,14 +204,41 @@
203204
for record in records:
204205
for sig in gas_sigs:
205206
shot=str(record['shot'])
206-
tmp_dic[shot][sig].append(record[sig])
207+
tmp_dic[shot][sig].append(str(record[sig]))
207208
with h5py.File(filename,'a') as final_data:
208209
for shot in tmp_dic:
209210
final_data.require_group(shot)
210211
for sig in gas_sigs:
211212
sig_name=sig+'_sql'
212213
final_data[shot][sig_name]=tmp_dic[shot][sig]
213214

215+
print('Writing log SQL signals')
216+
# pipeline for LOGS
217+
if cfg['data']['include_log_info']:
218+
log_sigs=['text','topic','username']
219+
conn = connect_d3drdb()
220+
query="""SELECT shot,{}
221+
FROM entries
222+
WHERE shot in {}
223+
""".format(
224+
','.join(log_sigs),
225+
'({})'.format(','.join([str(elem) for elem in shots]))
226+
)
227+
pipeline = Pipeline.from_sql(conn, query)
228+
records=pipeline.compute_serial()
229+
tmp_dic={str(shot): {sig: [] for sig in log_sigs} for shot in shots}
230+
for record in records:
231+
for sig in log_sigs:
232+
shot=str(record['shot'])
233+
tmp_dic[shot][sig].append(str(record[sig]))
234+
with h5py.File(filename,'a') as final_data:
235+
for shot in tmp_dic:
236+
final_data.require_group(shot)
237+
for sig in log_sigs:
238+
sig_name=sig+'_sql'
239+
final_data[shot][sig_name]=tmp_dic[shot][sig]
240+
241+
print('Writing timebased signals')
214242
# pipeline for regular signals
215243
pipeline = Pipeline(shots)
216244

@@ -461,21 +489,22 @@ def add_ech_info(record):
461489
record['ech_pwr_total']=standardize_time(record[f'ech_pwr_total_full']['data'],
462490
record[f'ech_pwr_total_full']['times'],
463491
record['standard_time'])
464-
num_systems=record['ech_num_systems']['data']
465-
record['ech_names']=[]
466-
sigs_0d=['frequency','R','Z']
467-
sigs_1d=['pwr','aziang','polang']
468-
for key in sigs_0d+sigs_1d:
469-
record[f'ech_{key}']=[]
470-
for i in range(1,num_systems+1):
471-
gyro=record[f'ech_name_{i}']['data'].upper()
472-
record['ech_names'].append(gyro)
473-
for key in sigs_0d:
474-
record[f'ech_{key}'].append(record[f'ech_{key}_{i}']['data'])
475-
for key in sigs_1d:
476-
record[f'ech_{key}'].append(standardize_time(record[f'ech_{key}_{gyro}']['data'],
477-
record[f'ech_{key}_{gyro}']['times'],
478-
record['standard_time']))
492+
if record['ech_num_systems'] is not None:
493+
num_systems=record['ech_num_systems']['data']
494+
record['ech_names']=[]
495+
sigs_0d=['frequency','R','Z']
496+
sigs_1d=['pwr','aziang','polang']
497+
for key in sigs_0d+sigs_1d:
498+
record[f'ech_{key}']=[]
499+
for i in range(1,num_systems+1):
500+
gyro=record[f'ech_name_{i}']['data'].upper()
501+
record['ech_names'].append(gyro)
502+
for key in sigs_0d:
503+
record[f'ech_{key}'].append(record[f'ech_{key}_{i}']['data'])
504+
for key in sigs_1d:
505+
record[f'ech_{key}'].append(standardize_time(record[f'ech_{key}_{gyro}']['data'],
506+
record[f'ech_{key}_{gyro}']['times'],
507+
record['standard_time']))
479508

480509
if cfg['data']['include_full_nb_data']:
481510
@pipeline.map
@@ -724,7 +753,7 @@ def pcs_processing(record):
724753

725754
with Timer():
726755
if cfg['logistics']['num_processes']>1:
727-
records=pipeline.compute_spark(numparts=cfg['logistics']['num_processes'])
756+
records=pipeline.compute_ray(numparts=cfg['logistics']['num_processes'])
728757
else:
729758
records=pipeline.compute_serial()
730759

@@ -738,6 +767,9 @@ def pcs_processing(record):
738767
if sig in final_data[shot]:
739768
del final_data[shot][sig]
740769
final_data[shot][sig]=record[sig]
741-
for key in record['errors']:
742-
print(key)
743-
print(record['errors'][key]['traceback'].replace('\\n','\n'))
770+
# print(sig)
771+
# print(record[sig])
772+
if cfg['logistics']['print_errors']:
773+
for key in record['errors']:
774+
print(key)
775+
print(record['errors'][key]['traceback'].replace('\\n','\n'))

omfit_run_dump.py

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
"""
2+
module load omfit
3+
omfit run_dump.py
4+
5+
(or copy/paste into an OMFIT command window and run from there)
6+
"""
7+
8+
import h5py
9+
import numpy as np
10+
import time
11+
12+
filename='/cscratch/abbatej/run_dump.h5'
13+
min_shot=140000
14+
max_shot=196512
15+
overwrite_runs=True
16+
17+
# splitting up into batches prob not necessary in retrospect...
18+
# the thought was to not have too much stuff in RAM at a time
19+
max_shots_per_run=10000
20+
21+
text_sigs=['text','topic','username']
22+
run_sigs=['brief']
23+
run_sig_string=','.join(run_sigs)
24+
text_string=','.join(text_sigs)
25+
26+
shot_dividers=list(reversed(np.arange(min_shot,max_shot,max_shots_per_run)))
27+
28+
prev_time=time.time()
29+
for i in range(len(shot_dividers)-1):
30+
prev_time=time.time()
31+
this_max_shot=shot_dividers[i]
32+
this_min_shot=shot_dividers[i+1]
33+
print(f"Starting {this_max_shot}-{this_min_shot}")
34+
sig_info=OMFITrdb(f"""SELECT DISTINCT UPPER(run) as run
35+
FROM shots
36+
WHERE shot>={this_min_shot} AND shot<{this_max_shot}""",db='d3drdb',server='d3drdb',by_column=True)
37+
runs=sig_info['run']
38+
run_string='({})'.format(','.join(["'"+run+"'" for run in runs]))
39+
tmp_dic={run: {sig: [] for sig in text_sigs} for run in runs}
40+
41+
sig_info=OMFITrdb(f"""SELECT UPPER(run) as run,{run_sig_string}
42+
FROM runs
43+
WHERE run in {run_string}""",db='d3drdb',server='d3drdb',by_column=True)
44+
for i in range(len(sig_info['run'])):
45+
for sig in run_sigs:
46+
tmp_dic[str(sig_info['run'][i])][sig]=str(sig_info[sig][i])
47+
48+
sig_info=OMFITrdb(f"""SELECT UPPER(run) as run,{text_string}
49+
FROM entries
50+
WHERE run in {run_string} AND shot IS NULL""",db='d3drdb',server='d3drdb',by_column=True)
51+
for i in range(len(sig_info['run'])):
52+
for sig in text_sigs:
53+
tmp_dic[str(sig_info['run'][i])][sig].append(str(sig_info[sig][i]))
54+
55+
with h5py.File(filename, 'a') as f:
56+
for run in tmp_dic:
57+
if overwrite_runs and run in f:
58+
del f[run]
59+
else:
60+
f.require_group(run)
61+
for sig in tmp_dic[run]:
62+
f[run][sig]=tmp_dic[run][sig]
63+
print(f'Took {time.time()-prev_time:.2f}s')

lib/plot_tools.py plot_tools.py

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

lib/transport_helpers.py transport_helpers.py

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ def __enter__(self):
2525

2626
def __exit__(self, *args):
2727
elapsed = time.time() - self.start
28-
print('---------------------')
2928
print('---> Ran in {0:.2f} s'.format(elapsed))
3029

3130
def standardize_time(old_signal,old_timebase,standard_times,

0 commit comments

Comments
 (0)