Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature 1454 nccf grid definition #1688

Merged
merged 8 commits into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions met/src/libcode/vx_data2d_nc_met/met_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ static const string valid_time_ut_att_name = "valid_time_ut";
static const string init_time_ut_att_name = "init_time_ut";
static const string accum_time_att_name = "accum_time_sec";

static const string name_att_name = "name";
static const string long_name_att_name = "long_name";
static const string level_att_name = "level";
static const string units_att_name = "units";

static const int max_met_args = 30;

////////////////////////////////////////////////////////////////////////
Expand Down
3 changes: 0 additions & 3 deletions met/src/libcode/vx_data2d_nc_pinterp/pinterp_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ static const char hpa_units_str [] = "hPa";

static const string init_time_att_name = "START_DATE";

static const string description_att_name = "description";
static const string units_att_name = "units";

static const int max_pinterp_args = 30;

static const double pinterp_missing = 1.0e35;
Expand Down
102 changes: 54 additions & 48 deletions met/src/libcode/vx_data2d_nccf/nccf_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ using namespace std;
////////////////////////////////////////////////////////////////////////


static const int max_met_args = 30;
static const int max_met_args = 30;
static const double DELTA_TOLERANCE_PERCENT = 0.05;

const double NcCfFile::DELTA_TOLERANCE = 15.0;

