Skip to content
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

Object detection controller #19

Merged
merged 24 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c5de048
modified: forcedphot/ephemeris/ephemeris_client.py
szilac Aug 19, 2024
2ce7996
modified: src/forcedphot/odc.py
szilac Aug 19, 2024
7d05871
modified: src/forcedphot/ephemeris/data_loader.py
szilac Aug 27, 2024
85a5760
new file: tests/forcedphot/ephemeris/data/Encke_2024-01-01_00-00-0…
szilac Aug 27, 2024
5c2d338
modified: src/forcedphot/ephemeris/ephemeris_client.py
szilac Aug 27, 2024
46f0179
modified: src/forcedphot/ephemeris/data_loader.py
szilac Aug 27, 2024
d3585d4
modified: tests/forcedphot/test_odc.py
szilac Aug 27, 2024
5668592
modified: src/forcedphot/odc.py
szilac Aug 27, 2024
c89bb1d
modified: src/forcedphot/odc.py
szilac Aug 27, 2024
df0f349
modified: src/forcedphot/odc.py
szilac Aug 27, 2024
0eb060b
modified: src/forcedphot/odc.py
szilac Aug 27, 2024
0cd80da
modified: src/forcedphot/ephemeris/ephemeris_client.py
szilac Aug 27, 2024
2cd2b8e
modified: tests/forcedphot/ephemeris/test_data_loader.py
szilac Aug 27, 2024
46b8428
modified: src/forcedphot/ephemeris/ephemeris_client.py
szilac Oct 1, 2024
6100566
modified: src/forcedphot/odc.py
szilac Oct 1, 2024
e023863
modified: tests/forcedphot/ephemeris/test_data_loader.py
szilac Oct 1, 2024
cb87396
modified: src/forcedphot/odc.py
szilac Oct 1, 2024
b2324f8
modified: tests/forcedphot/ephemeris/test_data_loader.py
szilac Oct 1, 2024
29fd3b9
modified: tests/forcedphot/ephemeris/test_data_loader.py
szilac Oct 1, 2024
4345f50
modified: tests/forcedphot/ephemeris/test_data_loader.py
szilac Oct 1, 2024
13eff44
modified: src/forcedphot/odc.py
szilac Oct 1, 2024
63c12c6
modified: src/forcedphot/odc.py
szilac Oct 1, 2024
8f6ddc8
modified: src/forcedphot/odc.py
szilac Oct 1, 2024
de97609
fix typos
jrob93 Oct 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions src/forcedphot/ephemeris/data_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,23 +132,3 @@ def load_multiple_ephemeris_files(file_paths: list[str]) -> list[EphemerisData]:
raise # Re-raise the exception to be caught by the calling function

return ephemeris_list


if __name__ == "__main__":
# Example usage
# file_path = "./Ceres_2024-01-01_00-00-00.000_2025-12-31_23-59-00.000.ecsv"
# try:
# ephemeris_data = DataLoader.load_ephemeris_from_ecsv(file_path)
# except Exception as e:
# print(f"Error: {str(e)}")

# Example of loading multiple files
file_paths = [
"./Ceres_2024-01-01_00-00-00.000_2025-12-31_23-59-00.000.ecsv",
"./Encke_2024-01-01_00-00-00.000_2024-06-30_23-59-00.000.ecsv",
]
try:
ephemeris_list = DataLoader.load_multiple_ephemeris_files(file_paths)
print(f"Loaded {len(ephemeris_list)} ephemeris files.")
except Exception as e:
print(f"Error: {str(e)}")
245 changes: 134 additions & 111 deletions src/forcedphot/ephemeris/ephemeris_client.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import argparse
import logging
from typing import Union

import pandas as pd
from astropy.time import Time

