[yt-svn] commit/yt: 3 new changesets

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Fri Nov 15 03:13:18 PST 2013


3 new commits in yt:

https://bitbucket.org/yt_analysis/yt/commits/f3a2f15fa688/
Changeset:   f3a2f15fa688
Branch:      yt
User:        brittonsmith
Date:        2013-11-10 18:55:20
Summary:     Adding function to download data files from the internet.
Affected #:  1 file

diff -r 58580d4b9d81dfd7ab4f4ee4ee189ac1c055ef57 -r f3a2f15fa688108462be4b1e29e2bbb3a9ec60a3 yt/funcs.py
--- a/yt/funcs.py
+++ b/yt/funcs.py
@@ -538,6 +538,16 @@
         contents = None
     return contents
 
+def download_file(url, filename):
+    import urllib
+    class MyURLopener(urllib.FancyURLopener):
+        def http_error_default(self, url, fp, errcode, errmsg, headers):
+            raise RuntimeError, \
+              "Attempt to download file from %s failed with error %s: %s." % \
+              (url, errcode, errmsg)
+    fn, h = MyURLopener().retrieve(url, filename)
+    return fn
+
 # This code snippet is modified from Georg Brandl
 def bb_apicall(endpoint, data, use_pass = True):
     import urllib, urllib2


https://bitbucket.org/yt_analysis/yt/commits/46bd6cfaa3fe/
Changeset:   46bd6cfaa3fe
Branch:      yt
User:        brittonsmith
Date:        2013-11-10 20:39:48
Summary:     Adding ability to download supplementary data for x-ray emissivity from the web.
Affected #:  1 file

diff -r f3a2f15fa688108462be4b1e29e2bbb3a9ec60a3 -r 46bd6cfaa3feb8b6691967cfb024523a50a7c204 yt/analysis_modules/spectral_integrator/spectral_frequency_integrator.py
--- a/yt/analysis_modules/spectral_integrator/spectral_frequency_integrator.py
+++ b/yt/analysis_modules/spectral_integrator/spectral_frequency_integrator.py
@@ -19,7 +19,10 @@
 import numpy as np
 import os
 
-from yt.funcs import *
+from yt.funcs import \
+     download_file, \
+     mylog, \
+     only_on_root
 
 from yt.data_objects.field_info_container import add_field
 from yt.utilities.exceptions import YTException
@@ -28,6 +31,23 @@
 
 xray_data_version = 1
 
+def _get_data_file():
+    data_file = "xray_emissivity.h5"
+    data_url = "http://yt-project.org/data"
+    if "YT_DEST" in os.environ and \
+      os.path.isdir(os.path.join(os.environ["YT_DEST"], "data")):
+        data_dir = os.path.join(os.environ["YT_DEST"], "data")
+    else:
+        data_dir = "."
+    data_path = os.path.join(data_dir, data_file)
+    if not os.path.exists(data_path):
+        mylog.info("Attempting to download supplementary data from %s to %s." % 
+                   (data_url, data_dir))
+        fn = download_file(os.path.join(data_url, data_file), data_path)
+        if fn != data_path:
+            raise RuntimeError, "Failed to download supplementary data."
+    return data_path
+
 class EnergyBoundsException(YTException):
     def __init__(self, lower, upper):
         self.lower = lower
@@ -62,8 +82,7 @@
 
         default_filename = False
         if filename is None:
-            filename = os.path.join(os.environ["YT_DEST"], 
-                                    "data", "xray_emissivity.h5")
+            filename = _get_data_file()
             default_filename = True
 
         if not os.path.exists(filename):


https://bitbucket.org/yt_analysis/yt/commits/6776fce7eac8/
Changeset:   6776fce7eac8
Branch:      yt
User:        MatthewTurk
Date:        2013-11-15 12:13:15
Summary:     Merged in brittonsmith/yt (pull request #636)

Adding ability to download supplementary data for x-ray emissivity from the web.
Affected #:  2 files

diff -r 874b5934452d12975e64584f3230396e73fff28f -r 6776fce7eac8b9828e85c6f0a9913e7417182408 yt/analysis_modules/spectral_integrator/spectral_frequency_integrator.py
--- a/yt/analysis_modules/spectral_integrator/spectral_frequency_integrator.py
+++ b/yt/analysis_modules/spectral_integrator/spectral_frequency_integrator.py
@@ -19,7 +19,10 @@
 import numpy as np
 import os
 
-from yt.funcs import *
+from yt.funcs import \
+     download_file, \
+     mylog, \
+     only_on_root
 
 from yt.data_objects.field_info_container import add_field
 from yt.utilities.exceptions import YTException
@@ -28,6 +31,23 @@
 
 xray_data_version = 1
 
+def _get_data_file():
+    data_file = "xray_emissivity.h5"
+    data_url = "http://yt-project.org/data"
+    if "YT_DEST" in os.environ and \
+      os.path.isdir(os.path.join(os.environ["YT_DEST"], "data")):
+        data_dir = os.path.join(os.environ["YT_DEST"], "data")
+    else:
+        data_dir = "."
+    data_path = os.path.join(data_dir, data_file)
+    if not os.path.exists(data_path):
+        mylog.info("Attempting to download supplementary data from %s to %s." % 
+                   (data_url, data_dir))
+        fn = download_file(os.path.join(data_url, data_file), data_path)
+        if fn != data_path:
+            raise RuntimeError, "Failed to download supplementary data."
+    return data_path
+
 class EnergyBoundsException(YTException):
     def __init__(self, lower, upper):
         self.lower = lower
@@ -62,8 +82,7 @@
 
         default_filename = False
         if filename is None:
-            filename = os.path.join(os.environ["YT_DEST"], 
-                                    "data", "xray_emissivity.h5")
+            filename = _get_data_file()
             default_filename = True
 
         if not os.path.exists(filename):

diff -r 874b5934452d12975e64584f3230396e73fff28f -r 6776fce7eac8b9828e85c6f0a9913e7417182408 yt/funcs.py
--- a/yt/funcs.py
+++ b/yt/funcs.py
@@ -538,6 +538,16 @@
         contents = None
     return contents
 
+def download_file(url, filename):
+    import urllib
+    class MyURLopener(urllib.FancyURLopener):
+        def http_error_default(self, url, fp, errcode, errmsg, headers):
+            raise RuntimeError, \
+              "Attempt to download file from %s failed with error %s: %s." % \
+              (url, errcode, errmsg)
+    fn, h = MyURLopener().retrieve(url, filename)
+    return fn
+
 # This code snippet is modified from Georg Brandl
 def bb_apicall(endpoint, data, use_pass = True):
     import urllib, urllib2

Repository URL: https://bitbucket.org/yt_analysis/yt/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the yt-svn mailing list