Go to the documentation of this file.
78 mc_antenna.set_gaussian_fwhm(za_fwhm, aa_fwhm);
126 const Index& max_time,
127 const Index& max_iter,
128 const Index& min_iter,
130 const Index& l_mc_scat_order,
131 const Index& t_interp_order,
138 "The atmospheric fields must be flagged to have "
139 "passed a consistency check (atmfields_checked=1).");
142 "The atmospheric geometry must be flagged to have "
143 "passed a consistency check (atmgeom_checked=1).");
146 throw runtime_error(
"The cloudbox must be activated (cloudbox_on=1).");
149 "The cloudbox must be flagged to have "
150 "passed a consistency check (cloudbox_checked=1).");
153 "The scat_data must be flagged to have "
154 "passed a consistency check (scat_data_checked=1).");
156 if (min_iter < 100)
throw runtime_error(
"*mc_min_iter* must be >= 100.");
158 if (max_time < 0 && max_iter < 0 && std_err < 0)
160 "At least one of std_err, max_time, and max_iter "
161 "must be positive.");
163 if (l_mc_scat_order <= 0)
164 throw runtime_error(
"*l_max_scat_order* must be > 0.");
168 "The option of f_index < 0 is not handled by this "
171 throw runtime_error(
"*f_index* is outside the range of *f_grid*.");
174 throw runtime_error(
"Only 3D atmospheres are handled. ");
178 os <<
"Expected number of columns in sensor_pos: 3.\n";
180 throw runtime_error(os.str());
184 os <<
"Expected number of rows in sensor_pos: 1.\n";
186 throw runtime_error(os.str());
191 os <<
"Expected number of columns in sensor_los: 2.\n";
193 throw runtime_error(os.str());
197 os <<
"Expected number of rows in sensor_los: 1.\n";
199 throw runtime_error(os.str());
204 time_t start_time =
time(NULL);
217 Z11maxvector[i_total] =
max(
scat_data[i_ss][i_se].pha_mat_data(
223 Numeric g, temperature, albedo, g_los_csc_theta;
234 Index termination_flag = 0;
265 bool convert_to_rjbt =
false;
269 convert_to_rjbt =
true;
274 os <<
"Invalid value for *iy_unit*:" <<
iy_unit <<
".\n"
275 <<
"This method allows only the options \"RJBT\" and \"1\".";
276 throw runtime_error(os.str());
284 bool keepgoing, oksampling;
294 Index scattering_order = 0;
306 R_stokes,
stokes_dim, prop_dir, prop_dir, R_prop, R_ant2enu);
358 out0 <<
"WARNING: A rejected path sampling (g=0)!\n(if this"
359 <<
"happens repeatedly, try to decrease *ppath_lmax*)";
360 }
else if (termination_flag == 1) {
372 }
else if (termination_flag == 2) {
375 local_surface_skin_t,
376 local_surface_emission,
378 local_surface_rmatrix,
389 if (local_surface_los.
empty()) {
401 for (
Index i = 0; i < local_surface_rmatrix.
nbooks(); i++) {
402 R11 += local_surface_rmatrix(i, 0, 0, 0);
409 I_i /= g * (1 - R11);
416 Numeric rsum = local_surface_rmatrix(i, 0, 0, 0);
419 rsum += local_surface_rmatrix(i, 0, 0, 0);
422 local_rte_los = local_surface_los(i,
joker);
427 Q /= g * local_surface_rmatrix(i, 0, 0, 0);
430 }
else if (inside_cloud) {
433 albedo = 1 - abs_vec_mono[0] / ext_mat_mono(0, 0);
436 if (rng.
draw() > albedo) {
439 Vector emission = abs_vec_mono;
440 emission *= planck_value;
442 mult(emissioncontri, evol_op, emission);
443 emissioncontri /= (g * (1 - albedo));
444 mult(I_i, Q, emissioncontri);
459 ext_mat_mono(0, 0) - abs_vec_mono[0],
463 Z /= g * g_los_csc_theta * albedo;
468 scattering_order += 1;
469 local_rte_los = new_rte_los;
475 Vector emission = abs_vec_mono;
476 emission *= planck_value;
478 mult(emissioncontri, evol_op, emission);
480 mult(I_i, Q, emissioncontri);
492 if (scattering_order < l_mc_scat_order) {
498 mult(I_hold, R_stokes, I_i);
502 assert(!std::isnan(I_i[j]));
503 Isquaredsum[j] += I_i[j] * I_i[j];
516 if (max_time > 0 && (
Index)(
time(NULL) - start_time) >= max_time) {
525 catch (
const std::runtime_error& e) {
528 out0 <<
"WARNING: A MC path sampling failed! Error was:\n";
529 cout << e.what() << endl;
532 "The MC path sampling has failed five times. A few failures "
533 "should be OK, but this number is suspiciously high and the "
534 "reason to these failures should be tracked down.");
539 if (convert_to_rjbt) {
589 const Index& t_interp_order,
603 throw runtime_error(
"This method requires that stokes_dim >= 2");
606 "The atmospheric fields must be flagged to have "
607 "passed a consistency check (atmfields_checked=1).");
610 "The atmospheric geometry must be flagged to have "
611 "passed a consistency check (atmgeom_checked=1).");
614 throw runtime_error(
"The cloudbox must be activated (cloudbox_on=1).");
617 "The cloudbox must be flagged to have "
618 "passed a consistency check (cloudbox_checked=1).");
621 "The scat_data must be flagged to have "
622 "passed a consistency check (scat_data_checked=1).");
626 "The option of f_index < 0 is not handled by this "
629 throw runtime_error(
"*f_index* is outside the range of *f_grid*.");
632 throw runtime_error(
"Only 3D atmospheres are handled.");
635 throw runtime_error(
"*mc_y_tx* must have size of *stokes_dim*.");
639 os <<
"Expected number of columns in sensor_pos: 3.\n";
641 throw runtime_error(os.str());
646 os <<
"Expected number of columns in sensor_los: 2.\n";
648 throw runtime_error(os.str());
653 "mc_max_iter must be positive, "
654 "as it is the only limiter.");
658 "The vector *range_bins* must contain strictly "
659 "increasing values.");
663 "The vector *range_bins* is not allowed to contain "
664 "negative distance or round-trip time.");
668 "MCRadar only works with "
669 "Gaussian antenna patterns.");
691 Index termination_flag = 0;
693 Vector range_bin_count(nbins);
706 Matrix pdir_array(1, 2), idir_array(1, 2);
720 for (
Index ibin = 0; ibin < nbins; ibin++) {
759 fac = cfac[0] / (2 *
PI);
762 os <<
"Invalid value for *iy_unit*:" <<
iy_unit <<
".\n"
763 <<
"This method allows only the options \"Ze\" and \"1\".";
764 throw runtime_error(os.str());
772 bool keepgoing, firstpass, integrity;
832 pnds(
joker, 0) = pnd_vec;
833 if (!inside_cloud || termination_flag != 0) {
840 Csca = ext_mat_mono(0, 0) - abs_vec_mono[0];
841 Cext = ext_mat_mono(0, 0);
842 if (anyptype_nonTotRan) {
843 const Numeric Irat = Ihold[1] / Ihold[0];
844 Csca += Irat * (ext_mat_mono(1, 0) - abs_vec_mono[1]);
845 Cext += Irat * ext_mat_mono(0, 1);
847 albedo = Csca / Cext;
885 Vector rte_los_antenna(2);
923 s_return =
ppath.end_lstep;
925 for (
Index ip = 1; ip < np2; ip++) {
926 s_return +=
ppath.lstep[ip - 1];
927 t_return +=
ppath.lstep[ip - 1] * 0.5 *
934 r_trav = 0.5 * (s_tot + s_return);
939 r_trav = t_tot + t_return;
943 if (r_trav <= r_max) {
963 pdir_array(0,
joker) = rte_los_geom;
964 idir_array(0,
joker) = local_rte_los;
981 pha_mat_Bulk(pha_mat_bulk, ptype_bulk, pha_mat_ssbulk, ptype_ssbulk);
988 mult(Ipath, evol_op, Ihold);
991 mult(Ihold, P, Ipath);
992 mult(I_i, trans_mat, Ihold);
994 if (Ihold[0] < 1e-40 || std::isnan(Ihold[0]) ||
995 std::isnan(Ihold[1]) ||
1001 if (r_trav > r_min && integrity) {
1005 while (r_bin < r_trav && ibin <= nbins + 1) {
1014 mc_antenna.return_los(antenna_wgt, R_rx, R_enu2ant);
1016 R_stokes,
stokes_dim, rx_dir, tx_dir, R_rx, R_ant2enu);
1017 mult(I_i_rot, R_stokes, I_i);
1021 assert(!std::isnan(I_i_rot[istokes]));
1022 Isum[ibiny] += antenna_wgt * I_i_rot[istokes];
1023 Isquaredsum[ibiny] += antenna_wgt * antenna_wgt *
1024 I_i_rot[istokes] * I_i_rot[istokes];
1026 range_bin_count[ibin] += 1;
1032 pdir_array(0,
joker) = new_rte_los;
1051 pha_mat_Bulk(pha_mat_bulk, ptype_bulk, pha_mat_ssbulk, ptype_ssbulk);
1056 mult(Ipath, Z, Ihold);
1058 local_rte_los = new_rte_los;
1072 if (!integrity) keepgoing =
false;
1078 for (
Index ibin = 0; ibin < nbins; ibin++) {
1081 if (range_bin_count[ibin] > 0) {
1082 y[ibiny] = Isum[ibiny] / ((
Numeric)mc_iter) / bin_height[ibin];
1084 bin_height[ibin] / bin_height[ibin] -
1085 y[ibiny] *
y[ibiny]) /
Index mc_iteration_count(Workspace &ws) noexcept
Index atmosphere_dim(Workspace &ws) noexcept
Ppath ppath_step(Workspace &ws) noexcept
Tensor3 z_field(Workspace &ws) noexcept
Numeric fac(const Index n)
fac
Agenda ppath_step_agenda(Workspace &ws) noexcept
Index atmgeom_checked(Workspace &ws) noexcept
void iy_space_agendaExecute(Workspace &ws, Matrix &iy, const Vector &f_grid, const Vector &rtp_pos, const Vector &rtp_los, const Agenda &input_agenda)
Index mc_max_scatorder(Workspace &ws) noexcept
const Numeric SPEED_OF_LIGHT
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 Numeric &ppath_lmax, const Numeric &ppath_lraytrace, const Numeric &taustep_limit, const Agenda &propmat_clearsky_agenda, const Index stokes_dim, const Index f_index, const Vector &f_grid, 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 ArrayOfArrayOfSingleScatteringData &scat_data, const Verbosity &verbosity)
mcPathTraceGeneral.
Vector mc_y_tx(Workspace &ws) noexcept
void id_mat(MatrixView I)
Identity Matrix.
Interpolation classes and functions created for use within Monte Carlo scattering simulations.
Vector lat_grid(Workspace &ws) noexcept
void ze_cfac(Vector &fac, const Vector &f_grid, const Numeric &ze_tref, const Numeric &k2)
Calculates factor to convert back-scattering to Ze.
Tensor4 pnd_field(Workspace &ws) noexcept
Verbosity verbosity(Workspace &ws) noexcept
void mult(ComplexVectorView y, const ConstComplexMatrixView &M, const ConstComplexVectorView &x)
Matrix-Vector Multiplication.
void mc_antennaSetPencilBeam(MCAntenna &mc_antenna, const Verbosity &)
WORKSPACE METHOD: mc_antennaSetPencilBeam.
void seed(unsigned long int n, const Verbosity &verbosity)
Seeds the Rng with the integer argument.
Index f_index(Workspace &ws) noexcept
ArrayOfIndex cloudbox_limits(Workspace &ws) noexcept
Vector y(Workspace &ws) noexcept
void mc_antennaSetGaussianByFWHM(MCAntenna &mc_antenna, const Numeric &za_fwhm, const Numeric &aa_fwhm, const Verbosity &)
WORKSPACE METHOD: mc_antennaSetGaussianByFWHM.
Index stokes_dim(Workspace &ws) noexcept
ArrayOfIndex mc_scat_order(Workspace &ws) noexcept
An Antenna object used by MCGeneral.
String iy_unit(Workspace &ws) noexcept
Numeric vector1(const StokesVector &a, const ConstVectorView &B, const StokesVector &da, const ConstVectorView &dB_dT, const StokesVector &dS, bool dT, Index i) noexcept
Tensor3 mc_points(Workspace &ws) noexcept
void mcPathTraceRadar(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 &stot, Numeric &ttot, Ppath &ppath_step, Index &termination_flag, bool &inside_cloud, const Agenda &ppath_step_agenda, const Numeric &ppath_lmax, const Numeric &ppath_lraytrace, const Agenda &propmat_clearsky_agenda, const bool &anyptype_nonTotRan, const Index stokes_dim, const Index f_index, const Vector &f_grid, const Vector &Iprop, 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 ArrayOfArrayOfSingleScatteringData &scat_data, const Verbosity &verbosity)
mcPathTraceRadar.
Agenda iy_space_agenda(Workspace &ws) noexcept
void Sample_los_uniform(VectorView new_rte_los, Rng &rng)
Sample_los_uniform.
The structure to describe a propagation path and releated quantities.
void MCGeneral(Workspace &ws, Vector &y, Index &mc_iteration_count, Vector &mc_error, Tensor3 &mc_points, ArrayOfIndex &mc_source_domain, ArrayOfIndex &mc_scat_order, 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 &ppath_step_agenda, const Numeric &ppath_lmax, const Numeric &ppath_lraytrace, const Agenda &iy_space_agenda, const Agenda &surface_rtprop_agenda, const Agenda &propmat_clearsky_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 Index &cloudbox_on, const ArrayOfIndex &cloudbox_limits, const Tensor4 &pnd_field, const ArrayOfArrayOfSingleScatteringData &scat_data, const Index &atmfields_checked, const Index &atmgeom_checked, const Index &scat_data_checked, const Index &cloudbox_checked, const String &iy_unit, const Index &mc_seed, const Numeric &std_err, const Index &max_time, const Index &max_iter, const Index &min_iter, const Numeric &taustep_limit, const Index &l_mc_scat_order, const Index &t_interp_order, const Verbosity &verbosity)
WORKSPACE METHOD: MCGeneral.
Agenda surface_rtprop_agenda(Workspace &ws) noexcept
Vector range_bins(Workspace &ws) noexcept
Numeric sqrt(const Rational r)
Square root.
const Numeric BOLTZMAN_CONST
Numeric invrayjean(const Numeric &i, const Numeric &f)
invrayjean
Implementation of Matrix, Vector, and such stuff.
member functions of the Rng class and gsl_rng code
This can be used to make arrays out of anything.
ArrayOfIndex mc_source_domain(Workspace &ws) noexcept
double draw()
Draws a double from the uniform distribution [0,1)
bool is_anyptype_nonTotRan(const ArrayOfArrayOfSingleScatteringData &scat_data)
is_anyptype_nonTotRan.
void Sample_los(VectorView new_rte_los, Numeric &g_los_csc_theta, MatrixView Z, Rng &rng, ConstVectorView rte_los, const ArrayOfArrayOfSingleScatteringData &scat_data, const Index f_index, const Index stokes_dim, ConstVectorView pnd_vec, ConstVectorView Z11maxvector, const Numeric Csca, const Numeric rtp_temperature, const Index t_interp_order)
Sample_los.
void pha_mat_Bulk(Tensor6 &pha_mat, Index &ptype, const ArrayOfTensor6 &pha_mat_ss, const ArrayOfIndex &ptypes_ss)
Scattering species bulk phase matrix.
void rotmat_stokes(MatrixView R_pra, const Index &stokes_dim, const Numeric &f1_dir, const Numeric &f2_dir, ConstMatrixView R_f1, ConstMatrixView R_f2)
rotmat_stokes.
Declarations having to do with the four output streams.
void MCSetSeedFromTime(Index &mc_seed, const Verbosity &)
WORKSPACE METHOD: MCSetSeedFromTime.
void surface_rtprop_agendaExecute(Workspace &ws, Numeric &surface_skin_t, 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)
Tensor4 vmr_field(Workspace &ws) noexcept
This file contains declerations of functions of physical character.
Index atmfields_checked(Workspace &ws) noexcept
Vector p_grid(Workspace &ws) noexcept
Ppath ppath(Workspace &ws) noexcept
NUMERIC Numeric
The type to use for all floating point numbers.
Linear algebra functions.
MCAntenna mc_antenna(Workspace &ws) noexcept
void pha_mat_NScatElems(ArrayOfArrayOfTensor6 &pha_mat, ArrayOfArrayOfIndex &ptypes, Matrix &t_ok, const ArrayOfArrayOfSingleScatteringData &scat_data, const Index &stokes_dim, const Vector &T_array, const Matrix &pdir_array, const Matrix &idir_array, const Index &f_index, const Index &t_interp_order)
Phase matrices from all scattering elements.
Index nbooks() const
Returns the number of books.
Time time(Workspace &ws) noexcept
Vector refellipsoid(Workspace &ws) noexcept
Vector f_grid(Workspace &ws) noexcept
Matrix sensor_pos(Workspace &ws) noexcept
ArrayOfArrayOfSingleScatteringData scat_data(Workspace &ws) noexcept
Vector lon_grid(Workspace &ws) noexcept
bool empty() const
Returns true if variable size is zero.
Numeric ppath_lmax(Workspace &ws) noexcept
Numeric ppath_lraytrace(Workspace &ws) noexcept
Index scat_data_checked(Workspace &ws) noexcept
Numeric planck(const Numeric &f, const Numeric &t)
planck
invlib::Vector< ArtsVector > Vector
invlib wrapper type for ARTS vectors.
Propagation path structure and functions.
void get_ppath_transmat(Workspace &ws, MatrixView &trans_mat, const Ppath &ppath, const Agenda &propmat_clearsky_agenda, const Index stokes_dim, const Index f_index, const Vector &f_grid, const Vector &p_grid, const Tensor3 &t_field, const Tensor4 &vmr_field, const ArrayOfIndex &cloudbox_limits, const Tensor4 &pnd_field, const ArrayOfArrayOfSingleScatteringData &scat_data, const Verbosity &verbosity)
get_ppath_transmat.
void ppathFromRtePos2(Workspace &ws, Ppath &ppath, Vector &rte_los, Numeric &ppath_lraytrace, const Agenda &ppath_step_agenda, const Index &atmosphere_dim, const Vector &p_grid, const Vector &lat_grid, const Vector &lon_grid, const Tensor3 &z_field, const Vector &f_grid, const Vector &refellipsoid, const Matrix &z_surface, const Vector &rte_pos, const Vector &rte_pos2, const Numeric &ppath_lmax, const Numeric &za_accuracy, const Numeric &pplrt_factor, const Numeric &pplrt_lowest, const Verbosity &verbosity)
WORKSPACE METHOD: ppathFromRtePos2.
bool is_increasing(ConstVectorView x)
Checks if a vector is sorted and strictly increasing.
Header file for logic.cc.
void mirror_los(Vector &los_mirrored, ConstVectorView los, const Index &atmosphere_dim)
Determines the backward direction for a given line-of-sight.
Declaration of functions in rte.cc.
Tensor3 t_field(Workspace &ws) noexcept
Header file for special_interp.cc.
Agenda propmat_clearsky_agenda(Workspace &ws) noexcept
void rotmat_enu(MatrixView R_ant2enu, ConstVectorView prop_los)
rotmat_enu.
Index mc_seed(Workspace &ws) noexcept
INDEX Index
The type to use for all integer numbers and indices.
ConstComplexMatrixView transpose(ConstComplexMatrixView m)
Const version of transpose.
void mc_antennaSetGaussian(MCAntenna &mc_antenna, const Numeric &za_sigma, const Numeric &aa_sigma, const Verbosity &)
WORKSPACE METHOD: mc_antennaSetGaussian.
void rte_losGeometricFromRtePosToRtePos2(Vector &rte_los, const Index &atmosphere_dim, const Vector &lat_grid, const Vector &lon_grid, const Vector &refellipsoid, const Vector &rte_pos, const Vector &rte_pos2, const Verbosity &)
WORKSPACE METHOD: rte_losGeometricFromRtePosToRtePos2.
Vector mc_error(Workspace &ws) noexcept
Matrix sensor_los(Workspace &ws) noexcept
Index mc_max_iter(Workspace &ws) noexcept
Index cloudbox_checked(Workspace &ws) noexcept
Matrix z_surface(Workspace &ws) noexcept
void MCRadar(Workspace &ws, Vector &y, Vector &mc_error, 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 Numeric &ppath_lmax, const Agenda &ppath_step_agenda, const Numeric &ppath_lraytrace, const Agenda &propmat_clearsky_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 Index &cloudbox_on, const ArrayOfIndex &cloudbox_limits, const Tensor4 &pnd_field, const ArrayOfArrayOfSingleScatteringData &scat_data, const Vector &mc_y_tx, const Vector &range_bins, const Index &atmfields_checked, const Index &atmgeom_checked, const Index &scat_data_checked, const Index &cloudbox_checked, const String &iy_unit, const Index &mc_max_scatorder, const Index &mc_seed, const Index &mc_max_iter, const Numeric &ze_tref, const Numeric &k2, const Index &t_interp_order, const Verbosity &verbosity)
WORKSPACE METHOD: MCRadar.
void pha_mat_ScatSpecBulk(ArrayOfTensor6 &pha_mat, ArrayOfIndex &ptype, const ArrayOfArrayOfTensor6 &pha_mat_se, const ArrayOfArrayOfIndex &ptypes_se, ConstMatrixView pnds, ConstMatrixView t_ok)
Scattering species bulk phase matrices.
The global header file for ARTS.
Index cloudbox_on(Workspace &ws) noexcept
This file contains basic functions to handle XML data files.