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 1823 global #1928

Merged
merged 27 commits into from
Oct 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7473c30
Per #1823, no actual code changes. Just making code header formatting…
JohnHalleyGotway Sep 3, 2021
d30a11d
Per #1823, more reformatting of headers for consistency. No code chan…
JohnHalleyGotway Sep 3, 2021
65e2348
Per #1823, more formatting.
JohnHalleyGotway Sep 3, 2021
d75f9df
Per #1823, updates to the vx_util library. But note that this is just…
JohnHalleyGotway Sep 3, 2021
14ba728
Per #1823, move _isGlobal into the GridTemplate base class since that…
JohnHalleyGotway Sep 7, 2021
7dbba9c
Per #1823, this is a clear and obvious bugfix. The interp.vld_thresh …
JohnHalleyGotway Sep 8, 2021
edc6693
Per #1823, update the GridTemplate member functions to wrap X for glo…
JohnHalleyGotway Sep 8, 2021
6d25638
Per #1823, update the interp_xy and interp_bilin functions to handle …
JohnHalleyGotway Sep 8, 2021
c36ef89
Per #1823, add LatLonGrid isGlobal member and set it right when the g…
JohnHalleyGotway Sep 8, 2021
fdc0e95
Per #1823, update compute_interp() and get_interp_points() functions …
JohnHalleyGotway Sep 8, 2021
6d7a981
Per #1823, remove the unused fractional_coverage_square() function ra…
JohnHalleyGotway Sep 8, 2021
d732bc1
Per #1823, update application code to make updated calls to DataPlane…
JohnHalleyGotway Sep 8, 2021
c88806f
Per #1823, update PairDataPoint and PairDataEnsemble classes for glob…
JohnHalleyGotway Sep 8, 2021
5069805
Per #1823, update regridding logic to only skip points off the grid i…
JohnHalleyGotway Sep 8, 2021
f249909
Per #1823, include the interpolation method/width in the log message …
JohnHalleyGotway Sep 8, 2021
870b65a
Per #1823, added a positive_modulo(int, int) utility function to mimi…
JohnHalleyGotway Sep 8, 2021
567c515
Merge branch 'develop' into feature_1823_global
JohnHalleyGotway Sep 28, 2021
6447a01
Per #1823, rename is_global related variables to wrap_lon instead. Th…
JohnHalleyGotway Sep 29, 2021
0d5e5d0
Per #1823, fix typo.
JohnHalleyGotway Sep 29, 2021
89cb3c9
Per #1823, add a new call to regrid_data_plane that in met version 10…
JohnHalleyGotway Sep 30, 2021
303d72a
Per #1823, switch the regrid_data_plane call to use existing input da…
JohnHalleyGotway Sep 30, 2021
8fc6940
Per #1823, print a log message when a global grid has a longitude spa…
JohnHalleyGotway Sep 30, 2021
b039add
Per #1823, working on the log message.
JohnHalleyGotway Sep 30, 2021
2de7640
Per #1823, change to debug 4.
JohnHalleyGotway Sep 30, 2021
dcdbe17
Per #1823, just whitespace
JohnHalleyGotway Sep 30, 2021
39b882f
Per #1823, fix spacing.
JohnHalleyGotway Oct 1, 2021
10d726f
Per #1823, correct halfheight to halfwidth.
JohnHalleyGotway Oct 1, 2021
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
10 changes: 10 additions & 0 deletions met/src/basic/vx_math/nint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,13 @@ return ( a );
////////////////////////////////////////////////////////////////////////


int positive_modulo(int i, int n)

{

return ( i % n + n ) % n;

}


////////////////////////////////////////////////////////////////////////
12 changes: 9 additions & 3 deletions met/src/basic/vx_math/nint.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
////////////////////////////////////////////////////////////////////////


#ifndef __PS_DITHER_NINT_H__
#define __PS_DITHER_NINT_H__
#ifndef __VX_MATH_NINT_H__
#define __VX_MATH_NINT_H__


////////////////////////////////////////////////////////////////////////
Expand All @@ -24,7 +24,13 @@ extern int nint(double);
////////////////////////////////////////////////////////////////////////


