[yt-svn] commit/yt: xarthisius: Merged in 0x414A/yt (pull request #2246)

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Sat Jun 25 17:17:51 PDT 2016


1 new commit in yt:

https://bitbucket.org/yt_analysis/yt/commits/d48c4a143f6e/
Changeset:   d48c4a143f6e
Branch:      yt
User:        xarthisius
Date:        2016-06-26 00:17:40+00:00
Summary:     Merged in 0x414A/yt (pull request #2246)

Move extraction code from YTSearchCmd to its own utility module
Affected #:  2 files

diff -r 9e8c28db275b8ccd25279e218b1f063ed2f2aec9 -r d48c4a143f6e3c69c9a1016725d8328f8ea3af53 yt/utilities/command_line.py
--- a/yt/utilities/command_line.py
+++ b/yt/utilities/command_line.py
@@ -43,6 +43,7 @@
 from yt.visualization.plot_window import \
     SlicePlot, \
     ProjectionPlot
+from yt.utilities.metadata import get_metadata
 from yt.utilities.exceptions import \
     YTOutputNotIdentified
 
@@ -1150,11 +1151,6 @@
     def __call__(self, args):
         from yt.utilities.parameter_file_storage import \
             output_type_registry
-        attrs = ("dimensionality", "refine_by", "domain_dimensions",
-                 "current_time", "domain_left_edge", "domain_right_edge",
-                 "unique_identifier", "current_redshift", 
-                 "cosmological_simulation", "omega_matter", "omega_lambda",
-                 "hubble_constant", "dataset_type")
         candidates = []
         for base, dirs, files in os.walk(".", followlinks=True):
             print("(% 10i candidates) Examining %s" % (len(candidates), base))
@@ -1173,26 +1169,10 @@
         for i, c in enumerate(sorted(candidates)):
             print("(% 10i/% 10i) Evaluating %s" % (i, len(candidates), c))
             try:
-                ds = load(c)
+                record = get_metadata(c, args.full_output)
             except YTOutputNotIdentified:
                 continue
-            record = {'filename': c}
-            for a in attrs:
-                v = getattr(ds, a, None)
-                if v is None:
-                    continue
-                if hasattr(v, "tolist"):
-                    v = v.tolist()
-                record[a] = v
-            if args.full_output:
-                params = {}
-                for p, v in ds.parameters.items():
-                    if hasattr(v, "tolist"):
-                        v = v.tolist()
-                    params[p] = v
-                record['params'] = params
             records.append(record)
-            ds.close()
         with open(args.output, "w") as f:
             json.dump(records, f, indent=4)
         print("Identified %s records output to %s" % (

diff -r 9e8c28db275b8ccd25279e218b1f063ed2f2aec9 -r d48c4a143f6e3c69c9a1016725d8328f8ea3af53 yt/utilities/metadata.py
--- /dev/null
+++ b/yt/utilities/metadata.py
@@ -0,0 +1,28 @@
+from yt.convenience import load
+
+DEFAULT_ATTRS = ("dimensionality", "refine_by", "domain_dimensions",
+                 "current_time", "domain_left_edge", "domain_right_edge",
+                 "unique_identifier", "current_redshift",
+                 "cosmological_simulation", "omega_matter", "omega_lambda",
+                 "hubble_constant", "dataset_type")
+
+
+def get_metadata(path, full_output=False, attrs=DEFAULT_ATTRS):
+    ds = load(path)
+    metadata = {'filename': path}
+    for a in attrs:
+        v = getattr(ds, a, None)
+        if v is None:
+            continue
+        if hasattr(v, "tolist"):
+            v = v.tolist()
+        metadata[a] = v
+    if full_output:
+        params = {}
+        for p, v in ds.parameters.items():
+            if hasattr(v, "tolist"):
+                v = v.tolist()
+            params[p] = v
+        metadata['params'] = params
+    ds.close()
+    return metadata

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