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
Ref/remote download #598
Ref/remote download #598
Conversation
@@ -256,7 +256,9 @@ def MeSigmaI(self): | |||
Inverse of the edge inner product matrix for \\(\\sigma\\). | |||
""" | |||
if getattr(self, '_MeSigmaI', None) is None: | |||
self._MeSigmaI = self.mesh.getEdgeInnerProduct(self.sigma, invMat=True) | |||
self._MeSigmaI = self.mesh.getEdgeInnerProduct( |
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 just white-space
SimPEG/Utils/io_utils.py
Outdated
""" | ||
|
||
# Download from cloud | ||
import urllib | ||
import shutil | ||
import os | ||
import sys | ||
|
||
def rename_path(downloadpath): |
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.
if we start to make heavy use of this function, I can see a number of scenarios where we do not necessarily want to over-write the contents of SimPEGtemp
, so here it will add SimPEGtemp(1)
(or up the integer value until we hit a unique name, similar to what you would see with a web browser)
SimPEG/Utils/io_utils.py
Outdated
@@ -146,35 +147,72 @@ def surface2inds(vrtx, trgl, mesh, boundaries=True, internal=True): | |||
return insideGrid | |||
|
|||
|
|||
def remoteDownload(url, remoteFiles, basePath=None): | |||
def remoteDownload( | |||
url, remoteFiles, path='.', directory='SimPEGtemp', rm_previous=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.
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.
Minor suggestions to the api.
SimPEG/Utils/io_utils.py
Outdated
print("Download files from URL...") | ||
# ensure we are working with absolute paths | ||
path = os.path.abspath(path) | ||
downloadpath = os.path.sep.join([path]+[directory]) |
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.
[path, directory]
? Same difference.
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.
Yeah, this is likely confusing. path
is the path to your working directory, directory
is the name of the new folder we are adding where we download things.
Thoughts on alternatives?
'LdM_topo.topo', 'LdM_input_file.inp' | ||
] | ||
|
||
# Download to Downloads/SimPEGtemp |
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.
Here we are not specifying where things get put? I think they should just go directly into pwd
? Unless you specify a folder
or something?
Can we just rename this to download
? seems a bit redundant.
file_names = download([url1, url2], folder='~/Downloads/mag_stuff', overwrite=True)
# or
file_name = download(url1)
# where
assert isinstance(file_names, list)
assert len(file_names) == 2
assert isinstance(file_name, str)
I think that the default should the the pwd of where the python file is run from, appending a SimPEGtemp
seems odd to me. Downloads are downloads.
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 also would mean that you don't have to reconstruct the file name after the fact, you just loop through the list:
with open(file_name, 'r') as f:
f.read()
with open(file_names[0], 'r') as f2:
f2.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.
download
works for me. @fourndo ?- SimPEGtemp was mainly motivated because we make heavy use of this in examples, so for someone unfamiliar it is easy to find (we can still do this and specify it in the example script rather than the util). However, I agree that can be cleared up by specifying the folder (I am tempted to call it
path
ordirectory
instead as it is not just a name of a folder but does include path information)
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 that it could be both? You can call abspath
on the thing and it should expand it out regardless.
folder='here'
folder='or/here'
folder='/Users/rowan/downloads/or/even/here'
I see all of these as folders?
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.
ok, fair enough, folder can work
Does this work on windows as well?
|
This |
You can use |
I think most of this works - the main subtlety here is the behaviour of |
Yeah, I think that removing things should never happen. :) Only overwriting files, never folders. |
…tories, update examples and tests accordingly
Codecov Report
@@ Coverage Diff @@
## dev #598 +/- ##
==========================================
- Coverage 74.75% 74.66% -0.09%
==========================================
Files 106 106
Lines 13545 13572 +27
==========================================
+ Hits 10126 10134 +8
- Misses 3419 3438 +19
Continue to review full report at Codecov.
|
tests/base/test_utils.py
Outdated
# where | ||
assert isinstance(file_names, list) | ||
assert len(file_names) == 2 | ||
assert isinstance(file_name, str) |
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.
Ha, it's like I coded...
This looks great! thanks @lheagy :) |
modify the
remoteDownload
utils so that more of the string handling is done by the util as per #596Before
After
I have also updated the examples and tests that rely on this function