Skip to content
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

Merged
merged 7 commits into from May 5, 2017
Merged

Ref/remote download #598

merged 7 commits into from May 5, 2017

Conversation

lheagy
Copy link
Member

@lheagy lheagy commented May 4, 2017

modify the remoteDownload utils so that more of the string handling is done by the util as per #596

Before

basePath = os.path.sep.join(os.path.abspath(os.getenv('HOME')).split(os.path.sep)+['Downloads']+['SimPEGtemp'])
basePath = os.path.abspath(remoteDownload(url, cloudfiles, basePath=basePath+os.path.sep))

After

basePath = download(url, path='~/Downloads', overwrite=True)

I have also updated the examples and tests that rely on this function

@lheagy lheagy requested review from rowanc1 and fourndo May 4, 2017 06:06
@@ -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(
Copy link
Member Author

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

"""

# Download from cloud
import urllib
import shutil
import os
import sys

def rename_path(downloadpath):
Copy link
Member Author

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)

@@ -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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see what you think of these input names @fourndo, @rowanc1

Copy link
Member

@rowanc1 rowanc1 left a 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.

print("Download files from URL...")
# ensure we are working with absolute paths
path = os.path.abspath(path)
downloadpath = os.path.sep.join([path]+[directory])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[path, directory]? Same difference.

Copy link
Member Author

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
Copy link
Member

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.

Copy link
Member

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()

Copy link
Member Author

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 or directory instead as it is not just a name of a folder but does include path information)

Copy link
Member

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?

Copy link
Member Author

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

@rowanc1
Copy link
Member

rowanc1 commented May 4, 2017

Does this work on windows as well?

C:\Users\Myname\Downloads?

@lheagy
Copy link
Member Author

lheagy commented May 4, 2017

This ~ as a path does not work on windows, but os.getenv('HOME') seems to work for most systems.

@rowanc1
Copy link
Member

rowanc1 commented May 4, 2017

@lheagy
Copy link
Member Author

lheagy commented May 4, 2017

I think most of this works - the main subtlety here is the behaviour of overwrite. Previously it deleted the old directory and replaced it with a new one, now, we are not forcing the creation of a new directory, so I am hesitant to have overwrite remove the directory - it should only overwrite the files (otherwise I can just see someone trying and rapidly regretting download(url, '~', overwrite=True))

@rowanc1
Copy link
Member

rowanc1 commented May 4, 2017

Yeah, I think that removing things should never happen. :) Only overwriting files, never folders.

…tories, update examples and tests accordingly
@codecov-io
Copy link

codecov-io commented May 4, 2017

Codecov Report

Merging #598 into dev will decrease coverage by 0.08%.
The diff coverage is 54.54%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
SimPEG/EM/Base.py 80.23% <100%> (ø) ⬆️
SimPEG/PF/MagneticsDriver.py 77.83% <100%> (ø) ⬆️
SimPEG/Utils/__init__.py 100% <100%> (ø) ⬆️
SimPEG/Utils/io_utils.py 27.58% <48.71%> (-0.2%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1bdd221...2818916. Read the comment docs.

@lheagy
Copy link
Member Author

lheagy commented May 4, 2017

please take a look when you get a chance and let me know what you think. Thanks!

# where
assert isinstance(file_names, list)
assert len(file_names) == 2
assert isinstance(file_name, str)
Copy link
Member

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...

@rowanc1
Copy link
Member

rowanc1 commented May 4, 2017

This looks great! thanks @lheagy :)

@lheagy lheagy merged commit f7bf464 into dev May 5, 2017
@lheagy lheagy deleted the ref/remoteDownload branch May 5, 2017 22:41
@lheagy lheagy mentioned this pull request May 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants