Skip to content

Commit

Permalink
filter-collections, docs and version 0.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
heikoklein committed Jan 8, 2024
1 parent 083c384 commit 608d778
Show file tree
Hide file tree
Showing 9 changed files with 391 additions and 40 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ print(pyaro.timeseries.filters.list)

with engines['csv_timeseries'].open(
filename=TEST_FILE,
filters=[pyaro.timeseries.filters.get('countries', include=['NO'])]
filters={'countries': {include=['NO']}}
) as ts:
for var in ts.variables():
# stations
Expand Down
58 changes: 40 additions & 18 deletions docs/tutorials/basic_api.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
"source": [
"# Pyaro basic example\n",
"\n",
"Install pyaro and check if installation is new enough:"
"* Install pyaro and check if installation is new enough:"
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 18,
"metadata": {},
"outputs": [
{
Expand All @@ -20,7 +20,7 @@
"'0.0.5'"
]
},
"execution_count": 2,
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -34,13 +34,13 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Check a list of installed engines. The most basic installation will install only the `csv_timeseries` engine.\n",
"* Check a list of installed engines. The most basic installation will install only the `csv_timeseries` engine.\n",
"Install e.g. `https://github.com/metno/pyaro-readers` for many more engines."
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 19,
"metadata": {},
"outputs": [
{
Expand All @@ -49,7 +49,7 @@
"{'csv_timeseries': <pyaro.csvreader.CSVTimeseriesReader.CSVTimeseriesEngine at 0x7ff77705f250>}"
]
},
"execution_count": 3,
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -62,12 +62,12 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Learn a bit about the engine."
"* Learn a bit about the engine."
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 20,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -144,12 +144,12 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Check the description and the open-arguments to open a database with this engine:"
"* Check the description and the open-arguments to open a database with this engine:"
]
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 21,
"metadata": {},
"outputs": [
{
Expand All @@ -170,6 +170,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Opening a datasource with an engine\n",
"\n",
"Open now the timeseries `ts` with a table. You could do that with a `with` clause in larger code, \n",
"but for simplicity, we don't do that here. `columns` map the files columns to the data, starting\n",
"with first column as 0, which contains the variable-name in our example file.\n",
Expand All @@ -180,7 +182,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -212,20 +214,22 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"`ts` is now the handle to all data."
"`ts` is now the handle to the data-source.\n",
"\n",
"* Accessing metadata in the datasource, like available variables and stations"
]
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 23,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"dict_keys(['SOx', 'NOx'])\n",
"{'station1': <pyaro.timeseries.Station.Station object at 0x7ff776c60d30>, 'station2': <pyaro.timeseries.Station.Station object at 0x7ff776c60790>}\n"
"{'station1': <pyaro.timeseries.Station.Station object at 0x7ff776cc9d20>, 'station2': <pyaro.timeseries.Station.Station object at 0x7ff776cca6e0>}\n"
]
}
],
Expand All @@ -234,11 +238,26 @@
"print(ts.stations())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* The timeseries must be accessed per variable. It will be returned for all\n",
"stations. The data-columns can be accessed by `keys()`:"
]
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 24,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('values', 'stations', 'latitudes', 'longitudes', 'altitudes', 'start_times', 'end_times', 'flags', 'standard_deviations')\n"
]
},
{
"data": {
"text/plain": [
Expand All @@ -265,14 +284,15 @@
" 93.348305 , 97.57919 , 19.217777 , 11.676097 ], dtype=float32)"
]
},
"execution_count": 15,
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"var = 'SOx'\n",
"ts_data = ts.data(var)\n",
"print(ts_data.keys())\n",
"ts_data.stations\n",
"ts_data.start_times\n",
"ts_data.end_times\n",
Expand All @@ -287,12 +307,14 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Conversion to pandas\n",
"\n",
"For pandas users, the timeseries data can be converted to a dataframe:"
]
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 25,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -495,7 +517,7 @@
"[104 rows x 9 columns]"
]
},
"execution_count": 16,
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
Expand Down
Loading

0 comments on commit 608d778

Please sign in to comment.