8000 Feature update angles computation by ninahakansson · Pull Request #30 · pytroll/pygac · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Feature update angles computation #30

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 12 additions & 2 deletions pygac/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,15 @@
CONFIG_FILE = ''

if not os.path.exists(CONFIG_FILE) or not os.path.isfile(CONFIG_FILE):
LOG.warning(str(CONFIG_FILE) + " pointed to by the environment "
+ "variable PYGAC_CONFIG_FILE is not a file or does not exist!")
LOG.warning(
str(CONFIG_FILE) + " pointed to by the environment "
+ "variable PYGAC_CONFIG_FILE is not a file or does not exist!")


def get_absolute_azimuth_angle_diff(sat_azi, sun_azi):
"""Calculates absolute azimuth difference angle. """
rel_azi = abs(sat_azi - sun_azi)
rel_azi = rel_azi % 360
# Not using np.where to avoid copying array
rel_azi[rel_azi > 180] = 360.0 - rel_azi[rel_azi > 180]
return rel_azi
4 changes: 0 additions & 4 deletions pygac/gac_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,6 @@ def save_gac(satellite_name,
lons = np.where(np.logical_or(lons < -180.00, lons > 180.00),
MISSING_DATA_LATLON, lons)

sat_azi -= 180.0
rel_azi = abs(rel_azi)
rel_azi = 180.0 - rel_azi

for array in [bt3, bt4, bt5]:
array[array != MISSING_DATA] = 100 * array[array != MISSING_DATA]
array[mask] = MISSING_DATA
Expand Down
8 changes: 2 additions & 6 deletions pygac/gac_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
specific read functions.
"""
import numpy as np
from pygac import CONFIG_FILE
from pygac import CONFIG_FILE, get_absolute_azimuth_angle_diff
try:
import ConfigParser
except ImportError:
Expand Down Expand Up @@ -364,11 +364,7 @@ def get_angles(self):
self.lons, self.lats)
del alt
sun_azi = np.rad2deg(sun_azi)
sun_azi = np.where(sun_azi < 0, sun_azi + 180, sun_azi - 180)

rel_azi = abs(sat_azi - sun_azi)
rel_azi = np.where(rel_azi > 180.0, 360.0 - rel_azi, rel_azi)

rel_azi = get_absolute_azimuth_angle_diff(sun_azi, sat_azi)
return sat_azi, sat_zenith, sun_azi, sun_zenith, rel_azi

def correct_times_median(self, year, jday, msec):
Expand Down
7 changes: 4 additions & 3 deletions pygac/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
"""The tests package.
"""

from pygac.tests import test_calibrate_pod, test_slerp, test_calibrate_klm, \
test_pod, test_corrections, test_reader, test_io
from pygac.tests import (test_calibrate_pod, test_slerp, test_calibrate_klm,
test_pod, test_corrections, test_reader, test_io,
test_angles)
import unittest


Expand All @@ -33,7 +34,7 @@ def suite():
"""
mysuite = unittest.TestSuite()
tests = (test_slerp, test_calibrate_klm, test_calibrate_pod,
test_pod, test_corrections, test_reader, test_io)
test_pod, test_corrections, test_reader, test_io, test_angles)
for test in tests:
mysuite.addTests(test.suite())

Expand Down
68 changes: 68 additions & 0 deletions pygac/tests/test_angles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (c) 2014-2019 Pytroll Developers

# Author(s):

# Nina Hakansson <nina.hakansson@smhi.se>
# Adam Dybbroe <adam.dypbroe@smhi.se>

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""Test function for the angle calculation."""

import unittest

import numpy as np

from pygac import get_absolute_azimuth_angle_diff


class TestAngles(unittest.TestCase):
"""Test function for the angle calculation."""

def test_azidiff_angle(self):
"""Test function for the azidiff angle."""
sat_az = np.ma.array([[48.0, 56.0, 64.0, 72.0],
[80.0, 88.0, 96.0, 104.0],
[-80.0, -88.0, -96.0, -104.0],
[-180.0, -188.0, -196.0, -204.0]], mask=False)
sun_az = np.ma.array([[148.0, 156.0, 164.0, 172.0],
[180.0, 188.0, 196.0, 204.0],
[180.0, 188.0, 196.0, 204.0],
[185.0, 193.0, 201.0, 209.0]], mask=False)

res = np.ma.array([[100., 100., 100., 100.],
[100., 100., 100., 100.],
[100., 84., 68., 52.],
[5., 21., 37., 53.]],
mask=False)
rel_azi = get_absolute_azimuth_angle_diff(sat_az, sun_az)

np.testing.assert_allclose(rel_azi, res)


def suite():
"""The suite for test_slerp
"""
loader = unittest.TestLoader()
mysuite = unittest.TestSuite()
mysuite.addTest(loader.loadTestsFromTestCase(TestAngles))

return mysuite


if __name__ == '__main__':
unittest.main()
0