#endif // __PS_DITHER_NINT_H__
extern int positive_modulo(int, int);


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


#endif // __VX_MATH_NINT_H__


////////////////////////////////////////////////////////////////////////
Expand Down
236 changes: 90 additions & 146 deletions met/src/basic/vx_util/CircularTemplate.cc
Original file line number Diff line number Diff line change
@@ -1,47 +1,25 @@
// *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
// ** Copyright UCAR (c) 1990 - 2021
// ** University Corporation for Atmospheric Research (UCAR)
// ** National Center for Atmospheric Research (NCAR)
// ** Boulder, Colorado, USA
// ** BSD licence applies - redistribution and use in source and binary
// ** forms, with or without modification, are permitted provided that
// ** the following conditions are met:
// ** 1) If the software is modified to produce derivative works,
// ** such modified software should be clearly marked, so as not
// ** to confuse it with the version available from UCAR.
// ** 2) Redistributions of source code must retain the above copyright
// ** notice, this list of conditions and the following disclaimer.
// ** 3) Redistributions in binary form must reproduce the above copyright
// ** notice, this list of conditions and the following disclaimer in the
// ** documentation and/or other materials provided with the distribution.
// ** 4) Neither the name of UCAR nor the names of its contributors,
// ** if any, may be used to endorse or promote products derived from
// ** this software without specific prior written permission.
// ** DISCLAIMER: THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS
// ** OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
// ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
// *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/

// RCS info: dixon $
// $Locker: $
// $Date: 2016/03/03 18:19:27 $
// $Id: CircularTemplate.cc,v 1.6 2016/03/03 18:19:27 dixon Exp $
// $Revision: 1.6 $
// $State: Exp $

/**-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**/
/*********************************************************************
* CircularTemplate.cc: class implementing a circular template to be
* applied on gridded data.
*
* RAP, NCAR, Boulder CO
*
* January 1999
*
* Nancy Rehak
*
*********************************************************************/
// *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
// ** Copyright UCAR (c) 1992 - 2021
// ** University Corporation for Atmospheric Research (UCAR)
// ** National Center for Atmospheric Research (NCAR)
// ** Research Applications Lab (RAL)
// ** P.O.Box 3000, Boulder, Colorado, 80307-3000, USA
// *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*

///////////////////////////////////////////////////////////////////////////////
//
// Filename: CircularTemplate.cc
//
// Description:
// Class implementing a Circular template to be
// applied on gridded data.
//
// Mod# Date Name Description
// ---- ---- ---- -----------
// 000 01-01-99 Rehak Initial version.
// 001 09-07-21 Halley Gotway Add wrap_lon.
//
///////////////////////////////////////////////////////////////////////////////

#include <vector>

Expand All @@ -56,126 +34,92 @@

using namespace std;

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

