Skip to content

Commit

Permalink
turn comments into doctests
Browse files Browse the repository at this point in the history
Many of the station_query() examples will test the same thing, so until someone
provides better testcases, I've turned them into pure comments.
  • Loading branch information
andreby committed Apr 10, 2024
1 parent c8260cd commit 6c6ea9a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 39 deletions.
32 changes: 17 additions & 15 deletions src/icoscp/sparql/sparqls.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,26 +322,28 @@ def station_query(filter: dict = None, return_filter: bool = False) -> str or (s
Example
-------
>>># The default call, will return all known stations
>>>station_query()
# The default call, will return all known stations
>>> station_query()
'...prefix cpmeta: <http://meta.icos-cp.eu/ontologies/cpmeta/>...'
>>># For ICOS stations use:
>>>station_query({'project': 'ICOS'})
# For ICOS stations use:
>>> station_query({'project': 'ICOS'})
'...'
>>># To fetch all atmospheric and ecosystem stations of ICOS, use
>>>station_query({ 'theme': ['AS','ES'], 'project': 'ICOS'})
# To fetch all atmospheric and ecosystem stations of ICOS, use
# station_query({ 'theme': ['AS','ES'], 'project': 'ICOS'})
>>># To fetch the atmospheric ICOS stations: 'BIR', 'HTM' and 'KIT', use
>>>station_query({ 'station': ['BIR', 'HTM', 'KIT'], 'project': 'ICOS'})
# To fetch the atmospheric ICOS stations: 'BIR', 'HTM' and 'KIT', use
# station_query({ 'station': ['BIR', 'HTM', 'KIT'], 'project': 'ICOS'})
>>># To fetch all atmospheric ICOS stations in Norway and Sweden, use
>>>station_query({ 'theme': 'AS', 'country': ['NO','SE'], 'project': 'ICOS'})
# To fetch all atmospheric ICOS stations in Norway and Sweden, use
# station_query({ 'theme': 'AS', 'country': ['NO','SE'], 'project': 'ICOS'})
>>># To fetch all ICOS and non-ICOS stations in Germany use
>>>station_query({ 'country': ['DE'], 'project': 'all'})
# To fetch all ICOS and non-ICOS stations in Germany use
# station_query({ 'country': ['DE'], 'project': 'all'})
>>># To reuse a filter we can use the return_filter option
>>>station_query(some_filter, return_filter = True)
# To reuse a filter we can use the return_filter option
# station_query(some_filter, return_filter = True)
"""

# Depending on the filter we will change the
Expand Down Expand Up @@ -1217,4 +1219,4 @@ def dobj_for_samplingheight(station, height):
}
order by desc(?submTime) """ % (station, height)

return query
return query
41 changes: 20 additions & 21 deletions src/icoscp/station/station.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,8 +536,7 @@ def get(stationId: str = None,
Example
-------
# Get the station object for the ICOS station Norunda
>>>st_nor = get('NOR')
>>>print(st_nor)
>>> st_nor = get('NOR')
{
"stationId": "NOR",
"name": "Norunda",
Expand Down Expand Up @@ -695,21 +694,21 @@ def _get_id_list(filter: dict = {'project': 'ICOS', 'theme': ['AS', 'ES', 'OS']}
Examples
--------
>>> # Get a folium map of all ICOS stations
>>>station_map = _get_id_list(outfmt='map')
# Get a folium map of all ICOS stations
>>> station_map = _get_id_list(outfmt='map')
>>> # Load a dataframe with the atmospheric ICOS stations:
>>> # 'BIR', 'HTM' and 'KIT':
>>>my_df = _get_id_list(filter={'station': ['BIR', 'HTM', 'KIT']})
# Load a dataframe with the atmospheric ICOS stations:
# 'BIR', 'HTM' and 'KIT':
>>> my_df = _get_id_list(filter={'station': ['BIR', 'HTM', 'KIT']})
>>> # To fetch all ecosystem ICOS stations in Germany, use
>>>de_df = _get_id_list(filter={'theme': 'ES', 'country': 'DE'})
# To fetch all ecosystem ICOS stations in Germany, use
>>> de_df = _get_id_list(filter={'theme': 'ES', 'country': 'DE'})
>>> # Get a dataframe of all atmospheric and ocean ICOS stations
>>>as_os_df = _get_id_list(filter={'theme': ['AS', 'OS']})
# Get a dataframe of all atmospheric and ocean ICOS stations
>>> as_os_df = _get_id_list(filter={'theme': ['AS', 'OS']})
>>> # Get a dataframe of all ICOS and non-ICOS stations
>>>all_stations_df = _get_id_list({'project': 'ALL'})
# Get a dataframe of all ICOS and non-ICOS stations
>>> all_stations_df = _get_id_list({'project': 'ALL'})
"""

if isinstance(filter, dict) and 'project' not in filter.keys():
Expand Down Expand Up @@ -870,17 +869,17 @@ def _station_list(theme: str or list = ['AS', 'ES', 'OS'],
`icoscp.sparql.sparqls`.
Example:
>>> # Get the list of all ICOS station objects
>>>_station_list()
Get the list of all ICOS station objects
>>> _station_list()
>>> # Get the list of ICOS atmospheric stations objects
>>>_station_list('AS')
Get the list of ICOS atmospheric stations objects
>>> _station_list('AS')
>>> # Get a list for ICOS atmosphere and ocean stations
>>>_station_list(['AS','OS'])
Get a list for ICOS atmosphere and ocean stations
>>> _station_list(['AS','OS'])
>>> # get list of stations with ids (ids are case sensitive..)
>>>_station_list(ids=['HTM', 'LMP', 'SAC'])
Get list of stations with ids (ids are case sensitive..)
>>> _station_list(ids=['HTM', 'LMP', 'SAC'])
"""

# list of returned station objects
Expand Down
11 changes: 8 additions & 3 deletions src/icoscp/stilt/stiltstation.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,13 @@ def __get_stations(ids: list | None = None,
return stations


def parse_loc(loc: str) -> dict[str, Any]:
# This is what a loc looks like -> 47.42Nx010.98Ex00730
def parse_location(loc: str) -> dict[str, Any]:
"""Pares a stilt location name such as 47.42Nx010.98Ex00730
>>> parse_location("47.42Nx010.98Ex00730")
{}
"""
# This is what a loc looks like ->
lat, lon, alt = loc.split('x')
return {
'lat': -float(lat[:-1]) if lat[-1] == 'S' else float(lat[:-1]),
Expand All @@ -424,7 +429,7 @@ def get_stn_info(loc: str,
icos_stations: Any) -> dict:
"""Return stilt-station metadata."""

stn_info = parse_loc(loc)
stn_info = parse_location(loc)
stn_info['id'] = station_id
station_name = station_id
stn_info['icos'] = False
Expand Down

0 comments on commit 6c6ea9a

Please sign in to comment.