-
-
Notifications
You must be signed in to change notification settings - Fork 422
Add vec_table
as an API Parameter for JPL Horizons
#3273
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
Open
megargayu
wants to merge
7
commits into
astropy:main
Choose a base branch
from
megargayu:horizons_vec_table
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 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
850a26b
added vec_table option to vectors_async and updated parse_result to s…
megargayu 8261eba
added all other modifier codes
megargayu b57093d
fixed repeat
megargayu 9846200
fixed repeat
megargayu 01d3f9a
added duplicate support for column names
megargayu 9685fb8
added tests
megargayu 0e15737
renamed to vector_table, fixed api link
megargayu 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 hidden or 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
This file contains hidden or 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 |
---|---|---|
|
@@ -959,8 +959,8 @@ | |
def vectors_async(self, *, get_query_payload=False, | ||
closest_apparition=False, no_fragments=False, | ||
get_raw_response=False, cache=True, | ||
refplane='ecliptic', aberrations='geometric', | ||
delta_T=False,): | ||
refplane='ecliptic', vec_table="3", | ||
aberrations='geometric', delta_T=False,): | ||
""" | ||
Query JPL Horizons for state vectors. | ||
|
||
|
@@ -1057,6 +1057,14 @@ | |
|
||
See :ref:`Horizons Reference Frames <jpl-horizons-reference-frames>` | ||
in the astroquery documentation for details. | ||
|
||
vec_table : string, optional | ||
Selects the table of vectors to be returned. Options are numbers 1-6, | ||
followed by any string of characters in the list [``'x'``, ``'a'``, | ||
``'r'``, ``'p'``]. Default: ``'3'``. | ||
|
||
See `Horizons User Manual <https://ssd.jpl.nasa.gov/horizons/manual.html#vec_table>`_ | ||
megargayu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for details. | ||
|
||
aberrations : string, optional | ||
Aberrations to be accounted for: [``'geometric'``, | ||
|
@@ -1156,6 +1164,7 @@ | |
('VEC_CORR', {'geometric': '"NONE"', | ||
'astrometric': '"LT"', | ||
'apparent': '"LT+S"'}[aberrations]), | ||
('VEC_TABLE', vec_table), | ||
('VEC_DELTA_T', {True: 'YES', False: 'NO'}[delta_T]), | ||
('OBJ_DATA', 'YES')] | ||
) | ||
|
@@ -1314,16 +1323,19 @@ | |
elif (self.query_type == 'elements' and "JDTDB," in line): | ||
headerline = str(line).split(',') | ||
headerline[-1] = '_dump' | ||
# read in vectors header line | ||
elif (self.query_type == 'vectors' and "JDTDB," in line): | ||
headerline = str(line).split(',') | ||
headerline[-1] = '_dump' | ||
# identify end of data block | ||
if "$$EOE" in line: | ||
data_end_idx = idx | ||
# identify start of data block | ||
if "$$SOE" in line: | ||
data_start_idx = idx + 1 | ||
|
||
# read in vectors header line | ||
# reading like this helps fix issues with commas after JDTDB | ||
if self.query_type == 'vectors': | ||
headerline_raw = str(src[idx - 2]).replace("JDTDB,", "JDTDB") | ||
headerline = [" JDTDB", *str(headerline_raw).split("JDTDB")[1].split(',')] | ||
headerline[-1] = '_dump' | ||
Comment on lines
+1333
to
+1338
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 the record, I haven't checked the correctness for all these changes, but trust the tests and the other review that these and the rest below are correct. |
||
# read in targetname | ||
if "Target body name" in line: | ||
targetname = line[18:50].strip() | ||
|
@@ -1404,6 +1416,20 @@ | |
# strip whitespaces from column labels | ||
headerline = [h.strip() for h in headerline] | ||
|
||
# add numbers to duplicates | ||
headerline_seen = {} # format - column_name: [headerline_idx, count] | ||
dup_col_to_orig = {} # format - remapped_column_name: [original_column_name, index], used for later processing | ||
for i, col in enumerate(headerline): | ||
if col in headerline_seen: | ||
headerline_seen[col][1] += 1 | ||
headerline[headerline_seen[col][0]] = f"{col}_1" | ||
dup_col_to_orig[f"{col}_1"] = [col, 1] | ||
|
||
headerline[i] = f"{col}_{headerline_seen[col][1]}" | ||
dup_col_to_orig[headerline[i]] = [col, headerline_seen[col][1]] | ||
else: | ||
headerline_seen[col] = [i, 1] | ||
|
||
# remove all 'Cut-off' messages | ||
raw_data = [line for line in src[data_start_idx:data_end_idx] | ||
if 'Cut-off' not in line] | ||
|
@@ -1469,14 +1495,22 @@ | |
# set column units | ||
rename = [] | ||
for col in data.columns: | ||
data[col].unit = column_defs[col][1] | ||
if data[col].name != column_defs[col][0]: | ||
# fetch from original definition, not remapped | ||
col_unit = column_defs[dup_col_to_orig[col][0] if col in dup_col_to_orig.keys() else col] | ||
|
||
data[col].unit = col_unit[1] | ||
if data[col].name != col_unit[0]: | ||
rename.append(data[col].name) | ||
|
||
# rename columns | ||
for col in rename: | ||
try: | ||
data.rename_column(data[col].name, column_defs[col][0]) | ||
if col in dup_col_to_orig.keys(): # preserve index on duplicate columns | ||
to_rename = f"{column_defs[dup_col_to_orig[col][0]][0]}_{dup_col_to_orig[col][1]}" | ||
else: | ||
to_rename = column_defs[col][0] | ||
|
||
data.rename_column(data[col].name, to_rename) | ||
except KeyError: | ||
pass | ||
|
||
|
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.