from forcedphot.ephemeris.data_loader import DataLoader
Expand Down Expand Up @@ -100,15 +100,38 @@ def query_from_csv(
Returns:
List of query results.
"""
if service.lower() == "horizons":
return HorizonsInterface.query_ephemeris_from_csv(
csv_file, observer_location, save_data=save_data
)
elif service.lower() == "miriade":
return MiriadeInterface.query_ephemeris_from_csv(csv_file, observer_location, save_data=save_data)
else:
self.logger.error(f"Invalid service: {service}. Use 'horizons' or 'miriade'.")
return None
try:
results = []
df = pd.read_csv(csv_file)

for _index, row in df.iterrows():
query = QueryInput(
target=row.iloc[0],
target_type=row.iloc[1],
start=Time(row.iloc[2], format="iso", scale="utc"),
end=Time(row.iloc[3], format="iso", scale="utc"),
step=row.iloc[4],
)

query_result = self.query_single(
service,
query.target,
query.target_type,
query.start,
query.end,
query.step,
observer_location,
save_data=save_data,
)

if query_result is not None:
results.append(query_result)

return results

except Exception as e:
self.logger.error(f"An error occured during query for CSV file {csv_file}")
self.logger.error(f"Error details: {str(e)}")

def load_ephemeris_from_ecsv(self, ecsv_file: str) -> EphemerisData:
"""
Expand All @@ -135,104 +158,104 @@ def load_ephemeris_from_multi_ecsv(self, ecsv_files: list[str]) -> EphemerisData
return DataLoader.load_multiple_ephemeris_files(ecsv_files)


def main():
"""
Main function to handle command-line arguments and execute ephemeris queries.

This function parses command-line arguments to determine whether to perform a single
query or batch processing from a CSV file. It supports querying ephemeris data using
either the JPL Horizons or Miriade services.

Command-line Arguments:
--service (str): The service to use for querying ('horizons' or 'miriade') deafult is 'horizons'.
--csv (str): Path to the CSV file for batch processing (optional).
--ecsv (str): Path to the ECSV file for single query (optional) or
list of ECSV files for batch processing (optional).
--target (str): Target object for a single query (optional).
--target_type (str): Target object type for a single query (optional).
--start (str): Start time for a single query (optional).
--end (str): End time for a single query (optional).
--step (str): Time step for a single query (optional).
--location (str): Observer location code (default is 'X05').
--save_data (bool): Flag to save query results as ECSV files (default is False).

Behavior:
- If the --csv argument is provided, the function will process multiple queries from the specified
CSV file.
- If all single query parameters (--target, --target_type, --start, --end, --step) are provided,
the function will perform a single query.
- If neither a CSV file nor all single query parameters are provided, the function will display
an error message.

Example Usage:
python ephemeris_client.py --service horizons --csv queries.csv --save_data
python ephemeris_client.py --service miriade --target Ceres --target_type smallbody
--start 2023-01-01 --end 2023-01-02 --step 1h
python ephemeris_client.py --ecsv ceres_ephemeris.ecsv,vesta_ephemeris.ecsv

Returns:
result (list[EphemerisData]): List of ephemeris data as a dataclass.
"""
parser = argparse.ArgumentParser(
description="Query ephemeris data using Horizons or Miriade services or"
" load ephemeris data from existing ECSV."
)
parser.add_argument(
"--service", choices=["horizons", "miriade"], default="horizons", help="Service to use for querying"
)
parser.add_argument(
"--ecsv", help="Path to ECSV file (or a list separated with ,) containing ephemeris data"
)
parser.add_argument("--csv", help="Path to CSV file for batch processing")
parser.add_argument("--target", help="Target object for single query")
parser.add_argument("--target_type", help="Target object type for single query")
parser.add_argument("--start", help="Start time for single query")
parser.add_argument("--end", help="End time for single query")
parser.add_argument("--step", help="Time step for single query")
parser.add_argument(
"--location",
default=EphemerisClient.DEFAULT_OBSERVER_LOCATION,
help="Observer location code, default: Rubin(X05)",
)
parser.add_argument("--save_data", action="store_true", help="Save query results as ECSV files")

args = parser.parse_args()

client = EphemerisClient()

if args.csv:
results = client.query_from_csv(args.service, args.csv, args.location, args.save_data)
elif all([args.target, args.target_type, args.start, args.end, args.step]):
result = client.query_single(
args.service,
args.target,
args.target_type,
args.start,
args.end,
args.step,
args.location,
args.save_data,
)
results = [result] if result else []
elif args.ecsv:
ecsv_files = args.ecsv.split(",") # Assume multiple files are comma-separated
if len(ecsv_files) > 1:
results = client.load_ephemeris_from_multi_ecsv(ecsv_files)
else:
results = client.load_ephemeris_from_ecsv(args.ecsv)
else:
parser.error(
"Either provide a CSV file or all single query parameters"
" like target, target_type,start, end, step"
" or ECSV file containing ephemeris data"
)

if results:
print(f"Successfully queried {len(results)} object(s)")
return results
else:
print("No results obtained")


if __name__ == "__main__":
main()
# def main():
# """
# Main function to handle command-line arguments and execute ephemeris queries.

# This function parses command-line arguments to determine whether to perform a single
# query or batch processing from a CSV file. It supports querying ephemeris data using
# either the JPL Horizons or Miriade services.

# Command-line Arguments:
# --service (str): The service to use for querying ('horizons' or 'miriade') deafult is 'horizons'.
# --csv (str): Path to the CSV file for batch processing (optional).
# --ecsv (str): Path to the ECSV file for single query (optional) or
# list of ECSV files for batch processing (optional).
# --target (str): Target object for a single query (optional).
# --target_type (str): Target object type for a single query (optional).
# --start (str): Start time for a single query (optional).
# --end (str): End time for a single query (optional).
# --step (str): Time step for a single query (optional).
# --location (str): Observer location code (default is 'X05').
# --save_data (bool): Flag to save query results as ECSV files (default is False).

# Behavior:
# - If the --csv argument is provided, the function will process multiple queries from the specified
# CSV file.
# - If all single query parameters (--target, --target_type, --start, --end, --step) are provided,
# the function will perform a single query.
# - If neither a CSV file nor all single query parameters are provided, the function will display
# an error message.

# Example Usage:
# python ephemeris_client.py --service horizons --csv queries.csv --save_data
# python ephemeris_client.py --service miriade --target Ceres --target_type smallbody
# --start 2023-01-01 --end 2023-01-02 --step 1h
# python ephemeris_client.py --ecsv ceres_ephemeris.ecsv,vesta_ephemeris.ecsv

# Returns:
# result (list[EphemerisData]): List of ephemeris data as a dataclass.
# """
# parser = argparse.ArgumentParser(
# description="Query ephemeris data using Horizons or Miriade services or"
# " load ephemeris data from existing ECSV."
# )
# parser.add_argument(
# "--service", choices=["horizons", "miriade"], default="horizons", help="Service to use for querying"
# )
# parser.add_argument(
# "--ecsv", help="Path to ECSV file (or a list separated with ,) containing ephemeris data"
# )
# parser.add_argument("--csv", help="Path to CSV file for batch processing")
# parser.add_argument("--target", help="Target object for single query")
# parser.add_argument("--target_type", help="Target object type for single query")
# parser.add_argument("--start", help="Start time for single query")
# parser.add_argument("--end", help="End time for single query")
# parser.add_argument("--step", help="Time step for single query")
# parser.add_argument(
# "--location",
# default=EphemerisClient.DEFAULT_OBSERVER_LOCATION,
# help="Observer location code, default: Rubin(X05)",
# )
# parser.add_argument("--save_data", action="store_true", help="Save query results as ECSV files")

# args = parser.parse_args()

# client = EphemerisClient()

# if args.csv:
# results = client.query_from_csv(args.service, args.csv, args.location, args.save_data)
# elif all([args.target, args.target_type, args.start, args.end, args.step]):
# result = client.query_single(
# args.service,
# args.target,
# args.target_type,
# args.start,
# args.end,
# args.step,
# args.location,
# args.save_data,
# )
# results = [result] if result else []
# elif args.ecsv:
# ecsv_files = args.ecsv.split(",") # Assume multiple files are comma-separated
# if len(ecsv_files) > 1:
# results = client.load_ephemeris_from_multi_ecsv(ecsv_files)
# else:
# results = client.load_ephemeris_from_ecsv(args.ecsv)
# else:
# parser.error(
# "Either provide a CSV file or all single query parameters"
# " like target, target_type,start, end, step"
# " or ECSV file containing ephemeris data"
# )

# if results:
# print(f"Successfully queried {len(results)} object(s)")
# return results
# else:
# print("No results obtained")


# if __name__ == "__main__":
# main()
Loading
Loading