Skip to content

Commit 3525be3

Browse files
authored
Fix #156 - Installation errors in windows (#157)
- Fix the permissions errors in datasets.download_pysteps_data and datasets.download_mrms_data functions (#156). - Update the installation instructions for Windows systems.
1 parent 9a9db53 commit 3525be3

File tree

2 files changed

+40
-36
lines changed

2 files changed

+40
-36
lines changed

doc/source/user_guide/set_pystepsrc.rst

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ following order:
4646
pystepsrc file inside that directory.
4747
- **$HOME/.pysteps/pystepsrc** (Unix and Mac OS X) : If the system variable $HOME is defined, it looks
4848
for the configuration file in this path.
49-
- **$USERPROFILE/pysteps/pystepsrc** (Windows only): It looks for the configuration file
50-
in the pysteps directory located user's home directory.
51-
- Lastly, it looks inside the library in *pysteps/pystepsrc* for a
49+
- **%USERPROFILE%\\pysteps\\pystepsrc** (Windows only): It looks for the configuration file
50+
in the pysteps directory located user's home directory (indicated by the %USERPROFILE%
51+
system variable).
52+
- Lastly, it looks inside the library in *pysteps\\pystepsrc* for a
5253
system-defined copy.
5354

5455
The recommended method to setup the configuration files is to edit a copy
@@ -73,15 +74,14 @@ need to create the directory if it does not exist. In a terminal, run::
7374

7475
$ mkdir -p ${HOME}/.pysteps
7576

76-
The next step is to find the location of the library's pystepsrc file being
77-
actually used.
77+
The next step is to find the location of the library's default pystepsrc file.
7878
When we import pysteps in a python interpreter, the configuration file loaded
7979
is shown::
8080

8181
import pysteps
8282
"Pysteps configuration file found at: /path/to/pysteps/library/pystepsrc"
8383

84-
Then we copy the library's default rc file to that directory::
84+
Then we copy the library's default configuration file to that directory::
8585

8686
$ cp /path/to/pysteps/library/pystepsrc ${HOME}/.pysteps/pystepsrc
8787

@@ -98,26 +98,36 @@ Windows
9898
~~~~~~~
9999

100100
For windows users, the recommended way to customize the pySTEPS
101-
configuration is placing the pystepsrc parameters file in the users folder
101+
configuration is placing the pystepsrc parameters file in the users' folder
102102
(defined in the %USERPROFILE% environment variable) in the following path:
103-
**%USERPROFILE%/pysteps/pystepsrc**
103+
**%USERPROFILE%\\pysteps\\pystepsrc**
104104

105-
To steps to setup up the configuration file in the home directory first we
106-
need to create the directory if it does not exist. In a terminal, run::
105+
To setup up the configuration file in the home directory first, we
106+
need to create the directory if it does not exist. In a **windows terminal**, run::
107+
108+
$ mkdir %USERPROFILE%\pysteps
109+
110+
**Important**
111+
112+
It was reported that the %USERPROFILE% variable may be interpreted as an string
113+
literal when the anaconda terminal is used.
114+
This will result in a '%USERPROFILE%' folder being created in the current working directory
115+
instead of the desired pysteps folder in the user's home.
116+
If that is the case, use the explicit path to your home folder instead of `%USERPROFILE%`.
117+
For example::
107118

108-
$ mkdir -p %USERPROFILE%\pysteps
119+
$ mkdir C:\Users\your_username\pysteps
109120

110-
The next step is to find the location of the library's pystepsrc file is
111-
actually used.
121+
The next step is to find the location of the library's default pystepsrc file.
112122
When we import pysteps in a python interpreter, the configuration file loaded
113123
is shown::
114124

115125
import pysteps
116126
"Pysteps configuration file found at: C:\path\to\pysteps\library\pystepsrc"
117127

118-
Then we copy the library's default rc file to that directory::
128+
Then we copy the library's default configuration file to that directory::
119129

120-
$ cp C:\path\to\pysteps\library\pystepsrc %USERPROFILE%\pysteps\pystepsrc
130+
$ copy C:\path\to\pysteps\library\pystepsrc %USERPROFILE%\pysteps\pystepsrc
121131

122132
Edit the file with the text editor of your preference and change the default
123133
configurations with your preferences.

pysteps/datasets.py

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ def delay(_counter):
258258
os.makedirs(sub_dir)
259259

260260
# Generate files URL from https://mtarchive.geol.iastate.edu
261-
262261
dest_file_name = datetime.strftime(
263262
current_date, "PrecipRate_00.00_%Y%m%d-%H%M%S.grib2"
264263
)
@@ -271,25 +270,23 @@ def delay(_counter):
271270

272271
file_url = archive_url + datetime.strftime(current_date, rel_url_fmt)
273272

274-
tmp_file = NamedTemporaryFile()
275273
try:
276274
print(f"Downloading {file_url} ", end="")
277-
request.urlretrieve(
278-
file_url, tmp_file.name,
279-
)
275+
tmp_file_name, _ = request.urlretrieve(file_url)
280276
print("DONE")
281-
except HTTPError as err:
282-
print(err)
283277

284-
dest_file_path = os.path.join(sub_dir, dest_file_name)
278+
dest_file_path = os.path.join(sub_dir, dest_file_name)
285279

286-
# Uncompress the data
287-
with gzip.open(tmp_file.name, "rb") as f_in:
288-
with open(dest_file_path, "wb") as f_out:
289-
shutil.copyfileobj(f_in, f_out)
280+
# Uncompress the data
281+
with gzip.open(tmp_file_name, "rb") as f_in:
282+
with open(dest_file_path, "wb") as f_out:
283+
shutil.copyfileobj(f_in, f_out)
290284

291-
current_date = current_date + timedelta(seconds=60 * 2)
292-
counter += 1
285+
current_date = current_date + timedelta(seconds=60 * 2)
286+
counter += 1
287+
288+
except HTTPError as err:
289+
print(err)
293290

294291

295292
def download_pysteps_data(dir_path, force=True):
@@ -308,7 +305,6 @@ def download_pysteps_data(dir_path, force=True):
308305
override existing files.
309306
310307
"""
311-
tmp_file = NamedTemporaryFile()
312308

313309
# Check if directory exists but is not empty
314310
if os.path.exists(dir_path) and os.path.isdir(dir_path):
@@ -324,17 +320,15 @@ def download_pysteps_data(dir_path, force=True):
324320
# The http response from github can either contain Content-Length (size of the file)
325321
# or use chunked Transfer-Encoding.
326322
# If Transfer-Encoding is chunked, then the Content-Length is not available since
327-
# the content is dynamically generated and we can't know the length a pr_iori easily.
323+
# the content is dynamically generated and we can't know the length a priori easily.
328324
pbar = ShowProgress()
329325
print("Downloading pysteps-data from github.")
330-
request.urlretrieve(
331-
"https://github.com/pySTEPS/pysteps-data/archive/master.zip",
332-
tmp_file.name,
333-
pbar,
326+
tmp_file_name, _ = request.urlretrieve(
327+
"https://github.com/pySTEPS/pysteps-data/archive/master.zip", reporthook=pbar,
334328
)
335329
pbar.end(message="Download complete\n")
336330

337-
with ZipFile(tmp_file.name, "r") as zip_obj:
331+
with ZipFile(tmp_file_name, "r") as zip_obj:
338332
tmp_dir = TemporaryDirectory()
339333

340334
# Extract all the contents of zip file in the temp directory

0 commit comments

Comments
 (0)