Skip to content

Commit

Permalink
Feature 2857 tripolar coordinates (#2928)
Browse files Browse the repository at this point in the history
* #2857 Added MetNcCFDataFile::build_grid_from_lat_lon_vars

* #2857 Added NcCfFile::build_grid_from_lat_lon_vars

* #2857 Check the coordinates attribute to find latitude, longitude, and time variables

* #2857 Get the lat/lon variables from coordinates attribute if exists

* #2857 Added two constants

* #2857 Deleted debug messages

* #2857 Added lat_vname and lon_vname for var_name_map

* #2857 Added two unit tests: point2grid_sea_ice_tripolar and point2grid_sea_ice_tripolar_config

* #2857 Initial release

* #2857 Correct dictinary to get file_type

* #2857 DO not check the time variable for point2grid

* #2857 Added point2grid_tripolar_rtofs

---------

Co-authored-by: Howard Soh <[email protected]>
  • Loading branch information
hsoh-u and Howard Soh authored Jul 9, 2024
1 parent 10a449e commit fddc39f
Show file tree
Hide file tree
Showing 10 changed files with 362 additions and 83 deletions.
12 changes: 11 additions & 1 deletion docs/Users_Guide/reformat_point.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,7 @@ point2grid Configuration File

The default configuration file for the point2grid tool named **Point2GridConfig_default** can be found in the installed *share/met/config* directory. It is recommended that users make a copy of this file prior to modifying its contents.

The point2grid configuration file is optional and only necessary when defining the variable name instead of GRIB code or filtering by time. The contents of the default MADIS2NC configuration file are described below.
The point2grid configuration file is optional and only necessary when defining the variable name instead of GRIB code or filtering by time. The contents of the default point2grid configuration file are described below.

_____________________

Expand Down Expand Up @@ -1194,6 +1194,16 @@ The configuration option listed above is common to many MET tools and are descri
This entry is an array of dictionaries, each containing a **GRIB code** string and mathcing **variable name** string which define a mapping of GRIB code to the output variable names.

.. code-block:: none
var_name_map = [
...
{ key = "lat_vname"; val = "NLAT"; },
{ key = "lon_vname"; val = "NLON"; }
...
]
The latitude and longitude variables for NetCDF input can be overridden by the configurations. There are two special keys, **lat_vname** and **lon_vname** which are applied to the NetCDF input, not for GRIB code.

Point NetCDF to ASCII Python Utility
====================================
Expand Down
4 changes: 4 additions & 0 deletions internal/test_unit/config/Point2GridConfig_lat_lon
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var_name_map = [
{ key = "lat_vname"; val = "NLAT"; },
{ key = "lon_vname"; val = "NLON"; }
];
73 changes: 73 additions & 0 deletions internal/test_unit/xml/unit_point2grid.xml
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,78 @@
</output>
</test>

<test name="point2grid_tripolar_sea_ice">
<exec>&MET_BIN;/point2grid</exec>
<env>
<pair><name>MET_TMP_DIR</name> <value>&OUTPUT_DIR;/point2grid</value></pair>
</env>
<param> \
&DATA_DIR_OBS;/point_obs/iceh.2018-01-03.c00.small.nc \
G171 \
&OUTPUT_DIR;/point2grid/point2grid_sea_ice.nc \
-field 'name="uvel_d"; level="(0,*,*)";' -field 'name="hi_d"; level="(0,*,*)";' \
-v 1
</param>
<output>
<grid_nc>&OUTPUT_DIR;/point2grid/point2grid_sea_ice.nc</grid_nc>
</output>
</test>

<test name="point2grid_tripolar_sea_ice_config">
<exec>&MET_BIN;/point2grid</exec>
<env>
<pair><name>MET_TMP_DIR</name> <value>&OUTPUT_DIR;/point2grid</value></pair>
</env>
<param> \
&DATA_DIR_OBS;/point_obs/iceh.2018-01-03.c00.small.nc \
G171 \
&OUTPUT_DIR;/point2grid/point2grid_sea_ice_snow.nc \
-config &CONFIG_DIR;/Point2GridConfig_lat_lon \
-field 'name="hs_d_without_att"; level="(0,*,*)";' \
-v 1
</param>
<output>
<grid_nc>&OUTPUT_DIR;/point2grid/point2grid_sea_ice_snow.nc</grid_nc>
</output>
</test>

<!--
<test name="point2grid_tripolar_gfs_ocean">
<exec>&MET_BIN;/point2grid</exec>
<env>
<pair><name>MET_TMP_DIR</name> <value>&OUTPUT_DIR;/point2grid</value></pair>
</env>
<param> \
&DATA_DIR_OBS;/point_obs/gfs.ocean.t00z.6hr_avg.f006_SST.nc \
"latlon 360 180 -90 -180 1.0 1.0" \
&OUTPUT_DIR;/point2grid/point2grid_gfs_ocean_SST.nc \
-field 'name="SST"; level="(0,*,*)";' \
-config &CONFIG_DIR;/Point2GridConfig_SST \
-v 1
</param>
<output>
<grid_nc>&OUTPUT_DIR;/point2grid/point2grid_gfs_ocean_SST.nc</grid_nc>
</output>
</test>
-->

<test name="point2grid_tripolar_rtofs">
<exec>&MET_BIN;/point2grid</exec>
<env>
<pair><name>MET_TMP_DIR</name> <value>&OUTPUT_DIR;/point2grid</value></pair>
</env>
<param> \
&DATA_DIR_OBS;/point_obs/rtofs_glo_2ds_f006_ice_coverage.nc \
"latlon 720 360 -80. -60. 0.5 0.5" \
&OUTPUT_DIR;/point2grid/point2grid_rtofs_ice_coverage.nc \
-field 'name="ice_coverage"; level="(0,*,*)";' \
-v 1
</param>
<output>
<grid_nc>&OUTPUT_DIR;/point2grid/point2grid_rtofs_ice_coverage.nc</grid_nc>
</output>
</test>

<test name="point2grid_GOES_16_AOD_TO_G212_unsigned">
<exec>&MET_BIN;/point2grid</exec>
<env>
Expand Down Expand Up @@ -283,4 +355,5 @@
<grid_nc>&OUTPUT_DIR;/point2grid/point2grid_2D_time_west_bering_sea.nc</grid_nc>
</output>
</test>

</met_test>
2 changes: 2 additions & 0 deletions src/basic/vx_config/config_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,8 @@ static const char conf_key_mask_sid[] = "mask.sid";
static const char conf_key_mask_llpnt[] = "mask.llpnt";
static const char conf_key_lat_thresh[] = "lat_thresh";
static const char conf_key_lon_thresh[] = "lon_thresh";
static const char conf_key_lat_vname[] = "lat_vname";
static const char conf_key_lon_vname[] = "lon_vname";
static const char conf_key_ci_alpha[] = "ci_alpha";
static const char conf_key_time_summary[] = "time_summary";
static const char conf_key_flag[] = "flag";
Expand Down
8 changes: 8 additions & 0 deletions src/libcode/vx_data2d_nc_cf/data2d_nc_cf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -673,4 +673,12 @@ long MetNcCFDataFile::convert_value_to_offset(double z_value, string z_dim_name)
return z_offset;
}

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

