|
12 | 12 | # -----------------------------------------------------------------------------
|
13 | 13 | def change_param_local(time, map, pfss, scheme=2, poynting_flux=-1.0, new_params={}, DoUseMarker=0):
|
14 | 14 |
|
| 15 | + params_pfss = ['CHANGEWEAKFIELD', 'BrFactor', 'BrMin'] |
| 16 | + |
| 17 | + # need to turn on CHANGEWEAKFIELD if BrFactor and/or BrMin are changed |
| 18 | + if 'BrFactor' in new_params['change'].keys() or 'BrMin' in new_params['change'].keys(): |
| 19 | + if 'add' in new_params.keys(): |
| 20 | + new_params['add']=new_params['add']+',CHANGEWEAKFIELD' |
| 21 | + else: |
| 22 | + new_params['add']='CHANGEWEAKFIELD' |
| 23 | + |
| 24 | + # need to turn on FACTORB0 if FactorB0 is changed |
| 25 | + if 'FactorB0' in new_params['change'].keys(): |
| 26 | + if 'add' in new_params.keys(): |
| 27 | + new_params['add']=new_params['add']+',FACTORB0' |
| 28 | + else: |
| 29 | + new_params['add']='FACTORB0' |
| 30 | + |
| 31 | + # well, for 5th order scheme, there is a 0.02 thick layer above rMin for AWSoM-R |
| 32 | + if 'rMin_AWSoMR' in new_params['change'].keys(): |
| 33 | + new_params['change']['rMaxLayer_AWSoMR'] = float(new_params['change']['rMin_AWSoMR']) + 0.02 |
| 34 | + |
| 35 | + # set the PFSS solver, FDIPS or Harmonics |
| 36 | + # If it is HARAMONICS, no need to change as HARMONICS is the default |
| 37 | + if (pfss == 'FDIPS'): |
| 38 | + if 'add' in new_params.keys(): |
| 39 | + new_params['add']=new_params['add']+',LOOKUPTABLE(FDIPS)' |
| 40 | + else: |
| 41 | + new_params['add']='LOOKUPTABLE(FDIPS)' |
| 42 | + if 'rm' in new_params.keys(): |
| 43 | + new_params['rm'] =new_params['rm']+',HARMONICSFILE,HARMONICSGRID' |
| 44 | + else: |
| 45 | + new_params['rm'] = 'HARMONICSFILE,HARMONICSGRID' |
| 46 | + elif pfss not in ['FDIPS','HARMONICS']: |
| 47 | + raise ValueError(pfss + ' must be either FDIPS') |
| 48 | + |
| 49 | + # for 5th order scheme |
| 50 | + if scheme == 5: |
| 51 | + if 'rm'in new_params.keys(): |
| 52 | + new_params['rm'] =new_params['rm']+',END(END_2nd_scheme)' |
| 53 | + else: |
| 54 | + new_params['rm'] ='END(END_2nd_scheme)' |
| 55 | + |
| 56 | + new_params_pfss = {} |
| 57 | + |
| 58 | + # key1 could be change, add, rm, replace |
| 59 | + for key1 in list(new_params.keys()): |
| 60 | + if key1 in ['change','replace']: |
| 61 | + # another dict for ['change','replace'] |
| 62 | + for key2 in list(new_params[key1].keys()): |
| 63 | + if key2 in params_pfss: |
| 64 | + if key1 not in new_params_pfss.keys(): |
| 65 | + new_params_pfss[key1]={key2:new_params[key1][key2]} |
| 66 | + else: |
| 67 | + new_params_pfss[key1][key2] = new_params[key1][key2] |
| 68 | + # delete the entry found in params_pfss |
| 69 | + new_params[key1].pop(key2,None) |
| 70 | + elif key1 in ['add','rm']: |
| 71 | + # a string for ['add','rm'] |
| 72 | + commands_local = new_params[key1] |
| 73 | + commands_list_local = commands_local.split(',') |
| 74 | + commands_list_pfss = [] |
| 75 | + |
| 76 | + for i in range(len(commands_list_local)): |
| 77 | + if commands_list_local[i] in params_pfss: |
| 78 | + commands_list_pfss.append(commands_list_local[i]) |
| 79 | + commands_list_local[i] = '' |
| 80 | + |
| 81 | + # remove '' in the list |
| 82 | + if '' in commands_list_local: |
| 83 | + commands_list_local.remove('') |
| 84 | + |
| 85 | + if len(commands_list_local) == 0: |
| 86 | + # remove the key if the list of the string is empty (for PARAM.in) |
| 87 | + new_params.pop(key1,None) |
| 88 | + else: |
| 89 | + new_params[key1] = ','.join(commands_list_local) |
| 90 | + |
| 91 | + # if the list of the string for the pfss is not empty, add the entry |
| 92 | + if len(commands_list_pfss) > 0: |
| 93 | + new_params_pfss[key1] = ','.join(commands_list_pfss) |
| 94 | + |
15 | 95 | if time != 'MapTime':
|
16 | 96 | # TIME is given with the correct format
|
17 | 97 | time_input = dt.datetime.strptime(time, "%Y-%m-%dT%H:%M:%S")
|
@@ -68,39 +148,34 @@ def change_param_local(time, map, pfss, scheme=2, poynting_flux=-1.0, new_params
|
68 | 148 | if 'add' in new_params.keys():
|
69 | 149 | commands_add=new_params['add']
|
70 | 150 | change_param.add_commands(commands_add, DoUseMarker=DoUseMarker)
|
71 |
| - change_param.add_commands(commands_add, DoUseMarker=DoUseMarker, filenameIn='FDIPS.in', filenameOut='FDIPS.in') |
72 |
| - change_param.add_commands(commands_add, DoUseMarker=DoUseMarker, filenameIn='HARMONICS.in',filenameOut='HARMONICS.in') |
| 151 | + |
| 152 | + if 'add' in new_params_pfss.keys(): |
| 153 | + commands_add=new_params_pfss['add'] |
| 154 | + change_param.add_commands(commands_add, DoUseMarker=DoUseMarker, filenameIn=pfss+'.in', filenameOut=pfss+'.in') |
73 | 155 |
|
74 | 156 | if 'rm' in new_params.keys():
|
75 | 157 | commands_rm=new_params['rm']
|
76 | 158 | change_param.remove_commands(commands_rm, DoUseMarker=DoUseMarker)
|
77 |
| - change_param.remove_commands(commands_rm, DoUseMarker=DoUseMarker, filenameIn='FDIPS.in', filenameOut='FDIPS.in') |
78 |
| - change_param.remove_commands(commands_rm, DoUseMarker=DoUseMarker, filenameIn='HARMONICS.in', filenameOut='HARMONICS.in') |
| 159 | + |
| 160 | + if 'rm' in new_params_pfss.keys(): |
| 161 | + commands_rm=new_params_pfss['rm'] |
| 162 | + change_param.remove_commands(commands_rm, DoUseMarker=DoUseMarker, filenameIn=pfss+'.in', filenameOut=pfss+'.in') |
79 | 163 |
|
80 | 164 | if 'replace' in new_params.keys():
|
81 | 165 | DictReplace = new_params['replace']
|
82 | 166 | change_param.replace_commands(DictReplace, DoUseMarker=DoUseMarker)
|
83 |
| - change_param.replace_commands(DictReplace, DoUseMarker=DoUseMarker, filenameIn='FDIPS.in', filenameOut='FDIPS.in') |
84 |
| - change_param.replace_commands(DictReplace, DoUseMarker=DoUseMarker, filenameIn='HARMONICS.in', filenameOut='HARMONICS.in') |
| 167 | + |
| 168 | + if 'replace' in new_params_pfss.keys(): |
| 169 | + DictReplace = new_params_pfss['replace'] |
| 170 | + change_param.replace_commands(DictReplace, DoUseMarker=DoUseMarker, filenameIn=pfss+'.in', filenameOut=pfss+'.in') |
85 | 171 |
|
86 | 172 | if 'change' in new_params.keys():
|
87 | 173 | DictChange = new_params['change']
|
88 | 174 | change_param.change_param_value(DictChange, DoUseMarker=DoUseMarker)
|
89 |
| - change_param.change_param_value(DictChange, DoUseMarker=DoUseMarker, filenameIn='FDIPS.in', filenameOut='FDIPS.in') |
90 |
| - change_param.change_param_value(DictChange, DoUseMarker=DoUseMarker, filenameIn='HARMONICS.in', filenameOut='HARMONICS.in') |
91 | 175 |
|
92 |
| - # set the PFSS solver, FDIPS or Harmonics |
93 |
| - if (pfss == 'FDIPS'): |
94 |
| - change_param.add_commands('LOOKUPTABLE(FDIPS)', DoUseMarker=DoUseMarker) |
95 |
| - change_param.remove_commands('MAGNETOGRAM,HARMONICSFILE,HARMONICSGRID', DoUseMarker=DoUseMarker) |
96 |
| - elif (pfss == 'HARMONICS'): |
97 |
| - change_param.remove_commands('LOOKUPTABLE(FDIPS)', DoUseMarker=DoUseMarker) |
98 |
| - change_param.add_commands('HARMONICSFILE,HARMONICSGRID', DoUseMarker=DoUseMarker) |
99 |
| - else: |
100 |
| - raise ValueError(pfss + ' must be either HARMONICS or FDIPS') |
101 |
| - |
102 |
| - if scheme == 5: |
103 |
| - change_param.remove_commands('END(END_2nd_scheme)',DoUseMarker=DoUseMarker) |
| 176 | + if 'change' in new_params_pfss.keys(): |
| 177 | + DictChange = new_params_pfss['change'] |
| 178 | + change_param.change_param_value(DictChange, DoUseMarker=DoUseMarker, filenameIn=pfss+'.in', filenameOut=pfss+'.in') |
104 | 179 |
|
105 | 180 | # prepare each realization map.
|
106 | 181 | str_exe = str('Scripts/remap_magnetogram.py ' + filename_map)
|
|
0 commit comments