Skip to content

Commit

Permalink
Merge pull request #460 from PCMDI/issue_459_json_update_json
Browse files Browse the repository at this point in the history
Issue 459 json update json
  • Loading branch information
durack1 committed Jan 6, 2017
2 parents 32dbbb7 + 138638d commit 883209e
Show file tree
Hide file tree
Showing 7 changed files with 21,767 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ install:

script:
- export HDF5_DISABLE_VERSION_CHECK=1
- python test/test_suite.py # --no-graphics
- python test/test_suite.py -V # --no-graphics

after_success:
- test $TRAVIS_BRANCH = "master" && $TRAVIS_PULL_REQUEST = "false" && conda install conda-build && conda install anaconda-client && bash conda-recipes/pcmdi_metrics/conda_upload.sh
23 changes: 7 additions & 16 deletions src/python/io/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ def write(self, data, type="json", mode="w", *args, **kargs):
data["uvcdat_version"] = cdat_info.get_version()
json.dump(data, f, cls=CDMSDomainsEncoder, *args, **kargs)
f.close()
print "Results saved to JSON file:", fnm
elif type.lower() in ["asc", "ascii", "txt"]:
f = open(fnm, mode)
for k in data.keys():
Expand Down Expand Up @@ -192,22 +191,16 @@ def addDict2Self(self, json_dict, json_struct, json_version):
V = json_dict[json_dict.keys()[0]]
for model in V.keys(): # loop through models
m = V[model]
# print "FIRST M:",m.keys()
for ref in m.keys():
aref = m[ref]
if not(isinstance(aref, dict) and "source" in aref): # not an obs key
continue
# print "\treading in ref:",ref
# print aref.keys()
reals = aref.keys()
src = reals.pop(reals.index("source"))
for real in reals:
# print "\t\treading in realization:",real
# print real
areal = aref[real]
areal2 = {"source": src}
for region in areal.keys():
# print "\t\t\tREGION:",region
reg = areal[region]
if region == "global":
region2 = ""
Expand All @@ -217,7 +210,6 @@ def addDict2Self(self, json_dict, json_struct, json_version):
areal2[region2 + "NHEX"] = {}
areal2[region2 + "SHEX"] = {}
areal2[region2 + "TROPICS"] = {}
# print "OK HERE REGIONS:",areal2.keys()
key_stats = reg.keys()
for k in key_stats:
if k[:7] == "custom_":
Expand All @@ -239,7 +231,6 @@ def addDict2Self(self, json_dict, json_struct, json_version):
else:
areal2[region2 + domain][stat] = stat_dict
# Now we can replace the realization with the correctly formatted one
# print "AREAL@:",areal2
aref[real] = areal2
# restore ref into model
m[ref] = aref
Expand All @@ -251,13 +242,9 @@ def addDict2Self(self, json_dict, json_struct, json_version):
aref = m[ref]
if not(isinstance(aref, dict) and "source" in aref): # not an obs key
continue
# print "\treading in ref:",ref
# print aref.keys()
reals = aref.keys()
src = reals.pop(reals.index("source"))
for real in reals:
# print "\t\treading in realization:",real
# print real
areal = aref[real]
for region in areal.keys():
reg = areal[region]
Expand Down Expand Up @@ -346,6 +333,8 @@ def addJson(self, filename):
tmp_dict = {varnm: tmp_dict["RESULTS"]}
else:
tmp_dict = tmp_dict["RESULTS"]
if json_struct != self.json_struct and self.json_struct == []:
self.json_struct = json_struct
self.addDict2Self(tmp_dict, json_struct, json_version)

def getAxis(self, axis):
Expand All @@ -355,9 +344,11 @@ def getAxis(self, axis):
return a
return None

def getAxisList(self, use_cache=True):
if use_cache and self.axes is not None:
return self.axes
def getAxisIds(self):
axes = self.getAxisList()
return [ax.id for ax in axes]

def getAxisList(self):
values = []
axes = []
for a in self.json_struct:
Expand Down
Loading

0 comments on commit 883209e

Please sign in to comment.