Skip to content

Commit 8d01bb8

Browse files
committed
make objname more flexible
1 parent 83d312a commit 8d01bb8

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

brav0/preprocess.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ def index_with_obj(
333333
file_obj_sep: str = "_",
334334
file_col: str = "RVFILE",
335335
obj_col: str = "OBJECT",
336+
obj_col_backup: str = "_INITIAL_BRAV0",
336337
row_col: str = "ROW",
337338
force_self_mask: bool = False,
338339
) -> DataFrame:
@@ -351,17 +352,30 @@ def index_with_obj(
351352
:type file_obj_ind: int
352353
:param file_obj_sep: Separator between filename parts, defaults to "_"
353354
:type file_obj_sep: str, optional
355+
:param obj_col: Column label to use for object names in output file
356+
:type obj_col: str, optional
357+
:param obj_col_backup: If there is already an obj_col column,
358+
add obj_col_backup to its name.
359+
:type obj_col_backup: str, optional
354360
"""
355361

356362
df = df.copy()
357363

358-
# NOTE: this is a strong assumption on raw format/filenames
359-
# can think of ways to improve it in the future
360364
if obj_col in df.columns:
361-
msg = f"There is already an {obj_col} column, doing nothing."
362-
warnings.warn(msg, category=RuntimeWarning)
363-
return
365+
msg = f"There is already an {obj_col} column, moving it to {obj_col}_{obj_col_backup}."
366+
new_obj_col = obj_col + obj_col_backup
367+
if new_obj_col not in df:
368+
warnings.warn(msg, category=RuntimeWarning)
369+
df = df.rename(columns={obj_col: new_obj_col})
370+
else:
371+
raise ValueError(
372+
f"Both {obj_col} and {new_obj_col} already exist in the dataframe. "
373+
"Provide new value for one of them."
374+
)
364375

376+
# NOTE: Also strong assumption. Straightforward default would be something
377+
# like OBJNAME.ext, with support for other ways to get name (block below
378+
# or header key)
365379
# Get filenames in pandas index object and split/index to get obj names
366380
file_lvl = df.index.get_level_values(file_col)
367381
objects = (

brav0/rmplanets.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
from radvel.orbit import timetrans_to_timeperi
1111
from scipy.stats import norm, truncnorm
1212

13+
# TODO: Remove radvel dependency ?
14+
15+
1316
ARCHIVE_URL = "https://exoplanetarchive.ipac.caltech.edu/TAP"
1417

1518
# Keys from the archive

brav0/rolling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def wmed(
5151
# if not tt.all(tt.ge(tt.extra_ops.diff(values), 0)):
5252
# NOTE: lexsort is a custom op implemented here, but might be included
5353
# in aesara later. Results are consistent with numpy.
54-
# It is slow, but argsort (from aesara is slow as well)
54+
# It is slow, but argsort (from aesara) is slow as well
5555
inds = lexsort((weights, values), axis=diff_ax)[0]
5656
# inds = tt.argsort(values, axis=diff_ax)
5757
values = take_along_axis(values, inds, axis)

0 commit comments

Comments
 (0)