-
Notifications
You must be signed in to change notification settings - Fork 32
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
Open
thareUSGS
wants to merge
3
commits into
main
Choose a base branch
from
radius_update
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
import os | ||
from pathlib import Path | ||
import sys | ||
|
||
import json | ||
import ale | ||
|
||
logger = logging.getLogger(__name__) | ||
|
@@ -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 " | ||
" '--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 " | ||
"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. " | ||
) | ||
parser.add_argument( | ||
"-v", "--verbose", | ||
action="store_true", | ||
|
@@ -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] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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}") | ||
|
@@ -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): | ||
|
@@ -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 | ||
): | ||
|
@@ -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) | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.