Grid MetNcCFDataFile::build_grid_from_lat_lon_vars(NcVar *lat_var, NcVar *lon_var,
const long lat_counts, const long lon_counts) {
return (nullptr != _file) ? _file->build_grid_from_lat_lon_vars(lat_var, lon_var, lat_counts, lon_counts) : grid();
}


////////////////////////////////////////////////////////////////////////
3 changes: 3 additions & 0 deletions src/libcode/vx_data2d_nc_cf/data2d_nc_cf.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ class MetNcCFDataFile : public Met2dDataFile {

void dump(std::ostream &, int = 0) const;

Grid build_grid_from_lat_lon_vars(netCDF::NcVar *lat_var, netCDF::NcVar *lon_var,
const long lat_counts, const long lon_counts);

};


Expand Down
33 changes: 26 additions & 7 deletions src/libcode/vx_data2d_nc_cf/nc_cf_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ double NcCfFile::getData(NcVar * var, const LongArray & a) const

if (!status)
{
mlog << Error << "\nNcCfFile::getData(NcVar *, const LongArray &) const -> "
mlog << Error << "\n" << method_name
<< "bad status for var->get()\n\n";
exit(1);
}
Expand Down Expand Up @@ -1091,8 +1091,8 @@ bool NcCfFile::getData(NcVar * v, const LongArray & a, DataPlane & plane) const

plane.set(value, x, y_offset);

} // for x
} // for y
} /* for y */
} /* for x */
}
else {
for (int x = 0; x< nx; ++x) {
Expand All @@ -1108,8 +1108,8 @@ bool NcCfFile::getData(NcVar * v, const LongArray & a, DataPlane & plane) const

plane.set(value, x, y_offset);

} // for y
} // for x
} /* for y */
} /* for x */
}

