Skip to content

Commit 371908d

Browse files
authored
Merge pull request #50 from OceanNetworksCanada/update-new-method-names
Update new method names
2 parents 93e2dd1 + 3892049 commit 371908d

File tree

14 files changed

+102
-93
lines changed

14 files changed

+102
-93
lines changed

README.md

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
onc is a Python client library that facilitates access to scientific data hosted by [Ocean Networks Canada](https://oceannetworks.ca)
1313
through the [Oceans 3.0 API](https://data.oceannetworks.ca/OpenAPI) public web services.
1414
It can help you explore and download our data, by consuming our
15-
_[discovery](https://oceannetworkscanada.github.io/api-python-client/API_Guide.html#discovery-methods)_,
16-
_[data product download](https://oceannetworkscanada.github.io/api-python-client/API_Guide.html#data-product-download-methods)_,
17-
_[archive file download](https://oceannetworkscanada.github.io/api-python-client/API_Guide.html#archive-file-download-methods)_, and
18-
_[near real-time data access](https://oceannetworkscanada.github.io/api-python-client/API_Guide.html#near-real-time-data-access-methods)_ services.
15+
_[discovery](https://oceannetworkscanada.github.io/Oceans3.0-API/API_Guide.html#discovery-methods)_,
16+
_[data product download](https://oceannetworkscanada.github.io/Oceans3.0-API/API_Guide.html#data-product-download-methods)_,
17+
_[archive file download](https://oceannetworkscanada.github.io/Oceans3.0-API/API_Guide.html#archive-file-download-methods)_, and
18+
_[near real-time data access](https://oceannetworkscanada.github.io/Oceans3.0-API/API_Guide.html#near-real-time-data-access-methods)_ services.
1919

2020
# Getting Started
2121

@@ -59,7 +59,7 @@ The example below uses the `getLocations` method to search for locations that in
5959
```python
6060
from onc import ONC
6161

62-
onc = ONC("YOUR_TOKEN_HERE")
62+
onc = ONC("YOUR_TOKEN")
6363

6464
onc.getLocations({"locationName": "Burrard"})
6565
```
@@ -74,7 +74,7 @@ onc.getDeviceCategories({"locationCode": "BIIP"})
7474
onc.getDataProducts({"locationCode": "BIIP", "deviceCategoryCode": "CTD"})
7575
```
7676

77-
Check more on the _[discovery methods guide](https://oceannetworkscanada.github.io/api-python-client/API_Guide.html#discovery-methods)_
77+
Check more on the _[discovery methods guide](https://oceannetworkscanada.github.io/Oceans3.0-API/API_Guide.html#discovery-methods)_
7878
and _[code examples](https://oceannetworkscanada.github.io/api-python-client/Code_Examples/index.html)_.
7979

8080
## Downloading data products
@@ -107,7 +107,7 @@ They also include a couple of filters to configure this specific data product ty
107107
which can be obtained from the [Data Product Options](https://wiki.oceannetworks.ca/display/DP/Data+Product+Options) documentation.
108108
You can download more than 120 different [types of data products](https://wiki.oceannetworks.ca/display/O2A/Available+Data+Products) including audio & video.
109109

110-
Check more on the _[data product download methods guide](https://oceannetworkscanada.github.io/api-python-client/API_Guide.html#data-product-download-methods)_
110+
Check more on the _[data product download methods guide](https://oceannetworkscanada.github.io/Oceans3.0-API/API_Guide.html#data-product-download-methods)_
111111
and _[code examples](https://oceannetworkscanada.github.io/api-python-client/Code_Examples/Download_Data_Products.html)_.
112112

113113
## Obtaining sensor readings in (near) real-time
@@ -125,13 +125,16 @@ params = {
125125
"dateFrom": "2019-06-20T00:00:00.000Z",
126126
"dateTo": "2019-06-20T00:00:05.000Z",
127127
}
128-
onc.getDirectByLocation(params)
128+
onc.getScalardata(params)
129+
130+
# Longer method name
131+
# onc.getScalardataByLocation(params)
129132
```
130133

131134
The result includes matching lists of "values" and "sampleTimes" (increases performance for long time ranges).
132135
We also use the property code "conductivity" to limit results to a specific property available in this CTD.
133136

134-
Check more on the _[near real-time data access methods guide](https://oceannetworkscanada.github.io/api-python-client/API_Guide.html#near-real-time-data-access-methods)_
137+
Check more on the _[near real-time data access methods guide](https://oceannetworkscanada.github.io/Oceans3.0-API/API_Guide.html#near-real-time-data-access-methods)_
135138
and _[code examples](https://oceannetworkscanada.github.io/api-python-client/Code_Examples/Request_Real_Time_Data.html)_.
136139

137140
## Downloading archived files
@@ -149,16 +152,19 @@ params = {
149152
"dateFrom": "2016-12-01T00:00:00.000Z",
150153
"dateTo": "2016-12-01T00:05:00.000Z",
151154
}
152-
result = onc.getListByLocation(params, allPages=True)
155+
result = onc.getArchivefile(params, allPages=True)
156+
157+
# Longer method name
158+
# result = onc.getArchivefileByLocation(params, allPages=True)
153159

154-
# download one of the files from result["files"]
155-
onc.getFile("AXISQ6044PTZACCC8E334C53_20161201T000001.000Z.jpg")
160+
# Download one of the files from result["files"]
161+
onc.downloadArchivefile("AXISQ6044PTZACCC8E334C53_20161201T000001.000Z.jpg", overwrite=True)
156162
```
157163

158-
You can use the method `getFile()` as above to download individual files or the method `getDirectFiles()`
164+
You can use the method `downloadArchivefile()` as above to download individual files or the method `downloadDirectArchivefile()`
159165
to download all the files that match your filters.
160166

161-
Check more on the _[archive file download methods guide](https://oceannetworkscanada.github.io/api-python-client/API_Guide.html#archive-file-download-methods)_
167+
Check more on the _[archive file download methods guide](https://oceannetworkscanada.github.io/Oceans3.0-API/API_Guide.html#archive-file-download-methods)_
162168
and _[code examples](https://oceannetworkscanada.github.io/api-python-client/Code_Examples/Download_Archived_Files.html)_.
163169

164170
# Documentation

doc/source/Tutorial/onc_Library_Tutorial.ipynb

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@
391391
"source": [
392392
"### 2.1 Near real-time scalar data download\n",
393393
"\n",
394-
"In this example we want to download one minute of **Pressure** sensor data from a **CTD** at location \"Bullseye\" (locationCode: **NC89**)\n"
394+
"In this example we want to download 10 seconds of **Pressure** sensor data from a **CTD** at location \"Bullseye\" (locationCode: **NC89**)\n"
395395
]
396396
},
397397
{
@@ -417,7 +417,7 @@
417417
"}\n",
418418
"\n",
419419
"# 2. Call methods in the onc library\n",
420-
"r = onc.getDirectByLocation(params)\n",
420+
"r = onc.getScalardata(params) # getScalardataByLocation(params) also works\n",
421421
"\n",
422422
"# 3. Return the dictionary keys (fields) of the query to get a sense what is contained in your returned message\n",
423423
"print(r.keys())\n",
@@ -470,7 +470,7 @@
470470
"source": [
471471
"### 2.2 Near real-time raw data readings\n",
472472
"\n",
473-
"In this example we want to download one minute of raw data from a **CTD** at location \"Bullseye\" (locationCode: **NC89**)\n"
473+
"In this example we want to download 10 seconds of raw data from a **CTD** at location \"Bullseye\" (locationCode: **NC89**)\n"
474474
]
475475
},
476476
{
@@ -495,7 +495,7 @@
495495
"}\n",
496496
"\n",
497497
"# 2. Call methods in the onc library\n",
498-
"r = onc.getDirectRawByLocation(params)\n",
498+
"r = onc.getRawdata(params) # getRawdataByLocation(params) also works\n",
499499
"\n",
500500
"# 3. Return the dictionary keys (fields) of the query to get a sense what is contained in your returned message\n",
501501
"print(r.keys())\n",
@@ -549,7 +549,7 @@
549549
"\n",
550550
"1. If you use **onc**.\n",
551551
"\n",
552-
"`getDirectRawByLocation` supports a boolean `allPages` parameter. When set to `True`, it will try to retrieve all the pages.\n",
552+
"`getRawdata` supports a boolean `allPages` parameter. When set to `True`, it will try to retrieve all the pages.\n",
553553
"\n",
554554
"2. If you use **requests**.\n",
555555
"\n",
@@ -570,7 +570,7 @@
570570
"metadata": {},
571571
"outputs": [],
572572
"source": [
573-
"# 1. Define your filter parameter with a longer date range (2 days of data)\n",
573+
"# 1. Define your filter parameter with a longer date range (1 day of data)\n",
574574
"params_longer_range = {\n",
575575
" \"locationCode\": \"NC89\",\n",
576576
" \"deviceCategoryCode\": \"CTD\",\n",
@@ -579,7 +579,9 @@
579579
"}\n",
580580
"\n",
581581
"# 2. Call methods in the onc library\n",
582-
"r = onc.getDirectRawByLocation(params_longer_range, allPages=True)\n",
582+
"r = onc.getRawdata(\n",
583+
" params_longer_range, allPages=True\n",
584+
") # getRawdataByLocation(params_longer_range, allPages=True) also works\n",
583585
"\n",
584586
"# 3. Read it into a DataFrame\n",
585587
"pd.DataFrame(r[\"data\"])"
@@ -704,7 +706,7 @@
704706
"}\n",
705707
"\n",
706708
"# 2. Call methods in the onc library\n",
707-
"r = onc.getListByLocation(params)\n",
709+
"r = onc.getArchivefile(params) # getArchivefileByLocation(params) also works\n",
708710
"\n",
709711
"# 3. This is the list of archived files:\n",
710712
"r[\"files\"]"
@@ -754,7 +756,7 @@
754756
}
755757
},
756758
"source": [
757-
"Once we have the file names, you can use the method **\"getFile()\"** to download individual files:\n"
759+
"Once we have the file names, you can use the method **\"downloadArchivefile()\"** to download individual files:\n"
758760
]
759761
},
760762
{
@@ -770,8 +772,11 @@
770772
"metadata": {},
771773
"outputs": [],
772774
"source": [
773-
"# 1. Call methods in the onc library with the filename. The file is downloaded in the output folder.\n",
774-
"onc.getFile(\"AXISQ6044PTZACCC8E334C53_20161201T000001.000Z.jpg\", overwrite=True)"
775+
"# 1. Call methods in the onc library with the filename. The file is downloaded in the output folder by default,\n",
776+
"# which can be customized in the outPath parameter of the ONC class.\n",
777+
"onc.downloadArchivefile(\n",
778+
" \"AXISQ6044PTZACCC8E334C53_20161201T000001.000Z.jpg\", overwrite=True\n",
779+
")"
775780
]
776781
},
777782
{
@@ -985,7 +990,7 @@
985990
],
986991
"metadata": {
987992
"kernelspec": {
988-
"display_name": "Python 3 (ipykernel)",
993+
"display_name": ".venv",
989994
"language": "python",
990995
"name": "python3"
991996
},

src/onc/modules/_OncArchive.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ def getArchivefileByLocation(self, filters: dict, allPages: bool):
2121
"""
2222
Return a list of archived files for a device category in a location.
2323
24-
The filenames obtained can be used to download files using the getFile() method.
25-
"""
24+
The filenames obtained can be used to download files using the ``downloadArchivefile`` method.
25+
""" # noqa: E501
2626
return self._getList(filters, by="location", allPages=allPages)
2727

2828
def getArchivefileByDevice(self, filters: dict, allPages: bool):
2929
"""
3030
Return a list of archived files from a specific device.
3131
32-
The filenames obtained can be used to download files using the getFile() method.
33-
"""
32+
The filenames obtained can be used to download files using the ``downloadArchivefile`` method.
33+
""" # noqa: E501
3434
return self._getList(filters, by="device", allPages=allPages)
3535

3636
def getArchivefile(self, filters: dict, allPages: bool):
@@ -84,8 +84,8 @@ def downloadDirectArchivefile(
8484
"""
8585
Download a list of archived files that match the filters provided.
8686
87-
This function invokes the method getListByLocation() or getListByDevice()
88-
to obtain a list of files, and the method getFile() to download all files found.
87+
This function invokes the method ``getArchivefile`` to obtain a list of files,
88+
and the method ``downloadArchivefile`` to download all files found.
8989
9090
See https://wiki.oceannetworks.ca/display/O2A/archivefiles
9191
for usage and available filters.
@@ -150,7 +150,7 @@ def _getDownloadUrl(self, filename: str):
150150

151151
def _getList(self, filters: dict, by: str = "location", allPages: bool = False):
152152
"""
153-
Wraps archivefiles getListByLocation and getListByDevice methods
153+
Wraps archivefiles getArchivefileByLocation and getArchivefileByDevice methods
154154
"""
155155
url = self._serviceUrl("archivefiles")
156156
filters["token"] = self._config("token")

tests/archive_file/test_archivefile_device.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,31 @@ def params_multiple_pages(params):
2323
def test_invalid_param_value(requester, params):
2424
params_invalid_param_value = params | {"deviceCode": "XYZ123"}
2525
with pytest.raises(requests.HTTPError, match=r"API Error 127"):
26-
requester.getListByDevice(params_invalid_param_value)
26+
requester.getArchivefile(params_invalid_param_value)
2727

2828

2929
def test_invalid_params_missing_required(requester, params):
3030
del params["deviceCode"]
31-
with pytest.raises(requests.HTTPError, match=r"API Error 128"):
32-
requester.getListByDevice(params)
31+
with pytest.raises(ValueError):
32+
requester.getArchivefile(params)
3333

3434

3535
def test_invalid_param_name(requester, params):
3636
params_invalid_param_name = params | {"deviceCodes": "BPR-Folger-59"}
3737
with pytest.raises(requests.HTTPError, match=r"API Error 129"):
38-
requester.getListByDevice(params_invalid_param_name)
38+
requester.getArchivefile(params_invalid_param_name)
3939

4040

4141
def test_no_data(requester, params):
4242
params_no_data = params | {"dateFrom": "2000-01-01", "dateTo": "2000-01-02"}
43-
data = requester.getListByDevice(params_no_data)
43+
data = requester.getArchivefile(params_no_data)
4444

4545
assert len(data["files"]) == 0
4646

4747

4848
def test_valid_params_one_page(requester, params, params_multiple_pages):
49-
data = requester.getListByDevice(params)
50-
data_all_pages = requester.getListByDevice(params_multiple_pages, allPages=True)
49+
data = requester.getArchivefile(params)
50+
data_all_pages = requester.getArchivefile(params_multiple_pages, allPages=True)
5151

5252
assert (
5353
len(data["files"]) > params_multiple_pages["rowLimit"]
@@ -63,7 +63,7 @@ def test_valid_params_one_page(requester, params, params_multiple_pages):
6363

6464

6565
def test_valid_params_multiple_pages(requester, params_multiple_pages):
66-
data = requester.getListByDevice(params_multiple_pages)
66+
data = requester.getArchivefile(params_multiple_pages)
6767

6868
assert (
6969
len(data["files"]) == params_multiple_pages["rowLimit"]

tests/archive_file/test_archivefile_direct_download.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
def test_valid_params_one_page(requester, params_location, util):
2-
data = requester.getListByLocation(params_location)
3-
result = requester.getDirectFiles(params_location)
2+
data = requester.getArchivefile(params_location)
3+
result = requester.downloadDirectArchivefile(params_location)
44

55
assert util.get_download_files_num(requester) == len(data["files"])
66

77
assert result["stats"]["fileCount"] == len(data["files"])
88

99

1010
def test_valid_params_multiple_pages(requester, params_location_multiple_pages, util):
11-
result = requester.getDirectFiles(params_location_multiple_pages)
11+
result = requester.downloadDirectArchivefile(params_location_multiple_pages)
1212

1313
assert (
1414
util.get_download_files_num(requester)

tests/archive_file/test_archivefile_download.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@
44

55
def test_invalid_param_value(requester):
66
with pytest.raises(requests.HTTPError, match=r"API Error 96"):
7-
requester.getFile("FAKEFILE.XYZ")
7+
requester.downloadArchivefile("FAKEFILE.XYZ")
88

99

1010
def test_invalid_params_missing_required(requester):
1111
with pytest.raises(requests.HTTPError, match=r"API Error 128"):
12-
requester.getFile()
12+
requester.downloadArchivefile()
1313

1414

1515
def test_valid_params(requester, util):
1616
filename = "BPR-Folger-59_20191123T000000.000Z.txt"
1717

18-
requester.getFile(filename)
18+
requester.downloadArchivefile(filename)
1919

2020
assert (requester.outPath / filename).exists()
2121

2222
with pytest.raises(FileExistsError):
23-
requester.getFile(filename)
23+
requester.downloadArchivefile(filename)
2424

25-
requester.getFile(filename, overwrite=True)
25+
requester.downloadArchivefile(filename, overwrite=True)
2626

2727
assert util.get_download_files_num(requester) == 1

tests/archive_file/test_archivefile_location.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@
55
def test_invalid_param_value(requester, params_location):
66
params_invalid_param_value = params_location | {"locationCode": "XYZ123"}
77
with pytest.raises(requests.HTTPError, match=r"API Error 127"):
8-
requester.getListByLocation(params_invalid_param_value)
8+
requester.getArchivefile(params_invalid_param_value)
99

1010

1111
def test_invalid_params_missing_required(requester, params_location):
1212
del params_location["locationCode"]
13-
with pytest.raises(requests.HTTPError, match=r"API Error 128"):
14-
requester.getListByLocation(params_location)
13+
with pytest.raises(ValueError):
14+
requester.getArchivefile(params_location)
1515

1616

1717
def test_invalid_param_name(requester, params_location):
1818
params_invalid_param_name = params_location | {"locationCodes": "NCBC"}
1919
with pytest.raises(requests.HTTPError, match=r"API Error 129"):
20-
requester.getListByLocation(params_invalid_param_name)
20+
requester.getArchivefile(params_invalid_param_name)
2121

2222

2323
def test_no_data(requester, params_location):
@@ -26,14 +26,14 @@ def test_no_data(requester, params_location):
2626
"dateTo": "2000-01-02",
2727
}
2828
with pytest.raises(requests.HTTPError, match=r"API Error 127"):
29-
requester.getListByLocation(params_no_data)
29+
requester.getArchivefile(params_no_data)
3030

3131

3232
def test_valid_params_one_page(
3333
requester, params_location, params_location_multiple_pages
3434
):
35-
data = requester.getListByLocation(params_location)
36-
data_all_pages = requester.getListByLocation(
35+
data = requester.getArchivefile(params_location)
36+
data_all_pages = requester.getArchivefile(
3737
params_location_multiple_pages, allPages=True
3838
)
3939

@@ -51,7 +51,7 @@ def test_valid_params_one_page(
5151

5252

5353
def test_valid_params_multiple_pages(requester, params_location_multiple_pages):
54-
data = requester.getListByLocation(params_location_multiple_pages)
54+
data = requester.getArchivefile(params_location_multiple_pages)
5555

5656
assert (
5757
len(data["files"]) == params_location_multiple_pages["rowLimit"]

0 commit comments

Comments
 (0)