Expand Down Expand Up @@ -2870,40 +2871,40 @@ void NcCfFile::get_grid_from_lat_lon_vars(NcVar *lat_var, NcVar *lon_var,

// Figure out the dlat/dlon values from the dimension variables

double lat_values[lat_counts];
double lon_values[lon_counts];

bool two_dim_corrd = false;
long x_size = get_data_size(lon_var);
long y_size = get_data_size(lat_var);
long latlon_counts = lon_counts*lat_counts;
if( x_size == latlon_counts || y_size == latlon_counts ) two_dim_corrd = true;
else if( x_size != lon_counts || y_size != lat_counts)
bool two_dim_corrd = (x_size == latlon_counts) && (y_size == latlon_counts );
if( !two_dim_corrd && (x_size != lon_counts || y_size != lat_counts))
{
mlog << Error << "\n" << method_name << " -> "
<< "Coordinate variables don't match dimension sizes in netCDF file.\n\n";
exit(1);
}

double lat_values[lat_counts];
double lon_values[lon_counts];
bool lat_first = false;
if (two_dim_corrd) {
lat_first = (lat_counts == get_dim_size(lat_var, 0));
long cur[2], length[2];
for (int i=0; i<2; i++) {
cur[i] = 0;
length[i] = 1;
}
length[0] = lat_counts;
cur[0] = cur[1] = 0;
length[0] = length[1] = 1;
if (lat_first) length[0] = lat_counts;
else length[1] = lat_counts;
get_nc_data(lat_var,lat_values, length, cur);
length[1] = lon_counts;
length[0] = 1;

length[0] = length[1] = 1;
if (lat_first) length[1] = lon_counts;
else length[0] = lon_counts;
get_nc_data(lon_var,lon_values, length, cur);
}
else {
get_nc_data(lat_var,lat_values);
get_nc_data(lon_var,lon_values);
}

// Calculate dlat and dlon assuming they are constant. MET requires that
// dlat be equal to dlon
// Calculate dlat and dlon assuming they are constant.

double dlat = lat_values[1] - lat_values[0];
double dlon = rescale_lon(lon_values[1] - lon_values[0]);
Expand All @@ -2919,53 +2920,58 @@ void NcCfFile::get_grid_from_lat_lon_vars(NcVar *lat_var, NcVar *lon_var,
// entire grid. CF compliancy doesn't require this, but MET does.

if (!skip_sanity_check) {
double degree_tolerance;
float lat_missing_value = bad_data_double;
float lon_missing_value = bad_data_double;
NcVarAtt *missing_value_att = (NcVarAtt*) 0;
missing_value_att = get_nc_att(lat_var, (string)"_FillValue");
if (IS_VALID_NC_P(missing_value_att)) {
lat_missing_value = get_att_value_double(missing_value_att);
}
if( missing_value_att ) delete missing_value_att;
missing_value_att = get_nc_att(lon_var, (string)"_FillValue");
if (IS_VALID_NC_P(missing_value_att)) {
lon_missing_value = get_att_value_double(missing_value_att);
}
if( missing_value_att ) delete missing_value_att;
bool sanity_check_failed = false;
get_var_att_float(lat_var, fill_value_att_name, lat_missing_value);
get_var_att_float(lon_var, fill_value_att_name, lon_missing_value);

if (fabs(dlat - dlon) > DELTA_TOLERANCE)
{
mlog << Error << "\n" << method_name << " -> "
<< "MET can only process Latitude/Longitude files where the delta lat and delta lon are the same\n\n";
exit(1);
}

degree_tolerance = fabs(dlat * DELTA_TOLERANCE_PERCENT);
for (int i = 1; i < (int)lat_counts; ++i)
{
if ((fabs(lat_missing_value - lat_values[i]) < DELTA_TOLERANCE) ||
(fabs(lat_missing_value - lat_values[i-1]) < DELTA_TOLERANCE)) continue;
if ((fabs(lat_missing_value - lat_values[i]) < degree_tolerance) ||
(fabs(lat_missing_value - lat_values[i-1]) < degree_tolerance)) continue;
double curr_delta = lat_values[i] - lat_values[i-1];
if (fabs(curr_delta - dlat) > DELTA_TOLERANCE)
if (fabs(curr_delta - dlat) > degree_tolerance)
{
mlog << Debug(4) << method_name << " -> lat["
<< i-1 << "]=" << lat_values[i-1] << " lat["
<< i << "]=" << lat_values[i] << " "
<< fabs(curr_delta - dlat) << " > " << degree_tolerance << "\n";
mlog << Error << "\n" << method_name << " -> "
<< "MET can only process Latitude/Longitude files where the lat delta is constant (dlat="
<< dlat <<", dlon=" << dlon << ")\n\n";
exit(1);
<< "MET can only process Latitude/Longitude files where the latitudes are evenly spaced (dlat="
<< dlat <<", delta[" << i << "]=" << curr_delta << ")\n\n";
sanity_check_failed = true;
break;
}
}


degree_tolerance = fabs(dlon * DELTA_TOLERANCE_PERCENT);
for (int i = 1; i < (int)lon_counts; ++i)
{
if ((fabs(lon_missing_value - lon_values[i]) < DELTA_TOLERANCE) ||
(fabs(lon_missing_value - lon_values[i-1]) < DELTA_TOLERANCE)) continue;
if ((fabs(lon_missing_value - lon_values[i]) < degree_tolerance) ||
(fabs(lon_missing_value - lon_values[i-1]) < degree_tolerance)) continue;
double curr_delta = rescale_lon(lon_values[i] - lon_values[i-1]);
if (fabs(curr_delta - dlon) > DELTA_TOLERANCE)
if (fabs(curr_delta - dlon) > degree_tolerance)
{
mlog << Debug(4) << method_name << " -> lon["
<< i-1 << "]=" << lon_values[i-1] << " lon["
<< i << "]=" << lon_values[i] << " "
<< fabs(curr_delta - dlon) << " > " << degree_tolerance << "\n";
mlog << Error << "\n" << method_name << " -> "
<< "MET can only process Latitude/Longitude files where the lon delta is constant\n\n";
exit(1);
<< "MET can only process Latitude/Longitude files where the longitudes are evenly spaced (dlon="
<< dlon <<", delta[" << i << "]=" << curr_delta << ")\n\n";
sanity_check_failed = true;
break;
}
}

if (sanity_check_failed) {
mlog << Error << "\n" << method_name << " -> "
<< "Please check the input data is the lat/lon projection\n\n";
exit(1);
}
}

// Fill in the data structure. Remember to negate the longitude
Expand All @@ -2991,9 +2997,9 @@ void NcCfFile::get_grid_from_lat_lon_vars(NcVar *lat_var, NcVar *lon_var,
data.lat_ll = lat_values[lat_counts-1];
}

grid.set(data);
grid.set(data); // resets swap_to_north to false
if (dlat < 0) grid.set_swap_to_north(true);

}

////////////////////////////////////////////////////////////////////////
5 changes: 0 additions & 5 deletions met/src/libcode/vx_nc_util/nc_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ using namespace netCDF::exceptions;

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

static const string level_att_name = "level";
static const string units_att_name = "units";
static const string missing_value_att_name = "missing_value";
static const string fill_value_att_name = "_FillValue";

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

void patch_nc_name(string *var_name) {
Expand Down
9 changes: 9 additions & 0 deletions met/src/libcode/vx_nc_util/nc_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ static const string nc_att_use_var_id = "use_var_id";
static const char nc_att_obs_version[] = "MET_Obs_version";
static const char nc_att_met_point_nccf[] = "MET_point_NCCF";

static const string description_att_name = "description";
static const string fill_value_att_name = "_FillValue";
static const string level_att_name = "level";
static const string long_name_att_name = "long_name";
static const string missing_value_att_name = "missing_value";
static const string name_att_name = "name";
static const string units_att_name = "units";


static const char nc_time_unit_exp[] = "^[a-z|A-Z]* since [0-9]\\{1,4\\}-[0-9]\\{1,2\\}-[0-9]\\{1,2\\}";

static const char MET_NC_Obs_ver_1_2[] = "1.02";
Expand Down
41 changes: 0 additions & 41 deletions test/xml/unit_plot_data_plane.xml
Original file line number Diff line number Diff line change
Expand Up @@ -343,47 +343,6 @@
</output>
</test>

<test name="plot_data_plane_CESM_SSMI_microwave">
<exec>&MET_BIN;/plot_data_plane</exec>
<param> \
&DATA_DIR_MODEL;/cesm/ssmi.ifrac.gx3v5.2003.nc \
&OUTPUT_DIR;/plot_data_plane/CESM_ssmi.ifrac.gx3v5.2003.ps \
'name="ifrac"; level="(0,*,*)";' \
-v 4
</param>
<output>
<ps>&OUTPUT_DIR;/plot_data_plane/CESM_ssmi.ifrac.gx3v5.2003.ps</ps>
</output>
</test>

<test name="plot_data_plane_CESM_sea_ice_nc">
<exec>&MET_BIN;/plot_data_plane</exec>
<param> \
&DATA_DIR_MODEL;/cesm/b.e11.B20TRC5CNBDRD.f09_g16.002.cice.h1.aice_d_nh.19200101-20051231.nc \
&OUTPUT_DIR;/plot_data_plane/CESM_b.e11.B20TRC5CNBDRD.f09_g16.002.cice.h1.aice_d_nh.19200101-20051231.ps \
'name="aice_d"; level="(0,*,*)";' \
-v 4
</param>
<output>
<ps>&OUTPUT_DIR;/plot_data_plane/CESM_b.e11.B20TRC5CNBDRD.f09_g16.002.cice.h1.aice_d_nh.19200101-20051231.ps</ps>
</output>
</test>

<!--
<test name="plot_data_plane_EaSM_CMIP5_histroical">
<exec>&MET_BIN;/plot_data_plane</exec>
<param> \
&DATA_DIR_MODEL;/easm/pr_day_MPI-ESM-MR_historical_r1i1p1_20000101-20051231.nc \
&OUTPUT_DIR;/plot_data_plane/EaSM_CMIP5_pr_day_MPI-ESM-MR_historical_r1i1p1_20000101-20051231.ps \
'name="pr"; level="(0,*,*)";' \
-v 4
</param>
<output>
<ps>&OUTPUT_DIR;/plot_data_plane/EaSM_CMIP5_pr_day_MPI-ESM-MR_historical_r1i1p1_20000101-20051231.ps</ps>
</output>
</test>
-->

<test name="plot_data_plane_EaSM_CMIP5_rcp85">
<exec>&MET_BIN;/plot_data_plane</exec>
<param> \
Expand Down