wmo-im / wis2box

WIS2 in a box is a reference implementation of a WMO WIS2 Node
https://docs.wis2box.wis.wmo.int
Apache License 2.0
40 stars 16 forks source link

error pyoscar get_station_report_summary when retrieving 0-76-0-5208707000000007 #773

Closed maaikelimper closed 1 month ago

maaikelimper commented 2 months ago

Hi Tom,

When getting metadata station 0-76-0-5208707000000007 we encounter an error originating in pyoscar, could you have look?

wis2box metadata station get 0-76-0-5208707000000007

Traceback (most recent call last):
  File "/usr/local/bin/wis2box", line 33, in <module>
    sys.exit(load_entry_point('wis2box', 'console_scripts', 'wis2box')())
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.10/dist-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/app/wis2box/metadata/station.py", line 470, in get
    station = client.get_station_report(wsi, format_='XML', summary=True)
  File "/usr/local/lib/python3.10/dist-packages/pyoscar/__init__.py", line 226, in get_station_report
    return self.get_station_report_summary(response)
  File "/usr/local/lib/python3.10/dist-packages/pyoscar/__init__.py", line 257, in get_station_report_summary
    station, '//wmdr:ObservingFacility/gml:identifier').split(',')[0]  # noqa
AttributeError: 'NoneType' object has no attribute 'split'
tomkralidis commented 2 months ago

Reproduced locally via:

pyoscar station "0-76-0-3170206000000036" -s -f XML

Interestingly enough, pyoscar station "0-76-0-3170206000000036" -s works fine (however we are explicitly asking for the WMDR XML output in wis2box). I've reached out to OSCAR/Surface and will report back on their response. cc @david-i-berry

david-i-berry commented 2 months ago

WIS2box, via pyoscar, accesses the following link:

https://[oscar.wmo.int/oai/provider?verb=GetRecord&metadataPrefix=wmdr&identifier=0-76-0-3170206000000036](https://oscar.wmo.int/oai/provider?verb=GetRecord&metadataPrefix=wmdr&identifier=0-76-0-3170206000000036)

This works and returns the XML via the browser.

david-i-berry commented 2 months ago

the following command also works:

pyoscar station "0-76-0-3170206000000036" --format=XML --env=prod

and returns the XML as expected.

david-i-berry commented 2 months ago

A bit more investigation:

import json
from pyoscar import OSCARClient
client = OSCARClient(env='prod')
station = client.get_station_report("0-76-0-3170206000000036", format_='XML', summary=True)
print(json.dumps(station, indent = 4))

gives the following output:

{
    "station_name": "UBERLANDIA",
    "wigos_station_identifier": "0-76-0-3170206000000036",
    "facility_type": "landFixed",
    "wmo_region": "southAmerica",
    "territory_name": "BRA",
    "latitude": -18.916944,
    "longitude": -48.255556,
    "elevation": 874.8,
    "barometer_height": 870.5
}

Using the WSI "0-76-0-5208707000000007" also works correctly.

This is the line from the wis2box-api where we fetch from OSCAR:

https://github.com/wmo-im/wis2box-api/blob/b351aa45fb67e69138c210b7b93158c09d459d32/wis2box_api/plugins/process/oscar2feature.py#L112

The error either occurs after here or there are network problems.

maaikelimper commented 1 month ago

José reported that the problem fixed itself after one day. This was the second day station where Brazil updated the primary wigos-id during the training, failed to import it into wis2box, then repeat the import one day later and it works.

We suspect that there is something about the way that OSCAR/Surface works, whereby an update does not immediately translate into the station being available for import into the wis2box, but can be imported one day later ...

tomkralidis commented 1 month ago

From OSCAR/Surface, for reference:

The OAI-PMH works with primary WIGOS IDs. For the station 0-76-0-3170206000000036 the primary WSI is 0-20000-0-86776 So if you try: https://oscardepl.wmo.int/oai/provider?verb=GetRecord&metadataPrefix=wmdr&identifier=0-20000-0-86776 you will get the file.

For the new system (OSCAR nextGen) we will make sure that WMDR XML files will be available also via non-primary WSI IDs.

maaikelimper commented 1 month ago

I don't think this an issue we can fix in wis2box, closing