64 #define FOR_ANALYTICAL_JACOBIANS_DO(what_to_do) \
65 for( Index iq=0; iq<jacobian_quantities.nelem(); iq++ ) \
67 if( jacobian_quantities[iq].Analytical() ) \
101 for(
Index irow=0; irow<diy_dx.
nrows(); irow++ )
103 for(
Index icol=0; icol<diy_dx.
ncols(); icol++ )
104 { diy_dx(irow,icol) += w * diy_dq(irow,icol); }
114 if( gp[i].fd[0] < 0 )
119 else if( gp[i].fd[0] > 1 )
131 const Index& atmosphere_dim,
137 const Numeric extpolfac = 1.0e99;
145 r_grid = jacobian_quantity.
Grids()[0];
148 p2gridpos( gp_p, r_grid, ppath_p, extpolfac );
154 if( atmosphere_dim > 1 )
156 gp_lat.resize(ppath.
np);
157 r_grid = jacobian_quantity.
Grids()[1];
158 nr2 = r_grid.
nelem();
165 if( atmosphere_dim > 2 )
167 gp_lon.resize(ppath.
np);
168 r_grid = jacobian_quantity.
Grids()[2];
174 if( atmosphere_dim == 1 )
176 for(
Index ip=0; ip<ppath.
np; ip++ )
178 if( gp_p[ip].fd[0] < 1 )
183 if( gp_p[ip].fd[0] > 0 )
192 else if( atmosphere_dim == 2 )
194 for(
Index ip=0; ip<ppath.
np; ip++ )
196 Index ix = nr1*gp_lat[ip].idx + gp_p[ip].idx;
200 gp_lat[ip].fd[1]*gp_p[ip].fd[1] );
204 gp_lat[ip].fd[1]*gp_p[ip].fd[0] );
208 gp_lat[ip].fd[0]*gp_p[ip].fd[1] );
212 gp_lat[ip].fd[0]*gp_p[ip].fd[0] );
217 else if( atmosphere_dim == 3 )
219 for(
Index ip=0; ip<ppath.
np; ip++ )
221 Index ix = nr2*nr1*gp_lon[ip].idx +
222 nr1*gp_lat[ip].idx + gp_p[ip].idx;
226 gp_lon[ip].fd[1]*gp_lat[ip].fd[1]*gp_p[ip].fd[1]);
230 gp_lon[ip].fd[1]*gp_lat[ip].fd[1]*gp_p[ip].fd[0]);
234 gp_lon[ip].fd[1]*gp_lat[ip].fd[0]*gp_p[ip].fd[1]);
238 gp_lon[ip].fd[1]*gp_lat[ip].fd[0]*gp_p[ip].fd[0]);
246 gp_lon[ip].fd[0]*gp_lat[ip].fd[1]*gp_p[ip].fd[1]);
250 gp_lon[ip].fd[0]*gp_lat[ip].fd[1]*gp_p[ip].fd[0]);
254 gp_lon[ip].fd[0]*gp_lat[ip].fd[0]*gp_p[ip].fd[1]);
258 gp_lon[ip].fd[0]*gp_lat[ip].fd[0]*gp_p[ip].fd[0]);
304 abs_species_i[iq] =
chk_contains(
"abs_species", abs_species, atag );
307 { abs_species_i[iq] = -1; }
364 Index& iy_error_type,
368 const Index& jacobian_do,
370 const Index& atmosphere_dim,
379 const Index& cloudbox_on,
380 const Index& stokes_dim,
382 const Agenda& iy_clearsky_agenda,
383 const Agenda& iy_space_agenda,
384 const Agenda& surface_prop_agenda,
385 const Agenda& iy_cloudbox_agenda,
406 rte_pos.
resize( atmosphere_dim );
407 rte_pos = ppath.
pos(np-1,
Range(0,atmosphere_dim));
411 if( atmosphere_dim > 1 )
413 if( atmosphere_dim > 2 )
416 out3 <<
"Radiative background: " << ppath.
background <<
"\n";
428 if( iy.
ncols() != stokes_dim || iy.
nrows() != nf )
431 os <<
"expected size = [" << stokes_dim <<
"," << nf <<
"]\n"
432 <<
"size of iy = [" << iy.
nrows() <<
"," << iy.
ncols()<<
"]\n"
433 <<
"The size of *iy* returned from *iy_space_agenda* is "
435 throw runtime_error( os.str() );
449 surface_rmatrix, rte_pos, rte_los,
450 rte_gp_p, rte_gp_lat, rte_gp_lon,
451 surface_prop_agenda );
461 "Number of columns in *surface_los* is not correct." );
462 if( nlos != surface_rmatrix.
nbooks() )
464 "Mismatch in size of *surface_los* and *surface_rmatrix*." );
465 if( surface_rmatrix.
npages() != nf )
467 "Mismatch in size of *surface_rmatrix* and *f_grid*." );
468 if( surface_rmatrix.
nrows() != stokes_dim ||
469 surface_rmatrix.
ncols() != stokes_dim )
471 "Mismatch between size of *surface_rmatrix* and *stokes_dim*." );
473 if( surface_emission.
ncols() != stokes_dim )
475 "Mismatch between size of *surface_emission* and *stokes_dim*." );
476 if( surface_emission.
nrows() != nf )
478 "Mismatch in size of *surface_emission* and f_grid*." );
482 Tensor3 I( nlos, nf, stokes_dim );
487 for(
Index ilos=0; ilos<nlos; ilos++ )
497 if( iy_transmission.
npages() )
506 lon_grid, r_geoid, z_surface,
507 rte_gp_lat, rte_gp_lat, los );
518 if( atmosphere_dim == 2 && los[0]<0 )
519 { los[0] =
max( -zamax+0.1, los[0] ); }
521 { los[0] =
min( zamax-0.1, los[0] ); }
528 if( iy_clearsky_agenda.
name() ==
"iy_clearsky_basic_agenda" )
531 cloudbox_on, iy_clearsky_agenda);
536 iy_aux, diy_dx, 0, iy_trans_new,
537 rte_pos, los, cloudbox_on, jacobian_do,
538 p_grid, lat_grid, lon_grid, t_field,
539 z_field, vmr_field, iy_clearsky_agenda );
547 surface_calc( iy, I, surface_los, surface_rmatrix, surface_emission );
556 iy_aux, diy_dx, iy_transmission,
557 rte_pos, rte_los, rte_gp_p, rte_gp_lat,
558 rte_gp_lon, iy_cloudbox_agenda );
560 if( iy.
nrows() != nf || iy.
ncols() != stokes_dim )
563 out1 <<
"expected size = [" << nf <<
"," << stokes_dim <<
"]\n";
564 out1 <<
"iy size = [" << iy.
nrows() <<
"," << iy.
ncols()<<
"]\n";
565 throw runtime_error(
"The size of *iy* returned from "
566 "*iy_cloudbox_agenda* is not correct." );
592 Index& iy_error_type,
595 const Index& imblock,
596 const Index& atmosphere_dim,
603 const Index& cloudbox_on,
604 const Index& stokes_dim,
610 const Index& antenna_dim,
611 const Agenda& iy_clearsky_agenda,
613 const Index& j_analytical_do,
622 if( antenna_dim == 1 )
624 const Index niyb = nf * nza * naa * stokes_dim;
635 if( j_analytical_do )
637 diyb_dx.resize( jacobian_indices.
nelem() );
639 diyb_dx[iq].resize( niyb, jacobian_indices[iq][1] -
640 jacobian_indices[iq][0] + 1 );
644 { diyb_dx.resize( 0 ); }
650 for(
Index is=0; is<stokes_dim; is++ )
651 { i_pol[is] = is + 1; }
656 Agenda l_iy_clearsky_agenda (iy_clearsky_agenda);
666 #pragma omp parallel for \
667 if(!arts_omp_in_parallel() && nza>1) \
668 firstprivate(l_ws, l_iy_clearsky_agenda)
669 for(
Index iza=0; iza<nza; iza++ )
675 for(
Index iaa=0; iaa<naa; iaa++ )
681 los = sensor_los( imblock,
joker );
682 los[0] += mblock_za_grid[iza];
686 if( antenna_dim == 2 )
687 {
map_daa( los[0], los[1], los[0], los[1],
688 mblock_aa_grid[iaa] ); }
689 else if( atmosphere_dim == 1 &&
abs(los[0]-90) > 90 )
690 {
if( los[0] < 0 ) { los[0] = -los[0]; }
691 else if( los[0] > 180 ) { los[0] = 360 - los[0]; } }
692 else if( atmosphere_dim == 2 &&
abs(los[0]) > 180 )
693 { los[0] = -
sign(los[0])*360 + los[0]; }
694 else if( atmosphere_dim == 3 &&
abs(los[0]-90) > 90 )
695 {
map_daa( los[0], los[1], los[0], los[1], 0 ); }
700 Matrix iy(0,0), iy_error(0,0), iy_aux(0,0);
701 Tensor3 iy_transmission(0,0,0);
707 iy_aux, diy_dx, 1, iy_transmission,
708 sensor_pos(imblock,
joker), los, cloudbox_on,
709 j_analytical_do, p_grid, lat_grid, lon_grid,
710 t_field, z_field, vmr_field, l_iy_clearsky_agenda );
714 const Index row0 = ( iza*naa + iaa ) * nf * stokes_dim;
718 if( j_analytical_do )
724 for(
Index ip=0; ip<jacobian_indices[iq][1] -
725 jacobian_indices[iq][0]+1; ip++ )
727 for(
Index is=0; is<stokes_dim; is++ )
729 diyb_dx[iq](
Range(row0+is,nf,stokes_dim),ip)=
730 diy_dx[iq](ip,
joker,is);
740 if( iy_error_type > 0 )
745 for(
Index is=0; is<stokes_dim; is++ )
747 iyb[
Range(row0+is,nf,stokes_dim)] = iy(
joker,is);
749 if( iy_error_type > 0 )
751 iyb_error[
Range(row0+is,nf,stokes_dim)] =
757 iyb_aux[
Range(row0+is,nf,stokes_dim)] = iy_aux(
joker,is);
764 catch (runtime_error e)
793 Index& iy_error_type,
796 const Index& iy_agenda_call1,
797 const Tensor3& iy_transmission,
800 const Index& jacobian_do,
801 const Index& atmosphere_dim,
813 const Index& cloudbox_on,
815 const Index& stokes_dim,
818 const Agenda& ppath_step_agenda,
819 const Agenda& abs_scalar_gas_agenda,
820 const Agenda& iy_clearsky_agenda,
821 const Agenda& iy_space_agenda,
822 const Agenda& surface_prop_agenda,
823 const Agenda& iy_cloudbox_agenda,
838 Index j_analytical_do = 0;
842 if( iy_agenda_call1 && j_analytical_do )
844 diy_dx.resize( jacobian_indices.
nelem() );
847 diy_dx[iq].resize( jacobian_indices[iq][1] - jacobian_indices[iq][0] +
857 ppath_calc( ws, ppath, ppath_step_agenda, atmosphere_dim, p_grid,
858 lat_grid, lon_grid, z_field, r_geoid, z_surface,
859 cloudbox_on, cloudbox_limits, rte_pos, rte_los, 1,
867 Vector ppath_p, ppath_t, ppath_wind_u, ppath_wind_v, ppath_wind_w;
871 Matrix emission_dummy, ppath_tau;
872 Tensor3 ppath_abs_scalar, iy_trans_new;
881 ppath_wind_u, ppath_wind_v, ppath_wind_w,
882 ppath, atmosphere_dim, p_grid, t_field, vmr_field,
883 wind_u_field, wind_v_field, wind_w_field );
887 emission_dummy, abs_scalar_gas_agenda, agenda_dummy,
888 ppath, ppath_p, ppath_t, ppath_vmr, ppath_wind_u,
889 ppath_wind_v, ppath_wind_w, f_grid, atmosphere_dim, 0 );
899 if( iy_agenda_call1 )
908 iy_trans_new, jacobian_do, ppath, atmosphere_dim,
909 p_grid, lat_grid, lon_grid, t_field, z_field,
910 vmr_field, r_geoid, z_surface, cloudbox_on, stokes_dim,
911 f_grid, iy_clearsky_agenda, iy_space_agenda,
912 surface_prop_agenda, iy_cloudbox_agenda, verbosity );
928 if( j_analytical_do )
930 diy_dpath.resize( nq );
931 abs_species_i.resize( nq );
935 diy_dpath[iq].resize( np, nf, stokes_dim );
939 jacobian_quantities, abs_species );
944 for(
Index iq=0; iq<is_t.
nelem() && do_t==0; iq++ )
945 {
if( is_t[iq] ) { do_t = 1; } }
949 Vector total_tau_dummy, t2 = ppath_t;
952 emission_dummy, abs_scalar_gas_agenda,
953 agenda_dummy, ppath, ppath_p, t2, ppath_vmr,
954 ppath_wind_u, ppath_wind_v, ppath_wind_w,
955 f_grid, atmosphere_dim, 0 );
960 for(
Index ip=np-2; ip>=0; ip-- )
964 if( j_analytical_do )
969 for(
Index iv=0; iv<nf; iv++ )
971 X[iv] = 0.5 * ppath.
l_step[ip] * exp( -total_tau[iv] );
976 for(
Index iq=0; iq<nq; iq++ )
978 if( jacobian_quantities[iq].Analytical() )
981 const Index isp = abs_species_i[iq];
988 jacobian_quantities[iq].Mode(),
989 ppath_vmr(isp,ip), ppath_p[ip],
992 jacobian_quantities[iq].Mode(),
993 ppath_vmr(isp,ip+1), ppath_p[ip+1],
996 for(
Index iv=0; iv<nf; iv++ )
999 for(
Index is=0; is<stokes_dim; is++ )
1001 const Numeric Z = -X[iv] * iy(iv,is);
1002 diy_dpath[iq](ip ,iv,is) += Z * unitscf1 *
1003 ppath_abs_scalar(iv,isp,ip);
1004 diy_dpath[iq](ip+1,iv,is) += Z * unitscf2 *
1005 ppath_abs_scalar(iv,isp,ip+1);
1013 for(
Index iv=0; iv<nf; iv++ )
1017 ppath_abs_scalar(iv,
joker,ip ).sum();
1019 ppath_abs_scalar(iv,
joker,ip+1).sum();
1021 ( ppath_as2(iv,
joker,ip ).sum() - k1 ) / dt;
1023 ( ppath_as2(iv,
joker,ip+1).sum() - k2 ) / dt;
1024 for(
Index is=0; is<stokes_dim; is++ )
1026 const Numeric Z = -X[iv] * iy(iv,is);
1027 diy_dpath[iq](ip ,iv,is) += Z * dkdt1;
1028 diy_dpath[iq](ip+1,iv,is) += Z * dkdt2;
1032 if( jacobian_quantities[iq].Subtag() ==
"HSE on" )
1034 const Numeric kbar = 0.5 * ( k1 + k2 );
1035 for(
Index is=0; is<stokes_dim; is++ )
1037 const Numeric Z = -X[iv] * iy(iv,is);
1038 diy_dpath[iq](ip ,iv,is) += Z * kbar /
1040 diy_dpath[iq](ip+1,iv,is) += Z * kbar /
1050 for(
Index iv=0; iv<nf; iv++ )
1051 { total_tau[iv] -= ppath_tau(iv,ip); }
1056 for(
Index iv=0; iv<nf; iv++ )
1058 const Numeric step_tr = exp( -ppath_tau(iv,ip) );
1060 for(
Index is=0; is<stokes_dim; is++ )
1061 { iy(iv,is) *= step_tr; }
1067 if( j_analytical_do )
1070 if( !iy_agenda_call1 )
1072 Matrix X, Y(stokes_dim,diy_dpath[0].npages());
1075 for(
Index iv=0; iv<nf; iv++ )
1087 diy_dpath[iq], atmosphere_dim, ppath, ppath_p );
1101 Index& iy_error_type,
1104 const Tensor3& iy_transmission,
1107 const Index& jacobian_do,
1108 const Index& atmosphere_dim,
1117 const Index& cloudbox_on,
1119 const Index& stokes_dim,
1121 const Agenda& ppath_step_agenda,
1122 const Agenda& abs_scalar_gas_agenda,
1123 const Agenda& iy_clearsky_agenda,
1125 const Index& use_mean_scat_data,
1127 const Agenda& opt_prop_gas_agenda,
1132 throw runtime_error(
"The cloudbox must be defined to use this method." );
1134 throw runtime_error(
1135 "This method does not provide any jacobians (jacobian_do must be 0)." );
1145 ppath_calc( ws, ppath, ppath_step_agenda, atmosphere_dim, p_grid,
1146 lat_grid, lon_grid, z_field, r_geoid, z_surface,
1147 cloudbox_on, cloudbox_limits, rte_pos, rte_los, 0,
1153 throw runtime_error(
"Observations where (unscattered) propagation path "
1154 "hits the surface inside the cloudbox are not yet "
1155 "handled by this method." );
1156 assert( bkgr == 3 );
1163 Vector ppath_p, ppath_t, ppath_wind_u, ppath_wind_v, ppath_wind_w;
1164 Matrix ppath_vmr, ppath_pnd;
1166 Matrix emission_dummy, ppath_tau;
1167 Tensor3 wind_field_dummy(0,0,0), iy_trans_new;
1168 Tensor3 ppath_asp_abs_vec, ppath_pnd_abs_vec, total_transmission;
1169 Tensor4 ppath_asp_ext_mat, ppath_pnd_ext_mat, ppath_transmission;
1179 ppath_wind_u, ppath_wind_v, ppath_wind_w,
1180 ppath, atmosphere_dim, p_grid, t_field, vmr_field,
1181 wind_field_dummy, wind_field_dummy, wind_field_dummy );
1184 get_ppath_pnd( ppath_pnd, ppath, atmosphere_dim, cloudbox_limits,
1189 ppath_pnd_abs_vec, ppath_pnd_ext_mat,
1190 ppath_transmission, total_transmission,
1191 emission_dummy, scat_data, abs_scalar_gas_agenda,
1192 agenda_dummy, opt_prop_gas_agenda,
1193 ppath, ppath_p, ppath_t, ppath_vmr, ppath_wind_u,
1194 ppath_wind_v, ppath_wind_w, ppath_pnd,
1195 use_mean_scat_data, scat_data_raw, stokes_dim,
1196 f_grid, atmosphere_dim, 0, verbosity );
1199 scat_data.resize( 0 );
1215 Vector rte_pos2, rte_los2;
1216 rte_pos2 = ppath.
pos(ppath.
np-1,
Range(0,atmosphere_dim));
1220 iy_aux, diy_dx, 0, iy_trans_new,
1221 rte_pos2, rte_los2, 0, jacobian_do,
1222 p_grid, lat_grid, lon_grid, t_field,
1223 z_field, vmr_field, iy_clearsky_agenda );
1228 for(
Index iv=0; iv<nf; iv++ )
1244 Index& iy_error_type,
1247 const Index& iy_agenda_call1,
1248 const Tensor3& iy_transmission,
1251 const Index& jacobian_do,
1252 const Index& atmosphere_dim,
1264 const Index& cloudbox_on,
1266 const Index& stokes_dim,
1269 const Agenda& ppath_step_agenda,
1270 const Agenda& emission_agenda,
1271 const Agenda& abs_scalar_gas_agenda,
1272 const Agenda& iy_clearsky_agenda,
1273 const Agenda& iy_space_agenda,
1274 const Agenda& surface_prop_agenda,
1275 const Agenda& iy_cloudbox_agenda,
1296 const Index nq = jacobian_quantities.
nelem();
1301 Index j_analytical_do = 0;
1305 if( iy_agenda_call1 && j_analytical_do )
1307 diy_dx.resize( nq );
1310 diy_dx[iq].resize( jacobian_indices[iq][1] - jacobian_indices[iq][0] +
1311 1, nf, stokes_dim );
1320 ppath_calc( ws, ppath, ppath_step_agenda, atmosphere_dim, p_grid,
1321 lat_grid, lon_grid, z_field, r_geoid, z_surface,
1322 cloudbox_on, cloudbox_limits, rte_pos, rte_los, 1,
1330 Vector ppath_p, ppath_t, ppath_wind_u, ppath_wind_v, ppath_wind_w;
1334 Matrix ppath_emission, ppath_tau;
1335 Tensor3 ppath_abs_scalar, iy_trans_new;
1343 ppath_wind_u, ppath_wind_v, ppath_wind_w,
1344 ppath, atmosphere_dim, p_grid, t_field, vmr_field,
1345 wind_u_field, wind_v_field, wind_w_field );
1349 ppath_emission, abs_scalar_gas_agenda, emission_agenda,
1350 ppath, ppath_p, ppath_t, ppath_vmr, ppath_wind_u,
1351 ppath_wind_v, ppath_wind_w, f_grid, atmosphere_dim, 1 );
1361 if( iy_agenda_call1 )
1370 iy_trans_new, jacobian_do, ppath, atmosphere_dim,
1371 p_grid, lat_grid, lon_grid, t_field, z_field,
1372 vmr_field, r_geoid, z_surface, cloudbox_on, stokes_dim,
1373 f_grid, iy_clearsky_agenda, iy_space_agenda,
1374 surface_prop_agenda, iy_cloudbox_agenda, verbosity);
1391 if( j_analytical_do )
1393 diy_dpath.resize( nq );
1394 abs_species_i.resize( nq );
1398 diy_dpath[iq].resize( np, nf, stokes_dim );
1399 diy_dpath[iq] = 0.0;
1402 jacobian_quantities, abs_species );
1407 for(
Index iq=0; iq<is_t.
nelem() && do_t==0; iq++ )
1408 {
if( is_t[iq] ) { do_t = 1; } }
1412 Vector total_tau_dummy, t2 = ppath_t;
1415 ppath_e2, abs_scalar_gas_agenda,
1416 emission_agenda, ppath, ppath_p, t2, ppath_vmr,
1417 ppath_wind_u, ppath_wind_v, ppath_wind_w,
1418 f_grid, atmosphere_dim, 1 );
1423 for(
Index ip=np-2; ip>=0; ip-- )
1426 Matrix iy_new(nf,stokes_dim);
1430 for(
Index iv=0; iv<nf; iv++ )
1432 const Numeric step_tr = exp( -ppath_tau(iv,ip) );
1435 esource[iv] = 0.5 * ( ppath_emission(iv,ip) +
1436 ppath_emission(iv,ip+1) );
1437 iy_new(iv,0) = iy(iv,0) * step_tr + esource[iv] * (1-step_tr);
1440 for(
Index is=1; is<stokes_dim; is++ )
1441 { iy_new(iv,is) = step_tr * iy(iv,is); }
1445 if( j_analytical_do )
1450 for(
Index iv=0; iv<nf; iv++ )
1452 X[iv] = 0.5 * ppath.
l_step[ip] * exp( -total_tau[iv] );
1453 Y[iv] = X[iv] * ( esource[iv] - iy(iv,0) );
1457 for(
Index iq=0; iq<nq; iq++ )
1459 if( jacobian_quantities[iq].Analytical() )
1462 const Index isp = abs_species_i[iq];
1469 jacobian_quantities[iq].Mode(),
1470 ppath_vmr(isp,ip), ppath_p[ip],
1473 jacobian_quantities[iq].Mode(),
1474 ppath_vmr(isp,ip+1), ppath_p[ip+1],
1477 for(
Index iv=0; iv<nf; iv++ )
1480 diy_dpath[iq](ip ,iv,0) += Y[iv] * unitscf1 *
1481 ppath_abs_scalar(iv,isp,ip);
1482 diy_dpath[iq](ip+1,iv,0) += Y[iv] * unitscf2 *
1483 ppath_abs_scalar(iv,isp,ip+1);
1485 for(
Index is=1; is<stokes_dim; is++ )
1487 const Numeric Z = -X[iv] * iy(iv,is);
1488 diy_dpath[iq](ip ,iv,is) += Z * unitscf1 *
1489 ppath_abs_scalar(iv,isp,ip);
1490 diy_dpath[iq](ip+1,iv,is) += Z * unitscf2 *
1491 ppath_abs_scalar(iv,isp,ip+1);
1499 for(
Index iv=0; iv<nf; iv++ )
1503 ppath_abs_scalar(iv,
joker,ip ).sum();
1505 ppath_abs_scalar(iv,
joker,ip+1).sum();
1507 ( ppath_as2(iv,
joker,ip ).sum() - k1 ) / dt;
1509 ( ppath_as2(iv,
joker,ip+1).sum() - k2 ) / dt;
1511 diy_dpath[iq](ip ,iv,0) += Y[iv] * dkdt1;
1512 diy_dpath[iq](ip+1,iv,0) += Y[iv] * dkdt2;
1514 for(
Index is=1; is<stokes_dim; is++ )
1516 const Numeric Z = -X[iv] * iy(iv,is);
1517 diy_dpath[iq](ip ,iv,is) += Z * dkdt1;
1518 diy_dpath[iq](ip+1,iv,is) += Z * dkdt2;
1523 exp(-(total_tau[iv]-ppath_tau(iv,ip))) *
1524 ( 1.0 - exp(-ppath_tau(iv,ip)) );
1525 diy_dpath[iq](ip ,iv,0) += V *
1527 ppath_emission(iv,ip) ) / dt;
1528 diy_dpath[iq](ip+1,iv,0) += V *
1529 ( ppath_e2(iv,ip+1) -
1530 ppath_emission(iv,ip+1) ) / dt;
1534 if( jacobian_quantities[iq].Subtag() ==
"HSE on" )
1537 const Numeric kbar = 0.5 * ( k1 + k2 );
1538 diy_dpath[iq](ip ,iv,0) += Y[iv] * kbar /
1540 diy_dpath[iq](ip+1,iv,0) += Y[iv] * kbar /
1543 for(
Index is=1; is<stokes_dim; is++ )
1545 const Numeric Z = -X[iv] * iy(iv,is);
1546 diy_dpath[iq](ip ,iv,is) += Z * kbar /
1548 diy_dpath[iq](ip+1,iv,is) += Z * kbar /
1558 for(
Index iv=0; iv<nf; iv++ )
1559 { total_tau[iv] -= ppath_tau(iv,ip); }
1568 if( j_analytical_do )
1571 if( !iy_agenda_call1 )
1573 Matrix X, Y(stokes_dim,diy_dpath[0].npages());
1576 for(
Index iv=0; iv<nf; iv++ )
1588 diy_dpath[iq], atmosphere_dim, ppath, ppath_p );
1597 iy_aux.
resize( nf, stokes_dim );
1599 for(
Index iv=0; iv<nf; iv++ )
1601 for(
Index is=0; is<stokes_dim; is++ )
1603 iy_aux( iv, is ) = iy_trans_new( iv, is, is );
1617 const Index& jacobian_do,
1618 const Index& atmosphere_dim,
1630 const Index& cloudbox_on,
1632 const Index& stokes_dim,
1634 const Agenda& ppath_step_agenda,
1635 const Agenda& emission_agenda,
1636 const Agenda& abs_scalar_gas_agenda,
1637 const Agenda& iy_clearsky_basic_agenda,
1638 const Agenda& iy_space_agenda,
1639 const Agenda& surface_prop_agenda,
1640 const Agenda& iy_cloudbox_agenda,
1646 throw runtime_error(
1647 "This method does not provide any jacobians (jacobian_do must be 0)" );
1657 ppath_calc( ws, ppath, ppath_step_agenda, atmosphere_dim, p_grid,
1658 lat_grid, lon_grid, z_field, r_geoid, z_surface,
1659 cloudbox_on, cloudbox_limits, rte_pos, rte_los, 1,
1666 Vector ppath_p, ppath_t, ppath_wind_u, ppath_wind_v, ppath_wind_w;
1670 Matrix ppath_emission, ppath_tau;
1671 Tensor3 ppath_abs_scalar, iy_trans_new;
1679 ppath_wind_u, ppath_wind_v, ppath_wind_w,
1680 ppath, atmosphere_dim, p_grid, t_field, vmr_field,
1681 wind_u_field, wind_v_field, wind_w_field );
1685 ppath_emission, abs_scalar_gas_agenda, emission_agenda,
1686 ppath, ppath_p, ppath_t, ppath_vmr, ppath_wind_u,
1687 ppath_wind_v, ppath_wind_w, f_grid, atmosphere_dim, 1 );
1698 0, ppath, atmosphere_dim, p_grid, lat_grid, lon_grid,
1699 t_field, z_field, vmr_field, r_geoid, z_surface,
1700 cloudbox_on, stokes_dim, f_grid,
1701 iy_clearsky_basic_agenda, iy_space_agenda,
1702 surface_prop_agenda, iy_cloudbox_agenda, verbosity );
1709 for(
Index ip=np-2; ip>=0; ip-- )
1712 for(
Index iv=0; iv<nf; iv++ )
1714 const Numeric step_tr = exp( -ppath_tau(iv,ip) );
1716 iy(iv,0) = iy(iv,0) * step_tr + 0.5 * (1-step_tr) *
1717 ( ppath_emission(iv,ip) + ppath_emission(iv,ip+1) );
1719 for(
Index is=1; is<stokes_dim; is++ )
1720 { iy(iv,is) *= step_tr; }
1735 Index& iy_error_type,
1738 const Index& iy_agenda_call1,
1739 const Tensor3& iy_transmission,
1742 const Index& jacobian_do,
1743 const Index& atmosphere_dim,
1752 const Index& cloudbox_on,
1754 const Index& cloudbox_checked,
1755 const Index& stokes_dim,
1758 const Agenda& iy_space_agenda,
1759 const Agenda& surface_prop_agenda,
1760 const Agenda& abs_scalar_gas_agenda,
1761 const Agenda& opt_prop_gas_agenda,
1765 const Index& mc_max_time,
1766 const Index& mc_max_iter,
1770 if( atmosphere_dim != 3 )
1771 throw runtime_error(
1772 "Only 3D atmospheres are allowed (atmosphere_dim must be 3)" );
1774 throw runtime_error(
1775 "The cloudbox must be activated (cloudbox_on must be 1)" );
1777 throw runtime_error(
1778 "This method does not provide any jacobians (jacobian_do must be 0)" );
1779 if( !iy_agenda_call1 )
1780 throw runtime_error(
1781 "Recursive usage not possible (iy_agenda_call1 must be 1)" );
1782 if( iy_transmission.
ncols() )
1783 throw runtime_error(
"*iy_transmission* must be empty" );
1791 iy.
resize( nf, stokes_dim );
1792 iy_error.
resize( nf, stokes_dim );
1801 Index mc_iteration_count, mc_seed;
1807 Matrix pos(1,3), los(1,2);
1809 pos(0,
joker) = rte_pos;
1810 los(0,
joker) = rte_los;
1812 for(
Index f_index=0; f_index<nf; f_index++ )
1817 f_grid, f_index, verbosity );
1825 MCGeneral( ws, y, mc_iteration_count, mc_error, mc_points, mc_antenna,
1826 f_grid, f_index, pos, los, stokes_dim, atmosphere_dim,
1827 iy_space_agenda, surface_prop_agenda, opt_prop_gas_agenda,
1828 abs_scalar_gas_agenda, p_grid, lat_grid, lon_grid, z_field,
1829 r_geoid, z_surface, t_field, vmr_field,
1830 cloudbox_on, cloudbox_limits,
1831 pnd_field, scat_data_mono, 1, cloudbox_checked,
1832 mc_seed, y_unit, mc_std_err, mc_max_time, mc_max_iter,
1836 assert( y.
nelem() == stokes_dim );
1839 if ( y_unit ==
"RJBT" )
1846 iy(f_index,
joker) = y;
1847 iy_error(f_index,
joker) = mc_error;
1866 const Index& basics_checked,
1867 const Index& atmosphere_dim,
1874 const Index& cloudbox_on,
1875 const Index& cloudbox_checked,
1876 const Index& stokes_dim,
1878 const Matrix& sensor_pos,
1879 const Matrix& sensor_los,
1880 const Vector& mblock_za_grid,
1881 const Vector& mblock_aa_grid,
1882 const Index& antenna_dim,
1883 const Sparse& sensor_response,
1884 const Vector& sensor_response_f,
1886 const Vector& sensor_response_za,
1887 const Vector& sensor_response_aa,
1888 const Agenda& iy_clearsky_agenda,
1890 const Agenda& jacobian_agenda,
1891 const Index& jacobian_do,
1900 if( antenna_dim == 1 )
1904 const Index niyb = nf * nza * naa * stokes_dim;
1913 if( !basics_checked )
1914 throw runtime_error(
"The atmosphere and basic control varaibles must be "
1915 "flagged to have passed a consistency check (basics_checked=1)." );
1916 if( !cloudbox_checked )
1917 throw runtime_error(
"The cloudbox must be flagged to have passed a "
1918 "consistency check (cloudbox_checked=1)." );
1922 if( sensor_pos.
ncols() != atmosphere_dim )
1923 throw runtime_error(
"The number of columns of sensor_pos must be "
1924 "equal to the atmospheric dimensionality." );
1925 if( atmosphere_dim <= 2 && sensor_los.
ncols() != 1 )
1926 throw runtime_error(
"For 1D and 2D, sensor_los shall have one column." );
1927 if( atmosphere_dim == 3 && sensor_los.
ncols() != 2 )
1928 throw runtime_error(
"For 3D, sensor_los shall have two columns." );
1929 if( sensor_los.
nrows() != nmblock )
1932 os <<
"The number of rows of sensor_pos and sensor_los must be "
1933 <<
"identical, but sensor_pos has " << nmblock <<
" rows,\n"
1934 <<
"while sensor_los has " << sensor_los.
nrows() <<
" rows.";
1935 throw runtime_error( os.str() );
1937 if(
max( sensor_los(
joker,0) ) > 180 )
1938 throw runtime_error(
1939 "First column of *sensor_los* is not allowed to have values above 180." );
1940 if( atmosphere_dim == 2 )
1942 if(
min( sensor_los(
joker,0) ) < -180 )
1943 throw runtime_error(
"For atmosphere_dim = 2, first column of "
1944 "*sensor_los* is not allowed to have values below -180." );
1948 if(
min( sensor_los(
joker,0) ) < 0 )
1949 throw runtime_error(
"For atmosphere_dim != 2, first column of "
1950 "*sensor_los* is not allowed to have values below 0." );
1952 if( atmosphere_dim == 3 &&
max( sensor_los(
joker,1) ) > 180 )
1953 throw runtime_error(
1954 "Second column of *sensor_los* is not allowed to have values above 180." );
1961 throw runtime_error(
"The measurement block zenith angle grid is empty." );
1964 if( antenna_dim == 1 )
1966 if( mblock_aa_grid.
nelem() != 0 )
1967 throw runtime_error(
1968 "For antenna_dim = 1, the azimuthal angle grid must be empty." );
1972 if( atmosphere_dim < 3 )
1973 throw runtime_error(
"2D antennas (antenna_dim=2) can only be "
1974 "used with 3D atmospheres." );
1975 if( mblock_aa_grid.
nelem() == 0 )
1976 throw runtime_error(
1977 "The measurement block azimuthal angle grid is empty." );
1983 if( sensor_response.
ncols() != niyb )
1986 os <<
"The *sensor_response* matrix does not have the right size,\n"
1987 <<
"either the method *sensor_responseInit* has not been run or some\n"
1988 <<
"of the other sensor response methods has not been correctly\n"
1990 throw runtime_error( os.str() );
1995 if( n1y != sensor_response_f.
nelem() || n1y != sensor_response_pol.
nelem() ||
1996 n1y != sensor_response_za.
nelem() || n1y != sensor_response_za.
nelem() )
1999 os <<
"Sensor auxiliary variables do not have the correct size.\n"
2000 <<
"The following variables should all have same size:\n"
2001 <<
"length(y) for one block : " << n1y <<
"\n"
2002 <<
"sensor_response_f.nelem() : " << sensor_response_f.
nelem()
2003 <<
"\nsensor_response_pol.nelem(): " << sensor_response_pol.
nelem()
2004 <<
"\nsensor_response_za.nelem() : " << sensor_response_za.
nelem()
2005 <<
"\nsensor_response_aa.nelem() : " << sensor_response_za.
nelem()
2007 throw runtime_error( os.str() );
2018 y_f.
resize( nmblock*n1y );
2019 y_pol.resize( nmblock*n1y );
2022 y_error.
resize( nmblock*n1y );
2023 y_aux.
resize( nmblock*n1y );
2030 Index j_analytical_do = 0;
2034 jacobian.
resize( nmblock*n1y,
2035 jacobian_indices[jacobian_indices.
nelem()-1][1]+1 );
2039 j_analytical_do = 1;
2043 { jacobian.
resize(0, 0); }
2053 Agenda l_jacobian_agenda (jacobian_agenda);
2054 Agenda l_iy_clearsky_agenda (iy_clearsky_agenda);
2063 #pragma omp parallel for \
2064 if(!arts_omp_in_parallel() && nmblock>1 && nmblock>=nza) \
2065 firstprivate(l_ws, l_jacobian_agenda, l_iy_clearsky_agenda)
2066 for(
Index imblock=0; imblock<nmblock; imblock++ )
2070 Vector iyb, iyb_aux, iyb_error, yb(n1y);
2071 Index iy_error_type;
2074 iyb_calc( l_ws, iyb, iyb_error, iy_error_type, iyb_aux, diyb_dx,
2075 imblock, atmosphere_dim, p_grid, lat_grid, lon_grid, t_field,
2076 z_field, vmr_field, cloudbox_on, stokes_dim, f_grid, sensor_pos,
2077 sensor_los, mblock_za_grid, mblock_aa_grid, antenna_dim,
2078 l_iy_clearsky_agenda, y_unit, j_analytical_do,
2079 jacobian_quantities, jacobian_indices, verbosity );
2087 mult( yb, sensor_response, iyb );
2093 if( iy_error_type == 1 )
2095 for(
Index i=0; i<n1y; i++ )
2097 const Index ithis = row0+i;
2099 for(
Index icol=0; icol<niyb; icol++ )
2101 y_error[ithis] += pow(
2102 sensor_response(i,icol)*iyb_error[icol], (
Numeric)2.0 );
2104 y_error[ithis] = sqrt( y_error[ithis] );
2107 else if( iy_error_type == 2 )
2108 {
mult( y_error[rowind], sensor_response, iyb_error ); }
2112 if( iyb_aux.
nelem() )
2113 {
mult( y_aux[rowind], sensor_response, iyb_aux ); }
2117 for(
Index i=0; i<n1y; i++ )
2119 y_f[row0+i] = sensor_response_f[i];
2120 y_pol[row0+i] = sensor_response_pol[i];
2121 y_pos(row0+i,
joker) = sensor_pos(imblock,
joker);
2122 y_los(row0+i,0) = sensor_los(imblock,0) + sensor_response_za[i];
2123 if( sensor_response_aa.
nelem() )
2125 y_los(row0+i,1) = sensor_los(imblock,0) + sensor_response_aa[i];
2132 if( j_analytical_do )
2135 mult( jacobian(rowind,
Range(jacobian_indices[iq][0],
2136 jacobian_indices[iq][1]-jacobian_indices[iq][0]+1)),
2137 sensor_response, diyb_dx[iq] );
2146 l_jacobian_agenda );
2166 {
throw runtime_error(
2167 "No need to use this method with *y_unit* = \"1\"." ); }
2172 os <<
"The spectrum vector *y* is required to have original radiance\n"
2173 <<
"unit, but this seems not to be the case. This as a value above\n"
2174 <<
"1e-3 is found in *y*.";
2175 throw runtime_error( os.str() );
2182 const bool do_j = jacobian.
nrows() == ny;
2183 const bool do_e = y_error.
nelem() == ny;
2186 if( do_j &&
max(jacobian) > 1e-3 )
2189 os <<
"The method can not be used with jacobian quantities that are not\n"
2190 <<
"obtained through radiative transfer calculations. One example on\n"
2191 <<
"quantity that can not be handled is *jacobianAddPolyfit*.\n"
2192 <<
"The maximum value of *jacobian* indicates that one or several\n"
2193 <<
"such jacobian quantities are included.";
2194 throw runtime_error( os.str() );
2203 if( y_unit ==
"PlanckBT" )
2218 while( i0+n < ny && y_f[i0] == y_f[i0+n] )
2223 bool any_quv =
false;
2225 for(
Index i=0; i<n; i++ )
2227 const Index ix=i0+i;
2229 i_pol[i] = y_pol[ix];
2230 if( i_pol[i] > 1 && i_pol[i] < 5 )
2239 if( any_quv && i_pol[0] != 1 )
2242 os <<
"The conversion to PlanckBT, of the Jacobian and "
2243 <<
"errors for Q, U and V, requires that I (first Stokes "
2244 <<
"element) is at hand and that the data are sorted in "
2245 <<
"such way that I comes first for each frequency.";
2246 throw runtime_error( os.str() );
2253 e(0,0,
joker) = y_error[ii];
2255 y_error[ii] = e(0,0,
joker);
2270 y[ii] = yv(0,
joker);
2286 for(
Index i=0; i<ny; i++ )
2289 i_pol[0] = y_pol[i];
2295 y_unit, y_f[i], i_pol );
2302 y_unit, y_f[i], i_pol );
2328 const Index& basics_checked,
2329 const Index& atmosphere_dim,
2336 const Index& cloudbox_on,
2337 const Index& cloudbox_checked,
2338 const Index& stokes_dim,
2340 const Matrix& sensor_pos,
2341 const Matrix& sensor_los,
2342 const Vector& mblock_za_grid,
2343 const Vector& mblock_aa_grid,
2344 const Index& antenna_dim,
2345 const Agenda& sensor_response_agenda,
2346 const Agenda& iy_clearsky_agenda,
2348 const Agenda& jacobian_agenda,
2349 const Index& jacobian_do,
2358 if( antenna_dim == 1 )
2361 const Index niyb = nf * nza * naa * stokes_dim;
2370 if( !basics_checked )
2371 throw runtime_error(
"The atmosphere and basic control varaibles must be "
2372 "flagged to have passed a consistency check (basics_checked=1)." );
2373 if( !cloudbox_checked )
2374 throw runtime_error(
"The cloudbox must be flagged to have passed a "
2375 "consistency check (cloudbox_checked=1)." );
2379 if( sensor_pos.
ncols() != atmosphere_dim )
2380 throw runtime_error(
"The number of columns of sensor_pos must be "
2381 "equal to the atmospheric dimensionality." );
2382 if( atmosphere_dim <= 2 && sensor_los.
ncols() != 1 )
2383 throw runtime_error(
"For 1D and 2D, sensor_los shall have one column." );
2384 if( atmosphere_dim == 3 && sensor_los.
ncols() != 2 )
2385 throw runtime_error(
"For 3D, sensor_los shall have two columns." );
2386 if( sensor_los.
nrows() != nmblock )
2389 os <<
"The number of rows of sensor_pos and sensor_los must be "
2390 <<
"identical, but sensor_pos has " << nmblock <<
" rows,\n"
2391 <<
"while sensor_los has " << sensor_los.
nrows() <<
" rows.";
2392 throw runtime_error( os.str() );
2394 if(
max( sensor_los(
joker,0) ) > 180 )
2395 throw runtime_error(
2396 "First column of *sensor_los* is not allowed to have values above 180." );
2397 if( atmosphere_dim == 2 )
2399 if(
min( sensor_los(
joker,0) ) < -180 )
2400 throw runtime_error(
"For atmosphere_dim = 2, first column of "
2401 "*sensor_los* is not allowed to have values below -180." );
2405 if(
min( sensor_los(
joker,0) ) < 0 )
2406 throw runtime_error(
"For atmosphere_dim != 2, first column of "
2407 "*sensor_los* is not allowed to have values below 0." );
2409 if( atmosphere_dim == 3 &&
max( sensor_los(
joker,1) ) > 180 )
2410 throw runtime_error(
2411 "Second column of *sensor_los* is not allowed to have values above 180." );
2418 throw runtime_error(
"The measurement block zenith angle grid is empty." );
2421 if( antenna_dim == 1 )
2423 if( mblock_aa_grid.
nelem() != 0 )
2424 throw runtime_error(
2425 "For antenna_dim = 1, the azimuthal angle grid must be empty." );
2429 if( atmosphere_dim < 3 )
2430 throw runtime_error(
"2D antennas (antenna_dim=2) can only be "
2431 "used with 3D atmospheres." );
2432 if( mblock_aa_grid.
nelem() == 0 )
2433 throw runtime_error(
2434 "The measurement block azimuthal angle grid is empty." );
2445 ArrayOfVector ya(nmblock), yf(nmblock), yerror(nmblock), yaux(nmblock);
2451 Index j_analytical_do = 0;
2456 j_analytical_do = 1;
2468 Agenda l_jacobian_agenda (jacobian_agenda);
2469 Agenda l_iy_clearsky_agenda (iy_clearsky_agenda);
2470 Agenda l_sensor_response_agenda (sensor_response_agenda);
2480 #pragma omp parallel for \
2481 if(!arts_omp_in_parallel() && nmblock>1 && nmblock>=nza) \
2482 firstprivate(l_ws, l_jacobian_agenda, l_iy_clearsky_agenda)
2483 for(
Index imblock=0; imblock<nmblock; imblock++ )
2487 Vector iyb, iyb_aux, iyb_error;
2488 Index iy_error_type;
2491 iyb_calc( l_ws, iyb, iyb_error, iy_error_type, iyb_aux, diyb_dx,
2492 imblock, atmosphere_dim, p_grid, lat_grid, lon_grid, t_field,
2493 z_field, vmr_field, cloudbox_on, stokes_dim, f_grid, sensor_pos,
2494 sensor_los, mblock_za_grid, mblock_aa_grid, antenna_dim,
2495 l_iy_clearsky_agenda, y_unit, j_analytical_do,
2496 jacobian_quantities, jacobian_indices, verbosity );
2501 Vector sensor_response_f;
2503 Vector sensor_response_za;
2504 Vector sensor_response_aa;
2507 sensor_response_pol, sensor_response_za,
2509 imblock, l_sensor_response_agenda );
2511 if( sensor_response.
ncols() != niyb )
2514 os <<
"The number of columns in *sensor_response* and the length\n"
2515 <<
"of *iyb* do not match.";
2516 throw runtime_error( os.str() );
2521 if( yl!=sensor_response_f.
nelem() || yl!=sensor_response_pol.
nelem() ||
2522 yl!= sensor_response_za.
nelem() || yl!=sensor_response_za.
nelem() )
2525 os <<
"Sensor auxiliary variables do not have the correct size.\n"
2526 <<
"The following variables should all have same size:\n"
2527 <<
"length(y) for one block : " << yl <<
"\n"
2528 <<
"sensor_response_f.nelem() : " << sensor_response_f.
nelem()
2529 <<
"\nsensor_response_pol.nelem(): " << sensor_response_pol.
nelem()
2530 <<
"\nsensor_response_za.nelem() : " << sensor_response_za.
nelem()
2531 <<
"\nsensor_response_aa.nelem() : " << sensor_response_za.
nelem()
2533 throw runtime_error( os.str() );
2538 ya[imblock].resize( yl );
2539 yf[imblock].resize( yl );
2540 ypol[imblock].resize( yl );
2541 ypos[imblock].resize( yl, sensor_pos.
ncols() );
2542 ylos[imblock].resize( yl, sensor_los.
ncols() );
2543 yerror[imblock].resize( yl );
2544 yaux[imblock].resize( yl );
2546 { ja[imblock].resize( yl,
2547 jacobian_indices[jacobian_indices.
nelem()-1][1]+1 ); }
2551 mult( ya[imblock], sensor_response, iyb );
2555 if( iy_error_type == 0 )
2556 { yerror[imblock] = 0; }
2557 else if( iy_error_type == 1 )
2559 for(
Index i=0; i<yl; i++ )
2561 yerror[imblock][i] = 0;
2562 for(
Index icol=0; icol<niyb; icol++ )
2564 yerror[imblock][i] += pow(
2565 sensor_response(i,icol)*iyb_error[icol], (
Numeric)2.0 );
2567 yerror[imblock][i] = sqrt( yerror[imblock][i] );
2570 else if( iy_error_type == 2 )
2571 {
mult( yerror[imblock], sensor_response, iyb_error ); }
2575 if( iyb_aux.
nelem() )
2576 {
mult( yaux[imblock], sensor_response, iyb_aux ); }
2578 { yaux[imblock] = 999; }
2582 for(
Index i=0; i<yl; i++ )
2584 yf[imblock][i] = sensor_response_f[i];
2585 ypol[imblock][i] = sensor_response_pol[i];
2586 ypos[imblock](i,
joker) = sensor_pos(imblock,
joker);
2587 ylos[imblock](i,0) = sensor_los(imblock,0)+sensor_response_za[i];
2588 if( sensor_response_aa.
nelem() )
2589 { ylos[imblock](i,1) = sensor_los(imblock,0)+sensor_response_aa[i];}
2595 if( j_analytical_do )
2599 jacobian_indices[iq][1]-jacobian_indices[iq][0]+1)),
2600 sensor_response, diyb_dx[iq] );
2609 l_jacobian_agenda );
2616 Index i0 =0 , n = 0;
2618 for(
Index m=0; m<nmblock; m++ )
2619 { n += ya[m].nelem(); }
2629 { jacobian.
resize( n, jacobian_indices[jacobian_indices.
nelem()-1][1]+1 );}
2631 for(
Index m=0; m<nmblock; m++ )
2633 for(
Index i=0; i<ya[m].nelem(); i++ )
2635 const Index r = i0 + i;
2638 y_pol[r] = ypol[m][i];
2641 y_error[r] = yerror[m][i];
2642 y_aux[r] = yaux[m][i];
2646 i0 += ya[m].
nelem();