@@ -379,7 +379,7 @@ def __init__(self, array, units, calendar=None):
379
379
calendar_msg = ('the default calendar' if calendar is None
380
380
else 'calendar %r' % calendar )
381
381
msg = ('unable to decode time units %r with %s. Try '
382
- 'opening your dataset with decode_times =False.'
382
+ 'opening your dataset with decode_datestimes =False.'
383
383
% (units , calendar_msg ))
384
384
if not PY3 :
385
385
msg += ' Full traceback:\n ' + traceback .format_exc ()
@@ -718,7 +718,8 @@ def encode_cf_variable(var, needs_copy=True, name=None):
718
718
719
719
720
720
def decode_cf_variable (var , concat_characters = True , mask_and_scale = True ,
721
- decode_times = True , decode_endianness = True ):
721
+ decode_datetimes = True , decode_timedeltas = False ,
722
+ decode_endianness = True ):
722
723
"""
723
724
Decodes a variable which may hold CF encoded information.
724
725
@@ -737,8 +738,10 @@ def decode_cf_variable(var, concat_characters=True, mask_and_scale=True,
737
738
mask_and_scale: bool
738
739
Lazily scale (using scale_factor and add_offset) and mask
739
740
(using _FillValue).
740
- decode_times : bool
741
+ decode_datetimes : bool
741
742
Decode cf times ('hours since 2000-01-01') to np.datetime64.
743
+ decode_timedeltas : bool
744
+ Decode cf time data ('seconds') to np.timedelta64.
742
745
decode_endianness : bool
743
746
Decode arrays from non-native to native endianness.
744
747
@@ -792,13 +795,13 @@ def decode_cf_variable(var, concat_characters=True, mask_and_scale=True,
792
795
data = MaskedAndScaledArray (data , fill_value , scale_factor ,
793
796
add_offset , dtype )
794
797
795
- if decode_times and 'units' in attributes :
798
+ if decode_datetimes and 'units' in attributes :
796
799
if 'since' in attributes ['units' ]:
797
800
# datetime
798
801
units = pop_to (attributes , encoding , 'units' )
799
802
calendar = pop_to (attributes , encoding , 'calendar' )
800
803
data = DecodedCFDatetimeArray (data , units , calendar )
801
- elif attributes ['units' ] in TIME_UNITS :
804
+ elif decode_timedeltas and attributes ['units' ] in TIME_UNITS :
802
805
# timedelta
803
806
units = pop_to (attributes , encoding , 'units' )
804
807
data = DecodedCFTimedeltaArray (data , units )
@@ -823,8 +826,9 @@ def decode_cf_variable(var, concat_characters=True, mask_and_scale=True,
823
826
824
827
825
828
def decode_cf_variables (variables , attributes , concat_characters = True ,
826
- mask_and_scale = True , decode_times = True ,
827
- decode_coords = True , drop_variables = None ):
829
+ mask_and_scale = True , decode_datetimes = True ,
830
+ decode_timedeltas = False , decode_coords = True ,
831
+ drop_variables = None ):
828
832
"""
829
833
Decode a several CF encoded variables.
830
834
@@ -860,7 +864,8 @@ def stackable(dim):
860
864
stackable (v .dims [- 1 ]))
861
865
new_vars [k ] = decode_cf_variable (
862
866
v , concat_characters = concat , mask_and_scale = mask_and_scale ,
863
- decode_times = decode_times )
867
+ decode_datetimes = decode_datetimes ,
868
+ decode_timedeltas = decode_timedeltas )
864
869
if decode_coords :
865
870
var_attrs = new_vars [k ].attrs
866
871
if 'coordinates' in var_attrs :
@@ -879,7 +884,8 @@ def stackable(dim):
879
884
880
885
881
886
def decode_cf (obj , concat_characters = True , mask_and_scale = True ,
882
- decode_times = True , decode_coords = True , drop_variables = None ):
887
+ decode_datetimes = True , decode_timedeltas = False ,
888
+ decode_coords = True , drop_variables = None ):
883
889
"""Decode the given Dataset or Datastore according to CF conventions into
884
890
a new Dataset.
885
891
@@ -893,9 +899,11 @@ def decode_cf(obj, concat_characters=True, mask_and_scale=True,
893
899
mask_and_scale: bool, optional
894
900
Lazily scale (using scale_factor and add_offset) and mask
895
901
(using _FillValue).
896
- decode_times : bool, optional
902
+ decode_datetimes : bool, optional
897
903
Decode cf times (e.g., integers since 'hours since 2000-01-01') to
898
904
np.datetime64.
905
+ decode_timedeltas : bool, optional
906
+ Decode cf time data (e.g., 'seconds') to np.timedelta64.
899
907
decode_coords : bool, optional
900
908
Use the 'coordinates' attribute on variable (or the dataset itself) to
901
909
identify coordinates.
@@ -924,8 +932,8 @@ def decode_cf(obj, concat_characters=True, mask_and_scale=True,
924
932
raise TypeError ('can only decode Dataset or DataStore objects' )
925
933
926
934
vars , attrs , coord_names = decode_cf_variables (
927
- vars , attrs , concat_characters , mask_and_scale , decode_times ,
928
- decode_coords , drop_variables = drop_variables )
935
+ vars , attrs , concat_characters , mask_and_scale , decode_datetimes ,
936
+ decode_timedeltas , decode_coords , drop_variables = drop_variables )
929
937
ds = Dataset (vars , attrs = attrs )
930
938
ds = ds .set_coords (coord_names .union (extra_coords ))
931
939
ds ._file_obj = file_obj
@@ -934,7 +942,7 @@ def decode_cf(obj, concat_characters=True, mask_and_scale=True,
934
942
935
943
def cf_decoder (variables , attributes ,
936
944
concat_characters = True , mask_and_scale = True ,
937
- decode_times = True ):
945
+ decode_datetimes = True , decode_timedeltas = False ):
938
946
"""
939
947
Decode a set of CF encoded variables and attributes.
940
948
@@ -952,8 +960,10 @@ def cf_decoder(variables, attributes,
952
960
mask_and_scale: bool
953
961
Lazily scale (using scale_factor and add_offset) and mask
954
962
(using _FillValue).
955
- decode_times : bool
963
+ decode_datetimes : bool
956
964
Decode cf times ('hours since 2000-01-01') to np.datetime64.
965
+ decode_timedeltas : bool
966
+ Decode cf time data ('seconds') to np.timedelta64.
957
967
958
968
Returns
959
969
-------
@@ -963,7 +973,8 @@ def cf_decoder(variables, attributes,
963
973
A dictionary mapping from attribute name to values.
964
974
"""
965
975
variables , attributes , _ = decode_cf_variables (
966
- variables , attributes , concat_characters , mask_and_scale , decode_times )
976
+ variables , attributes , concat_characters , mask_and_scale ,
977
+ decode_datetimes , decode_timedeltas )
967
978
return variables , attributes
968
979
969
980
0 commit comments