Skip to content

Commit

Permalink
feat: add function to extract default hemisphere
Browse files Browse the repository at this point in the history
  • Loading branch information
mdtanker committed Jun 14, 2024
1 parent c1200ca commit b8b4f0a
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/polartoolkit/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from __future__ import annotations

import logging
import os
import random
import typing

Expand Down Expand Up @@ -37,6 +38,38 @@
sns = None


def default_hemisphere(hemisphere: str | None) -> str:
"""
Returns the default hemisphere set in the users environment variables or raises a
error.
Parameters
----------
hemisphere : str | None
hemisphere to use, either "north" or "south", or None to use the default set in
the users environment variables.
Returns
-------
str
hemisphere to use, either "north" or "south"
"""

if hemisphere is None:
try:
return os.environ["POLARTOOLKIT_HEMISPHERE"]
except KeyError as e:
msg = (
"hemisphere not set, either set it as a temp environment variable in "
"python (os.environ['POLARTOOLKIT_HEMISPHERE']='north'), set it as a "
"permanent operating system environment variable (i.e. for Unix, add "
"'export POLARTOOLKIT_HEMISPHERE=south' to the end of your .bashrc "
"file) or pass it as an argument (hemisphere='north')"
)
raise KeyError(msg) from e
return hemisphere


def rmse(data: typing.Any, as_median: bool = False) -> float:
"""
function to give the root mean/median squared error (RMSE) of data
Expand Down

0 comments on commit b8b4f0a

Please sign in to comment.