Skip to content

Commit

Permalink
can also upload from same script
Browse files Browse the repository at this point in the history
  • Loading branch information
dlakaplan committed Jun 28, 2022
1 parent 859bd9b commit ce6a2d8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
32 changes: 29 additions & 3 deletions pulsardb/scripts/tim2csv.py → pulsardb/scripts/tim2db.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

def main():
parser = argparse.ArgumentParser(
description="""Add observations to database from tim file.
description="""Make CSV database entries from tim file, and optionally upload to database.
Can be read using e.g.,
`Table.read('test.csv',format='ascii.commented_header',delimiter=',')`""",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
Expand All @@ -41,6 +41,19 @@ def main():
parser.add_argument("--backend", help="Backend when not otherwise specified")
parser.add_argument("--projectflag", default="pta", help="Flag for project")
parser.add_argument("--project", help="Project when not otherwise specified")
parser.add_argument(
"--telescope", default=None, help="Telescope when not otherwise specified"
)
parser.add_argument(
"--db",
action="store_true",
default=False,
help="Directly upload to database (may be slow)?",
)
parser.add_argument(
"--apikey",
help="API key for direct submission (or specify via $PULSAR_API_KEY)",
)

parser.add_argument(
"--log-level",
Expand Down Expand Up @@ -89,7 +102,7 @@ def main():
project = toas[select].get_flag_value(
args.projectflag, fill_value=args.project
)[0][0]
telescope = None
telescope = args.telescope
for telname in telescopes["name"]:
if (
receiver
Expand All @@ -107,9 +120,22 @@ def main():
f"{start.mjd}, {stop.mjd}, {args.pulsar}, {project}, {telescope}, {receiver}, {backend}, {frequency.to_value(u.MHz)}, {args.submitter}",
file=fout,
)
if args.db:
response = pulsardb.Observations.post(
pulsar=args.pulsar,
telescope=telescope,
frequency=frequency,
project=project,
start=start,
stop=stop,
receiver=receiver,
backend=backend,
submitter=args.submitter,
key=args.apikey,
)
else:
log.warning(
f"Cannot post entry with undefined telescope for observation {name}"
f"Cannot determine entry with undefined telescope for observation {name}"
)
if args.out is not None:
log.info(f"Wrote to {args.out}")
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
packages=find_packages(),
entry_points={
"console_scripts": [
"tim2csv=pulsardb.scripts.tim2csv:main",
"tim2db=pulsardb.scripts.tim2db:main",
],
},
install_requires=["astropy", "pandas", "loguru", "requests"],
Expand Down

0 comments on commit ce6a2d8

Please sign in to comment.