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

How to specify data directory #49

Closed
xnchu opened this issue Sep 18, 2020 · 5 comments
Closed

How to specify data directory #49

xnchu opened this issue Sep 18, 2020 · 5 comments

Comments

@xnchu
Copy link
Contributor

xnchu commented Sep 18, 2020

I am loading OMNI data, and wish to set local_data_dir to D:/data/omni.
In pyspedas/omni/config.py, it seems that local _data_dir can be set using os.environ['OMNI_DATA_DIR']
However, the following code will still download OMNI data in the current directory instead of D:/data/omni.
This was because os.environ is not changed in config.py
The following code will reproduce the problem.
Thanks for your attention.

import pyspedas
import os

os.environ['OMNI_DATA_DIR'] = "C:/data/omni/"
omni_vars = pyspedas.omni.data(trange=['2013-11-5', '2013-11-6'])

@ericthewizard
Copy link
Collaborator

Hello!

The preferred way to set the environment variable is to set it in the operating system before opening Python, e.g., on Windows, in the command-line, use:

setx OMNI_DATA_DIR D:/data/omni/

Then restart your terminal and open python - your OMNI_DATA_DIR should be saved. You can also set it temporarily in the terminal using 'set' instead of setx with:

set OMNI_DATA_DIR=D:/data/omni/

Then open python. With 'set', you won't have to restart your terminal, but it won't persist through terminal sessions.

If you prefer to set the data directory in python before making the load routine call, you can update the OMNI CONFIG table directly with:

import pyspedas
pyspedas.omni.config.CONFIG['local_data_dir'] = 'D:/data/omni/'
omni_vars = pyspedas.omni.data(trange=['2013-11-5', '2013-11-6'])

Hope this helps!

@xnchu
Copy link
Contributor Author

xnchu commented Sep 18, 2020

I've tested the two solutions and both worked. Thanks a lot.

@xnchu xnchu closed this as completed Sep 18, 2020
@donglai96
Copy link
Contributor

Hi,

I tried this way to download the data in my jupyter notebook

from pyspedas.utilities.download import download

files = download(remote_file=remote_names, remote_path=remote_data_dir,
                         local_path=local_data_dir, no_download=no_update)

I set local path to D disk

And I found it created a lot of temporary files in my C disk and I couldn't locate them. Really curious why that happened

@ericthewizard
Copy link
Collaborator

The download function stores the files as temporary files before copying to the local data directory - this is to avoid problems with partial downloads. e.g., if the internet connection drops before a download completes and you only get 75% of a CDF, the load routines would crash trying to load that invalid file.

I think the temporary files could be added to the local data directory instead of the temp directory (just with a temp file name instead of .cdf); I'll look into changing this when I get a chance.

@donglai96
Copy link
Contributor

That's really helpful! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants