Spaces:
Runtime error
Runtime error
File size: 2,071 Bytes
98a2104 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
"""
Internal validation functions.
:copyright: (c) 2015 by Mark Richards.
:license: BSD 3-Clause, see LICENSE.txt for more details.
"""
from .convert import deg2rad
import numpy as np
# Internal constants
# Latitude
_MINLAT_RADIANS = deg2rad(-90.0)
_MAXLAT_RADIANS = deg2rad(90.0)
# Solar declination
_MINSOLDEC_RADIANS = deg2rad(-23.5)
_MAXSOLDEC_RADIANS = deg2rad(23.5)
# Sunset hour angle
_MINSHA_RADIANS = 0.0
_MAXSHA_RADIANS = deg2rad(180)
def check_day_hours(hours, arg_name):
"""
Check that *hours* is in the range 1 to 24.
"""
if not np.all((0 <= hours) & (hours <= 24)):
raise ValueError("{0} should be in range 0-24: {1!r}".format(arg_name, hours))
def check_doy(doy):
"""
Check day of the year is valid.
"""
if not np.all((1 <= doy) & (doy <= 366)):
raise ValueError(
"Day of the year (doy) must be in range 1-366."
)
def check_latitude_rad(latitude):
if not np.all((_MINLAT_RADIANS <= latitude) & (latitude <= _MAXLAT_RADIANS)):
raise ValueError(
"latitude outside valid range {0!r} to {1!r} rad: {2!r}".format(
_MINLAT_RADIANS, _MAXLAT_RADIANS, latitude
)
)
def check_sol_dec_rad(sd):
"""
Solar declination can vary between -23.5 and +23.5 degrees.
See http://mypages.iit.edu/~maslanka/SolarGeo.pdf
"""
if not np.all((_MINSOLDEC_RADIANS <= sd) & (sd <= _MAXSOLDEC_RADIANS)):
raise ValueError(
"solar declination outside valid range {0!r} to {1!r} rad: {2!r}".format(
_MINSOLDEC_RADIANS, _MAXSOLDEC_RADIANS, sd
)
)
def check_sunset_hour_angle_rad(sha):
"""
Sunset hour angle has the range 0 to 180 degrees.
See http://mypages.iit.edu/~maslanka/SolarGeo.pdf
"""
if not np.all((_MINSHA_RADIANS <= sha) & (sha <= _MAXSHA_RADIANS)):
raise ValueError(
"sunset hour angle outside valid range {0!r} to {1!r} rad: {2!r}".format(
_MINSHA_RADIANS, _MAXSHA_RADIANS, sha
)
)
|