From ebb6f4d49a0288755ac7319a8757cba628d6c03a Mon Sep 17 00:00:00 2001 From: dvt Date: Thu, 11 Apr 2024 16:10:59 -0500 Subject: [PATCH] Add files via upload Fixed read_adf11.py to have more robust pathing and a bit better optimization --- colradpy/read_adf11.py | 209 ++++++++++++++++++++--------------------- 1 file changed, 103 insertions(+), 106 deletions(-) diff --git a/colradpy/read_adf11.py b/colradpy/read_adf11.py index 97c870b..68964ff 100644 --- a/colradpy/read_adf11.py +++ b/colradpy/read_adf11.py @@ -1,106 +1,103 @@ -import numpy as np -import re - - -def read_adf11(fil): - """ Reads data formatted in adf11 format. This format is generally used for GCR coefficients. - The data is stored in arrays of log_10. - Creates a dictionary to hold the data - Args: - :param fil: The file path to the input file - :type fil: string - """ - - f = open(fil) - adf11 = {} - adf11['input_file'] = {} - - #reading the first line - tmp = re.findall('(\d+)',f.readline()) - adf11['input_file']['nuc_charge'] = int(tmp[0]) - adf11['input_file']['num_dens'] = int(tmp[1]) - adf11['input_file']['num_temp'] = int(tmp[2]) - adf11['input_file']['charge_min'] = int(tmp[3]) - adf11['input_file']['charge_max'] = int(tmp[4]) - - f.readline() #reading '-------------' - if( 'r' in re.split('_',re.split('/',fil)[-1])[0]): - - adf11['input_file']['metas'] = np.array(list( #metastables - map(int,re.findall('(\d+)',f.readline())))) - f.readline() #reading '---------------' - else: - adf11['input_file']['metas'] = np.ones(adf11['input_file']['charge_max']+1,dtype='int') - - #read in the density grid - adf11['input_file']['dens_grid'] = np.array([]) - while adf11['input_file']['dens_grid'].size 1): - tmp = stage_id[0] - stage_id[0] = stage_id[1] - stage_id[1] = tmp - else:#this accounts for unresolved files that don't follow the convection of resolved files - tmp = stage_id[0] - stage_id = np.array([1,1,tmp]) - - ii = ii+1 - else: - gcr_vals = np.array(list(map(float,re.findall(r'((?:-\d+|\d).\d+)',gcr_line))))#Si gcr has positive vals maybe other do to? - adf11['input_file'][str(stage_id[2]-1)][stage_id[0]-1,stage_id[1]-1, - temp_count,dens_count:dens_count+len(gcr_vals)] = gcr_vals - dens_count = dens_count + len(gcr_vals) - if(dens_count == len(adf11['input_file']['dens_grid'])): - temp_count = temp_count + 1 - dens_count = 0 - gcr_line = f.readline() - return adf11 +import numpy as np +import re +from pathlib import Path + + +def read_adf11(fil): + """ Reads data formatted in adf11 format. This format is generally used for GCR coefficients. + The data is stored in arrays of log_10. + Creates a dictionary to hold the data + Args: + :param fil: The file path to the input file + :type fil: string + """ + + path = Path(fil) + f = path.open() + adf11 = {} + adf11['input_file'] = {} + + is_ascd = 'acd' in path.name or 'scd' in path.name + is_qcd = 'qcd' in path.name + is_xcd = 'xcd' in path.name + is_plt = 'plt' in path.name + is_prb = 'prb' in path.name + + #reading the first line + tmp = re.findall('(\d+)',f.readline()) + adf11['input_file']['nuc_charge'] = int(tmp[0]) + adf11['input_file']['num_dens'] = int(tmp[1]) + adf11['input_file']['num_temp'] = int(tmp[2]) + adf11['input_file']['charge_min'] = int(tmp[3]) + adf11['input_file']['charge_max'] = int(tmp[4]) + + f.readline() #reading '-------------' + if( 'r' in path.name): + + adf11['input_file']['metas'] = np.array(list( #metastables + map(int,re.findall('(\d+)',f.readline())))) + f.readline() #reading '---------------' + else: + adf11['input_file']['metas'] = np.ones(adf11['input_file']['charge_max']+1,dtype='int') + + #read in the density grid + adf11['input_file']['dens_grid'] = np.array([]) + while adf11['input_file']['dens_grid'].size 1): + tmp = stage_id[0] + stage_id[0] = stage_id[1] + stage_id[1] = tmp + else:#this accounts for unresolved files that don't follow the convection of resolved files + tmp = stage_id[0] + stage_id = np.array([1,1,tmp]) + + ii = ii+1 + else: + gcr_vals = np.array(list(map(float,re.findall(r'((?:-\d+|\d).\d+)',gcr_line))))#Si gcr has positive vals maybe other do to? + adf11['input_file'][str(stage_id[2]-1)][stage_id[0]-1,stage_id[1]-1, + temp_count,dens_count:dens_count+len(gcr_vals)] = gcr_vals + dens_count = dens_count + len(gcr_vals) + if(dens_count == len(adf11['input_file']['dens_grid'])): + temp_count = temp_count + 1 + dens_count = 0 + gcr_line = f.readline() + return adf11