Skip to content

Commit 43af4d4

Browse files
committed
EAMxx: use fill val in cosp for night indices
1 parent 3221706 commit 43af4d4

File tree

4 files changed

+31
-18
lines changed

4 files changed

+31
-18
lines changed

components/eamxx/cime_config/testdefs/testmods_dirs/eamxx/mvkpert/yaml_outs/monthly_average_coarse.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ fields:
8484
- isccp_ctptau
8585
- modis_ctptau
8686
- misr_cthtau
87-
- cosp_sunlit
8887
- isccp_cldtot
8988

9089
output_control:

components/eamxx/cime_config/testdefs/testmods_dirs/eamxx/prod/yaml_outs/eamxx_output.decadal.1hourlyAVG_native.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ fields:
1111
- isccp_ctptau
1212
- modis_ctptau
1313
- misr_cthtau
14-
- cosp_sunlit
1514
- isccp_cldtot
1615
output_control:
1716
frequency: 1

components/eamxx/cime_config/testdefs/testmods_dirs/eamxx/prod/yaml_outs/eamxx_output.decadal.hourlyAVG_coarse.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ fields:
8484
- isccp_ctptau
8585
- modis_ctptau
8686
- misr_cthtau
87-
- cosp_sunlit
8887
- isccp_cldtot
8988

9089
output_control:

components/eamxx/src/physics/cosp/eamxx_cosp.cpp

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "eamxx_cosp.hpp"
22
#include "cosp_functions.hpp"
33
#include "physics/share/physics_constants.hpp"
4+
#include "share/util/eamxx_universal_constants.hpp"
45
#include "share/property_checks/field_within_interval_check.hpp"
56
#include "share/field/field_utils.hpp"
67

@@ -88,11 +89,11 @@ void Cosp::set_grids(const std::shared_ptr<const GridsManager> grids_manager)
8889
add_field<Required>("eff_radius_qc", scalar3d_mid, micron, grid_name);
8990
add_field<Required>("eff_radius_qi", scalar3d_mid, micron, grid_name);
9091
// Set of fields used strictly as output
92+
// NOTE we set their correspond masks in init impl
9193
add_field<Computed>("isccp_cldtot", scalar2d, percent, grid_name);
9294
add_field<Computed>("isccp_ctptau", scalar4d_ctptau, percent, grid_name, 1);
9395
add_field<Computed>("modis_ctptau", scalar4d_ctptau, percent, grid_name, 1);
9496
add_field<Computed>("misr_cthtau", scalar4d_cthtau, percent, grid_name, 1);
95-
add_field<Computed>("cosp_sunlit", scalar2d, nondim, grid_name);
9697

9798
// We can allocate these now
9899
m_z_mid = Field(FieldIdentifier("z_mid",scalar3d_mid,m,grid_name));
@@ -107,15 +108,12 @@ void Cosp::initialize_impl (const RunType /* run_type */)
107108
// Set property checks for fields in this process
108109
CospFunc::initialize(m_num_cols, m_num_subcols, m_num_levs);
109110

110-
111-
// Add note to output files about processing ISCCP fields that are only valid during
112-
// daytime. This can go away once I/O can handle masked time averages.
111+
// Set a mask field for each of the cosp computed fields
113112
using stratts_t = std::map<std::string,std::string>;
114113
std::list<std::string> vnames = {"isccp_cldtot", "isccp_ctptau", "modis_ctptau", "misr_cthtau"};
115114
for (const auto field_name : {"isccp_cldtot", "isccp_ctptau", "modis_ctptau", "misr_cthtau"}) {
116115
auto& f = get_field_out(field_name);
117-
auto& atts = f.get_header().get_extra_data<stratts_t>("io: string attributes");
118-
atts["note"] = "Night values are zero; divide by cosp_sunlit to get daytime mean";
116+
f.get_header().set_extra_data("mask_field", f.clone(field_name + "_mask"));
119117
}
120118
}
121119

@@ -221,31 +219,50 @@ void Cosp::run_impl (const double dt)
221219
const auto dtau105_h = get_field_in("dtau105").get_view<const Real**, Host>();
222220

