Skip to content

Commit

Permalink
Remove airmass PWV scaling (#39)
Browse files Browse the repository at this point in the history
Removes the airmass PWV scaling functionality
  • Loading branch information
djperrefort committed Mar 29, 2020
1 parent 5cbd77c commit a63debc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 74 deletions.
6 changes: 3 additions & 3 deletions pwv_kpno/__init__.py
Expand Up @@ -19,8 +19,8 @@
"""pwv_kpno provides models for the atmospheric transmission function due to
precipitable water vapor (PWV). Using PWV measurements published
by the SuomiNet project (https://www.suominet.ucar.edu), this package is
capable of returning the modeled PWV transmission for a given date, time, and
airmass at customizable geographic locations. By default, this functionality
capable of returning the modeled PWV transmission for a given date and time
at customizable geographic locations. By default, this functionality
is set to model Kitt Peak National Observatory. Default models cover
wavelengths from 3,000 to 12,000 Angstroms at a resolution of 0.05 Angstroms.
Expand Down Expand Up @@ -64,7 +64,7 @@
]

__license__ = 'GPL V3'
__version__ = '1.2.1'
__version__ = '1.2.2'
__email__ = 'djperrefort@pitt.edu'
__status__ = 'Release'

Expand Down
43 changes: 9 additions & 34 deletions pwv_kpno/pwv_atm.py
Expand Up @@ -64,12 +64,6 @@
>>> pwv_atm.trans_for_pwv(pwv, pwv_err)
To retrieve the atmospheric model for at the current site being modeled
at a given datetime and airmass:
>>> pwv_atm.trans_for_date(date=obsv_date,airmass=1.2,format=)
To access the PWV measurements for the current site being modeled as an
astropy table:
Expand Down Expand Up @@ -154,19 +148,16 @@ def _warn_available_data(

def _pwv_date(
date: Union[float, np.array, datetime],
airmass: float = 1,
format: str = None,
test_model: Table = None) \
-> Tuple[Union[float, np.array], Union[float, np.array]]:
"""Returns the modeled PWV column density at the current site
Interpolate from the modeled PWV column density at at the current site
being modeled and return the PWV column density for a given datetime and
airmass.
being modeled and return the PWV column density for a given datetime.
Args:
date: The date of the desired PWV column density
airmass: The airmass along line of sight
format: An astropy compatible time format
test_model: A mock PWV model used by the test suite
Expand All @@ -187,34 +178,27 @@ def _pwv_date(
pwv = np.interp(time_stamp, pwv_model['date'], pwv_model['pwv'])
pwv_err = np.interp(time_stamp, pwv_model['date'], pwv_model['pwv_err'])

# Determine the PWV level along line of sight as outlined in
# Horne et al. 2012
pwv_los = pwv * (airmass ** .6)
pwv_err_los = pwv_err * (airmass ** .6)
return pwv_los, pwv_err_los
return pwv, pwv_err


def pwv_date(
date: Union[float, np.array, datetime],
airmass: float = 1,
format: str = None) \
date: Union[float, np.array, datetime], format: str = None) \
-> Tuple[Union[float, np.array], Union[float, np.array]]:
"""Returns the modeled PWV column density at the current site
Interpolate from the modeled PWV column density at the current site being
modeled and return the PWV column density for a given datetime and airmass.
modeled and return the PWV column density for a given datetime.
Args:
date: The date of the desired PWV column density
airmass: The airmass along line of sight
format: An astropy compatible time format (e.g., unix, mjd, datetime)
Returns:
The modeled PWV column density at the current site
The error in modeled PWV column density
"""

return _pwv_date(date, airmass, format)
return _pwv_date(date, format)


def downloaded_years() -> List[int]:
Expand Down Expand Up @@ -464,12 +448,11 @@ def trans_for_pwv(
return transmission


def _raise_transmission_args(date: datetime, airmass: float):
def _raise_transmission_args(date: datetime):
"""Raise exception if arguments have wrong type or value
Args:
date: A datetime value
airmass: An airmass value
"""

if not isinstance(date, datetime):
Expand All @@ -487,21 +470,16 @@ def _raise_transmission_args(date: datetime, airmass: float):
err_msg = "Cannot model dates in the future (passed {})"
raise ValueError(err_msg.format(date))

if not isinstance(airmass, (float, int)):
raise TypeError("Argument 'airmass' (pos 2) must be an int or float")


def _trans_for_date(
date: Union[float, np.array, datetime],
airmass: float = 1,
format: str = None,
bins: Union[int, list] = None,
test_model: Table = None) -> Table:
"""Return a model for the atmospheric transmission function due to PWV
Args:
date: The datetime of the desired model
airmass: The airmass of the desired model
format: An astropy compatible time format
bins: Integer number of bins or sequence of bin edges
test_model: A mock PWV model used by the test suite
Expand All @@ -510,35 +488,32 @@ def _trans_for_date(
The modeled transmission function as an astropy table
"""

pwv, pwv_err = _pwv_date(date, airmass=airmass, format=format,
test_model=test_model)
pwv, pwv_err = _pwv_date(date, format=format, test_model=test_model)

return trans_for_pwv(pwv, pwv_err, bins)


def trans_for_date(
date: Union[float, np.array, datetime],
airmass: float = 1,
format: str = None,
bins: Union[int, list] = None) -> Table:
"""Return a model for the atmospheric transmission function due to PWV
For a given datetime and airmass, return a model for the atmospheric
For a given datetime, return a model for the atmospheric
transmission function due to precipitable water vapor at the current site
being modeled. The transmission function can optionally be binned by
specifying the `bins` argument.
Args:
date: The date of the desired model in the given format
airmass: The airmass of the desired model
format: An astropy compatible time format (e.g., unix, mjd, datetime)
bins: Integer number of bins or sequence of bin edges
Returns:
The modeled transmission function as an astropy table
"""

return _trans_for_date(date, airmass, format, bins)
return _trans_for_date(date, format, bins)


def get_all_receiver_data(receiver_id: str, apply_cuts: bool = True):
Expand Down
41 changes: 4 additions & 37 deletions tests/test_pwv_atm.py
Expand Up @@ -185,40 +185,10 @@ def test_data_gap_handling(self):
1,
mock_model)

def test_airmass_dependence(self):
"""PWV should be proportional to airmass ^ .6
This PWV airmass relation is presented in Horne et al. 2012
"""

test_date = datetime.utcfromtimestamp(self.pwv_model['date'][0])
test_date = test_date.replace(tzinfo=utc)
pwv, pwv_err = pwv_atm._pwv_date(test_date)
pwv_los, pwv_err_los = pwv_atm._pwv_date(test_date, airmass=2)

self.assertEqual(pwv_los, (2 ** .6) * pwv)
self.assertEqual(pwv_err_los, (2 ** .6) * pwv_err)


class TransmissionErrors(TestCase):
"""Test pwv_kpno.transmission for raised errors due to bad arguments"""

def test_argument_types(self):
"""Test errors raised from function call with wrong argument types"""

test_date = datetime(2011, 1, 5, 12, 47, tzinfo=utc)

# TypeError for date argument (should be datetime)
self.assertRaises(TypeError, pwv_atm._raise_transmission_args, "1", 1)

# TypeError for airmass argument (should be float or int)
self.assertRaises(TypeError, pwv_atm._raise_transmission_args,
test_date, "1")

# ValueError due to naive datetime with no time zone info
self.assertRaises(ValueError, pwv_atm._raise_transmission_args,
datetime.now(), 1)

def test_argument_values(self):
"""Test errors raise from function call with date out of data range
Expand All @@ -228,17 +198,14 @@ def test_argument_values(self):
"""

early_day = datetime(year=2009, month=12, day=31, tzinfo=utc)
self.assertRaises(ValueError, pwv_atm._raise_transmission_args,
early_day, 1)
self.assertRaises(ValueError, pwv_atm._raise_transmission_args, early_day)

now = datetime.now()
late_day = now + timedelta(days=1)
self.assertRaises(ValueError, pwv_atm._raise_transmission_args,
late_day, 1)
self.assertRaises(ValueError, pwv_atm._raise_transmission_args, late_day)

late_year = datetime(year=now.year + 1, month=1, day=1, tzinfo=utc)
self.assertRaises(ValueError, pwv_atm._raise_transmission_args,
late_year, 1)
self.assertRaises(ValueError, pwv_atm._raise_transmission_args, late_year)


class TransmissionResults(TestCase):
Expand Down Expand Up @@ -269,7 +236,7 @@ def test_column_units(self):
"""

sample_transm = pwv_atm.trans_for_date(
datetime(2011, 1, 1, tzinfo=utc), 1, format='datetime')
datetime(2011, 1, 1, tzinfo=utc), format='datetime')
w_units = sample_transm['wavelength'].unit
t_units = sample_transm['transmission'].unit

Expand Down

0 comments on commit a63debc

Please sign in to comment.