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 3 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
51 changes: 48 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,34 @@ 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(
"--semimajor",
required='--semiminor' in sys.argv,
type=float,
default=None,
help="Optional spherical radius (km) override. Setting "
AustinSanders marked this conversation as resolved.
Show resolved Hide resolved
" '--semimajor 3396.19' "
"will override both semi-major and semi-minor radius values with the same value. "
"An ellipse can be defined if '--semiminor' is also sent. "
"If not specified, the default radius "
"values (e.g.; from NAIF kernels or the ISIS Cube) will be used. "
"When is needed? Beyond a specialized need, it is common "
AustinSanders marked this conversation as resolved.
Show resolved Hide resolved
"that planetary bodies are defined as a triaxial body. "
"In most of these cases, the IAU WGCCRE report recommends the use of a "
"best-fit sphere for a 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 values are in kilometers."
)
parser.add_argument(
"--semiminor",
type=float,
default=None,
help="Optional semi-minor radius (km) override. When using this parameter, you must also define the semi-major radius. Setting "
" '--semimajor 3396.19 --semiminor 3376.2' "
"will override the semi-major and semi-minor radii to define an ellipse. "
)
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 +112,17 @@ def main():
except KeyError:
k = [args.kernel, ]

if args.semimajor is None:
radii = None
else:
if args.semiminor is None: # set a sphere
radii = [args.semimajor, args.semimajor]
else: # set as ellipse
radii = [args.semimajor, args.semiminor]
Copy link
Contributor

Choose a reason for hiding this comment

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

For testing, it will be easier if you move this logic into file_to_isd and just pass in semi-major, semi-minor as whatever the interface sets them to.


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, radii, 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 +132,7 @@ def main():
) as executor:
futures = {
executor.submit(
file_to_isd, f, **{"kernels": k, "log_level": log_level}
file_to_isd, f, **{"radii": radii, "kernels": k, "log_level": log_level}
): f for f in args.input
}
for f in concurrent.futures.as_completed(futures):
Expand All @@ -113,6 +149,7 @@ def main():
def file_to_isd(
file: os.PathLike,
out: os.PathLike = None,
radii: list = None,
kernels: list = None,
log_level=logging.WARNING
):
Expand Down Expand Up @@ -143,6 +180,14 @@ def file_to_isd(
else:
usgscsm_str = ale.loads(file)

if radii is not None:
usgscsm_json = json.loads(usgscsm_str)
usgscsm_json["radii"]["semimajor"] = radii[0]
usgscsm_json["radii"]["semiminor"] = radii[1]
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