223221
auto isccp_cldtot_h = get_field_out("isccp_cldtot").get_view<Real*, Host>();
222+
auto isccp_cldtot_h_mask = get_field_out("isccp_cldtot").get_header().get_extra_data<Field>("mask_field").get_view<Real*, Host>();
224223
auto isccp_ctptau_h = get_field_out("isccp_ctptau").get_view<Real***, Host>();
224+
auto isccp_ctptau_h_mask = get_field_out("isccp_ctptau").get_header().get_extra_data<Field>("mask_field").get_view<Real***, Host>();
225225
auto modis_ctptau_h = get_field_out("modis_ctptau").get_view<Real***, Host>();
226+
auto modis_ctptau_h_mask = get_field_out("modis_ctptau").get_header().get_extra_data<Field>("mask_field").get_view<Real***, Host>();
226227
auto misr_cthtau_h = get_field_out("misr_cthtau").get_view<Real***, Host>();
227-
auto cosp_sunlit_h = get_field_out("cosp_sunlit").get_view<Real*, Host>(); // Copy of sunlit flag with COSP frequency for proper averaging
228+
auto misr_cthtau_h_mask = get_field_out("misr_cthtau").get_header().get_extra_data<Field>("mask_field").get_view<Real***, Host>();
228229

229230
Real emsfc_lw = 0.99;
230-
Kokkos::deep_copy(cosp_sunlit_h, sunlit_h);
231231
CospFunc::main(
232232
m_num_cols, m_num_subcols, m_num_levs, m_num_tau, m_num_ctp, m_num_cth, emsfc_lw,
233233
sunlit_h, skt_h, T_mid_h, p_mid_h, p_int_h, z_mid_h, qv_h, qc_h, qi_h,
234234
cldfrac_h, reff_qc_h, reff_qi_h, dtau067_h, dtau105_h,
235235
isccp_cldtot_h, isccp_ctptau_h, modis_ctptau_h, misr_cthtau_h
236236
);
237-
// Remask night values to ZERO since our I/O does not know how to handle masked/missing values
238-
// in temporal averages; this is all host data, so we can just use host loops like its the 1980s
237+
// Mask night values
238+
constexpr auto fill_value = constants::fill_value<Real>;
239239
for (int i = 0; i < m_num_cols; i++) {
240240
if (sunlit_h(i) == 0) {
241-
isccp_cldtot_h(i) = 0;
241+
// if night, set to fill val and set mask to 0
242+
isccp_cldtot_h(i) = fill_value;
243+
isccp_cldtot_h_mask(i) = 0;
244+
for (int j = 0; j < m_num_tau; j++) {
245+
for (int k = 0; k < m_num_ctp; k++) {
246+
isccp_ctptau_h(i,j,k) = fill_value;
247+
isccp_ctptau_h_mask(i,j,k) = 0;
248+
modis_ctptau_h(i,j,k) = fill_value;
249+
modis_ctptau_h_mask(i,j,k) = 0;
250+
}
251+
for (int k = 0; k < m_num_cth; k++) {
252+
misr_cthtau_h (i,j,k) = fill_value;
253+
misr_cthtau_h_mask(i,j,k) = 0;
254+
}
255+
}
256+
} else {
257+
// if NOT night, persist and set mask to 1
258+
isccp_cldtot_h_mask(i) = 1;
242259
for (int j = 0; j < m_num_tau; j++) {
243260
for (int k = 0; k < m_num_ctp; k++) {
244-
isccp_ctptau_h(i,j,k) = 0;
245-
modis_ctptau_h(i,j,k) = 0;
261+
isccp_ctptau_h_mask(i,j,k) = 1;
262+
modis_ctptau_h_mask(i,j,k) = 1;
246263
}
247264
for (int k = 0; k < m_num_cth; k++) {
248-
misr_cthtau_h (i,j,k) = 0;
265+
misr_cthtau_h_mask(i,j,k) = 1;
249266
}
250267
}
251268
}
@@ -256,7 +273,6 @@ void Cosp::run_impl (const double dt)
256273
get_field_out("isccp_ctptau").sync_to_dev();
257274
get_field_out("modis_ctptau").sync_to_dev();
258275
get_field_out("misr_cthtau").sync_to_dev();
259-
get_field_out("cosp_sunlit").sync_to_dev();
260276
}
261277
}
262278

0 commit comments

Comments
 (0)