Skip to content

Commit

Permalink
Fix style and try please ruff - fix tests etc
Browse files Browse the repository at this point in the history
Signed-off-by: Adam.Dybbroe <[email protected]>
  • Loading branch information
Adam.Dybbroe committed Nov 21, 2024
1 parent e349c03 commit 532c5ae
Show file tree
Hide file tree
Showing 12 changed files with 507 additions and 499 deletions.
39 changes: 21 additions & 18 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@
# serve to show the default.
"""Configurations for sphinx based documentation."""

import sys
import datetime as dt
import os
import sys

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.

sys.path.insert(0, os.path.abspath('../../'))
sys.path.insert(0, os.path.abspath('../../pyorbital'))
from pyorbital import __version__ # noqa
sys.path.insert(0, os.path.abspath("../../"))
sys.path.insert(0, os.path.abspath("../../pyorbital"))
from pyorbital.version import __version__ # noqa

# -- General configuration -----------------------------------------------------

Expand All @@ -30,30 +31,32 @@

# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.coverage', 'sphinx.ext.napoleon']
extensions = ["sphinx.ext.autodoc", "sphinx.ext.doctest", "sphinx.ext.coverage", "sphinx.ext.napoleon"]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['.templates']
templates_path = [".templates"]

# The suffix of source filenames.
source_suffix = '.rst'
source_suffix = ".rst"

# The encoding of source files.
# #source_encoding = 'utf-8-sig'

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General information about the project.
project = u'pyorbital'
copyright = u'2012-2023, The Pytroll crew'
project = u"pyorbital"
copyright = u"2012, 2024-{}, The PyTroll Team".format(dt.datetime.utcnow().strftime("%Y")) # noqa: A001



# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = __version__.split('+')[0]
version = __version__.split("+")[0]
# The full version, including alpha/beta/rc tags.
release = __version__

Expand All @@ -69,7 +72,7 @@

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = []
# exclude_patterns = []

# The reST default role (used for this markup: `text`) to use for all documents.
# #default_role = None
Expand All @@ -86,7 +89,7 @@
# show_authors = False

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

# A list of ignored prefixes for module index sorting.
# #modindex_common_prefix = []
Expand Down Expand Up @@ -180,7 +183,7 @@
# #html_file_suffix = None

# Output file base name for HTML help builder.
htmlhelp_basename = 'pyorbitaldoc'
htmlhelp_basename = "pyorbitaldoc"


# -- Options for LaTeX output --------------------------------------------------
Expand All @@ -194,8 +197,8 @@
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'pyorbital.tex', u'pyorbital Documentation',
u'The Pytroll crew', 'manual'),
("index", "pyorbital.tex", u"pyorbital Documentation",
u"The Pytroll crew", "manual"),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -227,6 +230,6 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'pyorbital', u'pyorbital Documentation',
[u'The Pytroll crew'], 1)
("index", "pyorbital", u"pyorbital Documentation",
[u"The Pytroll crew"], 1)
]
50 changes: 26 additions & 24 deletions pyorbital/astronomy.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2011, 2013
# Copyright (c) 2011, 2013, 2024
#
# Author(s):
#
Expand Down Expand Up @@ -36,7 +36,6 @@
produce scalar outputs.
"""
import datetime

import numpy as np

Expand All @@ -48,23 +47,20 @@


def jdays2000(utc_time):
"""Get the days since year 2000.
"""
return _days(dt2np(utc_time) - np.datetime64('2000-01-01T12:00'))
"""Get the days since year 2000."""
return _days(dt2np(utc_time) - np.datetime64("2000-01-01T12:00"))


def jdays(utc_time):
"""Get the julian day of *utc_time*.
"""
"""Get the julian day of *utc_time*."""
return jdays2000(utc_time) + 2451545.0


def _days(dt):
"""Get the days (floating point) from *d_t*.
"""
"""Get the days (floating point) from *d_t*."""
if hasattr(dt, "shape"):
dt = np.asanyarray(dt, dtype=np.timedelta64)
return dt / np.timedelta64(1, 'D')
return dt / np.timedelta64(1, "D")


def gmst(utc_time):
Expand All @@ -81,14 +77,16 @@ def gmst(utc_time):

def _lmst(utc_time, longitude):
"""Local mean sidereal time, computed from *utc_time* and *longitude*.
In radians.
utc_time: The UTC time as a datetime.datetime object.
Logitude: The longitude in radians.
Returns: local mean sideral time in radians.
"""
return gmst(utc_time) + longitude


def sun_ecliptic_longitude(utc_time):
"""Ecliptic longitude of the sun at *utc_time*.
"""
"""Ecliptic longitude of the sun at *utc_time*."""
jdate = jdays2000(utc_time) / 36525.0
# mean anomaly, rad
m_a = np.deg2rad(357.52910 +
Expand All @@ -105,8 +103,7 @@ def sun_ecliptic_longitude(utc_time):


def sun_ra_dec(utc_time):
"""Right ascension and declination of the sun at *utc_time*.
"""
"""Right ascension and declination of the sun at *utc_time*."""
jdate = jdays2000(utc_time) / 36525.0
eps = np.deg2rad(23.0 + 26.0 / 60.0 + 21.448 / 3600.0 -
(46.8150 * jdate + 0.00059 * jdate * jdate -
Expand All @@ -124,9 +121,12 @@ def sun_ra_dec(utc_time):


def _local_hour_angle(utc_time, longitude, right_ascension):
"""Hour angle at *utc_time* for the given *longitude* and
*right_ascension*
longitude in radians
"""Derive the hour angle at *utc_time* for the given *longitude* and *right_ascension*.
utc_time: datetime.datetime instance of the UTC time
longitude: Longitude in radians.
right_ascension: The right ascension in radians.
Returns: Hour angle in radians.
"""
return _lmst(utc_time, longitude) - right_ascension

