ICOS-Carbon-Portal / pylib

Python library for direct access to ICOS time series data.
12 stars 3 forks source link

Error with station.get #194

Closed joe-pitt closed 3 weeks ago

joe-pitt commented 1 month ago

I've just upgraded to icoscp-0.2.0 (from 0.1.17) and for now I am still using the legacy station.get() function. In general this is working, but when I try for the site "RGL" using the following:

from icoscp_core.icos import bootstrap
from icoscp import cpauth
from icoscp.station import station

cookie_token = ...
meta, data = bootstrap.fromCookieToken(cookie_token)
cpauth.init_by(data.auth)

stat = station.get(stationId="RGL")

I get the following error:

TypeError                                 Traceback (most recent call last)
Cell In[9], line 1
----> 1 stat = station.get(stationId="RGL")

File ~/.conda/envs/openghg_dev_env/lib/python3.12/site-packages/icoscp/station/station.py:588, in get(stationId, station_df)
    586 if not stn[stn.project.str.upper() == "ICOS"].empty:
    587     if stn.lat.any():
--> 588         my_stn.lat = float(stn.lat[stn.project.str.upper() == 'ICOS'])
    589     if stn.lat.any():
    590         my_stn.lon = float(stn.lon[stn.project.str.upper() == 'ICOS'])

File ~/.conda/envs/openghg_dev_env/lib/python3.12/site-packages/pandas/core/series.py:248, in _coerce_method.<locals>.wrapper(self)
    240     warnings.warn(
    241         f"Calling {converter.__name__} on a single element Series is "
    242         "deprecated and will raise a TypeError in the future. "
   (...)
    245         stacklevel=find_stack_level(),
    246     )
    247     return converter(self.iloc[0])
--> 248 raise TypeError(f"cannot convert the series to {converter}")

TypeError: cannot convert the series to <class 'float'>

If I print "stn" just before this I find that it has 4 identical entries:

                                                  uri   id        name  \
234  http://meta.icos-cp.eu/resources/stations/AS_RGL  RGL  Ridge Hill   
235  http://meta.icos-cp.eu/resources/stations/AS_RGL  RGL  Ridge Hill   
236  http://meta.icos-cp.eu/resources/stations/AS_RGL  RGL  Ridge Hill   
237  http://meta.icos-cp.eu/resources/stations/AS_RGL  RGL  Ridge Hill   

    icosClass country      lat      lon elevation  \
234         2      GB  51.9975  -2.5399     207.0   
235         2      GB  51.9975  -2.5399     207.0   
236         2      GB  51.9975  -2.5399     207.0   
237         2      GB  51.9975  -2.5399     207.0   

                                    stationTheme firstName lastName  \
234  http://meta.icos-cp.eu/ontologies/cpmeta/AS    Kieran  Stanley   
235  http://meta.icos-cp.eu/ontologies/cpmeta/AS    Kieran  Stanley   
236  http://meta.icos-cp.eu/ontologies/cpmeta/AS    Kieran  Stanley   
237  http://meta.icos-cp.eu/ontologies/cpmeta/AS    Kieran  Stanley   

                         email    siteType project theme  
234  k.m.stanley@bristol.ac.uk  tall tower    ICOS    AS  
235  k.m.stanley@bristol.ac.uk  tall tower    ICOS    AS  
236  k.m.stanley@bristol.ac.uk  tall tower    ICOS    AS  
237  k.m.stanley@bristol.ac.uk  tall tower    ICOS    AS 

This doesn't seem to happen for other sites - is this a RGL-specific bug or am I doing something foolish?

ZogopZ commented 1 month ago

Thank you for bringing this to our attention, @joe-pitt! We’re currently looking into it and will update you as soon as we have more information.

joe-pitt commented 1 month ago

Not sure if this is related to attempts to fix this issue, but since 2024-10-04 station.get now retrieves no info for many sites:

from icoscp_core.icos import bootstrap
from icoscp import cpauth
from icoscp.station import station

cookie_token = ...
meta, data = bootstrap.fromCookieToken(cookie_token)
cpauth.init_by(data.auth)

station.get(stationId="BIK").info()

prints:

{'stationId': 'BIK',
 'name': None,
 'theme': None,
 'icosclass': None,
 'siteType': None,
 'lat': None,
 'lon': None,
 'eas': None,
 'firstName': None,
 'lastName': None,
 'email': None,
 'country': None,
 'project': None,
 'uri': None}

This means I can't retrieve data from these sites. Other sites (e.g. GAT) are still working fine.

ukarst commented 1 month ago

Other users are currently experiencing the same problem.

joe-pitt commented 1 month ago

OK thanks that's useful to know!

ZogopZ commented 3 weeks ago

Hey @joe-pitt,

The two issues you were encountering were partially related. You shouldn't be getting duplicates of the same station, which was a bug, and the empty station information was due to a server-side request. Both issues are now fixed in the latest icoscp version.

joe-pitt commented 3 weeks ago

Brilliant - thank you!