26
26
from anemoi .datasets .data .stores import open_zarr
27
27
from anemoi .datasets .data .stores import zarr_lookup
28
28
29
+ from . import Command
30
+
29
31
LOG = logging .getLogger (__name__ )
30
32
31
33
@@ -79,46 +81,12 @@ def __init__(self, path, zarr, metadata, version):
79
81
self .metadata = metadata
80
82
self .version = version
81
83
self .dataset = None
82
- # try:
83
84
self .dataset = open_dataset (self .path )
84
- # except Exception as e:
85
- # LOG.error("Error opening dataset '%s': %s", self.path, e)
86
85
87
86
def describe (self ):
88
87
print (f"📦 Path : { self .path } " )
89
88
print (f"🔢 Format version: { self .version } " )
90
89
91
- def probe (self ):
92
- if "cos_local_time" not in self .name_to_index :
93
- print ("⚠️ probe: no cos_local_time" )
94
- return
95
-
96
- try :
97
- lon = self .longitudes
98
- except AttributeError :
99
- print ("⚠️ probe: no longitudes" )
100
- return
101
- # print(json.dumps(self.metadata, indent=4))
102
- cos_local_time = self .name_to_index ["cos_local_time" ]
103
- data = self .data
104
- start , end , frequency = self .first_date , self .last_date , self .frequency
105
- date = start
106
- same = 0
107
- for i in range (10 ):
108
- field = data [i , cos_local_time ]
109
- buggy = cos_local_time_bug (lon , date ).reshape (field .hape )
110
- diff = np .abs (field - buggy )
111
- if np .max (diff ) < 1e-5 :
112
- same += 1
113
- date += datetime .timedelta (hours = frequency )
114
- if date > end :
115
- break
116
- if same > 1 :
117
- print ("❌ probe: cos_local_time is buggy" )
118
- return
119
-
120
- print ("✅ probe: cos_local_time is fixed" )
121
-
122
90
@property
123
91
def name_to_index (self ):
124
92
return find (self .metadata , "name_to_index" )
@@ -587,29 +555,35 @@ def build_lengths(self):
587
555
}
588
556
589
557
590
- class InspectZarr :
591
- """Inspect a checkpoint or zarr file ."""
558
+ class InspectZarr ( Command ) :
559
+ """Inspect a zarr dataset ."""
592
560
593
- def inspect_zarr (self , path , ** kwargs ):
594
- version = self ._info (path )
561
+ def add_arguments (self , command_parser ):
562
+ command_parser .add_argument ("path" , metavar = "DATASET" )
563
+ command_parser .add_argument ("--detailed" , action = "store_true" )
564
+
565
+ command_parser .add_argument ("--progress" , action = "store_true" )
566
+ command_parser .add_argument ("--statistics" , action = "store_true" )
567
+ command_parser .add_argument ("--size" , action = "store_true" , help = "Print size" )
595
568
596
- # try :
597
- # with open("/tmp/probe.json", "w") as f:
598
- # json.dump(version.metadata, f, indent=4, sort_keys=True)
599
- # except Exception :
600
- # pass
569
+ def run ( self , args ) :
570
+ self . inspect_zarr ( ** vars ( args ))
571
+
572
+ def inspect_zarr ( self , path , progress = False , statistics = False , detailed = False , size = False , ** kwargs ) :
573
+ version = self . _info ( path )
601
574
602
575
dotted_line ()
603
576
version .describe ()
604
577
605
578
try :
606
- if kwargs .get ("probe" ):
607
- return version .probe ()
608
- if kwargs .get ("progress" ):
579
+ if progress :
609
580
return version .progress ()
610
- if kwargs .get ("statistics" ):
581
+
582
+ if statistics :
611
583
return version .brute_force_statistics ()
612
- version .info (kwargs .get ("detailed" ), kwargs .get ("size" ))
584
+
585
+ version .info (detailed , size )
586
+
613
587
except Exception as e :
614
588
LOG .error ("Error inspecting zarr file '%s': %s" , path , e )
615
589
@@ -634,3 +608,6 @@ def _info(self, path):
634
608
candidate = klass
635
609
636
610
return candidate (path , z , metadata , version )
611
+
612
+
613
+ command = InspectZarr
0 commit comments