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 to isd_generate.py to allow for a NAIF radius override #486

Merged
merged 6 commits into from
Oct 28, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions ale/isd_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import os
from pathlib import Path
import sys

import json
import ale

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -51,6 +51,19 @@ def main():
"and the default strategy of replacing their final suffix with "
".json will be used to generate the output file paths."
)
parser.add_argument(
"-r", "--radius",
type=float,
default=None,
help="Optional spherical radius (km) override. If not specified, the default "
"radius values, as defined in the NAIF kernels, will be used. "
"There often cases were the defined NAIF radii are set as a triaxial "
"when the IAU WGCCRE report recommends a best-fit sphere for a "
thareUSGS marked this conversation as resolved.
Show resolved Hide resolved
"derived map product. For current IAU spherical recommendations see: "
"https://doi.org/10.1007/s10569-017-9805-5 or "
"http://voparis-vespa-crs.obspm.fr:8080/web/. "
"Make sure radius value is in kilometers."
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

What about nargs="+" (must pass one or more values, e.g., 3396190, 3376250 OR just 3396190) or nargs="2" (must pass two values, e.g.,3396190 3396190) here and making the radius fully overridable? When the args come, as a list, you would need some logic to determine the length and apply to semi major / semi minor axes properly.

I know that the current addition fits the Mars use case, but what if I want to use old (or new) IAU radii. It seems like it would be quite nice to be able to pass these fully dynamically.

Copy link
Contributor

Choose a reason for hiding this comment

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

If we want to add the ability to pass multiple radii, then we should defer to the 1 radii case as it's the most common. I do not like forcing users to enter the same radii twice when we can just add some extra logic.

Copy link
Contributor Author

@thareUSGS thareUSGS Aug 20, 2022

Choose a reason for hiding this comment

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

allow user to pass --semimajor as sphere or --semimajor --semiminor for ellipse. Fighting way too long with argparse to send "only" two values (as floats), so I went with two parameters. Sort of annoying but works.

parser.add_argument(
"-v", "--verbose",
action="store_true",
Expand Down Expand Up @@ -84,9 +97,12 @@ def main():
except KeyError:
k = [args.kernel, ]

if args.radius is not None:
rad = args.radius

thareUSGS marked this conversation as resolved.
Show resolved Hide resolved
if len(args.input) == 1:
try:
file_to_isd(args.input[0], args.out, kernels=k, log_level=log_level)
file_to_isd(args.input[0], args.out, rad, kernels=k, log_level=log_level)
except Exception as err:
# Seriously, this just throws a generic Exception?
sys.exit(f"File {args.input[0]}: {err}")
Expand All @@ -96,7 +112,7 @@ def main():
) as executor:
futures = {
executor.submit(
file_to_isd, f, **{"kernels": k, "log_level": log_level}
file_to_isd, f, **{"radius": rad, "kernels": k, "log_level": log_level}
): f for f in args.input
}
for f in concurrent.futures.as_completed(futures):
Expand All @@ -113,6 +129,7 @@ def main():
def file_to_isd(
file: os.PathLike,
out: os.PathLike = None,
radius: float = None,
kernels: list = None,
log_level=logging.WARNING
):
Expand Down Expand Up @@ -143,6 +160,14 @@ def file_to_isd(
else:
usgscsm_str = ale.loads(file)

if radius is not None:
usgscsm_json = json.loads(usgscsm_str)
usgscsm_json["radii"]["semimajor"] = radius
usgscsm_json["radii"]["semiminor"] = radius
logger.info(f"Overriding radius to:")
logger.info(usgscsm_json["radii"])
usgscsm_str = json.dumps(usgscsm_json, indent=2)

logger.info(f"Writing: {isd_file}")
isd_file.write_text(usgscsm_str)

Expand Down