blumenstiel commited on
Commit
c6d1dbd
·
1 Parent(s): 40a835d

Error handling for time and loc

Browse files
Files changed (1) hide show
  1. inference.py +9 -4
inference.py CHANGED
@@ -75,7 +75,11 @@ def read_geotiff(file_path: str):
75
  with rasterio.open(file_path) as src:
76
  img = src.read()
77
  meta = src.meta
78
- coords = src.lnglat()
 
 
 
 
79
 
80
  return img, meta, coords
81
 
@@ -137,7 +141,8 @@ def load_example(
137
 
138
  imgs.append(img)
139
  metas.append(meta)
140
- location_coords.append(coords)
 
141
 
142
  try:
143
  match = re.search(r'(\d{7,8}T\d{6})', file)
@@ -333,9 +338,9 @@ def main(
333
  file_paths=data_files, indices=input_indices, mean=mean, std=std
334
  )
335
 
336
- if not temporal_coords and 'time' in coords_encoding:
337
  coords_encoding.pop('time')
338
- if location_coords is None and 'location' in coords_encoding:
339
  coords_encoding.pop('location')
340
 
341
  # Create model and load checkpoint -------------------------------------------------------------
 
75
  with rasterio.open(file_path) as src:
76
  img = src.read()
77
  meta = src.meta
78
+ try:
79
+ coords = src.lnglat()
80
+ except:
81
+ # Cannot read coords
82
+ coords = None
83
 
84
  return img, meta, coords
85
 
 
141
 
142
  imgs.append(img)
143
  metas.append(meta)
144
+ if coords is not None:
145
+ location_coords.append(coords)
146
 
147
  try:
148
  match = re.search(r'(\d{7,8}T\d{6})', file)
 
338
  file_paths=data_files, indices=input_indices, mean=mean, std=std
339
  )
340
 
341
+ if len(temporal_coords) != num_frames and 'time' in coords_encoding:
342
  coords_encoding.pop('time')
343
+ if not len(location_coords) and 'location' in coords_encoding:
344
  coords_encoding.pop('location')
345
 
346
  # Create model and load checkpoint -------------------------------------------------------------