@@ -494,6 +494,7 @@ def build_variable_components(
494
494
read_keys : T .Iterable [str ] = (),
495
495
time_dims : T .Sequence [str ] = ("time" , "step" ),
496
496
extra_coords : T .Dict [str , str ] = {},
497
+ coords_as_attributes : T .Dict [str , str ] = {},
497
498
cache_geo_coords : bool = True ,
498
499
) -> T .Tuple [T .Dict [str , int ], Variable , T .Dict [str , Variable ]]:
499
500
data_var_attrs = enforce_unique_attributes (index , DATA_ATTRIBUTES_KEYS , filter_by_keys )
@@ -520,6 +521,9 @@ def build_variable_components(
520
521
and "GRIB_typeOfLevel" in data_var_attrs
521
522
):
522
523
coord_name = data_var_attrs ["GRIB_typeOfLevel" ]
524
+ if coord_name in coords_as_attributes and len (values ) == 1 :
525
+ data_var_attrs [f"GRIB_{ coord_name } " ] = values
526
+ continue
523
527
coord_name_key_map [coord_name ] = coord_key
524
528
attributes = {
525
529
"long_name" : "original GRIB coordinate for key: %s(%s)" % (orig_name , coord_name ),
@@ -666,6 +670,7 @@ def build_dataset_components(
666
670
read_keys : T .Iterable [str ] = (),
667
671
time_dims : T .Sequence [str ] = ("time" , "step" ),
668
672
extra_coords : T .Dict [str , str ] = {},
673
+ coords_as_attributes : T .Dict [str , str ] = {},
669
674
cache_geo_coords : bool = True ,
670
675
) -> T .Tuple [T .Dict [str , int ], T .Dict [str , Variable ], T .Dict [str , T .Any ], T .Dict [str , T .Any ]]:
671
676
dimensions = {} # type: T.Dict[str, int]
@@ -692,6 +697,7 @@ def build_dataset_components(
692
697
read_keys = read_keys ,
693
698
time_dims = time_dims ,
694
699
extra_coords = extra_coords ,
700
+ coords_as_attributes = coords_as_attributes ,
695
701
cache_geo_coords = cache_geo_coords ,
696
702
)
697
703
except DatasetBuildError as ex :
@@ -814,5 +820,4 @@ def open_file(
814
820
stream = messages .FileStream (path , errors = errors )
815
821
index_keys = compute_index_keys (time_dims , extra_coords )
816
822
index = open_fileindex (stream , indexpath , index_keys , ignore_keys = ignore_keys , filter_by_keys = filter_by_keys )
817
-
818
823
return open_from_index (index , read_keys , time_dims , extra_coords , errors = errors , ** kwargs )
0 commit comments