@@ -356,11 +356,11 @@ void post_process_output(const std::vector<ColumnResult>& col_results,
356356 }
357357}
358358
359- void compress_columns_weighted_avg (const int n_x, const int n_y,
360- const int n_out,
359+ void compress_columns_weighted_avg (const int n_x, const int n_y,
360+ const int n_out,
361361 const int n_tilt,
362362 const int compress_lay_start_idx,
363- std::vector<Float>& var, std::vector<Float>& var_weighting )
363+ std::vector<Float>& var, std::vector<Float>& p_lev )
364364{
365365 std::vector<Float> var_tmp (n_out * n_x * n_y);
366366
@@ -400,15 +400,18 @@ void compress_columns_weighted_avg(const int n_x, const int n_y,
400400 for (int k = 0 ; k < num_inputs; ++k)
401401 {
402402 int in_idx = ix + iy * n_x + (i_lay_in + k) * n_x * n_y;
403- t_sum += var[in_idx] * var_weighting[in_idx];
404- w_sum += var_weighting[in_idx];
403+ int in_idx_top = ix + iy * n_x + (i_lay_in + k + 1 ) * n_x * n_y;
404+
405+ const Float dp_local = abs (p_lev[in_idx] - p_lev[in_idx_top]);
406+ t_sum += var[in_idx] * dp_local;
407+ w_sum += dp_local;
405408 }
406409
407410 if (w_sum > 1e-6 )
408411 {
409412 var_tmp[out_idx] = t_sum / w_sum;
410- }
411- else
413+ }
414+ else
412415 {
413416 Float avg = 0.0 ;
414417 for (int k = 0 ; k < num_inputs; ++k)
@@ -592,8 +595,8 @@ void tilt_fields(const int n_z_in, const int n_zh_in, const int n_col_x, const i
592595
593596void compress_fields (const int compress_lay_start_idx, const int n_col_x, const int n_col_y,
594597 const int n_z_in, const int n_zh_in, const int n_z_tilt,
595- Array<Float,2 >* p_lay_copy, Array<Float,2 >* t_lay_copy, Array<Float,2 >* p_lev_copy, Array<Float,2 >* t_lev_copy,
596- Array<Float,2 >* rh_copy,
598+ Array<Float,2 >* p_lay_copy, Array<Float,2 >* t_lay_copy, Array<Float,2 >* p_lev_copy, Array<Float,2 >* t_lev_copy,
599+ Array<Float,2 >* rh_copy,
597600 Gas_concs& gas_concs_copy, std::vector<std::string> gas_names,
598601 Aerosol_concs& aerosol_concs_copy, std::vector<std::string> aerosol_names, const bool switch_aerosol_optics)
599602{
@@ -608,22 +611,23 @@ void compress_fields(const int compress_lay_start_idx, const int n_col_x, const
608611 Array<Float,2 > gas_tmp (gas);
609612 compress_columns_weighted_avg (n_col_x, n_col_y,
610613 n_z_in, n_z_tilt,
611- compress_lay_start_idx,
612- gas_tmp.v (),
613- p_lay_copy ->v ());
614+ compress_lay_start_idx,
615+ gas_tmp.v (),
616+ p_lev_copy ->v ());
614617 gas_tmp.expand_dims ({n_col, n_z_in});
615618 gas_concs_copy.set_vmr (gas_name, gas_tmp);
616619 }
617620 }
618621
619622 if (switch_aerosol_optics)
620623 {
621- std::vector<Float> ones (p_lay_copy-> v (). size (), 1.0 );
624+ // should we just recompute relative humidity after tilting water vapour and temperature?
622625 compress_columns_weighted_avg (n_col_x, n_col_y,
623626 n_z_in, n_z_tilt,
624- compress_lay_start_idx,
625- rh_copy->v (),
626- ones);
627+ compress_lay_start_idx,
628+ rh_copy->v (),
629+ p_lev_copy->v ());
630+
627631 rh_copy->expand_dims ({n_col, n_z_in});
628632
629633 for (const auto & aerosol_name : aerosol_names) {
@@ -635,9 +639,9 @@ void compress_fields(const int compress_lay_start_idx, const int n_col_x, const
635639 Array<Float,2 > gas_tmp (gas);
636640 compress_columns_weighted_avg (n_col_x, n_col_y,
637641 n_z_in, n_z_tilt,
638- compress_lay_start_idx,
639- gas_tmp.v (),
640- p_lay_copy ->v ());
642+ compress_lay_start_idx,
643+ gas_tmp.v (),
644+ p_lev_copy ->v ());
641645 gas_tmp.expand_dims ({n_col, n_z_in});
642646 aerosol_concs_copy.set_vmr (aerosol_name, gas_tmp);
643647 }
0 commit comments