Skip to content

Commit

Permalink
Feature #2966 local_solar_time (#3008)
Browse files Browse the repository at this point in the history
* Per #2966, add new solar_time() function to the vx_solar library.

* Per #2966, add support for new solar_time masking type. Also make log messages for consistent and eliminate the warning about -thresh not being specified becuase its fine to not specify a threshold.

* Per #2966, add a units attribute to the output NetCDF mask variable.

* Per #2966, modify solar azimuth and altitude strings to make the log messages align well.

* Per #2966, add gen_vx_mask unit test to demonstrate the solar_time masking type.

* Per #2966, add documentation about the -solar_time option

* Per #2966, reduce SonarQube code smells in gen_vx_mask

* Per #2966, reduce SonarQube findings

* Per #2966, support multiple mask types with the same mask field being supported in a single run. Still need to update the user's guide.

* Per #2966, add UTC

* Per #2966, update gen_vx_mask docs about supporting multiple -type options in a single run

* Per #2966, update logic to fix using data masking twice, add a unit test to demonstrate, and update the mask_type attribute to include the magic string for the gridded data used for data masking.

* Per #2966, adjust the logic slightly to revert to existing behavior where we only write the timing information of the input data to the gen_vx_mask output when no threshold was applied. This should reduce the number of diffs flagged by PR #3008

* Per #2966, update details about the -union, -intersection, and -symdiff options in the usage statement and documentation as recommended by @CPKalb.

---------

Co-authored-by: MET Tools Test Account <[email protected]>
  • Loading branch information
JohnHalleyGotway and MET Tools Test Account authored Nov 23, 2024
1 parent 40afea2 commit 183bccc
Show file tree
Hide file tree
Showing 6 changed files with 639 additions and 329 deletions.
130 changes: 83 additions & 47 deletions docs/Users_Guide/masking.rst

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions internal/test_unit/xml/unit_gen_vx_mask.xml
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,27 @@
</output>
</test>

<!-- -->
<!-- SOLAR_TIME: Solar time -->
<!-- -->

<test name="gen_vx_mask_SOLAR_TIME">
<exec>&MET_BIN;/gen_vx_mask</exec>
<param> \
'G004' \
'20050808_12' \
&OUTPUT_DIR;/gen_vx_mask/SOLAR_MIDNIGHT_NH.nc \
-type solar_time,solar_alt,lat \
-thresh 'ge21||le3,le0,ge0' \
-intersection \
-name SOLAR_MIDNIGHT_NH \
-v 3
</param>
<output>
<grid_nc>&OUTPUT_DIR;/gen_vx_mask/SOLAR_MIDNIGHT_NH.nc</grid_nc>
</output>
</test>

<!-- -->
<!-- LAT: latitude band -->
<!-- -->
Expand Down Expand Up @@ -472,6 +493,27 @@
</output>
</test>

<!-- -->
<!-- DATA/DATA/LAT/LON: freezing western hemisphere land points -->
<!-- -->

<test name="gen_vx_mask_DATA_DATA_LAT_LON">
<exec>&MET_BIN;/gen_vx_mask</exec>
<param> \
&DATA_DIR_MODEL;/grib2/gfs/gfs_2012040900_F012.grib2 \
&DATA_DIR_MODEL;/grib2/gfs/gfs_2012040900_F012.grib2 \
&OUTPUT_DIR;/gen_vx_mask/DATA_DATA_LAT_LON_mask.nc \
-type data,data,lat,lon \
-mask_field 'name="LAND"; level="L0";' \
-mask_field 'name="TMP"; level="L0";' \
-thresh eq1,lt273,gt0,lt0 \
-intersection -v 5
</param>
<output>
<grid_nc>&OUTPUT_DIR;/gen_vx_mask/DATA_DATA_LAT_LON_mask.nc</grid_nc>
</output>
</test>

<!-- -->
<!-- SHAPE: shapefile masking -->
<!-- -->
Expand Down
43 changes: 43 additions & 0 deletions src/libcode/vx_solar/solar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,49 @@ return;
////////////////////////////////////////////////////////////////////////


double solar_time(unixtime gmt, double lon)

{

//
// right ascension and declination
//

double Ra;
double Dec;

solar_radec(gmt, Ra, Dec);

//
// local hour angle
//

double lha = gmt_to_gmst(gmt) - lon - Ra;

//
// rescale angle to -180 to 180
//

lha -= 360.0*floor((lha + 180.0)/360.0);

//
// rescale local hour angle to decimal hours of the solar day
//

double solar_hr = (lha + 180.0)/360.0 * 24;

//
// done
//

return solar_hr;

}


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


void dh_to_aa(double lat, double Dec, double lha, double & alt, double & azi)

{
Expand Down
19 changes: 19 additions & 0 deletions src/libcode/vx_solar/solar.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,25 @@ extern void solar_altaz(unixtime gmt, double lat, double lon, double & alt, doub
////////////////////////////////////////////////////////////////////////


extern double solar_time(unixtime gmt, double lon);

//
// calculates the solar time for the given longitude.
//
//
// Input: gmt, greenwich mean time expressed as unix time
//
// lon, longitude (degrees) of given location (+ west, - east)
//
//
// Output: decimal hours f the solar day in range [0, 24),
// where 12 is solar noon
//


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


extern void solar_radec(unixtime gmt, double & Ra, double & Dec);

//
Expand Down
Loading

0 comments on commit 183bccc

Please sign in to comment.