-
Notifications
You must be signed in to change notification settings - Fork 77
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
Add script to get SNOs for two platforms #51
Closed
Closed
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
96c35bf
Add script to get SNOs for two platforms, typically Calipso and an Im…
adybbroe 39b0ddf
Refactor get-sno script and add template for RTD pages
adybbroe 61333a0
Refactoring and adding unittests, and removing the redundant area spec
adybbroe 7122095
Explaining what SNOs are.
adybbroe 5d5c978
Improve documentation
adybbroe 2b7a833
Encapsulate all the main part in a main-function, and document the ya…
adybbroe 91f9f74
Use the SafeLoader instead
adybbroe 4daedfa
Add the test suite for get_snos
adybbroe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ dist | |
build | ||
eggs | ||
parts | ||
bin | ||
var | ||
sdist | ||
develop-eggs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
exclude: '^$' | ||
fail_fast: false | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v2.2.3 | ||
hooks: | ||
- id: flake8 | ||
additional_dependencies: [flake8-docstrings, flake8-debugger, flake8-bugbear] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright (c) 2014 - 2019 Adam.Dybbroe | ||
|
||
# Author(s): | ||
|
||
# Adam.Dybbroe <[email protected]> | ||
# Nina Håkansson <[email protected]> | ||
# Erik Johansson <[email protected]> | ||
|
||
# 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/>. | ||
|
||
"""Getting SNOs for two configurable satellite platforms.""" | ||
|
||
import sys | ||
from datetime import datetime, timedelta | ||
|
||
from pyorbital.orbital import Orbital | ||
from pyorbital.sno_utils import get_config | ||
from pyorbital.sno_utils import get_arc | ||
from pyorbital.sno_utils import get_tle | ||
from pyorbital.sno_utils import get_sno_point | ||
|
||
import logging | ||
import time | ||
|
||
t = time.time() | ||
LOG = logging.getLogger('snos') | ||
|
||
handler = logging.StreamHandler(sys.stderr) | ||
handler.setLevel(0) | ||
LOG.setLevel(0) | ||
LOG.addHandler(handler) | ||
|
||
|
||
def get_arguments(): | ||
"""Get the comman line arguments required to run the script.""" | ||
import argparse | ||
|
||
parser = argparse.ArgumentParser(description='Calculate SNOS between two satellite platforms') | ||
parser.add_argument("-s", "--start-datetime", | ||
required=True, | ||
dest="start_datetime", | ||
type=str, | ||
default=None, | ||
help="The datetime string corresponding to the start time of when SNOS should be calculated") | ||
parser.add_argument("-e", "--end-datetime", | ||
required=True, | ||
dest="end_datetime", | ||
type=str, | ||
default=None, | ||
help="The datetime string corresponding to the end time of when SNOS should be calculated") | ||
parser.add_argument("-t", "--time-window", | ||
required=True, | ||
dest="time_window", | ||
type=str, | ||
default=None, | ||
help=("The time window in number of minutes - the maximum time allowed between " + | ||
"the two SNO observations")) | ||
parser.add_argument("-p", "--platform-name", | ||
required=True, | ||
dest="platform_name", | ||
type=str, | ||
default=None, | ||
help="The name of the satellite platform") | ||
parser.add_argument("-c", "--configfile", | ||
required=True, | ||
dest="configfile", | ||
type=str, | ||
default=None, | ||
help="The path to the configuration file") | ||
parser.add_argument("-l", "--log-file", dest="log", | ||
type=str, | ||
default=None, | ||
help="The file to log to (stdout per default).") | ||
|
||
args = parser.parse_args() | ||
return args | ||
|
||
|
||
if __name__ == "__main__": | ||
|
||
args = get_arguments() | ||
conf = get_config(args.configfile) | ||
|
||
station = {} | ||
station['lon'] = conf['station']['longitude'] | ||
station['lat'] = conf['station']['latitude'] | ||
station['alt'] = conf['station']['altitude'] | ||
|
||
ref_platform_name = conf['reference_platform']['name'] | ||
|
||
tle_dirs = conf['tle-dirs'] | ||
tle_file_format = conf['tle-file-format'] | ||
platform_id = args.platform_name | ||
minthr = int(args.time_window) | ||
time_start = datetime.strptime(args.start_datetime, "%Y%m%d") | ||
time_end = datetime.strptime(args.end_datetime, "%Y%m%d") | ||
|
||
dtime = timedelta(seconds=60 * minthr * 2.0) | ||
timestep = timedelta(seconds=60 * minthr * 1.0) | ||
delta_t = dtime | ||
|
||
tobj = time_start | ||
tle_ref_pltfrm = None | ||
tle_cmp_platform = None | ||
tobj_tmp = time_start | ||
is_within_antenna_horizon = False | ||
while tobj < time_end: | ||
if not tle_ref_pltfrm or abs(tle_ref_pltfrm.epoch.astype(datetime) - tobj) > timedelta(days=1): | ||
tle_ref_pltfrm = get_tle(tle_dirs, tle_file_format, ref_platform_name, tobj) | ||
if (not tle_cmp_platform or | ||
abs(tle_cmp_platform.epoch.astype(datetime) - tobj) > timedelta(days=2)): | ||
tle_cmp_platform = get_tle(tle_dirs, tle_file_format, platform_id, tobj) | ||
|
||
ref_pltfrm = Orbital(ref_platform_name, | ||
line1=tle_ref_pltfrm.line1, | ||
line2=tle_ref_pltfrm.line2) | ||
cmp_platform = Orbital(platform_id, | ||
line1=tle_cmp_platform.line1, | ||
line2=tle_cmp_platform.line2) | ||
|
||
arc_ref_pltfrm = get_arc(tobj, timestep, ref_pltfrm) | ||
arc_cmp_platform = get_arc(tobj, timestep, cmp_platform) | ||
|
||
if arc_ref_pltfrm and arc_cmp_platform: | ||
if arc_ref_pltfrm.intersects(arc_cmp_platform): | ||
# If the two sub-satellite tracks of the overpasses intersects | ||
# get the sub-satellite position and time where they cross, | ||
# and determine if the time deviation is smaller than the require threshold: | ||
sno = get_sno_point(platform_id, cmp_platform, ref_pltfrm, | ||
tobj, delta_t, arc_ref_pltfrm, | ||
arc_cmp_platform, station, minthr) | ||
|
||
if sno: | ||
print(" " + | ||
str(sno['maxt_ref_pltfrm'].strftime("%Y-%m-%d %H:%M, ")) + | ||
"%5.1f," % sno['ref_pltfrmsec'] + " "*5 + | ||
str(sno['maxt'].strftime("%Y-%m-%d %H:%M, ")) + | ||
"%5.1f," % sno['sec'] + | ||
# " imager-orbit, %d, " % (sno['orbit_nr'] + 1) + | ||
" %d, " % (sno['orbit_nr'] + 1) + | ||
" "*6 + "%7.2f, %7.2f," % (sno['point'][1], sno['point'][0]) + | ||
" " + "%4.1f," % abs(sno['tdmin']) + " " + str(sno['is_within_antenna_horizon']) | ||
) | ||
|
||
else: | ||
LOG.error("Failed getting the track-segments") | ||
|
||
tobj = tobj + dtime | ||
if tobj - tobj_tmp > timedelta(days=1): | ||
tobj_tmp = tobj | ||
LOG.debug(tobj_tmp.strftime("%Y-%m-%d")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
The :mod:`pyorbital` API | ||
========================= | ||
|
||
Orbital computations | ||
~~~~~~~~~~~~~~~~~~~~ | ||
|
||
.. automodule:: pyorbital.orbital | ||
:members: | ||
:undoc-members: | ||
|
||
TLE handling | ||
~~~~~~~~~~~~ | ||
|
||
.. automodule:: pyorbital.tlefile | ||
:members: | ||
:undoc-members: | ||
|
||
Astronomical computations | ||
~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
.. automodule:: pyorbital.astronomy | ||
:members: | ||
:undoc-members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Computing astronomical parameters | ||
--------------------------------- | ||
The astronomy module enables computation of certain parameters of interest for satellite remote sensing for instance the Sun-zenith angle: | ||
|
||
>>> from pyorbital import astronomy | ||
>>> from datetime import datetime | ||
>>> utc_time = datetime(2012, 5, 15, 15, 45) | ||
>>> lon, lat = 12, 56 | ||
>>> astronomy.sun_zenith_angle(utc_time, lon, lat) | ||
62.685986438071602 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
========================= | ||
Installation Instructions | ||
========================= | ||
|
||
Note | ||
---- | ||
Pyorbital comes with a file platforms.txt that maps satellite name to NORAD identifier. | ||
This file needs to be copied to the appropriate Satpy `etc` directory ($PPP_CONFIG_DIR). | ||
It is wise to check it contains your satellites of interest. The NORAD identifier can | ||
be found as the first number of each line in the Two-Line Elements (eg. from celestrak). | ||
|
||
Pip-based Installation | ||
====================== | ||
|
||
Pyorbital is available from the Python Packaging Index (PyPI). A sandbox | ||
environment for `pyorbital` can be created using | ||
`Virtualenv <http://pypi.python.org/pypi/virtualenv>`_. | ||
|
||
To install the `pyorbital` package and the python dependencies: | ||
|
||
.. code-block:: bash | ||
|
||
$ pip install pyorbital | ||
|
||
|
||
Conda-based Installation | ||
======================== | ||
|
||
Starting with version 1.3.1, Pyorbital is available from the conda-forge channel. If | ||
you have not configured your conda environment to search conda-forge already | ||
then do: | ||
|
||
.. code-block:: bash | ||
|
||
$ conda config --add channels conda-forge | ||
|
||
Then to install Pyorbital in to your current environment run: | ||
|
||
.. code-block:: bash | ||
|
||
$ conda install pyorbital |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Encapsulate all this in
main()
function, and inif __name__ == "__main__":
block call that. Can save some time later on when hunting a bug that is caused by polluted namespace.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!