11# stdlib imports
2+ import logging
3+ import re
4+ import time
5+ from collections import OrderedDict
26from datetime import datetime , timedelta
37from urllib .error import HTTPError
48from urllib .parse import urlparse
5- from collections import OrderedDict
6- import re
7- import time
8- import logging
99
10- # third party imports
11- from obspy .core .event import read_events
12- import pandas as pd
13- import numpy as np
1410import dateutil
11+ import numpy as np
12+ import pandas as pd
1513import requests
1614
15+ # third party imports
16+ from obspy .core .event import read_events
17+
1718# local imports
1819from libcomcat .exceptions import (
20+ ArgumentConflictError ,
1921 ConnectionError ,
22+ ContentNotFoundError ,
2023 ProductNotFoundError ,
21- ArgumentConflictError ,
2224 UndefinedVersionError ,
23- ContentNotFoundError ,
2425)
2526from libcomcat .utils import HEADERS , TIMEOUT
2627
@@ -674,12 +675,15 @@ def toDict(
674675 edict .update (_get_focal_mechanism_info (focal ))
675676
676677 if get_all_magnitudes :
678+ phases = []
677679 if self .hasProduct ("phase-data" ):
678- product = "phase-data"
679- else :
680- product = "origin"
681- phases = self .getProducts (product , source = "all" )
680+ phase_products = self .getProducts ("phase-data" , source = "all" )
681+ phases += phase_products
682+ if self .hasProduct ("origin" ):
683+ origin_products = self .getProducts ("origin" , source = "all" )
684+ phases += origin_products
682685 imag = 0
686+ unique_magnitudes = []
683687 for phase_data in phases :
684688 # we don't want duplicates of phase data information
685689 # from us origin product
@@ -691,14 +695,22 @@ def toDict(
691695 # ######################################
692696 phase_url = phase_data .getContentURL ("quakeml.xml" )
693697 try :
694- catalog = read_events (phase_url )
698+ catalog = read_events (phase_url , format = "QUAKEML" )
695699 except Exception as e :
700+ catalog = read_events (phase_url , format = "QUAKEML" )
696701 fmt = "Could not parse quakeml file from %s. " "Error: %s"
697702 tpl = (phase_url , str (e ))
698703 logging .warning (fmt % tpl )
699704 continue
700705 event = catalog .events [0 ]
701706 for magnitude in event .magnitudes :
707+ # since resource IDs for magnitudes are unique, we can use this
708+ # to track whether we're getting duplicate magnitudes
709+ # from phase-data and origin products.
710+ magid = magnitude .resource_id .id
711+ if magid in unique_magnitudes :
712+ continue
713+ unique_magnitudes .append (magid )
702714 edict ["magnitude%i" % imag ] = magnitude .mag
703715 edict ["magtype%i" % imag ] = magnitude .magnitude_type
704716 cname = "magsource%i" % imag
0 commit comments