Skip to content

Commit

Permalink
Use getattr() when dealing with config.options
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiodsf committed Jul 22, 2024
1 parent fbd5570 commit 64d5458
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions sourcespec2/input/event_and_picks.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,18 @@ def read_event_and_picks(trace1=None):
picks = []
ssp_event = None
# parse hypocenter file
if config.options.hypo_file is not None:
if getattr(config.options, 'hypo_file', None):
ssp_event, picks, file_format = _parse_hypo_file(
config.options.hypo_file, config.options.evid)
config.hypo_file_format = file_format
# parse pick file
if config.options.pick_file is not None:
if getattr(config.options, 'pick_file', None):
picks = parse_hypo71_picks()
# parse QML file
if config.options.qml_file is not None:
if getattr(config.options, 'qml_file', None):
ssp_event, picks = parse_qml_event_picks(config.options.qml_file)
# parse ASDF file
if config.options.asdf_file is not None:
if getattr(config.options, 'asdf_file', None):
ssp_event, picks = parse_asdf_event_picks(config.options.asdf_file)
if ssp_event is not None:
_log_event_info(ssp_event)
Expand Down
10 changes: 5 additions & 5 deletions sourcespec2/input/event_parsers/obspy_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ def _parse_event_metadata(obspy_event):
"""
# No need to parse event name from QuakeML if event name is given
# in the command line
if config.options.evname is None:
parse_event_name_from_description = config.qml_event_description
event_description_regex = config.qml_event_description_regex
else:
if getattr(config.options, 'evname', None):
parse_event_name_from_description = False
event_description_regex = None
else:
parse_event_name_from_description = config.qml_event_description
event_description_regex = config.qml_event_description_regex
ssp_event = SSPEvent()
ssp_event.event_id = _get_evid_from_resource_id(
str(obspy_event.resource_id.id))
Expand Down Expand Up @@ -282,7 +282,7 @@ def parse_obspy_catalog(obspy_catalog, event_id=None, file_name=''):
:return: a tuple of (SSPEvent, picks)
:rtype: tuple
"""
event_id = event_id or config.options.evid
event_id = event_id or getattr(config.options, 'evid', None)
try:
obspy_event = _get_event_from_obspy_catalog(
obspy_catalog, event_id, file_name)
Expand Down
4 changes: 2 additions & 2 deletions sourcespec2/input/traces.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def _filter_by_station(input_stream):
:return: Stream object
:rtype: :class:`obspy.core.stream.Stream`
"""
if config.options.station is None:
if getattr(config.options, 'station', None) is None:
return input_stream
return Stream([
trace for trace in input_stream.traces
Expand Down Expand Up @@ -112,7 +112,7 @@ def _read_trace_files():
:return: ObsPy Stream object
:rtype: :class:`obspy.core.stream.Stream`
"""
if config.options.trace_path is None:
if getattr(config.options, 'trace_path', None) is None:
return Stream()
# phase 1: build a file list
# ph 1.1: create a temporary dir and run '_build_filelist()'
Expand Down

0 comments on commit 64d5458

Please sign in to comment.