59 #define PART_TYPE scat_data_raw[i_pt].ptype
60 #define F_DATAGRID scat_data_raw[i_pt].f_grid
61 #define T_DATAGRID scat_data_raw[i_pt].T_grid
62 #define ZA_DATAGRID scat_data_raw[i_pt].za_grid
63 #define AA_DATAGRID scat_data_raw[i_pt].aa_grid
64 #define PHA_MAT_DATA_RAW scat_data_raw[i_pt].pha_mat_data //CPD: changed from pha_mat_data
65 #define EXT_MAT_DATA_RAW scat_data_raw[i_pt].ext_mat_data //which wouldn't let me play with
66 #define ABS_VEC_DATA_RAW scat_data_raw[i_pt].abs_vec_data //scat_data_mono.
67 #define PND_LIMIT 1e-12 // If particle number density is below this value,
76 const Vector& scat_za_grid,
77 const Vector& scat_aa_grid,
78 const Index& scat_za_index,
79 const Index& scat_aa_index,
84 const Index& scat_p_index,
85 const Index& scat_lat_index,
86 const Index& scat_lon_index,
92 out3 <<
"Calculate *pha_mat_spt* from database\n";
97 if (stokes_dim > 4 || stokes_dim < 1){
98 throw runtime_error(
"The dimension of the stokes vector \n"
99 "must be 1,2,3 or 4");
102 assert( pha_mat_spt.
nshelves() == N_pt );
110 for (
Index i_pt = 0; i_pt < N_pt; i_pt++)
114 if (pnd_field(i_pt, scat_p_index, scat_lat_index, scat_lon_index) >
PND_LIMIT)
152 pha_mat_data_int(i_za_sca,
167 for (
Index za_inc_idx = 0; za_inc_idx < scat_za_grid.
nelem();
170 for (
Index aa_inc_idx = 0; aa_inc_idx < scat_aa_grid.
nelem();
179 aa_inc_idx, scat_za_grid, scat_aa_grid,
194 const Index& doit_za_grid_size,
195 const Vector& scat_aa_grid,
196 const Index& scat_za_index,
197 const Index& scat_aa_index,
198 const Numeric& rte_temperature,
200 const Index& scat_p_index,
201 const Index& scat_lat_index,
202 const Index& scat_lon_index,
206 if (pnd_field.
ncols() > 1)
208 assert(pha_mat_sptDOITOpt.
nelem() == scat_data_mono.
nelem());
211 assert(pha_mat_sptDOITOpt[0].nlibraries() == scat_data_mono[0].T_grid.
nelem());
212 assert(pha_mat_sptDOITOpt[0].nvitrines() == doit_za_grid_size);
213 assert(pha_mat_sptDOITOpt[0].nshelves() == scat_aa_grid.
nelem() );
214 assert(pha_mat_sptDOITOpt[0].nbooks() == doit_za_grid_size);
215 assert(pha_mat_sptDOITOpt[0].npages() == scat_aa_grid.
nelem());
219 else if ( pnd_field.
ncols() == 1 )
224 assert(pha_mat_sptDOITOpt.
nelem() == scat_data_mono.
nelem());
227 assert(pha_mat_sptDOITOpt[0].nlibraries() == scat_data_mono[0].T_grid.
nelem());
228 assert(pha_mat_sptDOITOpt[0].nvitrines() == doit_za_grid_size);
229 assert(pha_mat_sptDOITOpt[0].nshelves() == 1);
230 assert(pha_mat_sptDOITOpt[0].nbooks() == doit_za_grid_size);
231 assert(pha_mat_sptDOITOpt[0].npages() == scat_aa_grid.
nelem());
234 assert(doit_za_grid_size > 0);
238 nlinspace(za_grid, 0, 180, doit_za_grid_size);
243 if (stokes_dim > 4 || stokes_dim < 1){
244 throw runtime_error(
"The dimension of the stokes vector \n"
245 "must be 1,2,3 or 4");
248 assert( pha_mat_spt.
nshelves() == N_pt );
257 for (
Index i_pt = 0; i_pt < N_pt; i_pt ++)
262 if (pnd_field(i_pt, scat_p_index, scat_lat_index, scat_lon_index) >
PND_LIMIT)
264 if( scat_data_mono[i_pt].T_grid.
nelem() > 1)
267 os <<
"The temperature grid of the scattering data does not cover the \n"
268 "atmospheric temperature at cloud location. The data should \n"
269 "include the value T="<< rte_temperature <<
" K. \n";
273 gridpos(T_gp, scat_data_mono[i_pt].T_grid, rte_temperature);
280 for (
Index za_inc_idx = 0; za_inc_idx < doit_za_grid_size;
283 for (
Index aa_inc_idx = 0; aa_inc_idx < scat_aa_grid.
nelem();
286 if( scat_data_mono[i_pt].T_grid.
nelem() == 1)
288 pha_mat_spt(i_pt, za_inc_idx, aa_inc_idx,
joker,
joker) =
289 pha_mat_sptDOITOpt[i_pt](0, scat_za_index,
290 scat_aa_index, za_inc_idx,
297 for (
Index i = 0; i< stokes_dim; i++)
299 for (
Index j = 0; j< stokes_dim; j++)
301 pha_mat_spt(i_pt, za_inc_idx, aa_inc_idx, i, j)=
302 interp(itw,pha_mat_sptDOITOpt[i_pt]
303 (
joker, scat_za_index,
304 scat_aa_index, za_inc_idx,
305 aa_inc_idx, i, j) , T_gp);
322 const Vector& scat_za_grid,
323 const Vector& scat_aa_grid,
324 const Index& scat_za_index,
325 const Index& scat_aa_index,
326 const Index& f_index,
328 const Numeric& rte_temperature,
330 const Index& scat_p_index,
331 const Index& scat_lat_index,
332 const Index& scat_lon_index,
338 const Numeric za_sca = scat_za_grid[scat_za_index];
339 const Numeric aa_sca = scat_aa_grid[scat_aa_index];
341 if (stokes_dim > 4 || stokes_dim < 1){
342 throw runtime_error(
"The dimension of the stokes vector \n"
343 "must be 1,2,3 or 4");
346 assert( ext_mat_spt.
npages() == N_pt );
347 assert( abs_vec_spt.
nrows() == N_pt );
360 for (
Index i_pt = 0; i_pt < N_pt; i_pt++)
365 if (pnd_field(i_pt, scat_p_index, scat_lat_index, scat_lon_index) >
PND_LIMIT)
395 os <<
"The temperature grid of the scattering data does not cover the \n"
396 "atmospheric temperature at cloud location. The data should \n"
397 "include the value T="<< rte_temperature <<
" K. \n";
417 ext_mat_data_int(i_za_sca, i_aa_sca, i) =
419 i_za_sca, i_aa_sca, i),
436 abs_vec_data_int(i_za_sca, i_aa_sca, i) =
461 ext_mat_data_int(i_za_sca, i_aa_sca, i) =
463 i_za_sca, i_aa_sca, i),
480 abs_vec_data_int(i_za_sca, i_aa_sca, i) =
508 za_sca, aa_sca, verbosity);
519 const Index& atmosphere_dim,
520 const Index& scat_p_index,
521 const Index& scat_lat_index,
522 const Index& scat_lon_index,
529 Matrix ext_mat_part(stokes_dim, stokes_dim, 0.0);
532 if (stokes_dim > 4 || stokes_dim < 1){
534 "The dimension of stokes vector can be "
537 if ( ext_mat_spt.
ncols() != stokes_dim){
539 throw runtime_error(
" The columns of ext_mat_spt should "
540 "agree to stokes_dim");
543 if (atmosphere_dim == 1)
546 for (
Index l = 0; l < N_pt; l++)
550 for (
Index m = 0; m < stokes_dim; m++)
552 for (
Index n = 0; n < stokes_dim; n++)
555 ext_mat_part(m, n) +=
556 (ext_mat_spt(l, m, n) * pnd_field(l, scat_p_index, 0, 0));
564 if (atmosphere_dim == 3)
568 for (
Index l = 0; l < N_pt; l++)
572 for (
Index m = 0; m < stokes_dim; m++)
574 for (
Index n = 0; n < stokes_dim; n++)
577 ext_mat_part(m, n) += (ext_mat_spt(l, m, n) *
578 pnd_field(l, scat_p_index,
595 const Matrix& abs_vec_spt,
597 const Index& atmosphere_dim,
598 const Index& scat_p_index,
599 const Index& scat_lat_index,
600 const Index& scat_lon_index,
607 Vector abs_vec_part(stokes_dim, 0.0);
609 if ((stokes_dim > 4) || (stokes_dim <1)){
610 throw runtime_error(
"The dimension of stokes vector "
611 "can be only 1,2,3, or 4");
614 if (atmosphere_dim == 1)
617 for (
Index l = 0; l < N_pt ; ++l)
621 for (
Index m = 0; m < stokes_dim; ++m)
625 (abs_vec_spt(l, m) * pnd_field(l, scat_p_index, 0, 0));
632 if (atmosphere_dim == 3)
635 for (
Index l = 0; l < N_pt ; ++l)
639 for (
Index m = 0; m < stokes_dim; ++m)
642 abs_vec_part[m] += (abs_vec_spt(l, m) *
643 pnd_field(l, scat_p_index,
657 const Index& stokes_dim,
658 const Index& f_index,
666 freq_dim = f_grid.
nelem();
675 out2 <<
"Set dimensions of ext_mat as ["
678 << stokes_dim <<
"] and initialized to 0.\n";
684 const Matrix& abs_scalar_gas,
692 if ( stokes_dim != ext_mat.
nrows() )
693 throw runtime_error(
"Row dimension of ext_mat inconsistent with "
694 "column dimension.");
701 if ( f_dim != abs_scalar_gas.
nrows() )
702 throw runtime_error(
"Frequency dimension of ext_mat and abs_scalar_gas\n"
703 "are inconsistent in ext_matAddGas.");
709 for (
Index i=0; i<f_dim; ++i )
710 abs_total[i] = abs_scalar_gas(i,
joker).sum();
712 for (
Index i=0; i<stokes_dim; ++i )
726 const Index& stokes_dim,
727 const Index& f_index,
735 freq_dim = f_grid.
nelem();
743 out2 <<
"Set dimensions of abs_vec as ["
745 << stokes_dim <<
"] and initialized to 0.\n";
751 const Matrix& abs_scalar_gas,
759 if ( f_dim != abs_scalar_gas.
nrows() )
760 throw runtime_error(
"Frequency dimension of abs_vec and abs_scalar_gas\n"
761 "are inconsistent in abs_vecAddGas.");
765 for (
Index i=0; i<f_dim; ++i )
769 abs_vec(i,0) += abs_scalar_gas(i,
joker).sum();
826 const Index& atmosphere_dim,
827 const Index& scat_p_index,
828 const Index& scat_lat_index,
829 const Index& scat_lon_index,
838 pha_mat.
resize(Nza, Naa, stokes_dim, stokes_dim);
843 if (atmosphere_dim == 1)
846 for (
Index pt_index = 0; pt_index < N_pt; ++ pt_index)
849 for (
Index za_index = 0; za_index < Nza; ++ za_index)
851 for (
Index aa_index = 0; aa_index < Naa; ++ aa_index)
855 for (
Index stokes_index_1 = 0; stokes_index_1 < stokes_dim;
858 for (
Index stokes_index_2 = 0; stokes_index_2 < stokes_dim;
862 pha_mat(za_index, aa_index,
863 stokes_index_1, stokes_index_2) +=
865 (pha_mat_spt(pt_index, za_index, aa_index,
866 stokes_index_1, stokes_index_2) *
867 pnd_field(pt_index,scat_p_index, 0, 0));
874 if (atmosphere_dim == 3)
877 for (
Index pt_index = 0; pt_index < N_pt; ++ pt_index)
881 for (
Index za_index = 0; za_index < Nza; ++ za_index)
883 for (
Index aa_index = 0; aa_index < Naa; ++ aa_index)
887 for (
Index i = 0; i < stokes_dim; ++ i)
889 for (
Index j = 0; j < stokes_dim; ++ j)
893 pha_mat(za_index, aa_index, i,j ) +=
894 (pha_mat_spt(pt_index, za_index, aa_index, i, j) *
895 pnd_field(pt_index, scat_p_index,
896 scat_lat_index, scat_lon_index));
922 for (
Index i_pt = 0; i_pt < N_pt; i_pt++)
933 Numeric Csca_data = Cext - Cabs_data;
935 out1 <<
" Coefficients in database: \n"
936 <<
"Cext: " << Cext <<
" Cabs: " << Cabs_data <<
" Csca: " << Csca_data
937 <<
" \n Calculated absorption cooefficient: \n"
938 <<
"Cabs calculated: " << Cabs
939 <<
" Csca: " << Csca <<
"\n";
950 const Index& doit_za_grid_size,
951 const Vector& scat_aa_grid,
955 const Index& f_index,
956 const Index& atmosphere_dim,
957 const Index& stokes_dim,
966 if(atmosphere_dim == 1)
969 N_aa_sca = scat_aa_grid.
nelem();
972 nlinspace(za_grid, 0, 180, doit_za_grid_size);
974 assert( scat_data_raw.
nelem() == scat_data_mono.
nelem() );
978 pha_mat_sptDOITOpt.resize(N_pt);
980 for (
Index i_pt = 0; i_pt < N_pt; i_pt++)
982 Index N_T = scat_data_mono[i_pt].T_grid.
nelem();
983 pha_mat_sptDOITOpt[i_pt].resize(N_T, doit_za_grid_size, N_aa_sca,
984 doit_za_grid_size, scat_aa_grid.
nelem(),
985 stokes_dim, stokes_dim);
988 pha_mat_sptDOITOpt[i_pt]= 0.;
992 for (
Index t_idx = 0; t_idx < N_T; t_idx ++)
995 for (
Index za_sca_idx = 0; za_sca_idx < doit_za_grid_size; za_sca_idx ++)
997 for (
Index aa_sca_idx = 0; aa_sca_idx < N_aa_sca; aa_sca_idx ++)
1000 for (
Index za_inc_idx = 0; za_inc_idx < doit_za_grid_size;
1003 for (
Index aa_inc_idx = 0; aa_inc_idx <
1004 scat_aa_grid.
nelem();
1009 aa_sca_idx, za_inc_idx, aa_inc_idx,
1011 scat_data_mono[i_pt].
1015 scat_data_mono[i_pt].za_grid,
1016 scat_data_mono[i_pt].aa_grid,
1017 scat_data_mono[i_pt].ptype,
1038 const Index& f_index,
1047 for (
Index i = 0; i<scat_data_raw.
nelem(); i++)
1051 scat_data_raw[i].f_grid,
1072 scat_data_mono.resize(N_pt);
1075 for (
Index i_pt = 0; i_pt < N_pt; i_pt++)
1087 scat_data_mono[i_pt].f_grid.resize(1);
1088 scat_data_mono[i_pt].f_grid=f_grid[f_index];
1089 scat_data_mono[i_pt].T_grid=scat_data_raw[i_pt].T_grid;
1094 scat_data_mono[i_pt].pha_mat_data.resize(1,
1110 for (
Index i_za_inc = 0; i_za_inc <
1114 for (
Index i_aa_inc = 0;
1120 scat_data_mono[i_pt].pha_mat_data(0, t_index,
1137 scat_data_mono[i_pt].ext_mat_data.resize(1,
T_DATAGRID.nelem(),
1152 scat_data_mono[i_pt].ext_mat_data(0, t_index,
1153 i_za_sca, i_aa_sca, i)
1161 scat_data_mono[i_pt].abs_vec_data.resize(1,
T_DATAGRID.nelem(),
1176 scat_data_mono[i_pt].abs_vec_data(0, t_index, i_za_sca,
1195 const Vector& scat_za_grid,
1196 const Vector& scat_aa_grid,
1197 const Index& scat_za_index,
1198 const Index& scat_aa_index,
1199 const Numeric& rte_temperature,
1201 const Index& scat_p_index,
1202 const Index& scat_lat_index,
1203 const Index& scat_lon_index,
1207 const Index stokes_dim = ext_mat_spt.
ncols();
1208 const Numeric za_sca = scat_za_grid[scat_za_index];
1209 const Numeric aa_sca = scat_aa_grid[scat_aa_index];
1211 if (stokes_dim > 4 || stokes_dim < 1){
1212 throw runtime_error(
"The dimension of the stokes vector \n"
1213 "must be 1,2,3 or 4");
1216 assert( ext_mat_spt.
npages() == N_pt );
1217 assert( abs_vec_spt.
nrows() == N_pt );
1228 for (
Index i_pt = 0; i_pt < N_pt; i_pt++)
1232 if (pnd_field(i_pt, scat_p_index, scat_lat_index, scat_lon_index) >
PND_LIMIT)
1244 Index ext_npages = scat_data_mono[i_pt].ext_mat_data.npages();
1245 Index ext_nrows = scat_data_mono[i_pt].ext_mat_data.nrows();
1246 Index ext_ncols = scat_data_mono[i_pt].ext_mat_data.ncols();
1247 Index abs_npages = scat_data_mono[i_pt].abs_vec_data.npages();
1248 Index abs_nrows = scat_data_mono[i_pt].abs_vec_data.nrows();
1249 Index abs_ncols = scat_data_mono[i_pt].abs_vec_data.ncols();
1250 Tensor3 ext_mat_data1temp(ext_npages,ext_nrows,ext_ncols,0.0);
1251 Tensor3 abs_vec_data1temp(abs_npages,abs_nrows,abs_ncols,0.0);
1256 if (t_grid.
nelem() > 1)
1264 gridpos(t_gp, scat_data_mono[i_pt].T_grid, rte_temperature);
1266 for (
Index i_p = 0; i_p < ext_npages ; i_p++)
1268 for (
Index i_r = 0; i_r < ext_nrows ; i_r++)
1270 for (
Index i_c = 0; i_c < ext_ncols ; i_c++)
1272 ext_mat_data1temp(i_p,i_r,i_c)=
interp(itw,
1273 scat_data_mono[i_pt].ext_mat_data(0,
joker,i_p,i_r,i_c),t_gp);
1286 scat_data_mono[i_pt].za_grid,
1287 scat_data_mono[i_pt].aa_grid,
1288 scat_data_mono[i_pt].ptype,
1295 if (t_grid.
nelem() > 1)
1298 for (
Index i_p = 0; i_p < abs_npages ; i_p++)
1300 for (
Index i_r = 0; i_r < abs_nrows ; i_r++)
1302 for (
Index i_c = 0; i_c < abs_ncols ; i_c++)
1304 abs_vec_data1temp(i_p,i_r,i_c)=
interp(itw,
1305 scat_data_mono[i_pt].abs_vec_data(0,
joker,i_p,i_r,i_c),t_gp);
1318 scat_data_mono[i_pt].za_grid,
1319 scat_data_mono[i_pt].aa_grid,
1320 scat_data_mono[i_pt].ptype,
1334 const Index& doit_za_grid_size,
1335 const Vector& scat_aa_grid,
1336 const Index& scat_za_index,
1337 const Index& scat_aa_index,
1338 const Numeric& rte_temperature,
1340 const Index& scat_p_index,
1341 const Index& scat_lat_index,
1342 const Index& scat_lon_index,
1347 out3 <<
"Calculate *pha_mat_spt* from scat_data_mono. \n";
1350 nlinspace(za_grid, 0, 180, doit_za_grid_size);
1353 const Index stokes_dim = pha_mat_spt.
ncols();
1357 if (stokes_dim > 4 || stokes_dim < 1){
1358 throw runtime_error(
"The dimension of the stokes vector \n"
1359 "must be 1,2,3 or 4");
1362 assert( pha_mat_spt.
nshelves() == N_pt );
1370 for (
Index i_pt = 0; i_pt < N_pt; i_pt ++)
1375 if (pnd_field(i_pt, scat_p_index, scat_lat_index, scat_lon_index) >
1379 Tensor3 pha_mat_spt_tmp(scat_data_mono[i_pt].T_grid.
nelem(),
1382 pha_mat_spt_tmp = 0.;
1384 if( scat_data_mono[i_pt].T_grid.
nelem() > 1)
1387 os <<
"The temperature grid of the scattering data does not cover the \n"
1388 "atmospheric temperature at cloud location. The data should \n"
1389 "include the value T="<< rte_temperature <<
" K. \n";
1393 gridpos(T_gp, scat_data_mono[i_pt].T_grid, rte_temperature);
1399 for (
Index za_inc_idx = 0; za_inc_idx < doit_za_grid_size;
1402 for (
Index aa_inc_idx = 0; aa_inc_idx < scat_aa_grid.
nelem();
1405 for (
Index t_idx = 0; t_idx <
1406 scat_data_mono[i_pt].T_grid.
nelem();
1410 scat_data_mono[i_pt].
1414 scat_data_mono[i_pt].za_grid,
1415 scat_data_mono[i_pt].aa_grid,
1416 scat_data_mono[i_pt].ptype,
1417 scat_za_index, scat_aa_index,
1419 aa_inc_idx, za_grid, scat_aa_grid,
1423 if( scat_data_mono[i_pt].T_grid.
nelem() > 1)
1425 for (
Index i = 0; i< stokes_dim; i++)
1427 for (
Index j = 0; j< stokes_dim; j++)
1429 pha_mat_spt(i_pt, za_inc_idx, aa_inc_idx, i, j)=
1436 pha_mat_spt(i_pt, za_inc_idx, aa_inc_idx,
joker,
joker) =