From 9573488793170908cb59a275761b5b079cbaeffb Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Wed, 16 Jun 2021 23:47:49 -0600 Subject: [PATCH 1/2] #1817 Added to_north argument at two_to_one() --- met/src/basic/vx_util/data_plane.cc | 4 ++-- met/src/basic/vx_util/data_plane.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/met/src/basic/vx_util/data_plane.cc b/met/src/basic/vx_util/data_plane.cc index 043e1d7c7b..c855b2a1d5 100644 --- a/met/src/basic/vx_util/data_plane.cc +++ b/met/src/basic/vx_util/data_plane.cc @@ -410,7 +410,7 @@ return; /////////////////////////////////////////////////////////////////////////////// -int DataPlane::two_to_one(int x, int y) const { +int DataPlane::two_to_one(int x, int y, bool to_north) const { int n; if((x < 0) || (x >= Nx) || (y < 0) || (y >= Ny)) { @@ -420,7 +420,7 @@ int DataPlane::two_to_one(int x, int y) const { exit(1); } - n = y*Nx + x; // don't change this! lots of downstream code depends on this! + n = (to_north ? y : (Ny-1-y))*Nx + x; // don't change this! lots of downstream code depends on this! return(n); } diff --git a/met/src/basic/vx_util/data_plane.h b/met/src/basic/vx_util/data_plane.h index 54e3606b55..650d62b226 100644 --- a/met/src/basic/vx_util/data_plane.h +++ b/met/src/basic/vx_util/data_plane.h @@ -109,7 +109,7 @@ class DataPlane { void replace_bad_data(const double value); - int two_to_one(int x, int y) const; + int two_to_one(int x, int y, bool to_north=true) const; void one_to_two(int n, int &x, int &y) const; bool s_is_on(int x, int y) const; From fad14e05cb58b0cc6837a38c5a40cf74b870e45e Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Wed, 16 Jun 2021 23:50:08 -0600 Subject: [PATCH 2/2] #1817 Calls two_to_one() with false for the third argument, to_north, if latitude moves north to south --- met/src/tools/other/point2grid/point2grid.cc | 63 +++++++++++++------- 1 file changed, 42 insertions(+), 21 deletions(-) diff --git a/met/src/tools/other/point2grid/point2grid.cc b/met/src/tools/other/point2grid/point2grid.cc index 6402fff121..8f718b0e2a 100644 --- a/met/src/tools/other/point2grid/point2grid.cc +++ b/met/src/tools/other/point2grid/point2grid.cc @@ -328,7 +328,6 @@ void process_command_line(int argc, char **argv) { //////////////////////////////////////////////////////////////////////// void process_data_file() { - DataPlane fr_dp; Grid fr_grid, to_grid; GrdFileType ftype; ConcatString run_cs; @@ -1282,10 +1281,11 @@ void regrid_nc_variable(NcFile *nc_in, Met2dDataFile *fr_mtddf, exit(1); } else { + bool is_to_north = !fr_grid.get_swap_to_north(); float *from_data = new float[from_data_size]; for (int xIdx=0; xIdx data_value) from_min_value = data_value; if (from_max_value < data_value) from_max_value = data_value; } - - valid_cnt++; } - + if (0 < dataArray.n()) { - int data_cnt = dataArray.n(); float to_value; - if (RGInfo.method == InterpMthd_Min) to_value = dataArray.min(); + int data_cnt = dataArray.n(); + if (1 == data_cnt) to_value = dataArray[0]; + else if (RGInfo.method == InterpMthd_Min) to_value = dataArray.min(); else if (RGInfo.method == InterpMthd_Max) to_value = dataArray.max(); else if (RGInfo.method == InterpMthd_Median) { dataArray.sort_array(); @@ -1349,12 +1347,23 @@ void regrid_nc_variable(NcFile *nc_in, Met2dDataFile *fr_mtddf, to_dp.set(to_value, xIdx, yIdx); to_cell_cnt++; - mlog << Debug(9) << method_name - << "max: " << dataArray.max() - << ", min: " << dataArray.min() - << ", mean: " << dataArray.sum()/data_cnt - << " from " << valid_cnt << " out of " - << data_cnt << " data values.\n"; + if(mlog.verbosity_level() >= 9) { + double to_lat, to_lon; + to_grid.xy_to_latlon(xIdx,yIdx, to_lat, to_lon); + to_lon *= -1; + if (1 == data_cnt) + mlog << Debug(9) << method_name + << "value: " << to_value << " to (" << to_lon << ", " << to_lat + << ") from offset " << from_index << ".\n"; + else + mlog << Debug(9) << method_name + << "value: " << to_value + << ", max: " << dataArray.max() + << ", min: " << dataArray.min() + << ", mean: " << dataArray.sum()/data_cnt + << " from " << data_cnt << " (out of " << cellArray.n() + << ") data values to (" << to_lon << ", " << to_lat << ").\n"; + } } } else { @@ -1685,7 +1694,7 @@ void check_lat_lon(int data_size, float *latitudes, float *longitudes) { for (int idx=0; idx MISSING_LATLON && longitudes[idx] > MISSING_LATLON) { - mlog << Debug(7) << method_name << "index: " << idx << " lat: " + mlog << Debug(11) << method_name << "index: " << idx << " lat: " << latitudes[idx] << ", lon: " << longitudes[idx] << "\n"; cnt_printed++; } @@ -1790,8 +1799,9 @@ static bool get_grid_mapping(Grid to_grid, IntArray *cellMapping, static void get_grid_mapping_latlon( DataPlane from_dp, DataPlane to_dp, Grid to_grid, IntArray *cellMapping, float *latitudes, float *longitudes, - int from_lat_count, int from_lon_count, bool *skip_times) { + int from_lat_count, int from_lon_count, bool *skip_times, bool to_north) { double x, y; + double to_ll_lat, to_ll_lon; float lat, lon; int idx_x, idx_y, to_offset; int count_in_grid = 0; @@ -1807,11 +1817,14 @@ static void get_grid_mapping_latlon( for (int xIdx=0; xIdx= 15) { + double to_lat, to_lon; + to_grid.xy_to_latlon(idx_x, idx_y, to_lat, to_lon); + mlog << Debug(15) << method_name << " [" << xIdx << "," << yIdx << "] to " << coord_offset + << " (" << lon << ", " << lat << ") to (" << (to_lon*-1) << ", " << to_lat << ")\n"; + } } } } @@ -1918,7 +1937,8 @@ static bool get_grid_mapping(Grid fr_grid, Grid to_grid, IntArray *cellMapping, if( status ) { get_grid_mapping_latlon(from_dp, to_dp, to_grid, cellMapping, latitudes, longitudes, from_lat_count, - from_lon_count, skip_times); + from_lon_count, skip_times, + !fr_grid.get_swap_to_north()); } if( latitudes ) delete [] latitudes; if( longitudes ) delete [] longitudes; @@ -2129,7 +2149,8 @@ void get_grid_mapping(Grid fr_grid, Grid to_grid, IntArray *cellMapping, else { check_lat_lon(data_size, latitudes, longitudes); get_grid_mapping_latlon(from_dp, to_dp, to_grid, cellMapping, latitudes, - longitudes, from_lat_count, from_lon_count, 0); + longitudes, from_lat_count, from_lon_count, 0, + !fr_grid.get_swap_to_north()); } if (latitudes_buf) delete [] latitudes_buf;