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

New utils: logger context manager and random RA and Decs #58

Merged
merged 8 commits into from
Aug 13, 2024

Conversation

taldcroft
Copy link
Member

@taldcroft taldcroft commented Aug 12, 2024

Description

Add two new functions to ska_helpers.utils:

  • random_radec_in_cone(): Get random sky coordinates within a cone.
  • set_log_level(): Context manager to temporarily set the log level for a logger

This also includes ruff whitespace changes to four files.

Interface impacts

Adds functions.

Testing

Unit tests

  • Mac (new test)
(ska3) ➜  ska_helpers git:(new-utils-logger-cm-random-ra-dec) git rev-parse HEAD 
f44f205935233cc45bfd74e5e8cfe957017c1e8a
(ska3) ➜  ska_helpers git:(new-utils-logger-cm-random-ra-dec) pytest
============================================== test session starts ==============================================
platform darwin -- Python 3.11.8, pytest-7.4.4, pluggy-1.4.0
rootdir: /Users/aldcroft/git
configfile: pytest.ini
plugins: timeout-2.2.0, anyio-4.3.0
collected 71 items                                                                                              

ska_helpers/retry/tests/test_retry.py ..............                                                      [ 19%]
ska_helpers/tests/test_chandra_models.py ..................                                               [ 45%]
ska_helpers/tests/test_git_helpers.py s                                                                   [ 46%]
ska_helpers/tests/test_paths.py ......                                                                    [ 54%]
ska_helpers/tests/test_run_info.py ..                                                                     [ 57%]
ska_helpers/tests/test_utils.py ..............................                                            [100%]

========================================= 70 passed, 1 skipped in 4.49s =========================================

Independent check of unit tests by Jean -

  • Linux
ska3-jeanconn-fido> pytest
========================================================== test session starts ===========================================================
platform linux -- Python 3.11.8, pytest-7.4.4, pluggy-1.4.0
rootdir: /proj/sot/ska/jeanproj/git
configfile: pytest.ini
plugins: anyio-4.3.0, timeout-2.2.0
collected 71 items                                                                                                                       

ska_helpers/retry/tests/test_retry.py ..............                                                                               [ 19%]
ska_helpers/tests/test_chandra_models.py ..................                                                                        [ 45%]
ska_helpers/tests/test_git_helpers.py .                                                                                            [ 46%]
ska_helpers/tests/test_paths.py ......                                                                                             [ 54%]
ska_helpers/tests/test_run_info.py ..                                                                                              [ 57%]
ska_helpers/tests/test_utils.py ..............................                                                                     [100%]

========================================================== 71 passed in 11.74s ===========================================================
ska3-jeanconn-fido> git rev-parse HEAD
2195a1cf683255cd31cc292063de603204c0d6b1

I note if I use pytest -vs there is some output printed, that I would think would be a problem for ska_testr:

ska_helpers/retry/tests/test_retry.py::test_retry WARNING: f() exception: division by zero, retrying in 1 seconds...

but ska_testr isn't catching that in the log checks for whatever reason so seems fine (and not due to this PR anyway).

Functional tests

random_radec_in_code

Looks like a random and spatially-uniform distribution:

>>> from ska_helpers import utils
>>> ras, decs = utils.random_radec_in_cone(95, 5, 5, 500000)
>>> plt.plot(ras, decs, ",")
image

@taldcroft
Copy link
Member Author

One thing is that maybe set_log_level should live in the logging sub-module instead of utils. This is easy enough right now but would require changes to sot/find_attitude#31.

Thoughts?

@jeanconn
Copy link
Contributor

Regarding "One thing is that maybe set_log_level should live in the logging sub-module instead of utils." I thought that when I saw it but also figured it doesn't make much difference.

@taldcroft
Copy link
Member Author

@jeanconn - ok let's just leave it.

@taldcroft taldcroft merged commit 8692a46 into master Aug 13, 2024
2 checks passed
@taldcroft taldcroft deleted the new-utils-logger-cm-random-ra-dec branch August 13, 2024 18:43
@javierggt javierggt mentioned this pull request Nov 7, 2024
@javierggt javierggt mentioned this pull request Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants