"""GFINDER CLI `definition` command."""
import click
from .docstring import set_docstring
from gfinder.datastore import DataStore
from gfinder.opportunity import OpportunityDefinition
import json
@click.command(name='definition', context_settings=dict(
ignore_unknown_options=True,
allow_extra_args=True,
))
@click.argument('odf_file')
@click.option('--target', type=click.STRING, help='Overwrites ODF target parameters.')
@click.option('--binning', type=click.INT, help='Detector binning: 1 (default), 2 or 4', default=1)
@click.option('--sc-slew-angles', type=click.STRING, help='Overwrites ODF SC_Slew_Angles parameters (run `geometry` command to know allowed parameters).')
@click.option('--majis-scan-angle', type=click.STRING, help='Overwrites ODF MAJIS_Scan_Angle parameters (run `geometry` command to know allowed parameters).')
@click.option('--to-json/--no-to-json', help='Output JSON', default='False')
@click.pass_context
def definition_cmd(ctx, odf_file, target, binning, sc_slew_angles, majis_scan_angle, to_json):
"""Get information about an observation opportunity definition (ODF file).
"""
# Retrieve extra arguments to be passed to the command function.
kwargs = []
for arg in ctx.args:
pair = arg[2:].split('=')
key = pair[0].replace('-', '_')
try:
val = float(pair[1])
except:
val = pair[1]
kwargs.append((key,val))
kwargs = dict(kwargs)
definition(
odf_file,
target=target,
binning=binning,
sc_slew_angles=sc_slew_angles,
majis_scan_angle=majis_scan_angle,
to_json=to_json,
**kwargs
)
[docs]@set_docstring(definition_cmd, {'odf_file': 'ODF file output_dir relative to ODF data store directory.'})
def definition(odf_file, target=None, binning=1, sc_slew_angles=None, majis_scan_angle=None, to_json=False, **kwargs):
# Init data store
datastore = DataStore()
# Load input Opportunity Definition File (ODF) (geometry event definition)
odf_file_abspath = datastore.get_ODF_filename(odf_file)
if odf_file_abspath:
opportunity_definition = OpportunityDefinition(
odf_file_abspath,
target=target,
binning=binning,
majis_scan_angle=majis_scan_angle,
sc_slew_angles=sc_slew_angles,
datastore=datastore,
**kwargs
)
else:
print(f'Input `{odf_file}` ODF file not valid or was not found (neither in your user data nor the app data directories).')
return
if to_json:
print(json.dumps(opportunity_definition.getDict(), sort_keys=False, indent=4))
return
print()
print(f'Name: {opportunity_definition.name}')
print(f'Description: {opportunity_definition.description}')
print(f'Observation Type: {opportunity_definition.observation_type}')
print(f'PTR Pointing Type: {opportunity_definition.ptr_pointing_type}')
print(f'Target: {opportunity_definition.target}')
print(f'Detector: {opportunity_definition.detector}')
print('Additional attributes:')
if opportunity_definition.extra_attributes:
for extra_attribute in opportunity_definition.extra_attributes:
print(f' {extra_attribute} = {getattr(opportunity_definition,extra_attribute)}')
print('Included ODF files:')
for included_odf in opportunity_definition.included_odf_list:
print(f' {included_odf}')
print('Conditions:')
geometry_definitions = opportunity_definition.getGeometryDefinitions('Measurement', searchable=True)
for geometry_definition in geometry_definitions:
name = geometry_definition['name']
rel_condition = geometry_definition['condition']['relationalCondition']
ref_value = geometry_definition['condition']['referenceValue']
print(' {} {} {}'.format(name, rel_condition, ref_value))
print('Measurement geometries:')
geometry_definitions = opportunity_definition.getGeometryDefinitions('Measurement')
for geometry_definition in geometry_definitions:
name = geometry_definition['name']
# parameters = geometry_definition["parameters"]
# print(f' {name} {parameters}')
print(f' {name}')
print('Observations geometries:')
geometry_definitions = opportunity_definition.getGeometryDefinitions('Observation')
for geometry_definition in geometry_definitions:
name = geometry_definition['name']
# parameters = geometry_definition["parameters"]
# print(f' {name} {parameters}')
print(f' {name}')
print()