Skip to content

Commit

Permalink
#2285 Uses MaskFilters
Browse files Browse the repository at this point in the history
  • Loading branch information
Howard Soh committed Apr 7, 2023
1 parent 521fb14 commit a5a16fe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 71 deletions.
58 changes: 6 additions & 52 deletions src/tools/other/ascii2nc/file_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,6 @@ FileHandler::FileHandler(const string &program_name) :
_nhdr(0),
_hdrNum(0),
_obsNum(0),
_gridMaskNum(0),
_areaMaskNum(0),
_polyMaskNum(0),
_sidMaskNum(0),
_gridMask(0),
_areaMask(0),
_polyMask(0),
_sidMask(0),
use_var_id(false),
do_monitor(false),
deflate_level(DEF_DEFLATE_LEVEL),
Expand Down Expand Up @@ -121,11 +113,11 @@ bool FileHandler::writeNetcdfFile(const string &nc_filename)
// List the number of rejected observations.

mlog << Debug(2)
<< "Rejected " << _gridMaskNum
<< "Rejected " << filters.get_grid_mask_cnt()
<< " observations off the masking grid.\n"
<< "Rejected " << _areaMaskNum + _polyMaskNum
<< "Rejected " << filters.get_area_mask_cnt() + filters.get_poly_mask_cnt()
<< " observations outside the masking polyline.\n"
<< "Rejected " << _sidMaskNum
<< "Rejected " << filters.get_sid_mask_cnt()
<< " observations not matched with station ID's.\n";

// Loop through the observations, counting the number of headers needed in
Expand Down Expand Up @@ -274,52 +266,14 @@ bool FileHandler::_addObservations(const Observation &obs)
double grid_x, grid_y;

//
// Apply the grid mask
// Apply the grid mask, the area mask, and the polyline mask
//
if(_gridMask) {
_gridMask->latlon_to_xy(obs.getLatitude(), -1.0*obs.getLongitude(),
grid_x, grid_y);

if(grid_x < 0 || grid_x >= _gridMask->nx() ||
grid_y < 0 || grid_y >= _gridMask->ny()) {
_gridMaskNum++;
return false;
}

//
// Apply the area mask
//
if(_areaMask) {
if(!_areaMask->s_is_on(nint(grid_x), nint(grid_y))) {
_areaMaskNum++;
return false;
}
}
}

//
// Apply the polyline mask
//
if(_polyMask)
{
if(!_polyMask->latlon_is_inside_dege(obs.getLatitude(), obs.getLongitude()))
{
_polyMaskNum++;
return false;
}
}
if(filters.is_filtered(obs.getLatitude(), obs.getLongitude())) return false;

//
// Apply the station ID mask
//
if(_sidMask)
{
if(!_sidMask->has(obs.getStationId().c_str()))
{
_sidMaskNum++;
return false;
}
}
if(filters.is_filtered_sid(obs.getStationId().c_str())) return false;

// Save obs because the obs vector is sorted after time summary
_observations.push_back(obs);
Expand Down
25 changes: 6 additions & 19 deletions src/tools/other/ascii2nc/file_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <netcdf>

#include "mask_poly.h"
#include "mask_filters.h"
#include "vx_grid.h"
#include "vx_config.h"
#include "vx_util.h"
Expand Down Expand Up @@ -92,15 +93,7 @@ class FileHandler
int _hdrNum;
int _obsNum;

int _gridMaskNum;
int _areaMaskNum;
int _polyMaskNum;
int _sidMaskNum;

Grid *_gridMask;
MaskPlane *_areaMask;
MaskPoly *_polyMask;
StringArray *_sidMask;
MaskFilters filters;

map<ConcatString, ConcatString> _messageTypeMap;

Expand Down Expand Up @@ -149,20 +142,14 @@ class FileHandler

void _closeNetcdf();
bool _openNetcdf(const string &nc_filename);
// bool _writeHdrInfo(const ConcatString &hdr_typ,
// const ConcatString &hdr_sid,
// const time_t hdr_vld,
// double lat, double lon, double elv);
// bool _writeObsInfo(int gc, float prs, float hgt, float obs,
// const ConcatString &qty);
void debug_print_observations(vector< Observation >, string);
};

inline void FileHandler::setCompressionLevel(int compressoion_level) { deflate_level = compressoion_level; }
inline void FileHandler::setGridMask(Grid &g) { _gridMask = &g; }
inline void FileHandler::setAreaMask(MaskPlane &a) { _areaMask = &a; }
inline void FileHandler::setPolyMask(MaskPoly &p) { _polyMask = &p; }
inline void FileHandler::setSIDMask (StringArray &s) { _sidMask = &s; }
inline void FileHandler::setGridMask(Grid &g) { filters.set_grid_mask(&g); }
inline void FileHandler::setAreaMask(MaskPlane &a) { filters.set_area_mask(&a); }
inline void FileHandler::setPolyMask(MaskPoly &p) { filters.set_poly_mask(&p); }
inline void FileHandler::setSIDMask (StringArray &s) { filters.set_sid_mask(&s); }
inline void FileHandler::setMessageTypeMap(map<ConcatString, ConcatString> m) {
_messageTypeMap = m;
}
Expand Down

0 comments on commit a5a16fe

Please sign in to comment.