Skip to content

Commit

Permalink
fixed file deletion error in mopsmap_wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
jsschlosser committed Sep 19, 2024
1 parent 07c10c9 commit 505d448
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 27 deletions.
12 changes: 6 additions & 6 deletions ISARA2.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def Retr_CRI(wvl,
for imode in sd:
RRI_d[imode] = rri
IRI_d[imode] = iri
results = mopsmap_wrapper.Model(wvl,size_equ,sd,dpg,rri,iri,nonabs_fraction,shape,rho,0,0,num_theta,optical_dataset,path_mopsmap_executable)
results = mopsmap_wrapper.Model(wvl,size_equ,sd,dpg,RRI_d,IRI_d,nonabs_fraction,shape,rho,0,0,num_theta,optical_dataset,path_mopsmap_executable)
scat_coef = results['ssa'][[0,3,5]]*results['ext_coeff'][[0,3,5]]
abs_coef = results['ext_coeff'][[1,2,4]]-results['ssa'][[1,2,4]]*results['ext_coeff'][[1,2,4]]
Cdif1 = abs(measured_sca_coef-scat_coef)/measured_sca_coef
Expand Down Expand Up @@ -157,7 +157,7 @@ def Retr_kappa(wvl,
L1 = len(kappa_p)
L3 = len(wvl)
Results = dict()
Results["kappa_p"] = None
Results["Kappa"] = None
Results["Cal_coef"] = None
Results["Cal_SSA"] = None
Results["Cal_ext_coef"] = None
Expand All @@ -172,11 +172,11 @@ def Retr_kappa(wvl,
IRI_w = {}
for imode in sd:
gf = np.power((1+kappa_p[i1]*RH/(100-RH)),1/3)
dpg_w[imode] = np.squeeze(np.multiply(gf,dpg1))
RRI_w[imode] = (CRI_d[imode][0]+((gf**3)-1)*RRIw)/(gf**3)
IRI_w[imode] = (CRI_d[imode][1]+((gf**3)-1)*IRIw)/(gf**3)#CRI1[1]
dpg_w[imode] = np.squeeze(np.multiply(gf,dpg[imode]))
RRI_w[imode] = (CRI_d[0]+((gf**3)-1)*RRIw)/(gf**3)
IRI_w[imode] = (CRI_d[1]+((gf**3)-1)*IRIw)/(gf**3)#CRI1[1]
if stop_indx == 0:
results = mopsmap_wrapper.Model(wvl,size_equ,sd,dpg,RRI,IRI,nonabs_fraction,shape,rho,0,0,num_theta,optical_dataset,path_mopsmap_executable)
results = mopsmap_wrapper.Model(wvl,size_equ,sd,dpg,RRI_w,IRI_w,nonabs_fraction,shape,rho,0,0,num_theta,optical_dataset,path_mopsmap_executable)
scat_coef = results['ssa']*results['ext_coeff']
abs_coef = results['ext_coeff']-results['ssa']*results['ext_coeff']
Cdif = abs(measured_wet_sca_coef-scat_coef[3])/measured_wet_sca_coef
Expand Down
7 changes: 4 additions & 3 deletions ISARA_ACTIVATE_Data_Retrieval.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@ def grab_keydata(key_starts_with):

resolution = 60

dpg2 = load_sizebins.Load('LAS_bin_sizes.csv')*pow(10,-3)
dpg1 = load_sizebins.Load('SMPS_bin_sizes.csv')*pow(10,-3)

dpData = load_sizebins.Load('LAS_bin_sizes.csv')
dpg2 = dpData["Mid Points"]*pow(10,-3)
dpData = load_sizebins.Load('SMPS_bin_sizes.csv')
dpg1 = dpData["Mid Points"]*pow(10,-3)
def handle_line(sd1, sd2, measured_coef_dry, measured_ext_coef_dry, measured_ssa_dry,
measured_coef_amb, measured_ext_coef_amb, measured_ssa_amb, measured_fRH,
wvl, size_equ, dpg1, dpg2, CRI, nonabs_fraction, shape, rho_dry,
Expand Down
12 changes: 6 additions & 6 deletions ISARA_Data_Retrieval.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ def grab_keydata(key_starts_with):
Abs = np.array([v for k, v in data.items() if k.startswith('Abs')])
Ext = np.array([v for k, v in data.items() if k.startswith('Ext')])
SSA = np.array([v for k, v in data.items() if (k.startswith('SSA')&k.__contains__('dry'))])
SSAa = np.array([v for k, v in data.items() if (k.startswith('SSA')&k.__contains__('amb'))])
SSAa =np.array(grab_keydata('SSA_amb_550nm_ZIEMBA'))
print(SSAa.size)
fRH = np.array(grab_keydata('fRH'))
return (data, time, date, alt, lat, lon, sd, RH_amb, RH_sp, Sc, Abs, Ext, SSA, SSAa, fRH)

Expand Down Expand Up @@ -178,7 +179,7 @@ def curry(i1):
Nonabs_fraction, Shape, Rho_dry, num_theta, path_optical_dataset, path_mopsmap_executable)

if Results["RRIdry"] is not None:
print(Results["RRIdry"])
#print(Results["RRIdry"])
RRI_dry = Results["RRIdry"]
IRI_dry = Results["IRIdry"]
CRI_dry = np.array([RRI_dry,IRI_dry])
Expand All @@ -193,12 +194,11 @@ def curry(i1):
#if (RH_amb[i1].astype(str) != 'nan') and (measured_coef_amb[i1].astype(str) != 'nan'):
if np.logical_not(np.isnan(measured_coef_amb[i1])):
meas_coef = np.multiply(measured_coef_amb[i1], pow(10, -6))
Results = ISARA2.Retr_kappa(wvl, meas_coef, Dndlogdp, Dpg, 80, kappa_p, CRI_dry, CRI_dry,
Results = ISARA2.Retr_kappa(wvl, meas_coef, Dndlogdp, Dpg, 80, kappa_p, CRI_dry,
Size_equ, Nonabs_fraction, Shape, Rho_amb, num_theta,
path_optical_dataset, path_mopsmap_executable)
if Results["Kappa"] is not None:
Kappa = Results["Kappa"]
print(Results["Kappa"])
CalCoef_amb = Results["Cal_coef"]
CalExtCoef_amb = Results["Cal_ext_coef"]
CalSSA_amb = Results["Cal_SSA"]
Expand Down Expand Up @@ -245,11 +245,11 @@ def curry(i1):
measured_coef_dry = np.vstack((Sc, Abs))
measured_ext_coef_dry = Ext[1, :]
measured_ssa_dry = SSA
measured_coef_amb = measured_coef_dry*fRH #Sc[0, :]
measured_coef_amb = Sc[0,:]*fRH #Sc[0, :]
measured_ext_coef_amb = Ext[0, :]
measured_ssa_amb = SSAa
measured_fRH = fRH

#print(measured_coef_amb[np.where(np.logical_not(np.isnan(measured_coef_amb)))])
Lwvl = len(wvl)
Lwvl_s = int(Lwvl/2)
L1 = RH_amb.size
Expand Down
26 changes: 14 additions & 12 deletions mopsmap_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def Model(wvl,size_equ,dndlogdp,dpg,RRI,IRI,nonabs_fraction,shape,density,RH,kap
"""

filename = f'tmp_mopsmap_{time.time()}_{np.random.randn()}_{np.random.randn()}_{np.random.randn()}'
dndlogdp_ary_filename =f'{filename}_dndp'

# create a input file for the Fortran code and a wavelength file
mopsmap_input_file = open(f'{filename}.inp', 'w')

Expand All @@ -60,26 +60,27 @@ def Model(wvl,size_equ,dndlogdp,dpg,RRI,IRI,nonabs_fraction,shape,density,RH,kap
# write modes
ikey = 1
for key in dndlogdp:
# dndlogdp_ary_filename =f'{filename}_{key}'
dndlogdp_ary = np.array(dndlogdp[key],ndmin = 1)
dpg_ary = np.array(dpg[key],ndmin = 1)
dndlogdp_ary_file = open(dndlogdp_ary_filename, 'w')
# write wavelength file
wvl = np.array(wvl,ndmin = 1)
for i in np.arange(dndlogdp_ary.shape[0]):
if i < dndlogdp_ary.shape[0]:
dndlogdp_ary_file.write('%10.4f %i\n'%(dpg_ary[i],dndlogdp_ary[i]))
else:
dndlogdp_ary_file.write('%10.4f %i'%(dpg_ary[i],dndlogdp_ary[i]))
dndlogdp_ary_file.close()
# dndlogdp_ary_file = open(dndlogdp_ary_filename, 'w')
# # write wavelength file
# wvl = np.array(wvl,ndmin = 1)
# for i in np.arange(dndlogdp_ary.shape[0]):
# if i < dndlogdp_ary.shape[0]:
# dndlogdp_ary_file.write('%10.4f %i\n'%(dpg_ary[i],dndlogdp_ary[i]))
# else:
# dndlogdp_ary_file.write('%10.4f %i'%(dpg_ary[i],dndlogdp_ary[i]))
# dndlogdp_ary_file.close()

if dndlogdp_ary.shape != dpg_ary.shape:
print("shapes of n and dpg do not agree")
raise SystemExit()
mopsmap_input_file.write("mode %d wavelength file tmp_mopsmap.wvl \n"%ikey) # write wvls
mopsmap_input_file.write('mode %d size_equ %s\n'%(ikey,size_equ[key])) # write size_equ
#dpg_dnlogdp = [dpg_ary,dndlogdp_ary]
dpg_dnlogdp = [dpg_ary,dndlogdp_ary]
#dpg_dnlogdp = np.reshape(dpg_dnlogdp, 2*dpg_ary.shape[0], order='F')
#listToStr = ' '.join(["%0.4E"%elem for elem in dpg_dnlogdp])
#listToStr = ' '.join(["%0.04E %i"%elem for elem in dpg_dnlogdp])
#mopsmap_input_file.write('mode %d size distr_list dndlogr %s\n'%(ikey,listToStr))
mopsmap_input_file.write('mode %d size distr_file dndlogr %s\n'%(ikey,dndlogdp_ary_filename))
mopsmap_input_file.write('mode %d density %f\n'%(ikey,density[key]))
Expand Down Expand Up @@ -150,6 +151,7 @@ def Model(wvl,size_equ,dndlogdp,dpg,RRI,IRI,nonabs_fraction,shape,density,RH,kap
results['delta_l'] = output_lidar['delta_l']
results['back_angstrom'] = output_lidar['back_angstrom']

remove(f'{filename}_{key}.txt')
remove(f'{filename}.inp')
remove(f'{filename}.integrated')
remove(f'{filename}.scattering_matrix')
Expand Down

0 comments on commit 505d448

Please sign in to comment.