diff --git a/modules/util/viirs_l1b_l2.py b/modules/util/viirs_l1b_l2.py
index 071fa4488fe183f639e3f2239af5d4d026edbcdf..0e79805d00fa1b6cce142cdcde0b7b2d7f674104 100644
--- a/modules/util/viirs_l1b_l2.py
+++ b/modules/util/viirs_l1b_l2.py
@@ -125,7 +125,7 @@ def run_all(directory, out_directory):
         np.save(out_directory+'label_valid_' + str(cnt), label_valid)
 
 
-def run(data_h5f, label_h5f, data_tiles, label_tiles, factor=2):
+def run(data_h5f, label_h5f, data_tiles, label_tiles, factor=2, border=9):
     if label_h5f is None:
         label_h5f = data_h5f
 
@@ -168,7 +168,6 @@ def run(data_h5f, label_h5f, data_tiles, label_tiles, factor=2):
     i_skip = 3 * mod_tile_width
     i_start = int(mod_num_pixels / 2) - int((num_keep_x_tiles * 3 * mod_tile_width) / 2)
 
-    border = 9
     num_keep_y_tiles = 16
     j_skip = 3 * mod_tile_width
     for j in range(num_keep_y_tiles):
@@ -181,7 +180,15 @@ def run(data_h5f, label_h5f, data_tiles, label_tiles, factor=2):
             i_m = i_c + border
             i_i = i_m * factor
 
-            nda = mod_data[:, j_m-border:j_m + mod_tile_width+border, i_m:i_m + mod_tile_width]
+            j_stop = j_m + mod_tile_width + border
+            if j_stop > mod_num_lines - 1:
+                continue
+
+            i_stop = i_m + mod_tile_width + border
+            if i_stop > mod_num_pixels - 1:
+                continue
+
+            nda = mod_data[:, j_m-border:j_stop, i_m-border:i_stop]
             data_tiles.append(nda)
 
             nda = img_data[:, j_i:j_i + img_tile_width, i_i:i_i + img_tile_width]