Skip to content
Snippets Groups Projects
Commit 63bb0b45 authored by Wernle, Alexandra Nicole's avatar Wernle, Alexandra Nicole
Browse files

Removed some unnecessary code, raise Abort() if no spikes detected.

parent aed7b732
No related branches found
No related tags found
1 merge request!344New MetadataAlgorithm, SpikesAlgorithm, and flag-spikes application
...@@ -11,7 +11,7 @@ from ..algorithm.SpikesAlgorithm import SpikesAlgorithm ...@@ -11,7 +11,7 @@ from ..algorithm.SpikesAlgorithm import SpikesAlgorithm
def flag_spikes( def flag_spikes(
observatory: str = typer.Option(..., help="Observatory code"), observatory: str = typer.Option(..., help="Observatory code"),
channels: str = typer.Option( channels: str = typer.Option(
default=["F"], help="Channels to despike, default is F. Example input: HEZF" default="F", help="Channels to despike, default is F. Example input: HEZF"
), ),
starttime: datetime = typer.Option( starttime: datetime = typer.Option(
default=None, default=None,
...@@ -64,13 +64,16 @@ def flag_spikes( ...@@ -64,13 +64,16 @@ def flag_spikes(
spikes = spike_algorithm.run() spikes = spike_algorithm.run()
if len(spikes) == 0:
print("No spikes found")
raise typer.Abort()
# confirm whether or not to create spike metadata # confirm whether or not to create spike metadata
if not force: if not force:
typer.confirm(f"Are you sure you want to create flag metadata?", abort=True) typer.confirm(f"Are you sure you want to create flag metadata?", abort=True)
print("Creating flag metadata") print("Creating flag metadata")
# write flag metadata to metadata service # write flag metadata to metadata service
metadata_factory = MetadataFactory(token=metadata_token, url=metadata_url)
with typer.progressbar( with typer.progressbar(
iterable=spikes, label="Uploading to metadata service" iterable=spikes, label="Uploading to metadata service"
) as progressbar: ) as progressbar:
...@@ -99,20 +102,14 @@ def upload_spike_metadata(algorithm: SpikesAlgorithm, spike: Metadata) -> Metada ...@@ -99,20 +102,14 @@ def upload_spike_metadata(algorithm: SpikesAlgorithm, spike: Metadata) -> Metada
Metadata Metadata
created metadata object. created metadata object.
""" """
# check if metadata already exists for period before uploading # check if metadata already exists for period before uploading
prior_metadata_ID = SpikesAlgorithm.check_existing_metadata( prior_metadata = SpikesAlgorithm.check_existing_metadata(algorithm, spike)
algorithm, metadata_obj=spike if prior_metadata:
)
if prior_metadata_ID:
# TODO: Confirm whether or not to add force or simply update automatically # TODO: Confirm whether or not to add force or simply update automatically
typer.confirm( typer.confirm(
f"Spikes already exist for this period, would you like to update this metadata?", f"Spikes already exist for this period, would you like to update this metadata?",
abort=True, abort=True,
) )
# set spike.id to prior_metadata.id to update that metadata object in the database
spike.id = prior_metadata_ID
return SpikesAlgorithm.update_metadata(algorithm, spike) return SpikesAlgorithm.update_metadata(algorithm, spike)
else: else:
return SpikesAlgorithm.create_new_metadata(algorithm, spike) return SpikesAlgorithm.create_new_metadata(algorithm, spike)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment