ICOS-Carbon-Portal / pylib

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

Property returns wrong content. #96

Closed atverm closed 1 year ago

atverm commented 2 years ago

station.name property returns some index number, not the string containing the station name. station[2] gives the correct station name.

See for example:

from icoscp.station import station
stationlist=station.getIdList(project='all')
for i, stat in stationlist.iterrows():
    if (stat.theme in ['AS','ATMO']): 
        print(stat.name,stat.id,stat.uri,stat[2])
claudiodonofrio commented 2 years ago

This is unfortunate but not really a bug. By default each row in a pandas dataframe has a 'name' which is the index. Hence accessing row.name returns the index and in this case not the value from the column 'name'. To mitigate this one has several options:

from icoscp.station import station
stationlist=station.getIdList(project='all')
for i, stat in stationlist.iterrows():
    if (stat.theme in ['AS','ATMO']): 
    print(stat.to_list())
atverm commented 2 years ago

Then in the pylib the property station.name should be renamed to station.stationName otherwise it will never work as documented:

@.***

Alex

From: claudiodonofrio @.> Sent: Friday, 19 August 2022 09:39 To: ICOS-Carbon-Portal/pylib @.> Cc: Alex Vermeulen @.>; Author @.> Subject: Re: [ICOS-Carbon-Portal/pylib] station.name property returns some index number, not the string containing the station name (Issue #96)

This is unfortunate but not really a bug. By default each row in a pandas dataframe has a 'name' which is the index. Hence accessing row.name returns the index and in this case not the value from the column 'name'. To mitigate this one has several options:

from icoscp.station import station

stationlist=station.getIdList(project='all')

for i, stat in stationlist.iterrows():

if (stat.theme in ['AS','ATMO']):

print(stat.to_list())

from icoscp.station import station

stationlist=station.getIdList(project='all')

stationlist.set_index('name', inplace=True, drop = False)

for i, stat in stationlist.iterrows():

if (stat.theme in ['AS','ATMO']):

    print(stat.name,stat.id,stat.uri,stat[2])

from icoscp.station import station

stationlist=station.getIdList(project='all')

stationlist.rename(columns={'name':'station_name'}, inplace=True)

for i, stat in stationlist.iterrows():

if (stat.theme in ['AS','ATMO']):

    print(stat.station_name,stat.id,stat.uri,stat[2])

— Reply to this email directly, view it on GitHubhttps://github.com/ICOS-Carbon-Portal/pylib/issues/96#issuecomment-1220352696, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACSQC3GIPSDYXCN6NSQJEO3VZ42XPANCNFSM56476ETQ. You are receiving this because you authored the thread.Message ID: @.**@.>>

claudiodonofrio commented 2 years ago

This is not entirely right, it is important to make a distinction between a station object, and list of station id's. The function used in the issue reported is station.getIdList() which is a helper function to return a pandas data frame with station ID's. From this data frame one can create 'station' objects, representing a station, where the property is valid and works as expected. station

Nevertheless, I will add a task to rename the column in the stationIdList() for the next Release.

altix commented 1 year ago

Instead of changing the column name, which would affect several notebooks, we will list some workarounds in the pylib-docs, and in the station-module.