Skip to content

Commit

Permalink
Per #2523, change the order of the NetCDF diensions written by the tc…
Browse files Browse the repository at this point in the history
…_rmw tool. The dimensions should have time first, vertical level second (if applicable), and then gridded dimensions (i.e. lat,lon) last.
  • Loading branch information
JohnHalleyGotway committed Apr 26, 2023
1 parent bf0e5ad commit 82dc790
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 72 deletions.
67 changes: 30 additions & 37 deletions src/libcode/vx_tc_util/vx_tc_nc_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -271,33 +271,32 @@ void def_tc_range_azimuth(NcFile* nc_out,

////////////////////////////////////////////////////////////////////////

void def_tc_lat_lon_time(NcFile* nc_out,
const NcDim& range_dim, const NcDim& azimuth_dim,
const NcDim& track_point_dim,
NcVar& lat_var, NcVar& lon_var, NcVar& valid_time_var) {
void def_tc_time_lat_lon(NcFile* nc_out,
const NcDim& track_point_dim, const NcDim& range_dim, const NcDim& azimuth_dim,
NcVar& valid_time_var, NcVar& lat_var, NcVar& lon_var) {

vector<NcDim> dims;
dims.push_back(track_point_dim);
dims.push_back(range_dim);
dims.push_back(azimuth_dim);
dims.push_back(track_point_dim);

lat_var = nc_out->addVar("lat", ncDouble, dims);
lon_var = nc_out->addVar("lon", ncDouble, dims);
valid_time_var = nc_out->addVar("valid_time", ncUint64,
track_point_dim);
lat_var = nc_out->addVar("lat", ncDouble, dims);
lon_var = nc_out->addVar("lon", ncDouble, dims);

// Set attributes
add_att(&valid_time_var, "long_name", "valid_time");
add_att(&valid_time_var, "units", "yyyymmddhh");
add_att(&valid_time_var, "standard_name", "valid_time");

add_att(&lat_var, "long_name", "latitude");
add_att(&lat_var, "units", "degrees_north");
add_att(&lat_var, "standard_name", "latitude");

add_att(&lon_var, "long_name", "longitude");
add_att(&lon_var, "units", "degrees_east");
add_att(&lon_var, "standard_name", "longitude");

add_att(&valid_time_var, "long_name", "valid_time");
add_att(&valid_time_var, "units", "yyyymmddhh");
add_att(&valid_time_var, "standard_name", "valid_time");
}

////////////////////////////////////////////////////////////////////////
Expand All @@ -324,20 +323,20 @@ void def_tc_variables(NcFile* nc_out,
map<string, vector<string> > variable_levels,
map<string, string> variable_long_names,
map<string, string> variable_units,
const NcDim& track_point_dim, const NcDim& pressure_dim,
const NcDim& range_dim, const NcDim& azimuth_dim,
const NcDim& pressure_dim, const NcDim& track_point_dim,
map<string, NcVar>& data_vars) {

vector<NcDim> dims;
dims.push_back(track_point_dim);
dims.push_back(range_dim);
dims.push_back(azimuth_dim);
dims.push_back(track_point_dim);

vector<NcDim> dims_3d;
dims_3d.push_back(track_point_dim);
dims_3d.push_back(pressure_dim);
dims_3d.push_back(range_dim);
dims_3d.push_back(azimuth_dim);
dims_3d.push_back(pressure_dim);
dims_3d.push_back(track_point_dim);

for (map<string, vector<string> >::iterator i = variable_levels.begin();
i != variable_levels.end(); ++i) {
Expand Down Expand Up @@ -373,9 +372,9 @@ void def_tc_data(NcFile* nc_out,
NcVar& data_var, VarInfo* data_info) {

vector<NcDim> dims;
dims.push_back(track_point_dim);
dims.push_back(range_dim);
dims.push_back(azimuth_dim);
dims.push_back(track_point_dim);

ConcatString var_name = data_info->name_attr();
var_name.add("_");
Expand All @@ -398,10 +397,10 @@ void def_tc_data_3d(NcFile* nc_out,
NcVar& data_var, VarInfo* data_info) {

vector<NcDim> dims;
dims.push_back(track_point_dim);
dims.push_back(pressure_dim);
dims.push_back(range_dim);
dims.push_back(azimuth_dim);
dims.push_back(pressure_dim);
dims.push_back(track_point_dim);

data_var = nc_out->addVar(
data_info->name_attr(), ncDouble, dims);
Expand All @@ -420,8 +419,8 @@ void def_tc_azi_mean_data(NcFile* nc_out,
NcVar& data_var, VarInfo* data_info) {

vector<NcDim> dims;
dims.push_back(range_dim);
dims.push_back(track_point_dim);
dims.push_back(range_dim);

ConcatString var_name = data_info->name_attr();
var_name.add("_");
Expand All @@ -445,14 +444,14 @@ void write_tc_data(NcFile* nc_out, const TcrmwGrid& grid,
vector<size_t> counts;

offsets.clear();
offsets.push_back(i_point);
offsets.push_back(0);
offsets.push_back(0);
offsets.push_back(i_point);

counts.clear();
counts.push_back(1);
counts.push_back(grid.range_n());
counts.push_back(grid.azimuth_n());
counts.push_back(1);

var.putVar(offsets, counts, data);
}
Expand All @@ -468,14 +467,14 @@ void write_tc_data_rev(NcFile* nc_out, const TcrmwGrid& grid,
double* data_rev;

offsets.clear();
offsets.push_back(i_point);
offsets.push_back(0);
offsets.push_back(0);
offsets.push_back(i_point);

counts.clear();
counts.push_back(1);
counts.push_back(grid.range_n());
counts.push_back(grid.azimuth_n());
counts.push_back(1);

data_rev = new double[
grid.range_n() * grid.azimuth_n()];
Expand Down Expand Up @@ -505,12 +504,12 @@ void write_tc_azi_mean_data(NcFile* nc_out, const TcrmwGrid& grid,
double* data_azi_mean;

offsets.clear();
offsets.push_back(0);
offsets.push_back(i_point);
offsets.push_back(0);

counts.clear();
counts.push_back(grid.range_n());
counts.push_back(1);
counts.push_back(grid.range_n());

data_rev = new double[
grid.range_n() * grid.azimuth_n()];
Expand Down Expand Up @@ -554,26 +553,26 @@ extern void write_tc_pressure_level_data(
int i_level = pressure_level_indices[level_str];

offsets.clear();
offsets.push_back(i_point);
offsets.push_back(0);
offsets.push_back(0);
offsets.push_back(i_point);

offsets_3d.clear();
offsets_3d.push_back(i_point);
offsets_3d.push_back(i_level);
offsets_3d.push_back(0);
offsets_3d.push_back(0);
offsets_3d.push_back(i_level);
offsets_3d.push_back(i_point);

counts.clear();
counts.push_back(1);
counts.push_back(grid.range_n());
counts.push_back(grid.azimuth_n());
counts.push_back(1);

counts_3d.clear();
counts_3d.push_back(grid.range_n());
counts_3d.push_back(grid.azimuth_n());
counts_3d.push_back(1);
counts_3d.push_back(1);
counts_3d.push_back(grid.range_n());
counts_3d.push_back(grid.azimuth_n());

data_rev = new double[
grid.range_n() * grid.azimuth_n()];
Expand All @@ -586,12 +585,6 @@ extern void write_tc_pressure_level_data(
}
}

// string label = level_str.substr(0, 1);
// if (label == "P") {
// var.putVar(offsets_3d, counts_3d, data_rev);
// } else {
// var.putVar(offsets, counts, data_rev);
// }
var.putVar(offsets_3d, counts_3d, data_rev);

delete[] data_rev;
Expand Down
2 changes: 1 addition & 1 deletion src/libcode/vx_tc_util/vx_tc_nc_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extern void def_tc_pressure(netCDF::NcFile*,
extern void def_tc_range_azimuth(netCDF::NcFile*,
const netCDF::NcDim&, const netCDF::NcDim&, const TcrmwGrid&, double);

extern void def_tc_lat_lon_time(netCDF::NcFile*,
extern void def_tc_time_lat_lon(netCDF::NcFile*,
const netCDF::NcDim&, const netCDF::NcDim&, const netCDF::NcDim&,
netCDF::NcVar&, netCDF::NcVar&, netCDF::NcVar&);

Expand Down
67 changes: 33 additions & 34 deletions src/tools/tc_utils/tc_rmw/tc_rmw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// 001 05/15/20 Halley Gotway Fix data file list option logic.
// 002 07/06/22 Howard Soh METplus-Internal #19 Rename main to met_main
// 003 09/28/22 Prestopnik MET #2227 Remove namspace std and netCDF from header files
// 004 04/26/23 Halley Gotway MET #2523 Reorder NetCDF dimensions
//
////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -168,7 +169,7 @@ void process_command_line(int argc, char **argv) {
// Add function calls for arguments
cline.add(set_data_files, "-data", -1);
cline.add(set_deck, "-deck", -1);
// Queitly support -adeck option for backward compatibility with met-9.0
// Quietly support -adeck option for backward compatibility with met-9.0
cline.add(set_deck, "-adeck", -1);
cline.add(set_config, "-config", 1);
cline.add(set_out, "-out", 1);
Expand Down Expand Up @@ -575,43 +576,44 @@ void setup_nc_file() {
<< ", Azimuth = " << tcrmw_grid.azimuth_n() << "\n";

// Define dimensions
track_point_dim = add_dim(nc_out, "track_point", NC_UNLIMITED);
range_dim = add_dim(nc_out, "range", (long) tcrmw_grid.range_n());
azimuth_dim = add_dim(nc_out, "azimuth", (long) tcrmw_grid.azimuth_n());
track_point_dim = add_dim(nc_out, "track_point", NC_UNLIMITED);

// Define range and azimuth dimensions
def_tc_range_azimuth(nc_out, range_dim, azimuth_dim, tcrmw_grid,
conf_info.rmw_scale);

// Define latitude and longitude arrays
def_tc_lat_lon_time(nc_out, range_dim, azimuth_dim,
track_point_dim, lat_arr_var, lon_arr_var, valid_time_var);
def_tc_time_lat_lon(nc_out,
track_point_dim, range_dim, azimuth_dim,
valid_time_var, lat_arr_var, lon_arr_var);

// Find all variable levels, long names, and units
for(int i_var = 0; i_var < conf_info.get_n_data(); i_var++) {
// Get VarInfo
data_info = conf_info.data_info[i_var];
mlog << Debug(4) << "Processing field: " << data_info->magic_str() << "\n";
string fname = data_info->name_attr();
string fname = data_info->name_attr();
variable_levels[fname].push_back(data_info->level_attr());
variable_long_names[fname] = data_info->long_name_attr();
variable_units[fname] = data_info->units_attr();
wind_converter.update_input(fname, data_info->units_attr());
wind_converter.update_input(fname, data_info->units_attr());
}

// Define pressure levels
pressure_level_strings = get_pressure_level_strings(variable_levels);
pressure_levels = get_pressure_levels(pressure_level_strings);
pressure_level_indices
= get_pressure_level_indices(pressure_level_strings, pressure_levels);
pressure_level_indices =
get_pressure_level_indices(pressure_level_strings, pressure_levels);
pressure_dim = add_dim(nc_out, "pressure", pressure_levels.size());
def_tc_pressure(nc_out, pressure_dim, pressure_levels);

wind_converter.append_nc_output_vars(variable_levels, variable_long_names, variable_units);

def_tc_variables(nc_out,
variable_levels, variable_long_names, variable_units,
range_dim, azimuth_dim, pressure_dim, track_point_dim,
track_point_dim, pressure_dim, range_dim, azimuth_dim,
data_3d_vars);
}

Expand All @@ -628,7 +630,7 @@ void compute_lat_lon(TcrmwGrid& tcrmw_grid,
tcrmw_grid.range_azi_to_latlon(
ir * tcrmw_grid.range_delta_km(),
ia * tcrmw_grid.azimuth_delta_deg(),
lat, lon);
lat, lon);
lat_arr[i] = lat;
lon_arr[i] = - lon;
}
Expand All @@ -638,7 +640,6 @@ void compute_lat_lon(TcrmwGrid& tcrmw_grid,
////////////////////////////////////////////////////////////////////////

void process_fields(const TrackInfoArray& tracks) {

VarInfo *data_info = (VarInfo *) 0;
DataPlane data_dp;

Expand Down Expand Up @@ -695,14 +696,13 @@ void process_fields(const TrackInfoArray& tracks) {
// Update the variable info with the valid time of the track point
data_info = conf_info.data_info[i_var];

string sname = data_info->name_attr().string();
string slevel = data_info->level_attr().string();
string sname = data_info->name_attr().string();
string slevel = data_info->level_attr().string();

data_info->set_valid(valid_time);
data_info->set_valid(valid_time);

// Find data for this track point
get_series_entry(i_point, data_info, data_files, ftype, data_dp,
latlon_arr);
get_series_entry(i_point, data_info, data_files, ftype, data_dp, latlon_arr);

// Check data range
double data_min, data_max;
Expand All @@ -711,32 +711,31 @@ void process_fields(const TrackInfoArray& tracks) {
mlog << Debug(4) << "data_max:" << data_max << "\n";

// Regrid data
data_dp = met_regrid(data_dp,
latlon_arr, grid, data_info->regrid());
data_dp.data_range(data_min, data_max);
data_dp = met_regrid(data_dp, latlon_arr, grid, data_info->regrid());
data_dp.data_range(data_min, data_max);
mlog << Debug(4) << "data_min:" << data_min << "\n";
mlog << Debug(4) << "data_max:" << data_max << "\n";

// if this is "U", setup everything for matching "V" and compute the radial/tangential
if (wind_converter.compute_winds_if_input_is_u(i_point, sname, slevel, valid_time, data_files, ftype,
latlon_arr, lat_arr, lon_arr, grid, data_dp, tcrmw_grid))
{
write_tc_pressure_level_data(nc_out, tcrmw_grid,
pressure_level_indices, data_info->level_attr(), i_point,
data_3d_vars[conf_info.radial_velocity_field_name.string()],
wind_converter.get_wind_r_arr());
write_tc_pressure_level_data(nc_out, tcrmw_grid,
pressure_level_indices, data_info->level_attr(), i_point,
data_3d_vars[conf_info.tangential_velocity_field_name.string()],
wind_converter.get_wind_t_arr());
}
// if this is "U", setup everything for matching "V" and compute the radial/tangential
if(wind_converter.compute_winds_if_input_is_u(i_point, sname, slevel, valid_time, data_files, ftype,
latlon_arr, lat_arr, lon_arr, grid, data_dp, tcrmw_grid)) {
write_tc_pressure_level_data(nc_out, tcrmw_grid,
pressure_level_indices, data_info->level_attr(), i_point,
data_3d_vars[conf_info.radial_velocity_field_name.string()],
wind_converter.get_wind_r_arr());
write_tc_pressure_level_data(nc_out, tcrmw_grid,
pressure_level_indices, data_info->level_attr(), i_point,
data_3d_vars[conf_info.tangential_velocity_field_name.string()],
wind_converter.get_wind_t_arr());
}

// Write data
if (variable_levels[data_info->name_attr()].size() > 1) {
if(variable_levels[data_info->name_attr()].size() > 1) {
write_tc_pressure_level_data(nc_out, tcrmw_grid,
pressure_level_indices, data_info->level_attr(),
i_point, data_3d_vars[data_info->name_attr()], data_dp.data());
} else {
}
else {
write_tc_data_rev(nc_out, tcrmw_grid, i_point,
data_3d_vars[data_info->name_attr()], data_dp.data());
}
Expand Down

0 comments on commit 82dc790

Please sign in to comment.