Skip to content

Commit

Permalink
Merge pull request #228 from sblunt/version_hotfix
Browse files Browse the repository at this point in the history
Backwards compatibility for previous orbitize! data formats
  • Loading branch information
sblunt committed May 11, 2021
2 parents a03c348 + 9f08d09 commit 4407596
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
5 changes: 5 additions & 0 deletions orbitize/example_data/old_orbitize_format.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# old orbitize format without covariance or instrument.
epoch,object,quant1,quant1_err,quant2,quant2_err,quant_type
55645.95,1,2479,16,327.94,0.39,seppa
55645.95,1,2479,16,327.94,0.39,radec
55645.95,1,2479,16,nan,nan,rv
21 changes: 20 additions & 1 deletion orbitize/read_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,25 @@ def read_file(filename):
else:
have_inst = np.zeros(num_measurements, dtype=bool)

# orbitize! backwards compatability since we added new columns, some old data formats may not have them
# fill in with default values
if orbitize_style:
if 'quant12_corr' not in input_table.keys():
default_corrs = np.nan * np.ones(len(input_table))
input_table.add_column(default_corrs, name="quant12_corr")
if 'instrument' not in input_table.keys():
default_insts = []
for this_quant_type in input_table['quant_type']:
if this_quant_type == "radec":
default_insts.append("defrd")
elif this_quant_type == "seppa":
default_insts.append("defsp")
elif this_quant_type == "rv":
default_insts.append("defrv")
else:
raise Exception("Invalid 'quant_type' {0}. Valid values are 'radec', 'seppa' or 'rv'".format(this_quant_type))
input_table.add_column(default_insts, name="instrument")

# loop through each row and format table
for index, row in enumerate(input_table):
# First check if epoch is a number
Expand Down Expand Up @@ -237,7 +256,7 @@ def read_file(filename):
output_table.add_row([MJD, row['object'], row['quant1'], row['quant1_err'],
row['quant2'], row['quant2_err'], quant12_corr, row['quant_type'], row['instrument']])
else: # catch wrong formats
raise Exception("Invalid 'quant_type'. Valid values are 'radec', 'seppa' or 'rv'")
raise Exception("Invalid 'quant_type' {0}. Valid values are 'radec', 'seppa' or 'rv'".format(row['quant_type']))

else: # When not in orbitize style

Expand Down
21 changes: 21 additions & 0 deletions tests/test_read_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,30 @@ def test_cov_input():
else:
assert truth == pytest.approx(meas)

def test_read_old_orbitize_format():
"""
Test the read_file function when using an old orbitize data file without `quant12_corr` and `instrument` fields.
"""
# Check that main test input is read in with correct values
input_file = os.path.join(orbitize.DATADIR, 'old_orbitize_format.csv')
input_data = read_file(input_file)

# check correlation and instrument are defualts
assert np.isnan(input_data['quant12_corr'][0])
assert input_data['instrument'][0] == 'defsp'

assert np.isnan(input_data['quant12_corr'][1])
assert input_data['instrument'][1] == 'defrd'

assert np.isnan(input_data['quant12_corr'][2])
assert input_data['instrument'][2] == 'defrv'



if __name__ == "__main__":
test_read_file()
test_read_formatted_file()
test_write_orbitize_input()
test_write_orbitize_input_2()
test_cov_input()
test_read_old_orbitize_format()

0 comments on commit 4407596

Please sign in to comment.