amacd31 / kiwis_pie

Python library for querying WISKI via KiWIS (KISTERS Web Interoperability Solution)
Other
17 stars 7 forks source link

Search sites using bbox #3

Closed Rajitha-Athukorala closed 1 year ago

Rajitha-Athukorala commented 1 year ago

I am trying to get a list of sites given a bbox using the get_site_list function

k.get_site_list(bbox=(147, -36, 148, -35))

but I keep getting an error message {"type": "error", "code": "InvalidParameterValue", "message": "Parameter bbox is not a valid bounding box, must contain four comma separated numbers."}

Something to do with the way I pass in the bbow coordinates?

amacd31 commented 1 year ago

I unfortunately haven't been able to confirm this against a KiWIS instance (is the server you are accessing publicly available?).

The implementation of kiwis-pie is fairly naive and is dynamically configured to wrap the API. As such it doesn't currently have much in terms of handling for special types like lists of numbers. I suspect if you try to pass as a string of comma separated values it might craft a URL that KiWIS is happy to respond to.

e.g. k.get_site_list(bbox="147,-36,148,-35")

Rajitha-Athukorala commented 1 year ago

I am testing this with AUS BoM waterdata: k = KIWIS('http://www.bom.gov.au/waterdata/services')

I think you are right, I tried a string of comma separated values which seems to accept it but no data could be retrieved.

{"type": "error", "code": "DatasourceError", "message": "Could not get site list from WDP."}

May be a manual edit to the request URL?

http://www.bom.gov.au/waterdata/services?service=kisters&type=QueryServices&format=json&bbox=147%2C+-36%2C+148%2C+-35&request=getSiteList

Anyways, Thanks a lot for your help Andrew.

amacd31 commented 1 year ago

That's a weird one. No idea why that is returning an error. It is hard to find documentation on the KiWIS API. Trying against some other public KiWIS systems I can find, I didn't get any errors, but I also didn't get any returned results (I may not have been picking ranges that worked for the system as configured).

Interestingly the bbox being set for Station List queries does work.

Depending on what you are after you may be able to work around this limitation of the Bureau of Meteorology implementation by using:

k.get_station_list(
    bbox="147,-36,148,-35",
    return_fields=[
        "station_name",
        "station_no",
        "station_id",
        "site_name",
        "site_no",
        "site_id",
        "station_longitude",
        "station_latitude"
    ]
)

Which seems to work fine and returns the site_id and site_no values that you'd get in a get_site_list query.

In fetching data from the Bureau of Meteorology site I've personally found get station list to be more useful to me as a station_id rather than a site_id is required to do a time series lookup, which is what I've largely used this library for in the past.

Rajitha-Athukorala commented 1 year ago

Tried with station_lits but it returns a key error. Strange how it worked for you. Are you using an updated version of the library?

station_list

amacd31 commented 1 year ago

Ah yes, sorry, picking up this problem on and off over the last week with everything else going I'd forgotten that I'd made a change to my dev version while testing this out.

There is the option to get relax the check for keywords that haven't been configured.

Until I get another release out with bbox added for get_station_list you can turn strict mode off this way:

k = KIWIS('http://www.bom.gov.au/waterdata/services', strict_mode=False)

The above should then work.

Rajitha-Athukorala commented 1 year ago

Yeah, it works. Thanks a lot Andrew. Really appreciate your support. I will close the issue now.

Rajitha-Athukorala commented 1 year ago

bbox search supported with station_list with stric_mode= False (at least for now till a new update)

amacd31 commented 1 year ago

Published version 0.10.2 which includes bbox in the listed keyword arguments for get_station_list.