-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I26 use urls #27
I26 use urls #27
Conversation
@jameshiebert I should mention that some of the |
@@ -73,7 +73,7 @@ SEARCH_FOR_CHANNEL: False | |||
#-- Path to Pour Points File (char) --# | |||
# A comma separated file of outlets to route to [lons, lats] - one coordinate pair per line (order not important) | |||
# May optionally include a column [names] - which will (if not aggregating) be included in param file | |||
FILE_NAME: https://docker-dev03.pcic.uvic.ca/twitcher/ows/proxy/thredds/dodsC/datasets/RVIC/sample_pour.txt | |||
FILE_NAME: https://docker-dev03.pcic.uvic.ca/twitcher/ows/proxy/thredds/fileServer/datasets/RVIC/sample_pour.txt | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the ideal use of pour
input is to get user inputs (lon and lat) and create a pour.txt
file in the tmp
directory. It is a variable that needs to be dynamically defined by users. @jameshiebert @corviday , do you think this is the right approach? I guess we don't have to worry about that in this PR. I will write an issue if it is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pytest is not passing for me. The error message is attached to one of the comments.
While it is good to download files from https
, there is a method you can use opendap
as I did in a thunderbird PR. xarray
library enables to copy netcdf
contents retrieved from oepdap
URL. You can create a copy of the files with the contents in the tmp
directory. I think it is worth to consider this method since I implemented thunderbird/wps_update_metadata
this way.
@@ -73,7 +73,7 @@ SEARCH_FOR_CHANNEL: False | |||
#-- Path to Pour Points File (char) --# |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to use this file in the jupyter lab demo as well
tests/test_wps_parameters.py
Outdated
@pytest.mark.parametrize( | ||
("config"), [resource_filename(__name__, "configs/parameter_https.cfg")], | ||
) | ||
def test_parameters_https(config, make_mock_urls): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is failing with the following error message:
Traceback (most recent call last):
File "/home/sangwonl/Desktop/osprey/venv/lib/python3.6/site-packages/pywps/app/Process.py", line 249, in _run_process
self.handler(wps_request, wps_response) # the user must update the wps_response.
File "/home/sangwonl/Desktop/osprey/osprey/processes/wps_parameters.py", line 119, in _handler
parameters(config, np)
File "/home/sangwonl/Desktop/osprey/venv/lib/python3.6/site-packages/rvic/parameters.py", line 51, in parameters
outlets, config_dict, directories = gen_uh_init(config_file)
File "/home/sangwonl/Desktop/osprey/venv/lib/python3.6/site-packages/rvic/parameters.py", line 161, in gen_uh_init
config_dict = copy_inputs(config_file, directories['inputs'])
File "/home/sangwonl/Desktop/osprey/venv/lib/python3.6/site-packages/rvic/core/utilities.py", line 243, in copy_inputs
copyfile(section['FILE_NAME'], new_file_name)
File "/usr/lib/python3.6/shutil.py", line 120, in copyfile
with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pywps_process_36j0za4t/sample_pour2b3izq8y.txt'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does each FILE_PATH
in your parameter_https.cfg
file look like? I just realized that running the notebook as is permanently changes it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, the demo doesn't use that .cfg
file, so it won't be modified. I'll look into it more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you try replacing self.workdir in this line with a different directory, and after the for loop in replace_urls, print filedata? I just want to see if the contents of the config file are being modified correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does each FILE_PATH in your parameter_https.cfg file look like? I just realized that running the notebook as is permanently changes it.
I think you are right here. I did git stash
and ran pytest again, and it passed.
Actually, the demo doesn't use that .cfg file, so it won't be modified. I'll look into it more.
Last time I ran the demo first by changing the input to the parameter_https.cfg
, so that caused the issue you said.
Could you fix this in RVIC and open a PR against RVIC as requested by Joe Hamman for your second testing note? Testing should be automated; it's not feasible/scalable to have to make manual changes to an installed virtual environment. We need to fix the root of this problem. And if its as simple as you note, it should be a no brainer. |
@jameshiebert I already made a PR in RVIC repo and emailed Joe Hamman, but still waiting for the reply. |
Unfortunately, we haven't had luck with getting those issues fixed in RVIC. The first issue has been fixed in RVIC 1.1.1, but for some reason, that version isn't installable as a python package (the only one available is v1.1.0.post1). @sum1lim opened a PR for the other issue a month ago and I believe emailed one of the devs about it, but neither of those have gotten responses. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall I think this is a nice solution to the issue, good work! That being said I am getting failures on my pytest
runs locally. I have followed the instructions in the README
but still get issues. Does it work locally for you? Are there any changes I need to make that aren't in the README
?
osprey/cli.py
Outdated
@@ -152,7 +152,7 @@ def stop(): | |||
@click.option( | |||
"--parallelprocesses", | |||
metavar="INT", | |||
default="2", | |||
default="20", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert this change
osprey/utils.py
Outdated
read_config = open(config, "r") | ||
filedata = read_config.readlines() | ||
read_config.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could use a context manager here.
for i in range(len(filedata)): | ||
if "https" in filedata[i]: | ||
url = filedata[i].split(" ")[-1] # https url is last word in line | ||
url = url.rstrip() # remove \n character at end | ||
r = requests.get(url) | ||
filename = url.split("/")[-1] | ||
prefix, suffix = filename.split(".") | ||
suffix = "." + suffix | ||
local_file = NamedTemporaryFile( | ||
suffix=suffix, prefix=prefix, dir=outdir, delete=False | ||
) | ||
local_file.write(r.content) | ||
filedata[i] = filedata[i].replace(url, local_file.name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this is fine, we generally don't want to use indices if we can help it. It is more understandable to iterate through the iterable object : for data in filedata:...
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used the index because I wasn't sure if the assignment in line 63 would modify the filedata
list if I iterated through each element.
local_file = NamedTemporaryFile( | ||
suffix=suffix, prefix=prefix, dir=outdir, delete=False | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great use of tempfile here 👍
osprey/utils.py
Outdated
write_config = open(config, "w") | ||
for line in filedata: | ||
write_config.write(f"{line}") | ||
write_config.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, we can use a context manager.
@@ -2,6 +2,6 @@ pywps>=4.2 | |||
jinja2 | |||
click | |||
psutil | |||
rvic==1.1.0post1 | |||
rvic==1.1.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -1,6 +1,7 @@ | |||
pytest | |||
flake8 | |||
pytest-flake8 | |||
requests-mock |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't know this package existed. I wonder if we can apply to our notebooks to make truly offline tests.
@@ -73,7 +73,7 @@ SEARCH_FOR_CHANNEL: False | |||
#-- Path to Pour Points File (char) --# | |||
# A comma separated file of outlets to route to [lons, lats] - one coordinate pair per line (order not important) | |||
# May optionally include a column [names] - which will (if not aggregating) be included in param file | |||
FILE_NAME: https://docker-dev03.pcic.uvic.ca/twitcher/ows/proxy/thredds/dodsC/datasets/RVIC/sample_pour.txt | |||
FILE_NAME: https://docker-dev03.pcic.uvic.ca/twitcher/ows/proxy/thredds/fileServer/datasets/RVIC/sample_pour.txt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of this change from dodsC
to fileServer
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is so that https
instead of OpenDAP
is used to download the file from THREDDS. James told me that it makes downloading entire files easier since I won't have to specify attributes or time ranges.
import pytest | ||
from osprey.testing import make_mock_urls | ||
|
||
|
||
@pytest.fixture | ||
def conftest_make_mock_urls(config, requests_mock): | ||
return make_mock_urls(config, requests_mock) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice fixture!
read_config = open(config, "r") | ||
temp_config.writelines(read_config.read()) | ||
temp_config.read() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason we aren't just directly reading into the temp_config
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you mean here.
What do the |
|
And in |
And here are the failures I got:
|
Oh, convolution is @sum1lim's process. I didn't modify anything involved with it in the PR, so the issues might be happening elsewhere. |
@nikola-rados if only |
OK, I know the problem. @eyvorchuk, could you change this line to following?
I actually encountered this problem after RVIC 1.1.1 is used. |
Works now. |
This PR resolves issue 26, which is to allow the config file for
wps_parameters.py
to haveFILE_PATH
s pointing to data files on THREDDS. For each URL, the data was copied to a temporary file in the working directory of the process, and the URL in the config file was replaced with the corresponding local file path. This functionality was tested by mocking the URLs prior to running the process to avoid requesting data that may not exist on THREDDS.