Skip to content

ENH: Add ability to point to a different Space Weather File location#101

Open
tristandijkstra wants to merge 4 commits into
SWxTREC:mainfrom
tristandijkstra:main
Open

ENH: Add ability to point to a different Space Weather File location#101
tristandijkstra wants to merge 4 commits into
SWxTREC:mainfrom
tristandijkstra:main

Conversation

@tristandijkstra

@tristandijkstra tristandijkstra commented Jun 24, 2026

Copy link
Copy Markdown

Hello!

I've made an attempt to implement #89 , allowing space weather to be set through a pymsis.set_space_weather_path() function. My main motivation is that celestrak throttles connection for heavy users.

I was not sure about bumping the version. I have decided to keep the celestrak download to the default location (inside the package folder) with the thinking that re-downloading might overwrite a custom SW file.

@tristandijkstra tristandijkstra marked this pull request as ready for review June 24, 2026 15:17

@greglucas greglucas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Overall this looks good to me, thanks for the PR! Some minor comments/questions for some use cases.

Comment thread pymsis/utils.py Outdated
Comment thread pymsis/utils.py Outdated
Comment on lines +51 to +55
# set the global variable to the new path
globals()["_F107_AP_PATH"] = Path(path)

# reset the global data
globals()["_DATA"] = None

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Rather than reaching into the global dictionary, this is a bit more standard I think.

Suggested change
# set the global variable to the new path
globals()["_F107_AP_PATH"] = Path(path)
# reset the global data
globals()["_DATA"] = None
# set the global variables that we are updating
global _F107_AP_PATH, _DATA
_F107_AP_PATH = Path(path)
_DATA = None

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

👍 , I've also updated _load_f107_ap_data() which also used the dictionary. It seems globals are generally discouraged, but I think finding an alternative is outside the scope of this PR.

Comment thread pymsis/utils.py Outdated
)


def set_space_weather_path(path: str | Path) -> None:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need a way of getting back to the default path / unsetting this variable? Probably not, but I figured I would call it out in case you wanted to add a default None as a sentinal meaning get back to the default.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I've added the option. I can only vaguely imagine a use case, but its easy enough to add and much more compatible with the new naming.

Comment thread pymsis/utils.py Outdated
Comment thread pymsis/utils.py Outdated
Comment on lines +97 to +101
if custom_file_used and not _F107_AP_PATH.exists():
raise FileNotFoundError(
f"""Custom space weather path has been set but does not exist:
{_F107_AP_PATH}"""
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You already produce this warning earlier when setting the path initially, I don't think we need it here again. Also, the triple-quote should just be single-quote here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This is to cover the case where a user has set the path through the environment variable directly. Its now also covered in test_space_weather_env_variable()

Comment thread tests/test_utils.py Outdated
@tristandijkstra

tristandijkstra commented Jun 29, 2026

Copy link
Copy Markdown
Author

Hi @greglucas , thanks for the review. I think I've implemented most the comments and solved the merge conflicts. Happy to make further changes as necessary 😄

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