crotwell / seisFile

A library for reading and writing seismic file formats in java.
GNU Lesser General Public License v3.0
27 stars 20 forks source link

Error parsing QuakeML #28

Closed andreabono closed 1 year ago

andreabono commented 1 year ago

I'm trying to read some QuakeMLs using standard FDSN web services using this routine

public edu.sc.seis.seisFile.fdsnws.quakeml.Event read_single_quakeml(String host, String event_id, boolean include_all_magnitudes, 
            boolean include_all_origins, boolean include_arrivals){
        try {
            FDSNEventQueryParams queryParams = new FDSNEventQueryParams();
            //
            queryParams.setHost(host.replace("http://", ""));
            queryParams.setEventid(event_id);
            queryParams.setIncludeAllMagnitudes(include_all_magnitudes);
            queryParams.setIncludeAllOrigins(include_all_origins);
            queryParams.setIncludeArrivals(include_arrivals);   
            //
            FDSNEventQuerier querier = new FDSNEventQuerier(queryParams);
            Quakeml quakeml = querier.getQuakeML();
            if (!quakeml.checkSchemaVersion()) {
                log_locally_for_bad_format(quakeml);
            }
            //
            if (quakeml.getEventParameters().getEvents().hasNext())
                return quakeml.getEventParameters().getEvents().next(); // <<<<<<<< ERROR HERE!!
            else
                return null;
            //
        } catch (Exception ex) {
//            logs an error....
            return null;
        }
    }

I get an error in the "ERROR HERE" line while attempting to cast the resulting QuakeML to an edu.sc.seis.seisFile.fdsnws.quakeml.Event object.
The reason is that the resulting QuakeML has NO LOCATION CODE in the waveformID tag.

You can try to replicate the error calling:
http://geofon.gfz-potsdam.de:80/fdsnws/event/1/query?eventid=gfz2023injc&includeallmagnitudes=true&includeallorigins=false&includearrivals=true
and then trying to cast it to Event. If you look at the "pick" objects the have no location code.

It's great to get an Event object via that cast, so is there a chance to get this thing fixed or solved in any way?

andreabono commented 1 year ago

A possible solution to avoid your cast error could be settig location code ="??" when empty

crotwell commented 1 year ago

Fixed in acf76936eb6d41dfeb8531723da93a3d1bd873e5 Loc code will be "" if chan code exists, or null if chan code is also missing (aka a station-only pick). I think this is the best as it matches how my stationxml code handles missing or space-space loc codes.

Sorry for long delay, somehow missed this notification. Will push out a new release soon.

andreabono commented 1 year ago

Ok great!! Thanks a lot!!

crotwell commented 1 year ago

2.0.6 published, may take a little time to show up on maven central...

andreabono commented 1 year ago

Great news!! Thanks a lot!! Andrea

Il Mar 1 Ago 2023, 18:18 Philip Crotwell @.***> ha scritto:

2.0.6 published, may take a little time to show up on maven central...

— Reply to this email directly, view it on GitHub https://github.com/crotwell/seisFile/issues/28#issuecomment-1660656890, or unsubscribe https://github.com/notifications/unsubscribe-auth/AL663WQZMNXVMDYOIUNMUJDXTET53ANCNFSM6AAAAAAXTBAJYY . You are receiving this because you authored the thread.Message ID: @.***>