3 (
NAME(
"mc_z_field_is_1D" ),
6 "Flag for MCGeneral and associated methods.\n" 8 "If fields outside the cloud box are 1D, this flag can be set to 1\n" 9 "and the calculations will be more rapid.\n" 11 "Usage: Set by the user.\n" 19 (
NAME(
"mc_IWP_cloud_opt_pathCalc" ),
22 "Calculates the FOV averaged ice water path and cloud optical path\n" 23 "for a given viewing direction\n" 26 OUT(
"mc_IWP",
"mc_cloud_opt_path",
"mc_IWP_error",
27 "mc_cloud_opt_path_error",
"mc_iteration_count" ),
31 IN(
"mc_antenna",
"sensor_pos",
"sensor_los",
"ppath_step_agenda",
32 "p_grid",
"lat_grid",
"lon_grid",
"refellipsoid",
"z_surface",
33 "z_field",
"t_field",
"vmr_field",
"edensity_field",
34 "f_grid",
"f_index",
"cloudbox_limits",
"pnd_field",
35 "scat_data_array_mono",
"particle_masses",
"mc_seed" ),
39 GIN_DESC(
"Maximum number of iterations." )
48 Numeric& mc_cloud_opt_path_error,
49 Index& mc_iteration_count,
54 const Agenda& ppath_step_agenda,
58 const Vector& refellipsoid,
69 const Matrix& particle_masses,
72 const Index& max_iter,
75 const Numeric f_mono = f_grid[f_index];
77 if( particle_masses.
ncols() != 1 )
79 "*particle_masses* is only allowed to have a single column" );
87 ppath_step_agenda,p_grid,lat_grid,lon_grid,
88 refellipsoid,z_surface,z_field,t_field,vmr_field,
89 edensity_field, f_mono, cloudbox_limits,
90 pnd_field,scat_data_array_mono,particle_masses,
103 rng.
seed(mc_seed, verbosity);
105 while (mc_iteration_count<max_iter)
108 mc_iteration_count+=1;
111 ppath_step_agenda,p_grid,lat_grid,lon_grid,
112 refellipsoid,z_surface,z_field,t_field,
113 vmr_field,edensity_field, f_mono,
115 pnd_field,scat_data_array_mono,particle_masses,
118 iwp_squared+=iwp*iwp;
119 mc_cloud_opt_path+=cloud_opt_path;
120 tau_squared+=cloud_opt_path*cloud_opt_path;
122 mc_IWP/=(
Numeric)mc_iteration_count;
123 mc_cloud_opt_path/=(
Numeric)mc_iteration_count;
124 mc_IWP_error=sqrt((iwp_squared/(
Numeric)mc_iteration_count-mc_IWP*mc_IWP)
126 mc_cloud_opt_path_error=sqrt((tau_squared/(
Numeric)mc_iteration_count-
127 mc_cloud_opt_path*mc_cloud_opt_path)
161 Index& termination_flag,
163 const Agenda& ppath_step_agenda,
164 const Agenda& propmat_clearsky_agenda,
165 const Index stokes_dim,
171 const Vector& refellipsoid,
189 Matrix T(stokes_dim,stokes_dim);
194 Matrix opt_depth_mat(stokes_dim,stokes_dim),incT(stokes_dim,stokes_dim,0.0);
195 Matrix old_evol_op(stokes_dim,stokes_dim);
199 evol_opArray[1]=evol_op;
203 lon_grid, z_field, refellipsoid, z_surface,
204 0, cloudbox_limits,
false,
205 rte_pos, rte_los, verbosity );
210 Range p_range(cloudbox_limits[0],
211 cloudbox_limits[1]-cloudbox_limits[0]+1);
212 Range lat_range(cloudbox_limits[2],
213 cloudbox_limits[3]-cloudbox_limits[2]+1);
214 Range lon_range(cloudbox_limits[4],
215 cloudbox_limits[5]-cloudbox_limits[4]+1);
223 propmat_clearsky_agenda,
224 stokes_dim, f_mono, ppath_step.
gp_p[0], ppath_step.
gp_lat[0],
225 ppath_step.
gp_lon[0],p_grid[p_range],
226 t_field(p_range,lat_range,lon_range),
227 vmr_field(
joker,p_range,lat_range,lon_range),pnd_field,
228 scat_data_array_mono, cloudbox_limits,ppath_step.
los(0,
joker),
234 propmat_clearsky_agenda, f_mono,
236 p_grid, t_field, vmr_field );
239 ext_matArray[1]=ext_mat_mono;
240 abs_vecArray[1]=abs_vec_mono;
241 tArray[1]=temperature;
242 pnd_vecArray[1]=pnd_vec;
245 while ((evol_op(0,0)>r)&(!termination_flag))
254 "5000 path points have been reached. Is this an infinite loop?" );
256 evol_opArray[0]=evol_opArray[1];
257 ext_matArray[0]=ext_matArray[1];
258 abs_vecArray[0]=abs_vecArray[1];
260 pnd_vecArray[0]=pnd_vecArray[1];
263 refellipsoid, z_surface, -1);
276 propmat_clearsky_agenda, stokes_dim, f_mono,
277 ppath_step.
gp_p[np-1],ppath_step.
gp_lat[np-1],
278 ppath_step.
gp_lon[np-1],p_grid[p_range],
279 t_field(p_range,lat_range,lon_range),
280 vmr_field(
joker,p_range,lat_range,lon_range),pnd_field,
281 scat_data_array_mono, cloudbox_limits,ppath_step.
los(np-1,
joker),
287 propmat_clearsky_agenda, f_mono,
288 ppath_step.
gp_p[np-1], ppath_step.
gp_lat[np-1],
289 ppath_step.
gp_lon[np-1], p_grid, t_field, vmr_field);
292 ext_matArray[1]=ext_mat_mono;
293 abs_vecArray[1]=abs_vec_mono;
294 tArray[1]=temperature;
295 pnd_vecArray[1]=pnd_vec;
296 opt_depth_mat=ext_matArray[1];
297 opt_depth_mat+=ext_matArray[0];
298 opt_depth_mat*=-cum_l_step[np-1]/2;
300 if ( stokes_dim == 1 )
302 incT(0,0)=exp(opt_depth_mat(0,0));
306 for (
Index j=0;j<stokes_dim;j++)
308 incT(j,j)=exp(opt_depth_mat(j,j));
316 mult(evol_op,evol_opArray[0],incT);
317 evol_opArray[1]=evol_op;
337 if (termination_flag)
340 rte_pos = ppath_step.
pos(np-1,
Range(0,3));
341 rte_los = ppath_step.
los(np-1,
joker);
352 k=-opt_depth_mat(0,0)/cum_l_step[np-1];
353 ds=log(evol_opArray[0](0,0)/r)/k;
359 x[1]=cum_l_step[np-1];
363 assert(gp[0].idx==0);
365 interp(ext_mat_mono, itw, ext_matArray, gp[0]);
366 opt_depth_mat = ext_mat_mono;
367 opt_depth_mat+=ext_matArray[gp[0].idx];
368 opt_depth_mat*=-ds/2;
369 if ( stokes_dim == 1 )
371 incT(0,0)=exp(opt_depth_mat(0,0));
375 for (
Index i=0;i<stokes_dim;i++)
377 incT(i,i)=exp(opt_depth_mat(i,i));
385 mult(evol_op,evol_opArray[gp[0].idx],incT);
386 interp(abs_vec_mono, itw, abs_vecArray,gp[0]);
387 temperature=
interp(itw,tArray,gp[0]);
388 interp(pnd_vec, itw,pnd_vecArray,gp[0]);
394 for (
Index i=0; i<2; i++)
410 (
"A specialised 3D reversed Monte Carlo radiative algorithm, that\n" 411 "mimics independent pixel appoximation simulations.\n" 414 OUT(
"y",
"mc_iteration_count",
"mc_error",
"mc_points" ),
418 IN(
"mc_antenna",
"f_grid",
"f_index",
"sensor_pos",
"sensor_los",
419 "stokes_dim",
"atmosphere_dim",
"iy_space_agenda",
420 "surface_rtprop_agenda",
421 "propmat_clearsky_agenda",
"ppath_step_agenda",
"p_grid",
"lat_grid",
422 "lon_grid",
"z_field",
"refellipsoid",
"z_surface",
"t_field",
423 "vmr_field",
"edensity_field",
"cloudbox_limits",
"pnd_field",
424 "scat_data_array_mono",
"mc_seed",
"iy_unit",
425 "mc_std_err",
"mc_max_time",
"mc_max_iter",
"mc_min_iter",
426 "mc_z_field_is_1D" ),
435 Index& mc_iteration_count,
440 const Index& f_index,
443 const Index& stokes_dim,
444 const Index& atmosphere_dim,
445 const Agenda& iy_space_agenda,
446 const Agenda& surface_rtprop_agenda,
447 const Agenda& propmat_clearsky_agenda,
448 const Agenda& ppath_step_agenda,
453 const Vector& refellipsoid,
461 const Index& mc_seed,
465 const Index& max_time,
466 const Index& max_iter,
467 const Index& min_iter,
468 const Index& z_field_is_1D,
472 {
throw runtime_error(
"*mc_min_iter* must be >= 100." ); }
475 if (max_time<0 && max_iter<0 && std_err<0){
476 throw runtime_error(
"At least one of std_err, max_time, and max_iter must be positive" );
479 if (! (atmosphere_dim == 3))
482 "For montecarlo, atmosphere_dim must be 3.");
487 time_t start_time=time(NULL);
494 findZ11max(Z11maxvector,scat_data_array_mono);
496 rng.
seed(mc_seed, verbosity);
497 bool keepgoing,inside_cloud;
498 Numeric g,temperature,albedo,g_los_csc_theta;
499 Matrix A(stokes_dim,stokes_dim),Q(stokes_dim,stokes_dim),evol_op(stokes_dim,stokes_dim),
500 ext_mat_mono(stokes_dim,stokes_dim),
q(stokes_dim,stokes_dim),newQ(stokes_dim,stokes_dim),
501 Z(stokes_dim,stokes_dim);
503 mc_iteration_count=0;
504 Vector vector1(stokes_dim),abs_vec_mono(stokes_dim),I_i(stokes_dim),Isum(stokes_dim),
505 Isquaredsum(stokes_dim);
508 Index termination_flag=0;
509 mc_error.
resize(stokes_dim);
511 Matrix local_iy(1,stokes_dim),local_surface_emission(1,stokes_dim),local_surface_los;
519 Isum=0.0;Isquaredsum=0.0;
520 const Numeric f_mono = f_grid[f_index];
522 bool convert_to_rjbt=
false;
523 if ( y_unit ==
"RJBT" )
527 convert_to_rjbt=
true;
529 else if ( y_unit ==
"1" )
536 os <<
"Invalid value for *y_unit*:" << y_unit <<
".\n" 537 <<
"This method allows only the options \"RJBT\" and \"1\".";
538 throw runtime_error( os.str() );
544 mc_iteration_count+=1;
549 local_rte_pos=sensor_pos(0,
joker);
556 p_grid, lat_grid, lon_grid, t_field, z_field, vmr_field,
557 edensity_field,
Vector(1, f_mono), refellipsoid,
558 z_surface, 0, cloudbox_limits, local_rte_pos, local_rte_los,
565 evol_op, abs_vec_mono, temperature, ext_mat_mono, rng,
566 local_rte_pos, local_rte_los, pnd_vec, g,
567 termination_flag, inside_cloud,
568 propmat_clearsky_agenda,
569 stokes_dim, f_mono, p_grid,
570 lat_grid, lon_grid, z_field, refellipsoid, z_surface,
571 t_field, vmr_field, cloudbox_limits, pnd_field,
572 scat_data_array_mono, z_field_is_1D, ppath,
576 mc_points(ppath.
gp_p[np-1].idx,ppath.
gp_lat[np-1].idx,
577 ppath.
gp_lon[np-1].idx)+=1;
578 if (termination_flag==1)
581 local_rte_pos, local_rte_los,
588 else if (termination_flag==2)
603 for(
Index i=0; i<ppath.
np; i++ )
605 if( ppath.
pos(i,0) < zmin )
607 zmin = ppath.
pos(i,0);
608 latt = ppath.
pos(i,1);
609 lont = ppath.
pos(i,2);
617 local_surface_emission, local_surface_los,
618 local_surface_rmatrix,
Vector(1,f_grid[f_index]),
619 local_rte_pos, local_rte_los, surface_rtprop_agenda );
621 if (local_surface_los.
nrows()==0)
623 mult(vector1,evol_op,local_surface_emission(0,
joker));
631 Numeric R11=local_surface_rmatrix(0,0,0,0);
640 mult(vector1,evol_op,local_surface_emission(0,
joker));
648 local_rte_los=local_surface_los(0,
joker);
657 else if (inside_cloud)
661 albedo=1-abs_vec_mono[0]/ext_mat_mono(0,0);
664 if (rng.
draw()>albedo)
668 Vector emission=abs_vec_mono;
669 emission*=planck_value;
670 Vector emissioncontri(stokes_dim);
671 mult(emissioncontri,evol_op,emission);
672 emissioncontri/=(g*(1-albedo));
673 mult(I_i,Q,emissioncontri);
682 Sample_los (new_rte_los,g_los_csc_theta,Z,rng,local_rte_los,
683 scat_data_array_mono,stokes_dim,
684 pnd_vec,anyptype30,Z11maxvector,ext_mat_mono(0,0)-abs_vec_mono[0],temperature,
687 Z/=g*g_los_csc_theta*albedo;
693 local_rte_los=new_rte_los;
703 Vector emission=abs_vec_mono;
704 emission*=planck_value;
705 Vector emissioncontri(stokes_dim);
706 mult(emissioncontri,evol_op,emission);
708 mult(I_i,Q,emissioncontri);
714 for(
Index j=0; j<stokes_dim; j++)
716 assert(!isnan(I_i[j]));
717 Isquaredsum[j] += I_i[j]*I_i[j];
720 y/=(
Numeric)mc_iteration_count;
721 for(
Index j=0; j<stokes_dim; j++)
723 mc_error[j]=sqrt((Isquaredsum[j]/(
Numeric)mc_iteration_count-y[j]*y[j])/(
Numeric)mc_iteration_count);
725 if (std_err>0 && mc_iteration_count>=min_iter && mc_error[0]<std_err_i){
break;}
726 if (max_time>0 && (
Index)(time(NULL)-start_time)>=max_time){
break;}
727 if (max_iter>0 && mc_iteration_count>=max_iter){
break;}
729 if ( convert_to_rjbt )
731 for(
Index j=0; j<stokes_dim; j++)
734 mc_error[j]=
invrayjean(mc_error[j],f_grid[0]);
742 (
NAME(
"pha_matExtractManually" ),
745 "A simple function for manually extract a single phase matrix.\n" 747 "The function returns the phase matrix for a single particle, for\n" 748 "scattering from (za_in,aa_in) to (za_out,aa_out).\n" 750 "Only a single particle type is handled and *scat_data_array* must\n" 751 "have length 1. The frequency is selected by *f_grid* and *f_index*.\n" 752 "The temperature is set by *rtp_temperature*.\n" 756 GOUT(
"pha_mat_single" ),
759 "Phase matrix for a single frequency and combination of angles" ),
760 IN(
"f_grid",
"f_index",
"stokes_dim",
"scat_data_array",
762 GIN(
"za_out",
"aa_out",
"za_in",
"aa_in" ),
763 GIN_TYPE(
"Numeric",
"Numeric",
"Numeric",
"Numeric" ),
765 GIN_DESC(
"Outgoing zenith angle",
"Outgoing azimuth angle",
766 "Incoming zenith angle",
"Incoming azimuth angle" )
772 const Index& f_index,
773 const Index& stokes_dim,
775 const Numeric& rtp_temperature,
782 if( scat_data_array.
nelem() > 1 )
783 throw runtime_error(
"Only one element in *scat_data_array* is allowed." );
790 pha_mat.
resize( stokes_dim, stokes_dim );
793 scat_data, stokes_dim, pnd, rtp_temperature,
818 for (
Index i=0; i<ppath.
np-1; i++)
820 cumsum += ppath.
lstep[i];
821 cum_l_step[i+1] = cumsum;
849 Index& termination_flag,
851 const Agenda& propmat_clearsky_agenda,
852 const Index stokes_dim,
858 const Vector& refellipsoid,
865 const Index z_field_is_1D,
879 Matrix T(stokes_dim,stokes_dim);
884 Matrix opt_depth_mat(stokes_dim,stokes_dim),incT(stokes_dim,stokes_dim,0.0);
885 Matrix old_evol_op(stokes_dim,stokes_dim);
893 Vector lon_iw(2),lat_iw(2);
902 z_grid=z_field(
joker,0,0);
903 rv_ellips=refellipsoid[0];
904 rv_surface=rv_ellips+z_surface(0,0);
908 evol_opArray[1]=evol_op;
914 lon_grid, z_field, refellipsoid, z_surface,
915 0, cloudbox_limits,
false,
916 rte_pos, rte_los, verbosity );
918 gp_p=ppath_step.
gp_p[0];
919 gp_lat=ppath_step.
gp_lat[0];
920 gp_lon=ppath_step.
gp_lon[0];
929 Range p_range(cloudbox_limits[0],
930 cloudbox_limits[1]-cloudbox_limits[0]+1);
931 Range lat_range(cloudbox_limits[2],
932 cloudbox_limits[3]-cloudbox_limits[2]+1);
933 Range lon_range(cloudbox_limits[4],
934 cloudbox_limits[5]-cloudbox_limits[4]+1);
942 propmat_clearsky_agenda, stokes_dim, f_mono,
943 gp_p, gp_lat, gp_lon,p_grid[p_range],
944 t_field(p_range,lat_range,lon_range),
945 vmr_field(
joker,p_range,lat_range,lon_range),
946 pnd_field,scat_data_array_mono, cloudbox_limits,rte_los,
952 propmat_clearsky_agenda, f_mono,
953 gp_p, gp_lat, gp_lon, p_grid, t_field, vmr_field);
956 ext_matArray[1]=ext_mat_mono;
957 abs_vecArray[1]=abs_vec_mono;
958 tArray[1]=temperature;
959 pnd_vecArray[1]=pnd_vec;
963 Numeric ppc, lat0, lon0, za0, aa0;
965 while ((evol_op(0,0)>r)&(!termination_flag))
974 evol_opArray[0]=evol_opArray[1];
975 ext_matArray[0]=ext_matArray[1];
976 abs_vecArray[0]=abs_vecArray[1];
978 pnd_vecArray[0]=pnd_vecArray[1];
991 if (Dxy/
abs(tan(rte_los[0]*
DEG2RAD))>Dz){dz=Dz;}
992 else {dz=Dxy/
abs(tan(rte_los[0]*DEG2RAD));}
994 if(dz*
abs(tan(rte_los[0]*DEG2RAD))>Dxy){dxy=Dxy;}
995 else{dxy=dz*
abs(tan(rte_los[0]*DEG2RAD));}
996 lstep=sqrt(dxy*dxy+dz*dz);
999 poslos2cart( x, y, z,
dx, dy, dz, rte_pos[0], rte_pos[1], rte_pos[2],
1000 rte_los[0], rte_los[1] );
1005 ppc = rte_pos[0]*sin(DEG2RAD*rte_los[0]);
1011 cart2poslos(rte_pos[0],rte_pos[1],rte_pos[2],rte_los[0],rte_los[1],
1012 x,y,z,dx,dy,dz,ppc,lat0,lon0,za0,aa0);
1014 gridpos( gp_lat, lat_grid, rte_pos[1] );
1015 gridpos( gp_lon, lon_grid, rte_pos[2] );
1018 z_at_latlon( z_grid, p_grid, lat_grid, lon_grid, z_field, gp_lat, gp_lon );
1020 rv_ellips =
refell2d(refellipsoid,lat_grid,gp_lat);
1021 rv_surface = rv_ellips +
interp( itw, z_surface, gp_lat, gp_lon );
1023 alt = rte_pos[0] - rv_ellips;
1025 if ((alt>=z_grid[p_grid.
nelem()-1])&(rte_los[0]<=90))
1031 alt=z_grid[p_grid.
nelem()-1];
1032 rte_pos[0]=alt+rv_ellips;
1035 if( (rte_pos[0] <= rv_surface)&(rte_los[0]>=90) )
1038 rte_pos[0]=rv_surface;
1039 alt = rte_pos[0] - rv_ellips;
1048 for (
Index i=1;i<np_ipa;i++)
1051 if (new_gp_diff<=gp_diff)
1053 gp_diff=new_gp_diff;
1062 gp_lat=ppath.
gp_lat[i_closest];
1063 gp_lon=ppath.
gp_lon[i_closest];
1070 rv_ellips =
refell2d(refellipsoid,lat_grid,gp_lat);
1073 gp_p,gp_lat,gp_lon);
1074 rte_pos[1]=
interp(lat_iw, lat_grid,gp_lat);
1075 rte_pos[2]=
interp(lon_iw, lon_grid,gp_lon);
1079 cloudbox_limits,
false );
1084 ext_mat_mono, abs_vec_mono, pnd_vec, temperature,
1085 propmat_clearsky_agenda, stokes_dim,
1086 f_mono, gp_p,gp_lat, gp_lon, p_grid[p_range],
1087 t_field(p_range,lat_range,lon_range),
1088 vmr_field(
joker,p_range,lat_range,lon_range),
1089 pnd_field, scat_data_array_mono, cloudbox_limits,rte_los,
1095 propmat_clearsky_agenda, f_mono,
1096 gp_p, gp_lat, gp_lon, p_grid, t_field, vmr_field);
1100 ext_matArray[1]=ext_mat_mono;
1101 abs_vecArray[1]=abs_vec_mono;
1102 tArray[1]=temperature;
1103 pnd_vecArray[1]=pnd_vec;
1104 opt_depth_mat=ext_matArray[1];
1106 opt_depth_mat+=ext_matArray[0];
1107 opt_depth_mat*=-lstep/2;
1109 if ( stokes_dim == 1 )
1111 incT(0,0)=exp(opt_depth_mat(0,0));
1115 for (
Index j=0;j<stokes_dim;j++)
1117 incT(j,j)=exp(opt_depth_mat(j,j));
1124 mult(evol_op,evol_opArray[0],incT);
1125 assert(incT(0,0)<1);
1126 assert(evol_op(0,0)<1);
1127 evol_opArray[1]=evol_op;
1130 if (termination_flag)
1146 k=-log(incT(0,0))/lstep;
1148 ds=log(evol_opArray[0](0,0)/r)/k;
1156 interp(ext_mat_mono, itw1d, ext_matArray, gp);
1157 opt_depth_mat = ext_mat_mono;
1158 opt_depth_mat+=ext_matArray[gp.
idx];
1159 opt_depth_mat*=-ds/2;
1160 if ( stokes_dim == 1 )
1162 incT(0,0)=exp(opt_depth_mat(0,0));
1166 for (
Index i=0;i<stokes_dim;i++)
1168 incT(i,i)=exp(opt_depth_mat(i,i));
1176 mult(evol_op,evol_opArray[gp.
idx],incT);
1177 interp(abs_vec_mono, itw1d, abs_vecArray,gp);
1178 temperature=
interp(itw1d,tArray, gp);
1179 interp(pnd_vec, itw1d, pnd_vecArray, gp);
1185 cart2poslos(rte_pos[0],rte_pos[1],rte_pos[2],rte_los[0],rte_los[1],
1186 x,y,z,
dx,dy,dz,ppc,lat0,lon0,za0,aa0);
1213 const Agenda& ppath_step_agenda,
1217 const Vector& refellipsoid,
1222 const Tensor3& edensity_field,
1227 const Matrix& particle_masses,
1232 Vector local_rte_pos=rte_pos;
1233 Vector local_rte_los=rte_los;
1238 p_grid, lat_grid, lon_grid, t_field, z_field, vmr_field,
1239 edensity_field,
Vector(1, f_mono), refellipsoid,
1240 z_surface, 1, cloudbox_limits, local_rte_pos, local_rte_los, 0,
1250 Range p_range(cloudbox_limits[0],
1251 cloudbox_limits[1]-cloudbox_limits[0]+1);
1252 Range lat_range(cloudbox_limits[2],
1253 cloudbox_limits[3]-cloudbox_limits[2]+1);
1254 Range lon_range(cloudbox_limits[4],
1255 cloudbox_limits[5]-cloudbox_limits[4]+1);
1258 p_grid, lat_grid, lon_grid, t_field, z_field, vmr_field,
1259 edensity_field,
Vector(1, f_mono), refellipsoid,
1260 z_surface, 1, cloudbox_limits, local_rte_pos, local_rte_los,
1267 Matrix ext_mat_part(1, 1, 0.0);
1268 Vector abs_vec_part(1, 0.0);
1271 ppath.
gp_lat,ppath.
gp_lon,cloudbox_limits,p_grid[p_range],
1272 t_field(p_range,lat_range,lon_range),
1273 vmr_field(
joker,p_range,lat_range,lon_range),
1279 for (
Index i = 0; i < ppath.
np ; ++i)
1281 opt_propCalc(ext_mat_part,abs_vec_part,ppath.
los(i,0),ppath.
los(i,1),scat_data_array_mono,
1282 1, pnd_ppath(
joker, i), t_ppath[i], verbosity);
1283 k_vec[i]=ext_mat_part(0,0);
1285 assert(particle_masses.
ncols()==1);
1286 assert(pnd_vec.
nelem()==particle_masses.
nrows());
1287 iwc_vec[i]=pnd_vec*particle_masses(
joker,0);
1290 for (
Index i = 0; i < ppath.
np-1 ; ++i)
1293 iwp+=0.5*(iwc_vec[i+1]+iwc_vec[i])*ppath.
lstep[i];
1294 cloud_opt_path+=0.5*(k_vec[i+1]+k_vec[i])*ppath.
lstep[i];
1343 const Vector& cum_l_step,
1345 const Index& stokes_dim,
1350 Matrix incT(stokes_dim,stokes_dim,0.0);
1351 Matrix opt_depth_mat(stokes_dim,stokes_dim);
1358 gridpos(gp, cum_l_step, pathlength);
1360 interp(K, itw,ext_matArray,gp[0]);
1361 delta_s = pathlength - cum_l_step[gp[0].idx];
1363 opt_depth_mat+=ext_matArray[gp[0].idx];
1364 opt_depth_mat*=-delta_s/2;
1365 if ( stokes_dim == 1 )
1367 incT(0,0)=exp(opt_depth_mat(0,0));
1371 for (
Index i=0;i<stokes_dim;i++)
1373 incT(i,i)=exp(opt_depth_mat(i,i));
1381 mult(T,TArray[gp[0].idx],incT);
1383 interp(K_abs, itw, abs_vecArray,gp[0]);
1385 temperature=
interp(itw,t_ppath,gp[0]);
1387 for (
Index i=0;i<N_pt;i++)
1392 for (
Index i=0; i<2; i++)
1414 Index& termination_flag,
1416 const Agenda& ppath_step_agenda,
1417 const Numeric& ppath_lraytrace,
1418 const Agenda& propmat_clearsky_agenda,
1419 const Index stokes_dim,
1425 const Vector& refellipsoid,
1438 Matrix opt_depth_mat(stokes_dim,stokes_dim);
1439 Matrix incT(stokes_dim,stokes_dim,0.0);
1442 Matrix T(stokes_dim,stokes_dim);
1446 Matrix old_evol_op(stokes_dim,stokes_dim);
1452 evol_opArray[1]=evol_op;
1455 Range p_range( cloudbox_limits[0],
1456 cloudbox_limits[1]-cloudbox_limits[0]+1);
1457 Range lat_range( cloudbox_limits[2],
1458 cloudbox_limits[3]-cloudbox_limits[2]+1 );
1459 Range lon_range( cloudbox_limits[4],
1460 cloudbox_limits[5]-cloudbox_limits[4]+1 );
1464 lon_grid, z_field, refellipsoid, z_surface,
1465 0, cloudbox_limits,
false,
1466 rte_pos, rte_los, verbosity );
1475 cloudbox_limits, 0, 3 );
1481 temperature, propmat_clearsky_agenda,
1482 stokes_dim, f_mono, ppath_step.
gp_p[0],
1485 t_field(p_range,lat_range,lon_range),
1486 vmr_field(
joker,p_range,lat_range,lon_range),
1487 pnd_field, scat_data_array_mono, cloudbox_limits,
1488 ppath_step.
los(0,
joker), verbosity );
1493 propmat_clearsky_agenda, f_mono,
1495 ppath_step.
gp_lon[0], p_grid, t_field, vmr_field );
1500 ext_matArray[1] = ext_mat_mono;
1501 abs_vecArray[1] = abs_vec_mono;
1502 tArray[1] = temperature;
1503 pnd_vecArray[1] = pnd_vec;
1510 while( (evol_op(0,0)>r) && (!termination_flag) )
1516 throw runtime_error(
"5000 path points have been reached. " 1517 "Is this an infinite loop?" );
1520 evol_opArray[0] = evol_opArray[1];
1521 ext_matArray[0] = ext_matArray[1];
1522 abs_vecArray[0] = abs_vecArray[1];
1523 tArray[0] = tArray[1];
1524 pnd_vecArray[0] = pnd_vecArray[1];
1527 if( ip == ppath_step.
np-1 )
1530 z_field, vmr_field, f_grid,
1531 ppath_step_agenda );
1538 cloudbox_limits, 0, 3 );
1543 dl = ppath_step.
lstep[ip-1];
1548 temperature, propmat_clearsky_agenda,
1549 stokes_dim, f_mono, ppath_step.
gp_p[ip],
1552 t_field(p_range,lat_range,lon_range),
1553 vmr_field(
joker,p_range,lat_range,lon_range),
1554 pnd_field, scat_data_array_mono, cloudbox_limits,
1555 ppath_step.
los(ip,
joker), verbosity );
1560 propmat_clearsky_agenda, f_mono,
1562 ppath_step.
gp_lon[ip], p_grid, t_field,
1567 ext_matArray[1] = ext_mat_mono;
1568 abs_vecArray[1] = abs_vec_mono;
1569 tArray[1] = temperature;
1570 pnd_vecArray[1] = pnd_vec;
1571 opt_depth_mat = ext_matArray[1];
1572 opt_depth_mat += ext_matArray[0];
1573 opt_depth_mat *= -dl/2;
1576 if( opt_depth_mat(0,0) < -4 )
1578 out0 <<
"WARNING: A MC path step of high optical depth (" 1579 <<
abs(opt_depth_mat(0,0)) <<
")!\n";
1582 if( stokes_dim == 1 )
1583 { incT(0,0) = exp( opt_depth_mat(0,0) ); }
1586 for (
Index j=0;j<stokes_dim;j++)
1587 { incT(j,j) = exp( opt_depth_mat(j,j) ); }
1591 mult( evol_op, evol_opArray[0], incT );
1592 evol_opArray[1] = evol_op;
1594 if( evol_op(0,0)>r )
1600 if( ip == ppath_step.
np - 1 )
1603 { termination_flag = 2; }
1606 { termination_flag = 1; }
1612 if( termination_flag )
1614 rte_pos = ppath_step.
pos(ip,
joker);
1615 rte_los = ppath_step.
los(ip,
joker);
1626 k = -opt_depth_mat(0,0) / dl;
1627 ds = log( evol_opArray[0](0,0) / r ) / k;
1636 assert( gp[0].idx == 0 );
1638 interp( ext_mat_mono, itw, ext_matArray, gp[0] );
1639 opt_depth_mat = ext_mat_mono;
1640 opt_depth_mat += ext_matArray[gp[0].idx];
1641 opt_depth_mat *= -ds/2;
1642 if( stokes_dim == 1 )
1643 { incT(0,0) = exp( opt_depth_mat(0,0) ); }
1646 for (
Index i=0;i<stokes_dim;i++)
1647 { incT(i,i) = exp( opt_depth_mat(i,i) ); }
1651 mult( evol_op, evol_opArray[gp[0].idx], incT );
1652 interp( abs_vec_mono, itw, abs_vecArray,gp[0] );
1653 temperature =
interp( itw, tArray, gp[0] );
1654 interp( pnd_vec, itw, pnd_vecArray, gp[0] );
1655 for(
Index i=0; i<2; i++ )
1657 rte_pos[i] =
interp( itw, ppath_step.
pos(
Range(ip-1,2),i), gp[0] );
1658 rte_los[i] =
interp( itw, ppath_step.
los(
Range(ip-1,2),i), gp[0] );
1660 rte_pos[2] =
interp( itw, ppath_step.
pos(
Range(ip-1,2),2), gp[0] );
1663 assert(isfinite(g));
1666 const Index np = ip+1;
1689 assert( A.
ncols()==m );
INDEX Index
The type to use for all integer numbers and indices.
void clear_rt_vars_at_gp(Workspace &ws, MatrixView ext_mat_mono, VectorView abs_vec_mono, Numeric &temperature, const Agenda &propmat_clearsky_agenda, const Numeric &f_mono, const GridPos &gp_p, const GridPos &gp_lat, const GridPos &gp_lon, ConstVectorView p_grid, ConstTensor3View t_field, ConstTensor4View vmr_field)
clear_rt_vars_at_gp
Index nelem() const
Number of elements.
void interp_atmfield_by_gp(VectorView x, const Index &atmosphere_dim, ConstTensor3View x_field, const ArrayOfGridPos &gp_p, const ArrayOfGridPos &gp_lat, const ArrayOfGridPos &gp_lon)
interp_atmfield_by_gp
const Numeric BOLTZMAN_CONST
Global constant, the Boltzmann constant [J/K].
Numeric invrayjean(const Numeric &i, const Numeric &f)
invrayjean
void findZ11max(Vector &Z11maxvector, const ArrayOfSingleScatteringData &scat_data_array_mono)
findZ11max
void ppath_start_stepping(Ppath &ppath, const Index &atmosphere_dim, ConstVectorView p_grid, ConstVectorView lat_grid, ConstVectorView lon_grid, ConstTensor3View z_field, ConstVectorView refellipsoid, ConstMatrixView z_surface, const Index &cloudbox_on, const ArrayOfIndex &cloudbox_limits, const bool &ppath_inside_cloudbox_do, ConstVectorView rte_pos, ConstVectorView rte_los, const Verbosity &verbosity)
ppath_start_stepping
Numeric interp(ConstVectorView itw, ConstVectorView a, const GridPos &tc)
Red 1D Interpolate.
void cum_l_stepCalc(Vector &cum_l_step, const Ppath &ppath)
cum_l_stepCalc
void draw_los(VectorView &sampled_rte_los, Rng &rng, ConstVectorView bore_sight_los) const
draws a line of sight by sampling the antenna response function
void ppath_step_agendaExecute(Workspace &ws, Ppath &ppath_step, const Numeric ppath_lraytrace, const Tensor3 &t_field, const Tensor3 &z_field, const Tensor4 &vmr_field, const Vector &f_grid, const Agenda &input_agenda)
void ppath_step_geom_3d(Ppath &ppath, ConstVectorView lat_grid, ConstVectorView lon_grid, ConstTensor3View z_field, ConstVectorView refellipsoid, ConstMatrixView z_surface, const Numeric &lmax)
ppath_step_geom_3d
Numeric fractional_gp(const GridPos &gp)
fractional_gp
void pha_matExtractManually(Matrix &pha_mat, const Vector &f_grid, const Index &f_index, const Index &stokes_dim, const ArrayOfSingleScatteringData &scat_data_array, const Numeric &rtp_temperature, const Numeric &za_out, const Numeric &aa_out, const Numeric &za_in, const Numeric &aa_in, const Verbosity &verbosity)
Numeric refell2d(ConstVectorView refellipsoid, ConstVectorView lat_grid, const GridPos gp)
refell2d
All information for one workspace method.
void mcPathTraceIPA(Workspace &ws, MatrixView evol_op, Vector &abs_vec_mono, Numeric &temperature, MatrixView ext_mat_mono, Rng &rng, Vector &rte_pos, Vector &rte_los, Vector &pnd_vec, Numeric &g, Index &termination_flag, bool &inside_cloud, const Agenda &propmat_clearsky_agenda, const Index stokes_dim, const Numeric &f_mono, const Vector &p_grid, const Vector &lat_grid, const Vector &lon_grid, const Tensor3 &z_field, const Vector &refellipsoid, const Matrix &z_surface, const Tensor3 &t_field, const Tensor4 &vmr_field, const ArrayOfIndex &cloudbox_limits, const Tensor4 &pnd_field, const ArrayOfSingleScatteringData &scat_data_array_mono, const Index z_field_is_1D, const Ppath &ppath, const Verbosity &verbosity)
mcPathTraceIPA
Index nelem() const
Returns the number of elements.
Structure to store a grid position.
Index ppath_what_background(const Ppath &ppath)
ppath_what_background
void mult(VectorView y, const ConstMatrixView &M, const ConstVectorView &x)
Matrix Vector multiplication.
The implementation for String, the ARTS string class.
Index ncols() const
Returns the number of columns.
void Sample_los(VectorView new_rte_los, Numeric &g_los_csc_theta, MatrixView Z, Rng &rng, ConstVectorView rte_los, const ArrayOfSingleScatteringData &scat_data_array_mono, const Index stokes_dim, ConstVectorView pnd_vec, const bool anyptype30, ConstVectorView Z11maxvector, const Numeric Csca, const Numeric rtp_temperature, const Verbosity &verbosity)
Sample_los.
void scat_data_array_monoCalc(ArrayOfSingleScatteringData &scat_data_array_mono, const ArrayOfSingleScatteringData &scat_data_array, const Vector &f_grid, const Index &f_index, const Verbosity &)
WORKSPACE METHOD: scat_data_array_monoCalc.
void cart2poslos(Numeric &r, Numeric &lat, Numeric &za, const Numeric &x, const Numeric &z, const Numeric &dx, const Numeric &dz, const Numeric &ppc, const Numeric &lat0, const Numeric &za0)
cart2poslos
void matrix_exp_p30(MatrixView M, ConstMatrixView A)
matrix_exp_p30
void gridpos(ArrayOfGridPos &gp, ConstVectorView old_grid, ConstVectorView new_grid, const Numeric &extpolfac)
Set up a grid position Array.
bool is_inside_cloudbox(const Ppath &ppath_step, const ArrayOfIndex &cloudbox_limits, const bool include_boundaries)
void iy_space_agendaExecute(Workspace &ws, Matrix &iy, const Vector &f_grid, const Vector &rtp_pos, const Vector &rtp_los, const Agenda &input_agenda)
bool is_diagonal(ConstMatrixView A)
Checks if a square matrix is diagonal.
NUMERIC Numeric
The type to use for all floating point numbers.
void opt_propCalc(MatrixView ext_mat_mono, VectorView abs_vec_mono, const Numeric za, const Numeric aa, const ArrayOfSingleScatteringData &scat_data_array_mono, const Index stokes_dim, ConstVectorView pnd_vec, const Numeric rtp_temperature, const Verbosity &verbosity)
opt_propCalc
void interpTArray(Matrix &T, Vector &K_abs, Numeric &temperature, MatrixView &K, Vector &rte_pos, Vector &rte_los, VectorView &pnd_vec, const ArrayOfMatrix &TArray, const ArrayOfMatrix &ext_matArray, const ArrayOfVector &abs_vecArray, const Vector &t_ppath, const Matrix &pnd_ppath, const Vector &cum_l_step, const Numeric &pathlength, const Index &stokes_dim, const Ppath &ppath)
interpTarray
void z_at_latlon(VectorView z, ConstVectorView p_grid, ConstVectorView lat_grid, ConstVectorView lon_grid, ConstTensor3View z_field, const GridPos &gp_lat, const GridPos &gp_lon)
z_at_latlon
Numeric refell2r(ConstVectorView refellipsoid, const Numeric &lat)
refell2r
An Antenna object used by MCGeneral.
void iwp_cloud_opt_pathCalc(Workspace &ws, Numeric &iwp, Numeric &cloud_opt_path, const Vector &rte_pos, const Vector &rte_los, const Agenda &ppath_step_agenda, const Vector &p_grid, const Vector &lat_grid, const Vector &lon_grid, const Vector &refellipsoid, const Matrix &z_surface, const Tensor3 &z_field, const Tensor3 &t_field, const Tensor4 &vmr_field, const Tensor3 &edensity_field, const Numeric &f_mono, const ArrayOfIndex &cloudbox_limits, const Tensor4 &pnd_field, const ArrayOfSingleScatteringData &scat_data_array_mono, const Matrix &particle_masses, const Verbosity &verbosity)
iwp_cloud_opt_pathCalc
void resize(Index p, Index r, Index c)
Resize function.
const Numeric DEG2RAD
Global constant, conversion from degrees to radians.
This can be used to make arrays out of anything.
void MCIPA(Workspace &ws, Vector &y, Index &mc_iteration_count, Vector &mc_error, Tensor3 &mc_points, const MCAntenna &mc_antenna, const Vector &f_grid, const Index &f_index, const Matrix &sensor_pos, const Matrix &sensor_los, const Index &stokes_dim, const Index &atmosphere_dim, const Agenda &iy_space_agenda, const Agenda &surface_rtprop_agenda, const Agenda &propmat_clearsky_agenda, const Agenda &ppath_step_agenda, const Vector &p_grid, const Vector &lat_grid, const Vector &lon_grid, const Tensor3 &z_field, const Vector &refellipsoid, const Matrix &z_surface, const Tensor3 &t_field, const Tensor4 &vmr_field, const Tensor3 &edensity_field, const ArrayOfIndex &cloudbox_limits, const Tensor4 &pnd_field, const ArrayOfSingleScatteringData &scat_data_array_mono, const Index &mc_seed, const String &y_unit, const Numeric &std_err, const Index &max_time, const Index &max_iter, const Index &min_iter, const Index &z_field_is_1D, const Verbosity &verbosity)
void mcPathTraceGeneral(Workspace &ws, MatrixView evol_op, Vector &abs_vec_mono, Numeric &temperature, MatrixView ext_mat_mono, Rng &rng, Vector &rte_pos, Vector &rte_los, Vector &pnd_vec, Numeric &g, Ppath &ppath_step, Index &termination_flag, bool &inside_cloud, const Agenda &ppath_step_agenda, const Agenda &propmat_clearsky_agenda, const Index stokes_dim, const Numeric &f_mono, const Vector &p_grid, const Vector &lat_grid, const Vector &lon_grid, const Tensor3 &z_field, const Vector &refellipsoid, const Matrix &z_surface, const Tensor3 &t_field, const Tensor4 &vmr_field, const Tensor3 &edensity_field, const ArrayOfIndex &cloudbox_limits, const Tensor4 &pnd_field, const ArrayOfSingleScatteringData &scat_data_array_mono, const Verbosity &verbosity)
mcPathTraceGeneral
void resize(Index n)
Assignment operator from VectorView.
void cloud_atm_vars_by_gp(VectorView pressure, VectorView temperature, MatrixView vmr, MatrixView pnd, const ArrayOfGridPos &gp_p, const ArrayOfGridPos &gp_lat, const ArrayOfGridPos &gp_lon, const ArrayOfIndex &cloudbox_limits, ConstVectorView p_grid_cloud, ConstTensor3View t_field_cloud, ConstTensor4View vmr_field_cloud, ConstTensor4View pnd_field)
cloud_atm_vars_by_gp
void cloudy_rt_vars_at_gp(Workspace &ws, MatrixView ext_mat_mono, VectorView abs_vec_mono, VectorView pnd_vec, Numeric &temperature, const Agenda &propmat_clearsky_agenda, const Index stokes_dim, const Numeric &f_mono, const GridPos &gp_p, const GridPos &gp_lat, const GridPos &gp_lon, ConstVectorView p_grid_cloud, ConstTensor3View t_field_cloud, ConstTensor4View vmr_field_cloud, const Tensor4 &pnd_field, const ArrayOfSingleScatteringData &scat_data_array_mono, const ArrayOfIndex &cloudbox_limits, const Vector &rte_los, const Verbosity &verbosity)
cloudy_rt_vars_at_gp
A constant view of a Matrix.
Numeric planck(const Numeric &f, const Numeric &t)
planck
Index nbooks() const
Returns the number of books.
bool is_anyptype30(const ArrayOfSingleScatteringData &scat_data_array_mono)
is_anyptype30
void ppath_calc(Workspace &ws, Ppath &ppath, const Agenda &ppath_step_agenda, const Index &atmosphere_dim, const Vector &p_grid, const Vector &lat_grid, const Vector &lon_grid, const Tensor3 &t_field, const Tensor3 &z_field, const Tensor4 &vmr_field, const Vector &f_grid, const Vector &refellipsoid, const Matrix &z_surface, const Index &cloudbox_on, const ArrayOfIndex &cloudbox_limits, const Vector &rte_pos, const Vector &rte_los, const Numeric &ppath_lraytrace, const bool &ppath_inside_cloudbox_do, const Verbosity &verbosity)
ppath_calc
void id_mat(MatrixView I)
Identity Matrix.
void seed(unsigned long int n, const Verbosity &verbosity)
void mc_IWP_cloud_opt_pathCalc(Workspace &ws, Numeric &mc_IWP, Numeric &mc_cloud_opt_path, Numeric &mc_IWP_error, Numeric &mc_cloud_opt_path_error, Index &mc_iteration_count, const MCAntenna &mc_antenna, const Matrix &sensor_pos, const Matrix &sensor_los, const Agenda &ppath_step_agenda, const Vector &p_grid, const Vector &lat_grid, const Vector &lon_grid, const Vector &refellipsoid, const Matrix &z_surface, const Tensor3 &z_field, const Tensor3 &t_field, const Tensor4 &vmr_field, const Tensor3 &edensity_field, const Vector &f_grid, const Index &f_index, const ArrayOfIndex &cloudbox_limits, const Tensor4 &pnd_field, const ArrayOfSingleScatteringData &scat_data_array_mono, const Matrix &particle_masses, const Index &mc_seed, const Index &max_iter, const Verbosity &verbosity)
The structure to describe a propagation path and releated quantities.
This class contains all static information for one workspace variable.
bool is_gp_inside_cloudbox(const GridPos &gp_p, const GridPos &gp_lat, const GridPos &gp_lon, const ArrayOfIndex &cloudbox_limits, const bool &include_boundaries, const Index &atmosphere_dim)
void interpweights(VectorView itw, const GridPos &tc)
Red 1D interpolation weights.
void surface_rtprop_agendaExecute(Workspace &ws, Matrix &surface_emission, Matrix &surface_los, Tensor4 &surface_rmatrix, const Vector &f_grid, const Vector &rtp_pos, const Vector &rtp_los, const Agenda &input_agenda)
void poslos2cart(Numeric &x, Numeric &z, Numeric &dx, Numeric &dz, const Numeric &r, const Numeric &lat, const Numeric &za)
poslos2cart
const Numeric SPEED_OF_LIGHT
Index nrows() const
Returns the number of rows.
void pha_mat_singleCalc(MatrixView Z, const Numeric za_sca, const Numeric aa_sca, const Numeric za_inc, const Numeric aa_inc, const ArrayOfSingleScatteringData &scat_data_array_mono, const Index stokes_dim, ConstVectorView pnd_vec, const Numeric rtp_temperature, const Verbosity &verbosity)
pha_mat_singleCalc
AntennaType get_type(void) const
returns the antenna type
const Array< MdRecord > md_data_raw
Lookup information for workspace methods.
void resize(Index r, Index c)
Resize function.