Skip to content

Commit

Permalink
human sort list fix PCMDI/click#10 (#605)
Browse files Browse the repository at this point in the history
* human sort list fix PCMDI/click#10

* correct path for linux machines

* new key for cache
  • Loading branch information
doutriaux1 committed May 30, 2019
1 parent c74a639 commit 22dc990
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
20 changes: 10 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ jobs:
- checkout
- restore_cache:
keys:
- macos_py2_2019-05-30
- macos_py2_2019-06-01
- run: *create_conda_env
- save_cache:
key: macos_py2_2019-05-30
key: macos_py2_2019-06-01
paths: /Users/distiller/miniconda
- run: *setup_pmp
- run: *run_pmp_tests
Expand All @@ -132,10 +132,10 @@ jobs:
- checkout
- restore_cache:
keys:
- macos_py3_2019-05-30
- macos_py3_2019-06-01
- run: *create_conda_env
- save_cache:
key: macos_py3_2019-05-30
key: macos_py3_2019-06-01
paths: /Users/distiller/miniconda
- run: *setup_pmp
- run: *run_pmp_tests
Expand All @@ -159,11 +159,11 @@ jobs:
- checkout
- restore_cache:
keys:
- linux_py2_2019-05-30
- linux_py2_2019-06-01
- run: *create_conda_env
- save_cache:
key: linux_py2_2019-05-30
paths: /Users/distiller/miniconda
key: linux_py2_2019-06-01
paths: /home/circleci/miniconda
- run: *setup_pmp
- run: *run_pmp_tests
- store_artifacts:
Expand All @@ -187,11 +187,11 @@ jobs:
- checkout
- restore_cache:
keys:
- linux_py3_2019-05-30
- linux_py3_2019-06-01
- run: *create_conda_env
- save_cache:
key: linux_py3_2019-05-30
paths: /Users/distiller/miniconda
key: linux_py3_2019-06-01
paths: /home/circleci/miniconda
- run: *setup_pmp
- run: *run_pmp_tests
- run: *conda_upload
Expand Down
23 changes: 21 additions & 2 deletions pcmdi_metrics/io/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import shlex
import datetime
from pcmdi_metrics import LOG_LEVEL
import copy
import re


value = 0
Expand Down Expand Up @@ -189,6 +191,18 @@ def generateProvenance():
return prov


def sort_human(input_list):
lst = copy.copy(input_list)

def convert(text):
return int(text) if text.isdigit() else text

def alphanum(key):
return [convert(c) for c in re.split('([0-9]+)', key)]
lst.sort(key=alphanum)
return lst


def scrap(data, axis=0):
originalOrder = data.getOrder(ids=True)
if axis not in ['x', 'y', 'z', 't'] and not isinstance(axis, int):
Expand Down Expand Up @@ -558,13 +572,14 @@ def get_array_values_from_dict_recursive(self, out, ids, nms, axval, axes):
out[tuple(ids)] = 9.99e20

def __init__(self, files=[], structure=[], ignored_keys=[],
oneVariablePerFile=True):
oneVariablePerFile=True, sortHuman=True):
self.json_version = 3.0
self.json_struct = structure
self.data = {}
self.axes = None
self.ignored_keys = ignored_keys
self.oneVariablePerFile = oneVariablePerFile
self.sortHuman = sortHuman
if len(files) == 0:
raise Exception("You need to pass at least one file")

Expand Down Expand Up @@ -615,8 +630,12 @@ def getAxisList(self):
0, len(self.json_struct) - 1, self.data, values)
autoBounds = cdms2.getAutoBounds()
cdms2.setAutoBounds("off")
if self.sortHuman:
sortFunc = sort_human
else:
sortFunc = sorted
for i, nm in enumerate(self.json_struct):
axes.append(cdms2.createAxis(sorted(list(values[i])), id=nm))
axes.append(cdms2.createAxis(sortFunc(list(values[i])), id=nm))
self.axes = axes
cdms2.setAutoBounds(autoBounds)
return self.axes
Expand Down

0 comments on commit 22dc990

Please sign in to comment.