Skip to content

Commit

Permalink
Feature #2523 dim_order (#2524)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnHalleyGotway authored May 10, 2023
1 parent 349e3ec commit 0502262
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 101 deletions.
8 changes: 4 additions & 4 deletions docs/Users_Guide/tc-rmw.rst
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,12 @@ tc_rmw output file

The NetCDF output file contains the following dimensions:

1. *range* - the radial dimension of the range-azimuth grid
1. *track_point* - the track points corresponding to the model output valid times

2. *azimuth* - the azimuthal dimension of the range-azimuth grid
2. *pressure* - if any pressure levels are specified in the data variable list, they will be sorted and combined into a 3D NetCDF variable, which pressure as the vertical dimension and range and azimuth as the horizontal dimensions

3. *pressure* - if any pressure levels are specified in the data variable list, they will be sorted and combined into a 3D NetCDF variable, which pressure as the vertical dimension and range and azimuth as the horizontal dimensions
3. *range* - the radial dimension of the range-azimuth grid

4. *track_point* - the track points corresponding to the model output valid times
4. *azimuth* - the azimuthal dimension of the range-azimuth grid

For each data variable specified in the data variable list, a corresponding NetCDF variable will be created with the same name and units.
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
50 changes: 25 additions & 25 deletions src/tools/tc_utils/rmw_analysis/rmw_analysis.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ void setup() {
}

mlog << Debug(2)
<< "(n_range, n_azimuth, n_level) = ("
<< n_range << ", " << n_azimuth << ", " << n_level << ")\n";
<< "(n_level, n_range, n_azimuth) = ("
<< n_level << ", " << n_range << ", " << n_azimuth << ")\n";

// Get dimension coordinates
vector<size_t> start;
Expand Down Expand Up @@ -255,11 +255,11 @@ void setup() {
DataCube* data_max_2d = new DataCube();
DataCube* data_min_2d = new DataCube();

data_count_2d->set_size(n_range, n_azimuth, 1);
data_mean_2d->set_size(n_range, n_azimuth, 1);
data_stdev_2d->set_size(n_range, n_azimuth, 1);
data_max_2d->set_size(n_range, n_azimuth, 1);
data_min_2d->set_size(n_range, n_azimuth, 1);
data_count_2d->set_size(1, n_range, n_azimuth);
data_mean_2d->set_size(1, n_range, n_azimuth);
data_stdev_2d->set_size(1, n_range, n_azimuth);
data_max_2d->set_size(1, n_range, n_azimuth);
data_min_2d->set_size(1, n_range, n_azimuth);

data_count_2d->set_constant(0);
data_mean_2d->set_constant(0);
Expand All @@ -281,11 +281,11 @@ void setup() {
DataCube* data_max_3d = new DataCube();
DataCube* data_min_3d = new DataCube();

data_count_3d->set_size(n_range, n_azimuth, n_level);
data_mean_3d->set_size(n_range, n_azimuth, n_level);
data_stdev_3d->set_size(n_range, n_azimuth, n_level);
data_max_3d->set_size(n_range, n_azimuth, n_level);
data_min_3d->set_size(n_range, n_azimuth, n_level);
data_count_3d->set_size(n_level, n_range, n_azimuth);
data_mean_3d->set_size(n_level, n_range, n_azimuth);
data_stdev_3d->set_size(n_level, n_range, n_azimuth);
data_max_3d->set_size(n_level, n_range, n_azimuth);
data_min_3d->set_size(n_level, n_range, n_azimuth);

data_count_3d->set_constant(0);
data_mean_3d->set_constant(0);
Expand All @@ -312,10 +312,10 @@ void process_files() {
DataCube data_3d;
DataCube data_3d_sq;

data_2d.set_size(n_range, n_azimuth, 1);
data_2d_sq.set_size(n_range, n_azimuth, 1);
data_3d.set_size(n_range, n_azimuth, n_level);
data_3d_sq.set_size(n_range, n_azimuth, n_level);
data_2d.set_size(1, n_range, n_azimuth);
data_2d_sq.set_size(1, n_range, n_azimuth);
data_3d.set_size(n_level, n_range, n_azimuth);
data_3d_sq.set_size(n_level, n_range, n_azimuth);

// Set up array track point slices
vector<size_t> start_2d;
Expand All @@ -325,17 +325,17 @@ void process_files() {
start_2d.push_back(0);
start_2d.push_back(0);
start_2d.push_back(0);
count_2d.push_back(1);
count_2d.push_back(n_range);
count_2d.push_back(n_azimuth);
count_2d.push_back(1);
start_3d.push_back(0);
start_3d.push_back(0);
start_3d.push_back(0);
start_3d.push_back(0);
count_3d.push_back(1);
count_3d.push_back(n_level);
count_3d.push_back(n_range);
count_3d.push_back(n_azimuth);
count_3d.push_back(n_level);
count_3d.push_back(1);

for(int i_file = 0; i_file < data_files.n_elements(); i_file++) {
mlog << Debug(1) << "Processing "
Expand All @@ -362,7 +362,7 @@ void process_files() {

for(int i_track = 0; i_track < n_track_point; i_track++) {
if (data_n_dims[i_var] == 2) {
start_2d[2] = (size_t) i_track;
start_2d[0] = (size_t) i_track;
mlog << Debug(4) << data_names[i_var] << i_track << "\n";
var.getVar(start_2d, count_2d, data_2d.data());

Expand All @@ -387,7 +387,7 @@ void process_files() {
}
if (data_n_dims[i_var] == 3) {
mlog << Debug(4) << data_names[i_var] << i_track << "\n";
start_3d[3] = (size_t) i_track;
start_3d[0] = (size_t) i_track;
var.getVar(start_3d, count_3d, data_3d.data());

// Update partial sums
Expand Down Expand Up @@ -442,22 +442,22 @@ void write_stats() {
dims_2d.push_back(azimuth_dim);

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

NcVar level_var = nc_out->addVar(level_name, ncDouble, level_dim);
NcVar range_var = nc_out->addVar("range", ncDouble, range_dim);
NcVar azimuth_var = nc_out->addVar("azimuth", ncDouble, azimuth_dim);
NcVar level_var = nc_out->addVar(level_name, ncDouble, level_dim);

vector<size_t> offset;
vector<size_t> count_range;
vector<size_t> count_azimuth;
vector<size_t> count_level;
offset.push_back(0);
count_level.push_back(n_level);
count_range.push_back(n_range);
count_azimuth.push_back(n_azimuth);
count_level.push_back(n_level);

for (int r = 0; r < n_range; r++) {
range_coord[r] = r;
Expand Down Expand Up @@ -485,9 +485,9 @@ void write_stats() {
offset_3d.push_back(0);
offset_3d.push_back(0);
offset_3d.push_back(0);
count_3d.push_back(n_level);
count_3d.push_back(n_range);
count_3d.push_back(n_azimuth);
count_3d.push_back(n_level);

for(int i_var = 0; i_var < data_names.size(); i_var++) {
if (data_n_dims[i_var] == 2) {
Expand Down
Loading

0 comments on commit 0502262

Please sign in to comment.