delete [] d;
Expand All @@ -1130,7 +1130,7 @@ bool NcCfFile::getData(const char *var_name,
NcVarInfo *&info) const
{
info = find_var_name(var_name);
if (info == 0)
if (info == nullptr)
return false;

bool found = getData(info->var, a, plane);
Expand Down Expand Up @@ -1475,6 +1475,25 @@ void NcCfFile::read_netcdf_grid()
////////////////////////////////////////////////////////////////////////


Grid NcCfFile::build_grid_from_lat_lon_vars(NcVar *lat_var, NcVar *lon_var,
const long lat_counts, const long lon_counts) {
Grid grid_ll;
bool swap_to_north;
LatLonData data = get_data_from_lat_lon_vars(lat_var, lon_var,
lat_counts, lon_counts,
swap_to_north);

data.dump();

grid_ll.set(data); // resets swap_to_north to false
if (swap_to_north) grid_ll.set_swap_to_north(true);
return grid_ll;
}


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


void NcCfFile::get_grid_from_grid_mapping(const NcVarAtt *grid_mapping_att)
{
static const string method_name = "NcCfFile::get_grid_from_grid_mapping()";
Expand Down Expand Up @@ -3180,7 +3199,7 @@ bool NcCfFile::get_grid_from_dimensions()
}

if (!has_var(_ncFile, dim_name.c_str())) {
mlog << Debug(4) << method_name << " -> " << "The coordinate variable \""
mlog << Debug(6) << method_name << " -> " << "The coordinate variable \""
<< _dims[dim_num]->getName() << "\" does not exist.\n";
continue;
}
Expand Down
18 changes: 11 additions & 7 deletions src/libcode/vx_data2d_nc_cf/nc_cf_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,18 @@ class NcCfFile {

return GET_NC_SIZE_P(_xDim);
}

int getNy() const
{
if (_yDim == 0)
return 0;

return GET_NC_SIZE_P(_yDim);
}

NcVarInfo *get_time_var_info() const { return _time_var_info; }



//
// time
//
Expand All @@ -93,6 +94,7 @@ class NcCfFile {
int Nvars;

NcVarInfo * Var; // allocated
StringArray coord_var_names;

//
// Grid
Expand All @@ -110,13 +112,15 @@ class NcCfFile {

bool getData(const char *, const LongArray &, DataPlane &, NcVarInfo *&) const;

Grid build_grid_from_lat_lon_vars(netCDF::NcVar *lat_var, netCDF::NcVar *lon_var,
const long lat_counts, const long lon_counts);
NcVarInfo* find_var_name(const char * var_name) const;
NcVarInfo* find_var_by_dim_name(const char *dim_name) const;

private:

static const double DELTA_TOLERANCE;

netCDF::NcFile * _ncFile; // allocated

//
Expand All @@ -142,7 +146,7 @@ class NcCfFile {
netCDF::NcVar *_xCoordVar;
netCDF::NcVar *_yCoordVar;
NcVarInfo *_time_var_info;

void init_from_scratch();

NcCfFile(const NcCfFile &);
Expand All @@ -164,7 +168,7 @@ class NcCfFile {

void read_netcdf_grid();
void get_grid_from_grid_mapping(const netCDF::NcVarAtt *grid_mapping_att);

void get_grid_mapping_albers_conical_equal_area(const netCDF::NcVar *grid_mapping_var);
void get_grid_mapping_azimuthal_equidistant(const netCDF::NcVar *grid_mapping_var);
void get_grid_mapping_lambert_azimuthal_equal_area(const netCDF::NcVar *grid_mapping_var);
Expand All @@ -179,7 +183,7 @@ class NcCfFile {
void get_grid_mapping_transverse_mercator(const netCDF::NcVar *grid_mapping_var);
void get_grid_mapping_vertical_perspective(const netCDF::NcVar *grid_mapping_var);
void get_grid_mapping_geostationary(const netCDF::NcVar *grid_mapping_var);

bool get_grid_from_coordinates(const netCDF::NcVar *data_var);
bool get_grid_from_dimensions();
void get_grid_from_lat_lon_vars(netCDF::NcVar *lat_var, netCDF::NcVar *lon_var,
Expand Down
Loading

0 comments on commit fddc39f

Please sign in to comment.