Expand All @@ -152,9 +152,12 @@ def get_alt_az(utc_time, lon, lat):


def cos_zen(utc_time, lon, lat):
"""Cosine of the sun-zenith angle for *lon*, *lat* at *utc_time*.
"""Derive the cosine of the sun-zenith angle for *lon*, *lat* at *utc_time*.
utc_time: datetime.datetime instance of the UTC time
lon and lat in degrees.
lon: Longitude in degrees
lat: Latitude in degrees.
Returns: Cosine of the sun zenith angle.
"""
lon = np.deg2rad(lon)
lat = np.deg2rad(lat)
Expand All @@ -169,8 +172,9 @@ def cos_zen(utc_time, lon, lat):

def sun_zenith_angle(utc_time, lon, lat):
"""Sun-zenith angle for *lon*, *lat* at *utc_time*.
lon,lat in degrees.
The angle returned is given in degrees
The sun zenith angle returned is in degrees.
"""
sza = np.rad2deg(np.arccos(cos_zen(utc_time, lon, lat)))
if not isinstance(lon, float):
Expand All @@ -179,8 +183,7 @@ def sun_zenith_angle(utc_time, lon, lat):


def sun_earth_distance_correction(utc_time):
"""Calculate the sun earth distance correction, relative to 1 AU.
"""
"""Calculate the sun earth distance correction, relative to 1 AU."""
# Computation according to
# https://web.archive.org/web/20150117190838/http://curious.astro.cornell.edu/question.php?number=582
# with
Expand Down Expand Up @@ -208,7 +211,6 @@ def observer_position(utc_time, lon, lat, alt):
http://celestrak.com/columns/v02n03/
"""

lon = np.deg2rad(lon)
lat = np.deg2rad(lat)

Expand Down
26 changes: 16 additions & 10 deletions pyorbital/geoloc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (c) 2011 - 2019 Pytroll Community
# Copyright (c) 2011 - 2019, 2024 Pytroll Community

# Author(s):

Expand All @@ -21,8 +21,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""Module to compute geolocalization of a satellite scene.
"""
"""Module to compute geolocalization of a satellite scene."""

# TODO:
# - Attitude correction
Expand All @@ -31,20 +30,21 @@
# - test !!!

from __future__ import print_function

import numpy as np

# DIRTY STUFF. Needed the get_lonlatalt function to work on pos directly if
# we want to print out lonlats in the end.
from pyorbital import astronomy
from pyorbital.orbital import XKMPER, F
from pyorbital.orbital import Orbital
from pyorbital.orbital import XKMPER, F, Orbital

A = 6378.137 # WGS84 Equatorial radius (km)
B = 6356.75231414 # km, GRS80
# B = 6356.752314245 # km, WGS84


def geodetic_lat(point, a=A, b=B):
"""Get the Geodetic latitude of a point."""
x, y, z = point
r = np.sqrt(x * x + y * y)
geoc_lat = np.arctan2(z, r)
Expand Down Expand Up @@ -84,8 +84,9 @@ class ScanGeometry(object):
"""

def __init__(self, fovs, times, attitude=(0, 0, 0)):
"""Initialize the class."""
self.fovs = np.array(fovs)
self._times = np.array(times) * np.timedelta64(1000000000, 'ns')
self._times = np.array(times) * np.timedelta64(1000000000, "ns")
self.attitude = attitude

def vectors(self, pos, vel, roll=0.0, pitch=0.0, yaw=0.0):
Expand Down Expand Up @@ -120,6 +121,7 @@ def vectors(self, pos, vel, roll=0.0, pitch=0.0, yaw=0.0):
return qrotate(xy_rotated, nadir, yaw)

def times(self, start_of_scan):
"""Return an array with the times of each scan line."""
# tds = [timedelta(seconds=i) for i in self._times]
# tds = self._times.astype('timedelta64[us]')
try:
Expand All @@ -129,12 +131,15 @@ def times(self, start_of_scan):


class Quaternion(object):
"""Some class, that I don't know what is doing..."""

def __init__(self, scalar, vector):
"""Initialize the class."""
self.__x, self.__y, self.__z = vector.reshape((3, -1))
self.__w = scalar.ravel()

def rotation_matrix(self):
"""Get the rotation matrix."""
x, y, z, w = self.__x, self.__y, self.__z, self.__w
zero = np.zeros_like(x)
return np.array(
Expand Down Expand Up @@ -240,27 +245,28 @@ def compute_pixels(orb, sgeom, times, rpy=(0.0, 0.0, 0.0)):


def norm(v):
"""Return the norm of the vector *v*."""
return np.sqrt(np.dot(v, v.conj()))


def mnorm(m, axis=None):
"""norm of a matrix of vectors stacked along the *axis* dimension."""
"""Norm of a matrix of vectors stacked along the *axis* dimension."""
if axis is None:
axis = np.ndim(m) - 1
return np.sqrt((m**2).sum(axis))


def vnorm(m):
"""norms of a matrix of column vectors."""
"""Norms of a matrix of column vectors."""
return np.sqrt((m**2).sum(0))


def hnorm(m):
"""norms of a matrix of row vectors."""
"""Norms of a matrix of row vectors."""
return np.sqrt((m**2).sum(1))


if __name__ == '__main__':
if __name__ == "__main__":
# NOAA 18 (from the 2011-10-12, 16:55 utc)
# 1 28654U 05018A 11284.35271227 .00000478 00000-0 28778-3 0 9246
# 2 28654 99.0096 235.8581 0014859 135.4286 224.8087 14.11526826329313
Expand Down
Loading

0 comments on commit 532c5ae

Please sign in to comment.