/**********************************************************************
* Constructor
*/
CircularTemplate::CircularTemplate(const int width, bool wrap_lon) :
GridTemplate(), _width(width) {

CircularTemplate::CircularTemplate(const int width) :
GridTemplate(),
_width(width)
{
_wrapLon = wrap_lon;

//width of 2 is not supported
if (width == 2){
mlog << Error << "\nCircularTemplate::CircularTemplate() -> "
<< "unsupported width of " << width
<< " for circles.\n\n";
// width of 2 is not supported
if (width == 2) {
mlog << Error << "\nCircularTemplate::CircularTemplate() -> "
<< "unsupported width of " << width << " for circles.\n\n";
exit(1);
}

bool evenWidth = ((width % 2) == 0);
// if the width is even, that means we are dealing with a point interpolation
// because grid interpolation has to be odd.

// for an ODD WIDTH the reference point is the same as the center point and is the nearest grid point

// for an EVEN WIDTH, we move the "reference" point, to the lower left grid point,
// this means offsets are stored relative to the lower left corner of the true center.
// but we find distances based on the the true center location when determining if an
// offset is within the circle.

double radius = (width-1)/2.0;
bool evenWidth = ((width % 2) == 0);

// if the width is even, that means we are dealing with a point interpolation
// because grid interpolation has to be odd.
// for an ODD WIDTH the reference point is the same as the center point and is the nearest grid point
// for an EVEN WIDTH, we move the "reference" point, to the lower left grid point,
// this means offsets are stored relative to the lower left corner of the true center.
// but we find distances based on the the true center location when determining if an
// offset is within the circle.

double radius = (width-1)/2.0;

// Create the offsets list.

// If the radius is small, then just make the
// template cover the current grid square.
// radius < 1 no longer supported.
/*
if (radius < 1.0)
{
_addOffset(0, 0);
return;
}
*/
// Create the offsets list.

// need to increase the area we look at if the width is even, because
// some valid offset points will actually be farther from the reference point
// than the radius, because the reference point is offset from the true
// center of the circle.
int maxOffset = static_cast<int>(floor(radius));
if (evenWidth){
maxOffset++;
}
// Need to increase the area we look at if the width is even, because
// some valid offset points will actually be farther from the reference point
// than the radius, because the reference point is offset from the true
// center of the circle.

int maxOffset = static_cast<int>(floor(radius));
if(evenWidth) maxOffset++;

int minOffset = static_cast<int>(floor(-1 * radius));
int minOffset = static_cast<int>(floor(-1 * radius));

for (int y = minOffset; y <= maxOffset; y++)
{
for (int x = minOffset; x <= maxOffset; x++)
{
double double_x = (double)x;
double double_y = (double)y;

if (evenWidth){
// if width is even, the reference point is actually shifted 1/2 a grid spacing down and to the left,
// from the true center of the circle.
//
// so when we calculate distance, we need to subtract .5 so that the distance reflects the distance from the center
// of the circle, instead of the distance from the reference.
//
// for example - a circle with width == 4. The reference point is the lower left corner of the center square.
// the point directly below that is at (0,-1), but it's actually (-.5, -1.5) from the center of the circle.
//
// another example - same circle. The point directly to the right of the reference point is (1,0), but it's
// actually (.5,-.5) from the center.
for(int y = minOffset; y <= maxOffset; y++) {
for(int x = minOffset; x <= maxOffset; x++) {
double double_x = (double)x;
double double_y = (double)y;

if(evenWidth) {
// if width is even, the reference point is actually shifted 1/2 a grid spacing down and to the left,
// from the true center of the circle.
//
// so when we calculate distance, we need to subtract .5 so that the distance reflects the distance from the center
// of the circle, instead of the distance from the reference.
//
// for example - a circle with width == 4. The reference point is the lower left corner of the center square.
// the point directly below that is at (0,-1), but it's actually (-.5, -1.5) from the center of the circle.
//
// another example - same circle. The point directly to the right of the reference point is (1,0), but it's
// actually (.5,-.5) from the center.

double_x -= 0.5;
double_y -= 0.5;
}
double distance= sqrt((double_x * double_x) + (double_y * double_y));

if (distance <= radius)
{
_addOffset(x, y);
}

} /* endfor - x */

} /* endfor - y */

_setEdgeOffsets();

}
double_x -= 0.5;
double_y -= 0.5;
}
double distance= sqrt((double_x * double_x) + (double_y * double_y));

if(distance <= radius) _addOffset(x, y);

} // end for x
} // end for y

/**********************************************************************
* Destructor
*/
_setEdgeOffsets();

CircularTemplate::~CircularTemplate(void)
{
// Do nothing
}


/**********************************************************************
* printOffsetList() - Print the offset list to the given stream. This
* is used for debugging.
*/
///////////////////////////////////////////////////////////////////////////////

void CircularTemplate::printOffsetList(FILE *stream)
{
fprintf(stream, "\n\n");
fprintf(stream, "Circular template with width %d grid spaces:\n",
_width);

GridTemplate::printOffsetList(stream);
CircularTemplate::~CircularTemplate(void) {
// Do nothing
}

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

void CircularTemplate::printOffsetList(FILE *stream) {
fprintf(stream, "\n\n");
fprintf(stream, "Circular template:");
fprintf(stream, " width = %d\n", _width);
fprintf(stream, " wrap_lon = %d\n", _wrapLon);
fprintf(stream, " grid points:\n");

GridTemplate::printOffsetList(stream);
}

/**********************************************************************
* Private Member Functions *
**********************************************************************/
///////////////////////////////////////////////////////////////////////////////
Loading