@@ -49,7 +49,7 @@ def yesno(question):
4949 return False
5050
5151
52- def check_existence (wdir , verb ):
52+ def check_existence (wdir , kinetic_mode , verb ):
5353 """Check for the existence of necessary files."""
5454 kinetic_mode = False
5555 k_exist = False
@@ -64,7 +64,8 @@ def check_existence(wdir, verb):
6464 c0_exist = any ([last_row_index .lower () in rows_to_search ])
6565 k_exist = all ([column in df .columns for column in columns_to_search ])
6666 if not c0_exist :
67- logging .critical ("Initial concentration not found in rxn_network.csv." )
67+ logging .critical (
68+ "Initial concentration not found in rxn_network.csv." )
6869
6970 else :
7071 logging .critical ("rxn_network.csv not found." )
@@ -93,12 +94,12 @@ def check_existence(wdir, verb):
9394 kinetic_exists = os .path .exists (
9495 os .path .join (wdir , "kinetic_data.csv" )
9596 ) or os .path .exists (os .path .join (wdir , "kinetic_data.xlsx" ))
96- if kinetic_exists :
97- kinetic_mode = yesno (
98- "kinetic_profile.csv exists Do you want to use kinetic information instead of the energy profile data"
99- )
100-
101- return kinetic_mode
97+ if kinetic_mode :
98+ if kinetic_exists :
99+ if verb > 2 :
100+ logging . info ( "Found kinetic data file." )
101+ else :
102+ logging . critical ( "kinetic_data file not found." )
102103
103104
104105def check_km_inp (
@@ -148,8 +149,7 @@ def check_km_inp(
148149 if mode == "energy" :
149150 # all INT names in nx are the same as in the profile
150151 missing_states = [
151- state for state in states_network_int if state not in states_profile
152- ]
152+ state for state in states_network_int if state not in states_profile ]
153153 if missing_states :
154154 clear = False
155155 logging .warning (
@@ -166,7 +166,8 @@ def check_km_inp(
166166 # initial conc
167167 if len (states_network ) != len (initial_conc ):
168168 clear = False
169- logging .warning ("\n Your initial concentration seems wrong. Double check!" )
169+ logging .warning (
170+ "\n Your initial concentration seems wrong. Double check!" )
170171
171172 # check network sanity
172173 mask = (~ df_network .isin ([- 1 , 1 ])).all (axis = 1 )
@@ -312,6 +313,13 @@ def preprocess_data_mkm(arguments, mode):
312313 action = "store_true" ,
313314 help = """Toggle to plot LFESRs. (default: False)""" ,
314315 )
316+ parser .add_argument (
317+ "-k" ,
318+ "--kinetic" ,
319+ dest = "kinetic_mode" ,
320+ action = "store_true" ,
321+ help = """Toggle to read and use kinetic profiles. (default: False)""" ,
322+ )
315323 parser .add_argument (
316324 "-iq" ,
317325 "--iq" ,
@@ -390,15 +398,20 @@ def preprocess_data_mkm(arguments, mode):
390398 )
391399
392400 args = parser .parse_args (arguments )
401+ verb = args .verb
402+ wdir = args .dir
403+ profile_choice = args .profile_choice
404+ x_scale = args .xscale
405+ more_species_mkm = args .addition
406+ quality = args .int_quality
407+ temperatures = args .temp
408+ kinetic_mode = args .kinetic_mode
409+ t_finals = args .time
410+ ncore = args .ncore
411+ imputer_strat = args .imputer_strat
412+
393413 if mode == "mkm_solo" :
394- verb = args .verb
395- wdir = args .dir
396- x_scale = args .xscale
397- more_species_mkm = args .addition
398414 profile_choice = args .profile_choice
399- quality = args .int_quality
400- t_finals = args .time
401- temperatures = args .temp
402415
403416 if t_finals is None :
404417 if verb > 0 :
@@ -427,7 +440,7 @@ def preprocess_data_mkm(arguments, mode):
427440 df_network .fillna (0 , inplace = True )
428441 states = df_network .columns [:].tolist ()
429442
430- kinetic_mode = check_existence (wdir , verb )
443+ check_existence (wdir , kinetic_mode , verb )
431444 ks = None
432445 if kinetic_mode :
433446 filename_xlsx = Path (wdir , "kinetic_data.xlsx" )
@@ -498,30 +511,22 @@ def preprocess_data_mkm(arguments, mode):
498511 lmargin = args .lmargin
499512 rmargin = args .rmargin
500513 xbase = args .xbase
501- verb = args .verb
502- wdir = args .dir
503- imputer_strat = args .imputer_strat
504514 report_as_yield = args .percent
505- quality = args .int_quality
506515 p_quality = args .plot_quality
507516 plotmode = args .plotmode
508- more_species_mkm = args .addition
509517 lfesr = args .lfesr
510518 x_scale = args .xscale
511519 comp_ci = args .confidence_interval
512- ncore = args .ncore
513520 nd = args .run_mode
514521 lfesrs_idx = args .idx
515- times = args .time
516- temperatures = args .temp
517522
518523 nx_path = Path (wdir , "rxn_network.csv" )
519524 df_network = pd .read_csv (nx_path , index_col = 0 )
520525 df_network .fillna (0 , inplace = True )
521526 states = df_network .columns [:].tolist ()
522527 n_target = len ([states .index (i ) for i in states if "*" in i ])
523528
524- kinetic_mode = check_existence (wdir , verb )
529+ check_existence (wdir , kinetic_mode , verb )
525530 if kinetic_mode :
526531 filename_xlsx = Path (wdir , "kinetic_data.xlsx" )
527532 filename_csv = Path (wdir , "kinetic_data.csv" )
@@ -577,24 +582,14 @@ def preprocess_data_mkm(arguments, mode):
577582 ncore ,
578583 nd ,
579584 lfesrs_idx ,
580- times ,
585+ t_finals ,
581586 temperatures ,
582587 kinetic_mode ,
583588 )
584589
585590 elif mode == "mkm_cond" :
586- wdir = args .dir
587- x_scale = args .xscale
588591 plot_evo = args .plot_evo
589592 map_tt = args .map
590- ncore = args .ncore
591- more_species_mkm = args .addition
592- imputer_strat = args .imputer_strat
593- verb = args .verb
594- profile_choice = args .profile_choice
595- quality = args .int_quality
596- t_finals = args .time
597- temperatures = args .temp
598593
599594 if t_finals is None :
600595 t_finals = [86400 ]
@@ -610,7 +605,7 @@ def preprocess_data_mkm(arguments, mode):
610605 elif len (temperatures ) > 1 :
611606 pass
612607
613- kinetic_mode = check_existence (wdir , verb )
608+ check_existence (wdir , kinetic_mode , verb )
614609 nx_path = Path (wdir , "rxn_network.csv" )
615610 df_network = pd .read_csv (nx_path , index_col = 0 )
616611 df_network .fillna (0 , inplace = True )
@@ -696,9 +691,14 @@ def preprocess_data_mkm(arguments, mode):
696691 )
697692
698693
699- def process_data_mkm (
700- dg : np .ndarray , df_network : pd .DataFrame , tags : List [str ], states : List [str ]
701- ) -> Tuple [np .ndarray , List [np .ndarray ], List [float ], List [np .ndarray ], np .ndarray ]:
694+ def process_data_mkm (dg : np .ndarray ,
695+ df_network : pd .DataFrame ,
696+ tags : List [str ],
697+ states : List [str ]) -> Tuple [np .ndarray ,
698+ List [np .ndarray ],
699+ List [float ],
700+ List [np .ndarray ],
701+ np .ndarray ]:
702702 """
703703 Processes data for micokinetic modeling.
704704
@@ -765,7 +765,8 @@ def process_data_mkm(
765765 loc_nx = np .where (np .array (states ) == all_df [i + 1 ].columns [2 ])[0 ]
766766 # int to which new cycle is connected (the first -1)
767767
768- if df_network .columns .to_list ()[branch_step + 1 ].lower ().startswith ("p" ):
768+ if df_network .columns .to_list ()[
769+ branch_step + 1 ].lower ().startswith ("p" ):
769770 # conneting profiles
770771 cp_idx = branch_step
771772 else :
@@ -923,7 +924,8 @@ def test_process_data_mkm():
923924
924925 assert np .array_equal (dgr_all , dgr_all_expected )
925926 assert len (coeff_ts_all ) == len (coeff_ts_all_expected )
926- for coeff_ts , coeff_ts_expected in zip (coeff_ts_all , coeff_ts_all_expected ):
927+ for coeff_ts , coeff_ts_expected in zip (
928+ coeff_ts_all , coeff_ts_all_expected ):
927929 assert np .array_equal (coeff_ts , coeff_ts_expected )
928930
929931 assert np .array_equal (rxn_network_all , rxn_network_all_expected )
0 commit comments