59 const Index& atmosphere_dim,
63 const Index n = gp_p.
nelem();
65 if (atmosphere_dim == 1) {
70 else if (atmosphere_dim == 2) {
76 else if (atmosphere_dim == 3) {
85 const Index& atmosphere_dim,
86 ConstTensor3View x_field,
90 ConstMatrixView itw) {
93 if (atmosphere_dim == 1) {
95 interp(x, itw, x_field(Range(joker), 0, 0), gp_p);
98 else if (atmosphere_dim == 2) {
100 interp(x, itw, x_field(Range(joker), Range(joker), 0), gp_p, gp_lat);
103 else if (atmosphere_dim == 3) {
105 interp(x, itw, x_field, gp_p, gp_lat, gp_lon);
110 const Index& atmosphere_dim,
111 ConstTensor3View x_field,
123 ConstTensor3View x_field,
131 if (atmosphere_dim > 1) {
136 if (atmosphere_dim > 2) {
155 const Index& atmosphere_dim,
158 if (atmosphere_dim == 1) {
160 gp_p_out.
idx -= cloudbox_limits[0];
164 }
else if (atmosphere_dim == 2) {
167 gp_p_out.
idx -= cloudbox_limits[0];
168 gp_lat_out.
idx -= cloudbox_limits[2];
177 gp_p_out.
idx -= cloudbox_limits[0];
178 gp_lat_out.
idx -= cloudbox_limits[2];
179 gp_lon_out.
idx -= cloudbox_limits[4];
208 const Index& atmosphere_dim,
211 if (atmosphere_dim == 1) {
216 else if (atmosphere_dim == 2) {
217 const Index n = gp_lat.
nelem();
222 else if (atmosphere_dim == 3) {
223 const Index n = gp_lat.
nelem();
231 const Index& atmosphere_dim,
232 ConstMatrixView x_surface,
235 ConstMatrixView itw) {
236 if (atmosphere_dim == 1) {
241 else if (atmosphere_dim == 2) {
244 interp(x, itw, x_surface(Range(joker), 0), gp_lat);
247 else if (atmosphere_dim == 3) {
250 interp(x, itw, x_surface, gp_lat, gp_lon);
255 const Index& atmosphere_dim,
256 ConstMatrixView x_surface,
267 ConstMatrixView x_surface,
272 if (atmosphere_dim > 1) {
277 if (atmosphere_dim > 2) {
294 const Index& atmosphere_dim,
295 ConstTensor3View field_old,
299 const Index n1 = gp_p.
nelem();
301 if (atmosphere_dim == 1) {
302 field_new.resize(n1, 1, 1);
305 interp(field_new(joker, 0, 0), itw, field_old(joker, 0, 0), gp_p);
306 }
else if (atmosphere_dim == 2) {
307 const Index n2 = gp_lat.
nelem();
308 field_new.resize(n1, n2, 1);
309 Tensor3 itw(n1, n2, 4);
311 interp(field_new(joker, joker, 0),
313 field_old(joker, joker, 0),
316 }
else if (atmosphere_dim == 3) {
317 const Index n2 = gp_lat.
nelem();
318 const Index n3 = gp_lon.
nelem();
319 field_new.resize(n1, n2, n3);
320 Tensor4 itw(n1, n2, n3, 8);
322 interp(field_new, itw, field_old, gp_p, gp_lat, gp_lon);
327 const Index& atmosphere_dim,
328 ConstMatrixView field_old,
331 if (atmosphere_dim == 1) {
332 field_new = field_old;
333 }
else if (atmosphere_dim == 2) {
334 const Index n1 = gp_lat.
nelem();
335 field_new.resize(n1, 1);
338 interp(field_new(joker, 0), itw, field_old(joker, 0), gp_lat);
339 }
else if (atmosphere_dim == 3) {
340 const Index n1 = gp_lat.
nelem();
341 const Index n2 = gp_lon.
nelem();
342 field_new.resize(n1, n2);
343 Tensor3 itw(n1, n2, 4);
345 interp(field_new, itw, field_old, gp_lat, gp_lon);
353 const Index& atmosphere_dim,
354 const Vector& p_grid,
355 const Vector& lat_grid,
356 const Vector& lon_grid) {
357 gp_p.resize(rq.
Grids()[0].nelem());
360 if (atmosphere_dim >= 2) {
361 gp_lat.resize(rq.
Grids()[1].nelem());
367 if (atmosphere_dim >= 3) {
368 gp_lon.resize(rq.
Grids()[2].nelem());
378 const Index& atmosphere_dim,
379 const Vector& lat_grid,
380 const Vector& lon_grid) {
381 if (atmosphere_dim >= 2) {
382 gp_lat.resize(rq.
Grids()[0].nelem());
388 if (atmosphere_dim >= 3) {
389 gp_lon.resize(rq.
Grids()[1].nelem());
402 const ArrayOfVector& ret_grids,
403 const Index& atmosphere_dim,
404 const Vector& p_grid,
405 const Vector& lat_grid,
406 const Vector& lon_grid) {
409 const Numeric inf_proxy = 1.0e99;
411 gp_p.resize(p_grid.nelem());
412 n_p = ret_grids[0].
nelem();
414 p2gridpos(gp_p, ret_grids[0], p_grid, inf_proxy);
420 if (atmosphere_dim >= 2) {
421 gp_lat.resize(lat_grid.nelem());
422 n_lat = ret_grids[1].
nelem();
424 gridpos(gp_lat, ret_grids[1], lat_grid, inf_proxy);
434 if (atmosphere_dim >= 3) {
435 gp_lon.resize(lon_grid.nelem());
436 n_lon = ret_grids[2].
nelem();
438 gridpos(gp_lon, ret_grids[2], lon_grid, inf_proxy);
453 const ArrayOfVector& ret_grids,
454 const Index& atmosphere_dim,
455 const Vector& lat_grid,
456 const Vector& lon_grid) {
459 const Numeric inf_proxy = 1.0e99;
461 if (atmosphere_dim >= 2) {
462 gp_lat.resize(lat_grid.nelem());
463 n_lat = ret_grids[0].
nelem();
465 gridpos(gp_lat, ret_grids[0], lat_grid, inf_proxy);
475 if (atmosphere_dim >= 3) {
476 gp_lon.resize(lon_grid.nelem());
477 n_lon = ret_grids[1].
nelem();
479 gridpos(gp_lon, ret_grids[1], lon_grid, inf_proxy);
491 const Index& atmosphere_dim,
492 ConstTensor3View field_old,
496 const Index n1 = gp_p.
nelem();
498 const bool np_is1 = field_old.npages() == 1 ? true :
false;
499 const bool nlat_is1 =
500 atmosphere_dim > 1 && field_old.nrows() == 1 ? true :
false;
501 const bool nlon_is1 =
502 atmosphere_dim > 2 && field_old.ncols() == 1 ? true :
false;
505 if (!np_is1 && !nlat_is1 && !nlon_is1) {
507 field_new, atmosphere_dim, field_old, gp_p, gp_lat, gp_lon);
510 if (atmosphere_dim == 1) {
511 field_new.resize(n1, 1, 1);
512 field_new(joker, 0, 0) = field_old(0, 0, 0);
516 else if (atmosphere_dim == 2) {
517 const Index n2 = gp_lat.
nelem();
518 field_new.resize(n1, n2, 1);
520 if (np_is1 && nlat_is1)
523 field_new(joker, joker, 0) = field_old(0, 0, 0);
529 interp(tmp, itw, field_old(0, joker, 0), gp_lat);
530 for (Index p = 0; p < n1; p++) {
532 field_new(p, joker, 0) = tmp;
539 interp(tmp, itw, field_old(joker, 0, 0), gp_p);
540 for (Index lat = 0; lat < n2; lat++) {
542 field_new(joker, lat, 0) = tmp;
548 else if (atmosphere_dim == 3) {
549 const Index n2 = gp_lat.
nelem();
550 const Index n3 = gp_lon.
nelem();
551 field_new.resize(n1, n2, n3);
553 if (np_is1 && nlat_is1 && nlon_is1)
555 field_new(joker, joker, joker) = field_old(0, 0, 0);
565 interp(tmp, itw, field_old(0, 0, joker), gp_lon);
566 for (Index p = 0; p < n1; p++) {
568 for (Index lat = 0; lat < n2; lat++) {
570 field_new(p, lat, joker) = tmp;
578 interp(tmp, itw, field_old(0, joker, 0), gp_lat);
579 for (Index p = 0; p < n1; p++) {
581 for (Index lon = 0; lon < n3; lon++) {
583 field_new(p, joker, lon) = tmp;
588 Tensor3 itw(n2, n3, 4);
591 interp(tmp, itw, field_old(0, joker, joker), gp_lat, gp_lon);
592 for (Index p = 0; p < n1; p++) {
594 field_new(p, joker, joker) = tmp;
601 if (nlat_is1 && nlon_is1)
606 interp(tmp, itw, field_old(joker, 0, 0), gp_p);
607 for (Index lat = 0; lat < n2; lat++) {
609 for (Index lon = 0; lon < n3; lon++) {
611 field_new(joker, lat, lon) = tmp;
616 Tensor3 itw(n1, n3, 4);
619 interp(tmp, itw, field_old(joker, 0, joker), gp_p, gp_lon);
620 for (Index lat = 0; lat < n2; lat++) {
622 field_new(joker, lat, joker) = tmp;
626 Tensor3 itw(n1, n2, 4);
629 interp(tmp, itw, field_old(joker, joker, 0), gp_p, gp_lat);
630 for (Index lon = 0; lon < n3; lon++) {
632 field_new(joker, joker, lon) = tmp;
642 const Index& atmosphere_dim,
643 ConstMatrixView field_old,
647 if (atmosphere_dim == 1) {
648 field_new = field_old;
650 const bool nlat_is1 = field_old.nrows() == 1 ? true :
false;
651 const bool nlon_is1 =
652 atmosphere_dim > 2 && field_old.ncols() == 1 ? true :
false;
655 if (!nlat_is1 && !nlon_is1) {
657 field_new, atmosphere_dim, field_old, gp_lat, gp_lon);
659 if (atmosphere_dim == 2) {
660 const Index n1 = gp_lat.
nelem();
661 field_new.resize(n1, 1);
662 field_new(joker, 0) = field_old(0, 0);
664 const Index n1 = gp_lat.
nelem();
665 const Index n2 = gp_lon.
nelem();
666 field_new.resize(n1, n2);
668 if (nlat_is1 && nlon_is1)
670 field_new(joker, joker) = field_old(0, 0);
676 interp(tmp, itw, field_old(joker, 0), gp_lat);
677 for (Index lon = 0; lon < n2; lon++) {
679 field_new(joker, lon) = tmp;
686 interp(tmp, itw, field_old(0, joker), gp_lon);
687 for (Index lat = 0; lat < n1; lat++) {
689 field_new(lat, joker) = tmp;
702 ConstVectorView p_grid,
704 ConstMatrixView itw) {
709 Vector logpgrid(p_grid.nelem());
711 transform(logpgrid, log, p_grid);
713 interp(p_values, itw, logpgrid, gp);
715 transform(p_values, exp, p_values);
743 ConstVectorView old_pgrid,
744 ConstVectorView new_pgrid,
745 const Numeric& extpolfac) {
747 Vector logold(old_pgrid.nelem());
748 Vector lognew(new_pgrid.nelem());
750 transform(logold, log, old_pgrid);
751 transform(lognew, log, new_pgrid);
753 gridpos(gp, logold, lognew, extpolfac);
759 const Index& atmosphere_dim,
760 ConstVectorView p_grid,
761 ConstVectorView lat_grid,
762 ConstVectorView lon_grid,
763 ConstTensor3View z_field,
764 ConstVectorView rte_pos) {
767 if (atmosphere_dim == 1) {
769 "Altitude interpolation", z_field(joker, 0, 0), rte_pos[0]);
770 gridpos(gp_p, z_field(joker, 0, 0), rte_pos[0]);
773 const Index np = p_grid.nelem();
780 gridpos(gp_lat, lat_grid, rte_pos[1]);
782 if (atmosphere_dim == 2) {
783 for (Index i = 0; i < np; i++) {
788 interp(z_grid, itw, z_field(joker, joker, 0), agp_z, agp_lat);
791 gridpos(gp_lon, lon_grid, rte_pos[2]);
793 for (Index i = 0; i < np; i++) {
799 interp(z_grid, itw, z_field, agp_z, agp_lat, agp_lon);
804 gridpos(gp_p, z_grid, rte_pos[0]);
810 const Index& atmosphere_dim,
811 ConstVectorView lat_grid,
812 ConstVectorView lon_grid,
813 ConstVectorView rte_pos) {
816 if (atmosphere_dim == 1) {
819 gridpos(gp_lat, lat_grid, rte_pos[1]);
821 if (atmosphere_dim == 3) {
823 gridpos(gp_lon, lon_grid, rte_pos[2]);
829 ConstVectorView p_grid,
832 ConstVectorView lat_grid,
836 ConstMatrixView z_field,
838 const Index np = p_grid.nelem();
844 Matrix z_matrix(np, 1);
846 Tensor3 itw(np, 1, 4);
851 interp(z_matrix, itw, z_field, gp_z, agp_lat);
853 z = z_matrix(Range(joker), 0);
857 ConstVectorView p_grid,
860 ConstVectorView lat_grid,
861 ConstVectorView lon_grid,
866 ConstTensor3View z_field,
869 const Index np = p_grid.nelem();
876 Tensor3 z_tensor(np, 1, 1);
878 Tensor4 itw(np, 1, 1, 8);
882 gridpos(agp_z, p_grid, p_grid);
885 interp(z_tensor, itw, z_field, agp_z, agp_lat, agp_lon);
887 z = z_tensor(Range(joker), 0, 0);
898 ConstVectorView f_grid,
899 ConstVectorView t_grid) {
901 Index gfield_fID = 0;
902 Index gfield_tID = 1;
903 Index gfield_compID = 2;
913 if (complex_n.
data.ncols() != 2) {
915 os <<
"The data in *" << varname
916 <<
"* must have exactly two pages. One page "
917 <<
"each\nfor the real and imaginary part of the complex refractive index.";
921 const Index nf_in = complex_n.
data.npages();
922 const Index nt_in = complex_n.
data.nrows();
923 const Index nf_out = f_grid.nelem();
924 const Index nt_out = t_grid.nelem();
927 ARTS_ASSERT(n_real.nrows() == nf_out && n_real.ncols() == nt_out);
928 ARTS_ASSERT(n_imag.nrows() == nf_out && n_imag.ncols() == nt_out);
935 Matrix nrf(nf_out, nt_in), nif(nf_out, nt_in);
938 for (Index i = 0; i < nf_out; i++) {
939 nrf(i, joker) = complex_n.
data(0, joker, 0);
940 nif(i, joker) = complex_n.
data(0, joker, 1);
946 Matrix itw(nf_out, 2);
947 gridpos(gp, f_grid_in, f_grid);
949 for (Index i = 0; i < nt_in; i++) {
950 interp(nrf(joker, i), itw, complex_n.
data(joker, i, 0), gp);
951 interp(nif(joker, i), itw, complex_n.
data(joker, i, 1), gp);
958 for (Index i = 0; i < nt_out; i++) {
959 n_real(joker, i) = nrf(joker, 0);
960 n_imag(joker, i) = nif(joker, 0);
966 Matrix itw(nt_out, 2);
967 gridpos(gp, t_grid_in, t_grid);
969 for (Index i = 0; i < nf_out; i++) {
970 interp(n_real(i, joker), itw, nrf(i, joker), gp);
971 interp(n_imag(i, joker), itw, nif(i, joker), gp);
Index nelem() const ARTS_NOEXCEPT
void checksize_strict() const final
Strict consistency check.
const Vector & get_numeric_grid(Index i) const
Get a numeric grid.
Deals with internal derivatives, Jacobian definition, and OEM calculations.
const ArrayOfVector & Grids() const
Returns the grids of the retrieval.
#define ARTS_ASSERT(condition,...)
void gridpos(ArrayOfGridPos &gp, ConstVectorView old_grid, ConstVectorView new_grid, const Numeric &extpolfac)
Set up a grid position Array.
void gridpos_upperend_check(GridPos &gp, const Index &ie)
gridpos_upperend_check
void interpweights(VectorView itw, const GridPos &tc)
Red 1D interpolation weights.
void gp4length1grid(ArrayOfGridPos &gp)
Grid position matching a grid of length 1.
Numeric interp(ConstVectorView itw, ConstVectorView a, const GridPos &tc)
Red 1D Interpolate.
void gridpos_copy(GridPos &gp_new, const GridPos &gp_old)
gridpos_copy
void gridpos_1to1(ArrayOfGridPos &gp, ConstVectorView grid)
gridpos_1to1
void jacobian_type_extrapol(ArrayOfGridPos &gp)
Adopts grid positions to extrapolation used for jacobians.
Declarations having to do with the four output streams.
void complex_n_interp(MatrixView n_real, MatrixView n_imag, const GriddedField3 &complex_n, const String &varname, ConstVectorView f_grid, ConstVectorView t_grid)
General function for interpolating data of complex n type.
void regrid_atmfield_by_gp(Tensor3 &field_new, const Index &atmosphere_dim, ConstTensor3View field_old, const ArrayOfGridPos &gp_p, const ArrayOfGridPos &gp_lat, const ArrayOfGridPos &gp_lon)
Regrids an atmospheric field, for precalculated grid positions.
void interp_atmsurface_gp2itw(Matrix &itw, const Index &atmosphere_dim, const ArrayOfGridPos &gp_lat, const ArrayOfGridPos &gp_lon)
Converts atmospheric grid positions to weights for interpolation of a surface-type variable.
void regrid_atmfield_by_gp_oem(Tensor3 &field_new, const Index &atmosphere_dim, ConstTensor3View field_old, const ArrayOfGridPos &gp_p, const ArrayOfGridPos &gp_lat, const ArrayOfGridPos &gp_lon)
Regridding of atmospheric field OEM-type.
void get_gp_atmsurf_to_rq(ArrayOfGridPos &gp_lat, ArrayOfGridPos &gp_lon, const RetrievalQuantity &rq, const Index &atmosphere_dim, const Vector &lat_grid, const Vector &lon_grid)
Determines grid positions for regridding of atmospheric surfaces to retrieval grids.
void regrid_atmsurf_by_gp(Matrix &field_new, const Index &atmosphere_dim, ConstMatrixView field_old, const ArrayOfGridPos &gp_lat, const ArrayOfGridPos &gp_lon)
Regrids an atmospheric surface, for precalculated grid positions.
void interp_atmfield_gp2itw(Matrix &itw, const Index &atmosphere_dim, const ArrayOfGridPos &gp_p, const ArrayOfGridPos &gp_lat, const ArrayOfGridPos &gp_lon)
Converts atmospheric grid positions to weights for interpolation of an atmospheric field.
void itw2p(VectorView p_values, ConstVectorView p_grid, const ArrayOfGridPos &gp, ConstMatrixView itw)
Converts interpolation weights to pressures.
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)
Returns the geomtrical altitudes of p_grid for one latitude and one longitude.
void p2gridpos(ArrayOfGridPos &gp, ConstVectorView old_pgrid, ConstVectorView new_pgrid, const Numeric &extpolfac)
Calculates grid positions for pressure values.
void interp_cloudfield_gp2itw(VectorView itw, GridPos &gp_p_out, GridPos &gp_lat_out, GridPos &gp_lon_out, const GridPos &gp_p_in, const GridPos &gp_lat_in, const GridPos &gp_lon_in, const Index &atmosphere_dim, const ArrayOfIndex &cloudbox_limits)
Converts atmospheric a grid position to weights for interpolation of a field defined ONLY inside the ...
void get_gp_rq_to_atmgrids(ArrayOfGridPos &gp_p, ArrayOfGridPos &gp_lat, ArrayOfGridPos &gp_lon, Index &n_p, Index &n_lat, Index &n_lon, const ArrayOfVector &ret_grids, const Index &atmosphere_dim, const Vector &p_grid, const Vector &lat_grid, const Vector &lon_grid)
Determines grid positions for regridding of atmospheric fields to retrieval grids.
void regrid_atmsurf_by_gp_oem(Matrix &field_new, const Index &atmosphere_dim, ConstMatrixView field_old, const ArrayOfGridPos &gp_lat, const ArrayOfGridPos &gp_lon)
Regridding of surface field OEM-type.
void get_gp_atmgrids_to_rq(ArrayOfGridPos &gp_p, ArrayOfGridPos &gp_lat, ArrayOfGridPos &gp_lon, const RetrievalQuantity &rq, const Index &atmosphere_dim, const Vector &p_grid, const Vector &lat_grid, const Vector &lon_grid)
Determines grid positions for regridding of atmospheric fields to retrieval grids.
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)
Interpolates an atmospheric field given the grid positions.
void rte_pos2gridpos(GridPos &gp_p, GridPos &gp_lat, GridPos &gp_lon, const Index &atmosphere_dim, ConstVectorView p_grid, ConstVectorView lat_grid, ConstVectorView lon_grid, ConstTensor3View z_field, ConstVectorView rte_pos)
Converts a geographical position (rte_pos) to grid positions for p, lat and lon.
void interp_atmfield_by_itw(VectorView x, const Index &atmosphere_dim, ConstTensor3View x_field, const ArrayOfGridPos &gp_p, const ArrayOfGridPos &gp_lat, const ArrayOfGridPos &gp_lon, ConstMatrixView itw)
Interpolates an atmospheric field with pre-calculated weights by interp_atmfield_gp2itw.
void z_at_lat_2d(VectorView z, ConstVectorView p_grid, ConstVectorView lat_grid, ConstMatrixView z_field, const GridPos &gp_lat)
Returns the geomtrical altitudes of p_grid for one latitude.
void interp_atmsurface_by_gp(VectorView x, const Index &atmosphere_dim, ConstMatrixView x_surface, const ArrayOfGridPos &gp_lat, const ArrayOfGridPos &gp_lon)
Interpolates a surface-type variable given the grid positions.
void interp_atmsurface_by_itw(VectorView x, const Index &atmosphere_dim, ConstMatrixView x_surface, const ArrayOfGridPos &gp_lat, const ArrayOfGridPos &gp_lon, ConstMatrixView itw)
Interpolates a surface-type variable with pre-calculated weights by interp_atmsurface_gp2itw.
Header file for special_interp.cc.
Structure to store a grid position.