1+ import math
12import netCDF4 as nc
23import numpy as np
34from scipy .interpolate import interp1d
4-
5+ from . spec_util import create_list
56from .optics import optics_var
67from .read_yang_ice_library import read_yang_ice_library
78
8-
9- def compute_ice (path_ori , habit , roughness , file_lut , file_pade , a , wavenum_out , source ,
10- band_limit , re_range_lut , re_range_pade , re_ref_pade , thin_flag ):
11- rau_ice = 917 * 10 ** 3 # ice density g/m**3
12- dr = 0.1 # um, integrate step of ice particle size
13- d = np .append (np .append (np .arange (1 , 20 ,0.2 ), np .arange (22 , 200 , 2 )), np .arange (210 , 1000 , 10 )) # ice dimension
14- a = np .repeat (a , len (d ), axis = 0 )
9+ def compute_ice (path_ori , habit , roughness , file_outres , file_band , file_pade , a , wavenum_out , source ,
10+ band_limit , re_range_pade , re_ref_pade , thin_flag ):
11+ rau = 917 * 10 ** 3 # ice density g/m**3
12+ nwav = len (wavenum_out )
13+ r = create_list (1 ,10000 ,20 )
14+ nr = len (r )
15+ r_out = np .zeros ((nr ,))
16+ v = np .zeros ((nr ,))
17+ s = np .zeros ((nr ,))
1518
1619 [wavenum_in , r_in , d_in , s_in , v_in , ext_cross_section_in , sca_cross_section_in , asy_in ] = \
1720 read_yang_ice_library (path_ori , habit , roughness )
18- # linearly interpolate the library into a higher resolution
19- d_hres = np .arange (dr * 2 , d_in [- 1 ], dr * 2 )
21+ nwav = len (wavenum_in )
22+ asy = np .zeros ((nr ,nwav ))
23+ ext = np .zeros ((nr ,nwav ))
24+ ssa = np .zeros ((nr ,nwav ))
25+ sca = np .zeros ((nr ,nwav ))
26+ for i in range (nr ):
27+ r_out [i ], s [i ], v [i ], ext [i ,:], sca [i ,:], ssa [i ,:], asy [i ,:] = compute_Yang_singlesize (a ,2.0 * r [i ],rau ,wavenum_in ,wavenum_in ,d_in , s_in , v_in , ext_cross_section_in , sca_cross_section_in , asy_in )
28+ optics_outres = optics_var (r_out , s , v , ext , sca , ssa , asy , rau , wavenum = wavenum_in )
29+ optics_outres .write_lut_spectralpoints (file_outres )
30+
31+ nwav = len (wavenum_out )
32+ asy = np .zeros ((nr ,nwav ))
33+ ext = np .zeros ((nr ,nwav ))
34+ ssa = np .zeros ((nr ,nwav ))
35+ sca = np .zeros ((nr ,nwav ))
36+ # Mie Theory & integrate over gamma PSD
37+ for i in range (nr ):
38+ r_out [i ], s [i ], v [i ], ext [i ,:], sca [i ,:], ssa [i ,:], asy [i ,:] = compute_Yang_singlesize (a ,2.0 * r [i ],rau ,wavenum_out ,wavenum_in ,d_in , s_in , v_in , ext_cross_section_in , sca_cross_section_in , asy_in )
39+ optics_outres = optics_var (r_out , s , v , ext , sca , ssa , asy , rau , wavenum = wavenum_out )
40+
41+ if thin_flag == True :
42+ optics_band = optics_outres .thin_average (source ,band_limit )
43+ else :
44+ optics_band = optics_outres .thick_average (source ,band_limit )
45+ optics_band .write_lut_spectralpoints (file_band )
46+
47+ v_range = np .zeros (np .shape (re_range_pade ))
48+ try :
49+ v_range [0 ,:] = interp1d (optics_band .r ,optics_band .v ** (1 / 3.0 ))(re_range_pade [0 ,:])** 3
50+ except :
51+ print ('WARNING: Padé approximant size range re_range exceeds lower-limit at ' + '{:4.1f}' .format (optics_band .r [0 ])+ ' microns' )
52+ v_range [0 ,:] = interp1d (optics_band .r ,optics_band .v ** (1 / 3.0 ),fill_value = "extrapolate" )(re_range_pade [0 ,:])** 3
53+ try :
54+ v_range [1 ,:] = interp1d (optics_band .r ,optics_band .v ** (1 / 3.0 ))(re_range_pade [1 ,:])** 3
55+ except :
56+ print ('WARNING: Padé approximant size range re_range exceeds upper-limit at ' + '{:4.1f}' .format (optics_band .r [- 1 ])+ ' microns' )
57+ v_range [1 ,:] = interp1d (optics_band .r ,optics_band .v ** (1 / 3.0 ),fill_value = "extrapolate" )(re_range_pade [1 ,:])** 3
58+ # output parameterization netcdf file following Padé approximant
59+ optics_band .create_pade_coeff (re_range_pade ,re_ref_pade ,v_range ,file_pade )
60+
61+
62+ def compute_Yang_singlesize (a ,d ,rau ,wavenum_out ,wavenum_in ,d_in , s_in , v_in , ext_cross_section_in , sca_cross_section_in , asy_in ):
63+ nwav = len (wavenum_in )
64+ dr = min (d / 100.0 ,1 ) # um, integrate step of particle size
65+ d_hres = np .append (np .array ([]), np .arange (dr , d * 3.5 , dr )) # radius
66+ d = np .array ([d ])
67+
68+ nr = len (d_hres )
69+ r_hres = d_hres / 2.0
70+ s_hres = np .zeros (np .shape (r_hres ))
71+ v_hres = np .zeros (np .shape (r_hres ))
72+
73+ ext_hres = np .zeros ((nwav ,nr ))
74+ scat_hres = np .zeros ((nwav ,nr ))
75+ asy_hres = np .zeros ((nwav ,nr ))
76+
2077 try :
2178 v_hres = interp1d (d_in [:], v_in [:]** (1 / 3.0 ))(d_hres [:])** 3.0
2279 s_hres = interp1d (d_in [:], s_in [:]** (1 / 2.0 ))(d_hres [:])** 2.0
@@ -35,40 +92,14 @@ def compute_ice(path_ori, habit, roughness, file_lut, file_pade, a, wavenum_out,
3592 scat_hres [scat_hres < 0 ] = 0
3693 asy_hres [asy_hres < 0 ] = 0
3794
38- # integrate over ice particle size distribution (PSD)
39- cloud_optics_inres = optics_var .gamma_int (wavenum_in , a , d_hres , v_hres , s_hres , d , dr , ext_hres , scat_hres , asy_hres , rau_ice )
40- del ext_hres , scat_hres , asy_hres
41- cloud_optics_outres = cloud_optics_inres .interp_cloud_optics (wavenum_out )
42-
43- if thin_flag == True :
44- cloud_optics_band = cloud_optics_outres .thin_average (source , band_limit )
45- else :
46- cloud_optics_band = cloud_optics_outres .thick_average (source , band_limit )
47-
48- v_range = np .zeros (np .shape (re_range_lut ))
49- try :
50- v_range [0 ,:] = interp1d (cloud_optics_band .r , cloud_optics_band .v ** (1 / 3.0 ))(re_range_lut [0 ,:])** 3
51- except :
52- print ('WARNING: look-up-table size range re_range exceeds lower-limit at ' + '{:4.1f}' .format (cloud_optics_band .r [0 ])+ ' microns' )
53- v_range [0 ,:] = interp1d (cloud_optics_band .r ,cloud_optics_band .v ** (1 / 3.0 ),fill_value = "extrapolate" )(re_range_lut [0 ,:])** 3
54- try :
55- v_range [1 ,:] = interp1d (cloud_optics_band .r ,cloud_optics_band .v ** (1 / 3.0 ))(re_range_lut [1 ,:])** 3
56- except :
57- print ('WARNING: look-up-table size range re_range exceeds upper-limit at ' + '{:4.1f}' .format (cloud_optics_band .r [- 1 ])+ ' microns' )
58- v_range [1 ,:] = interp1d (cloud_optics_band .r ,cloud_optics_band .v ** (1 / 3.0 ),fill_value = "extrapolate" )(re_range_lut [1 ,:])** 3
59- # output parameterization netcdf file following piece-wise linear interpolation
60- cloud_optics_band .create_lut_coeff (re_range_lut ,v_range ,file_lut )
61-
62- v_range = np .zeros (np .shape (re_range_pade ))
63- try :
64- v_range [0 ,:] = interp1d (cloud_optics_band .r ,cloud_optics_band .v ** (1 / 3.0 ))(re_range_pade [0 ,:])** 3
65- except :
66- print ('WARNING: Padé approximant size range re_range exceeds lower-limit at ' + '{:4.1f}' .format (cloud_optics_band .r [0 ])+ ' microns' )
67- v_range [0 ,:] = interp1d (cloud_optics_band .r ,cloud_optics_band .v ** (1 / 3.0 ),fill_value = "extrapolate" )(re_range_pade [0 ,:])** 3
68- try :
69- v_range [1 ,:] = interp1d (cloud_optics_band .r ,cloud_optics_band .v ** (1 / 3.0 ))(re_range_pade [1 ,:])** 3
70- except :
71- print ('WARNING: Padé approximant size range re_range exceeds upper-limit at ' + '{:4.1f}' .format (cloud_optics_band .r [- 1 ])+ ' microns' )
72- v_range [1 ,:] = interp1d (cloud_optics_band .r ,cloud_optics_band .v ** (1 / 3.0 ),fill_value = "extrapolate" )(re_range_pade [1 ,:])** 3
73- # output parameterization netcdf file following Padé approximant
74- cloud_optics_band .create_pade_coeff (re_range_pade ,re_ref_pade ,v_range ,file_pade )
95+ a = np .array ([a ])
96+ optics_inres = optics_var .gamma_int (wavenum_in , a , d_hres ,v_hres ,s_hres ,d ,dr ,ext_hres ,scat_hres ,asy_hres ,rau )
97+ optics_singlepsd = optics_inres .interp_cloud_optics (wavenum_out )
98+ r_out = optics_singlepsd .r
99+ s = optics_singlepsd .s
100+ v = optics_singlepsd .v
101+ ext = optics_singlepsd .ext
102+ sca = optics_singlepsd .sca
103+ ssa = optics_singlepsd .ssa
104+ asy = optics_singlepsd .asy
105+ return r_out , s , v , ext , sca , ssa , asy
0 commit comments