@@ -72,16 +72,16 @@ def __init__(self, filename):
7272
7373 self .run_output_dir = None
7474 self .is_run_vertical = None
75- # self.post_process_file = None
75+ self .post_process_file = None
7676
7777 self .emission_module = None
7878 self .grid_spec_module = None
79- # self.post_process_module = None
79+ self .post_process_module = None
8080
8181 self .load_configure (filename )
8282 self .load_emission_module ()
8383 self .load_grid_spec_module ()
84- # self.load_post_process_module()
84+ self .load_post_process_module ()
8585
8686 def load_configure (self , filename ):
8787 dom = minidom .parse (filename )
@@ -90,7 +90,7 @@ def load_configure(self, filename):
9090 # Emission
9191 emission = root .getElementsByTagName ('Emission' )[0 ]
9292 emission_read = emission .getElementsByTagName ('Read' )[0 ]
93- self .emission_read_file = emission_read .getAttribute ('ScriptFile' )
93+ self .emission_read_file = os . path . abspath ( os . path . join ( dir_configure , emission_read .getAttribute ('ScriptFile' )) )
9494 emission_sectors = emission .getElementsByTagName ("Sectors" )[0 ]
9595 sector_list = emission_sectors .getElementsByTagName ("Sector" )
9696 for sector in sector_list :
@@ -140,7 +140,7 @@ def load_configure(self, filename):
140140 use_gsf = grid_spec .getAttribute ("Enable" )
141141 self .voc_use_grid_spec = True if use_gsf == "True" else False
142142 grid_spec_read = grid_spec .getElementsByTagName ("Read" )[0 ]
143- self .grid_spec_read_file = grid_spec_read .getAttribute ("ScriptFile" )
143+ self .grid_spec_read_file = os . path . abspath ( os . path . join ( dir_configure , grid_spec_read .getAttribute ("ScriptFile" )) )
144144 grid_spec_mech = grid_spec .getElementsByTagName ("ChemMech" )[0 ]
145145 self .chemical_mechanism = ChemMechEnum [grid_spec_mech .getAttribute ("name" )]
146146
@@ -155,41 +155,43 @@ def load_configure(self, filename):
155155 self .run_output_dir = output .getAttribute ("Directory" )
156156 steps = run .getElementsByTagName ("Steps" )[0 ]
157157 self .is_run_vertical = True if steps .getAttribute ("RunVertical" ) == "True" else False
158- # post_process = run.getElementsByTagName("PostProcess")[0]
159- # self.post_process_file = post_process.getAttribute("ScriptFile")
158+ post_process = run .getElementsByTagName ("PostProcess" )[0 ]
159+ self .post_process_file = os . path . abspath ( os . path . join ( dir_configure , post_process .getAttribute ("ScriptFile" )) )
160160
161161 def load_emission_module (self ):
162- if os .path .isfile (self .emission_read_file ):
163- run_path = os .path .dirname (self .emission_read_file )
162+ emission_read_file = os .path .abspath (os .path .join (dir_configure , os .pardir , self .emission_read_file ))
163+ if os .path .isfile (emission_read_file ):
164+ run_path = os .path .dirname (emission_read_file )
164165 if run_path not in sys .path :
165166 sys .path .append (run_path )
166- run_module = os .path .basename (self . emission_read_file )
167+ run_module = os .path .basename (emission_read_file )
167168 run_module = os .path .splitext (run_module )[0 ]
168169 self .emission_module = importlib .import_module (run_module )
169170 else :
170- print ('Read emission script file not exist!\n {}' .format (self . emission_read_file ))
171+ print ('Read emission script file not exist!\n {}' .format (emission_read_file ))
171172
172173 def load_grid_spec_module (self ):
173- if os .path .isfile (self .grid_spec_read_file ):
174- run_path = os .path .dirname (self .grid_spec_read_file )
174+ grid_spec_read_file = os .path .abspath (os .path .join (dir_configure , os .pardir , self .grid_spec_read_file ))
175+ if os .path .isfile (grid_spec_read_file ):
176+ run_path = os .path .dirname (grid_spec_read_file )
175177 if run_path not in sys .path :
176178 sys .path .append (run_path )
177- run_module = os .path .basename (self . grid_spec_read_file )
179+ run_module = os .path .basename (grid_spec_read_file )
178180 run_module = os .path .splitext (run_module )[0 ]
179181 self .grid_spec_module = importlib .import_module (run_module )
180182 else :
181- print ('Read grid speciation script file not exist!\n {}' .format (self . grid_spec_read_file ))
182-
183- # def load_post_process_module(self):
184- # if os.path.isfile(self.post_process_file):
185- # run_path = os.path.dirname(self.post_process_file)
186- # if run_path not in sys.path:
187- # sys.path.append(run_path)
188- # run_module = os.path.basename(self.post_process_file)
189- # run_module = os.path.splitext(run_module)[0]
190- # self.post_process_module = importlib.import_module(run_module)
191- # else:
192- # print('Post process script file not exist!\n {}'.format(self.post_process_file))
183+ print ('Read grid speciation script file not exist!\n {}' .format (grid_spec_read_file ))
184+
185+ def load_post_process_module (self ):
186+ if os .path .isfile (self .post_process_file ):
187+ run_path = os .path .dirname (self .post_process_file )
188+ if run_path not in sys .path :
189+ sys .path .append (run_path )
190+ run_module = os .path .basename (self .post_process_file )
191+ run_module = os .path .splitext (run_module )[0 ]
192+ self .post_process_module = importlib .import_module (run_module )
193+ else :
194+ print ('Post process script file not exist!\n {}' .format (self .post_process_file ))
193195
194196 def save_configure (self , filename = None ):
195197 doc = minidom .Document ()
@@ -201,7 +203,7 @@ def save_configure(self, filename=None):
201203 # Emission
202204 emission = doc .createElement ('Emission' )
203205 emission_read = doc .createElement ('Read' )
204- emission_read .setAttribute ('ScriptFile' , self .emission_read_file )
206+ emission_read .setAttribute ('ScriptFile' , os . path . relpath ( self .emission_read_file , dir_configure ) )
205207 emission .appendChild (emission_read )
206208
207209 elem_sectors = doc .createElement ("Sectors" )
@@ -246,21 +248,21 @@ def save_configure(self, filename=None):
246248 # Temporal
247249 temporal = doc .createElement ('Temporal' )
248250 file_name = doc .createElement ('FileName' )
249- file_name .setAttribute ('Profile' , self .temporal_prof_file )
250- file_name .setAttribute ('Reference' , self .temporal_ref_file )
251+ file_name .setAttribute ('Profile' , os . path . basename ( self .temporal_prof_file ) )
252+ file_name .setAttribute ('Reference' , os . path . basename ( self .temporal_ref_file ) )
251253 temporal .appendChild (file_name )
252254 root .appendChild (temporal )
253255
254256 # Chemical
255257 chemical = doc .createElement ("Chemical" )
256258 cfiles = doc .createElement ("FileName" )
257- cfiles .setAttribute ("Profile" , self .chemical_prof_file )
258- cfiles .setAttribute ("Reference" , self .chemical_ref_file )
259+ cfiles .setAttribute ("Profile" , os . path . basename ( self .chemical_prof_file ) )
260+ cfiles .setAttribute ("Reference" , os . path . basename ( self .chemical_ref_file ) )
259261 chemical .appendChild (cfiles )
260262 grid_spec = doc .createElement ("GridSpeciation" )
261263 grid_spec .setAttribute ("Enable" , "True" if self .voc_use_grid_spec else "False" )
262264 grid_spec_read = doc .createElement ("Read" )
263- grid_spec_read .setAttribute ("ScriptFile" , self .grid_spec_read_file )
265+ grid_spec_read .setAttribute ("ScriptFile" , os . path . relpath ( self .grid_spec_read_file , dir_configure ) )
264266 grid_spec .appendChild (grid_spec_read )
265267 grid_spec_mech = doc .createElement ("ChemMech" )
266268 grid_spec_mech .setAttribute ("name" , self .chemical_mechanism .name )
@@ -283,9 +285,9 @@ def save_configure(self, filename=None):
283285 steps = doc .createElement ("Steps" )
284286 steps .setAttribute ("RunVertical" , "True" if self .is_run_vertical else "False" )
285287 run .appendChild (steps )
286- # post_process = doc.createElement("PostProcess")
287- # post_process.setAttribute("ScriptFile", self.post_process_file)
288- # run.appendChild(post_process)
288+ post_process = doc .createElement ("PostProcess" )
289+ post_process .setAttribute ("ScriptFile" , os . path . relpath ( self .post_process_file , dir_configure ) )
290+ run .appendChild (post_process )
289291 root .appendChild (run )
290292
291293 # Write config file
0 commit comments