Skip to content
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

Update astronomy.py #158

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Update astronomy.py #158

wants to merge 1 commit into from

Conversation

Yusufibin
Copy link

@Yusufibin Yusufibin commented Jul 10, 2024

Error handling has been optimized with the observer_position function, which now checks the type and value of the altitude, and raises appropriate exceptions in case of invalidity. Important astronomical constants are defined at the beginning of the file to improve code readability and maintainability. Type annotations have been added for better understanding and readability of the code.

  • Closes #xxxx
  • Tests added
  • Tests passed
  • Passes flake8 pyorbital
  • Fully documented

Error handling has been optimized with the observer_position function, which now checks the type and value of the altitude, and raises appropriate exceptions in case of invalidity. Important astronomical constants are defined at the beginning of the file to improve code readability and maintainability. Type annotations have been added for better understanding and readability of the code.
Copy link
Member

@djhoese djhoese left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice attempt at tackling this. I had a couple suggestions and changes I'd like to see if we plan on merging this. Also note that I'm pretty in favor of annotations but others on the maintainer team may not enjoy all the clutter it adds. Especially for this module where so many types are possible as arguments.


# Type alias for time arguments
TimeLike = Union[dt.datetime, np.datetime64, np.ndarray]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is the numpy.typing module added in numpy 1.20 I believe. Could this be used to define the dtype of the ndarray? Using something like npt.ArrayLike[np.datetime64]?

Comment on lines +64 to +67
:param utc_time: UTC time
:type utc_time: datetime.datetime, numpy.datetime64, or array-like
:return: Days since year 2000
:rtype: float or numpy.ndarray
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if pyorbital has a defined docstring format it follows, but in Satpy we've been using Google style docstrings:

https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html

Would it be possible to reformat these to match? If other parts of pyorbital are using numpy style docstrings then I'd be open to that as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally, I think you can remove the type in the docstrings if you have the annotations. We'll need to possibly enable the correct sphinx options to copy the annotations to the rendered documentation, but that can come after everything else is sorted.

Comment on lines +83 to +87
def _days(dt: TimeLike) -> Union[float, np.ndarray]:
"""Get the days (floating point) from *d_t*.

:param dt: Time delta
:type dt: datetime.timedelta or numpy.timedelta64
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these type annotations and docstrings are incorrect I think. This function for example takes datetime.timedelta objects or a numpy array of timedelta64 objects. You have TimeLike listed here.

A = 6378.137 # WGS84 Equatorial radius
# Astronomical constants
AU = 149597870700.0 # Astronomical unit in meters
EARTH_ flattening = 1 / 298.257223563 # Earth flattening WGS-84
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo here (extra space). Also why not uppercase for the flattening part?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants