OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
viirs_files.py
Go to the documentation of this file.
1 '''
2 * NAME: viirs_files.py
3 *
4 * DESCRIPTION: VIIRS product and LUT object classes and supporting data structures.
5 * This is not an executable but is required for cal_viirs.py and obc_viirs.py.
6 
7 * Created on July 15, 2016
8 
9 * Author: Samuel Anderson
10 '''
11 
12 import os
13 import sys
14 
15 l1b_type = {"OBC_S":"OBC",
16  "L1B-D":"L1B-DNB",
17  "L1B-I":"L1B-IMG",
18  "L1B-M":"L1B-MOD",
19  "GEO-D":"GEO-DNB",
20  "GEO-I":"GEO-IMG",
21  "GEO-M_":"GEO-MOD",
22  "L1A_S":"L1A"
23  }
24 
25 vcst_type = {"SVIMG_":"SVIMG",
26  "SVMOD_":"SVMOD",
27  "SVDNB_":"SVDNB",
28  "IVCDB_":"IVCDB",
29  "IVOBC_":"IVOBC",
30  "GEOGRC":"GEOGRC",
31  "GEODEG":"GEODEG",
32  "GEOTC_":"GEOTC",
33  "V-RVIR":"V-RVIRS"
34  }
35 
36 idps_type = {"SVI01":"VIIRS-I1-SDR",
37  "SVI02":"VIIRS-I2-SDR",
38  "SVI03":"VIIRS-I3-SDR",
39  "SVI04":"VIIRS-I4-SDR",
40  "SVI05":"VIIRS-I5-SDR",
41  "SVM01":"VIIRS-M1-SDR",
42  "SVM02":"VIIRS-M2-SDR",
43  "SVM03":"VIIRS-M3-SDR",
44  "SVM04":"VIIRS-M4-SDR",
45  "SVM05":"VIIRS-M5-SDR",
46  "SVM06":"VIIRS-M6-SDR",
47  "SVM07":"VIIRS-M7-SDR",
48  "SVM08":"VIIRS-M8-SDR",
49  "SVM09":"VIIRS-M9-SDR",
50  "SVM10":"VIIRS-M10-SDR",
51  "SVM11":"VIIRS-M11-SDR",
52  "SVM12":"VIIRS-M12-SDR",
53  "SVM13":"VIIRS-M13-SDR",
54  "SVM14":"VIIRS-M14-SDR",
55  "SVM15":"VIIRS-M15-SDR",
56  "SVM16":"VIIRS-M16-SDR",
57  "SVM16":"VIIRS-M16-SDR",
58  "SVDNB":"VIIRS-DNB-SDR",
59  "IVOBC":"VIIRS-OBC-IP",
60  "IVCDB":"VIIRS-DualGain-Cal-IP",
61  "RNSCA":"VIIRS-Sci-RDR",
62  "GDNBO":"VIIRS-DNB-SDR",
63  "GMODO":"VIIRS-MOD-SDR",
64  "GIMGO":"VIIRS-IMG-SDR"
65  }
66 
67 lut_type = {"TERRAIN-PATH":(0,"TERRAIN_PATH_LUN"),
68  "LANDWATER-PATH":(0,"LANDWATER_PATH_LUN"),
69  "CMNGEO-LEAPSEC":(0,"LEAPSEC_FILE_LUN"),
70  "CMNGEO-PLANET-EPHEMERIS-LUT":(0,"JPL_EPHEMERIS_LUN"),
71  "CMNGEO-SAA-LUT":(0,"SAA_COEFFS_LUN"),
72  "CMNGEO-POLAR-WANDER-LUT":(0,"POLAR_WANDER_LUN"),
73  "CMNGEO-PARAM-LUT":(120,"CMNGEO_PARAM_LUT_LUN"),
74  "VIIRS-SDR-GEO-DNB-PARAM-LUT":(6664,"GEOLOCATION_DNB_PARAMS_LUN"),
75  "VIIRS-SDR-GEO-IMG-PARAM-LUT":(6664,"GEOLOCATION_IMG_PARAMS_LUN"),
76  "VIIRS-SDR-GEO-MOD-PARAM-LUT":(6664,"GEOLOCATION_MOD_PARAMS_LUN"),
77  "VIIRS-SDR-DG-ANOMALY-DN-LIMITS-LUT":(768,"SDR_DG_ANOMALY_DN_LIMITS_LUT_LUN"),
78  "VIIRS-SDR-DNB-DN0-LUT":(1560576,"DNB_DN0_LUT_LUN"),
79  "VIIRS-SDR-DNB-RVF-LUT":(520192,"DNB_RVS_LUT_LUN"),
80  "VIIRS-SDR-DNB-STRAY-LIGHT-LUT":(88,"SDR_DNB_STRAY_LIGHT_LUT_LUN"),
81  "VIIRS-SDR-DNB-FRAME-TO-ZONE-LUT":(16256,"DNB_FRAME_TO_ZONE_LUN"),
82  "VIIRS-SDR-DNB-C-COEFFS-LUT":(73728,"DNB_C_COEFF_LUT_LUN"),
83  "VIIRS-SDR-DNB-F-PREDICTED-LUT":(24592,"SDR_DNB_F_PREDICTED_LUT_LUN"),
84  "VIIRS-SDR-F-PREDICTED-LUT":(101408,"SDR_F_PREDICTED_LUT_LUN"),
85  "VIIRS-SDR-GAIN-LUT":(176,"SDR_GAIN_LUT_LUN"),
86  "VIIRS-SDR-HAM-ER-LUT":(120024,"SDR_HAM_ER_LUT_LUN"),
87  "VIIRS-SDR-RTA-ER-LUT":(120024,"SDR_RTA_ER_LUT_LUN"),
88  "VIIRS-SDR-OBC-ER-LUT":(120024,"SDR_OBC_ER_LUT_LUN"),
89  "VIIRS-SDR-OBC-RR-LUT":(120024,"SDR_OBC_RR_LUT_LUN"),
90  "VIIRS-SDR-EBBT-LUT":(16800056,"SDR_EB_BT_LUT_LUN"),
91  "VIIRS-SDR-TELE-COEFFS-LUT":(928,"SDR_TELEM_COEFFS_LUN"),
92  "VIIRS-SDR-SOLAR-IRAD-LUT":(799216,"SDR_SOLAR_IRAD_LUT_LUN"),
93  "VIIRS-SDR-RSR-LUT":(224056,"SDR_RSR_LUT_LUN"),
94  "VIIRS-SDR-OBS-TO-PIXELS-LUT":(25216,"SDR_OBS_TO_PIXELS_LUT_LUN"),
95  "VIIRS-SDR-RADIOMETRIC-PARAM-LUT":(220,"SDR_RADIOMETRIC_PARAMS_LUN"),
96  "VIIRS-SDR-RADIOMETRIC-PARAM-V2-LUT":(232,"SDR_RADIOMETRIC_PARAMS_LUN"),
97  "VIIRS-SDR-RADIOMETRIC-PARAM-V3-LUT":(236,"SDR_RADIOMETRIC_PARAMS_LUN"),
98  "VIIRS-SDR-QA-LUT":(3812,"SDR_QA_LUT_LUN"),
99  "VIIRS-SDR-EMISSIVE-LUT":(48,"SDR_EMISSIVE_LUT_LUN"),
100  "VIIRS-SDR-REFLECTIVE-LUT":(8,"SDR_REFLECTIVE_LUT_LUN"),
101  "VIIRS-SDR-RVF-LUT":(17533440,"SDR_RVS_LUT_LUN"),
102  "VIIRS-SDR-BB-TEMP-COEFFS-LUT":(240,"SDR_BB_TEMP_CONSTANTS_LUN"),
103  "VIIRS-SDR-COEFF-A-LUT":(901120,"SDR_COEFF_A_LUT_LUN"),
104  "VIIRS-SDR-COEFF-B-LUT":(450560,"SDR_COEFF_B_LUT_LUN"),
105  "VIIRS-SDR-DELTA-C-LUT":(4505920,"SDR_DELTA_C_LUT_LUN"),
106  "VIIRS-SOLAR-DIFF-VOLT-LUT":(1280,"SOLAR_DIFF_VOLT_LUT_LUN"),
107  "VIIRS-SOLAR-DIFF-AGG-HISTORY-AUX-AC":(184,"SOLAR_DIFF_HIST_AGG_AUX_LUN"),
108  "VIIRS-SOLAR-DIFF-AGG-LUT":(1208,"SOLAR_DIFF_AGG_LUT_LUN"),
109  "VIIRS-SOLAR-DIFF-PROC-COEFFS-LUT":(176,"SOLAR_DIFF_PROC_COEFFS_LUN"),
110  "VIIRS-SOLAR-DIFF-REFL-LUT":(2296848,"SOLAR_DIFF_REFLECTANCE_LUT_LUN"),
111  "VIIRS-SOLAR-DIFF-ROT-MATRIX-LUT":(72,"SOLAR_DIFF_ROT_MAT_LUT_LUN"),
112  "VIIRS-SOLAR-DIFF-RVF-LUT":(7168,"SOLAR_DIFF_RVS_LUT_LUN"),
113  "VIIRS-SOLAR-DIFF-SDSM-BRDF-LUT":(19520,"SOLAR_DIFF_SDSM_BRDF_LUT_LUN"),
114  "VIIRS-SOLAR-DIFF-SDSM-TIME-LUT":(20,"SOLAR_DIFF_SDSM_TIME_LUT_LUN"),
115  "VIIRS-SOLAR-DIFF-SDSM-TRANS-SCREEN-LUT":(16608,"SOLAR_DIFF_SDSM_TRN_SCR_LUT_LUN"),
116  "VIIRS-SOLAR-DIFF-TRANS-SCREEN-LUT":(19520,"SOLAR_DIFF_TRANS_SCR_LUT_LUN"),
117  "VIIRS-SDR-CAL-AUTOMATE-LUT":(21408,"SDR_CAL_AUTOMATE_LUT_LUN"),
118  "VIIRS-SDR-ONBOARD-DNB-OFFSETS-LUT":(520192,"SDR_ONBOARD_DNB_OFFSETS_LUT_LUN"),
119  "VIIRS-SDR-DNB-GAIN-RATIOS-LUT":(27648,"SDR_DNB_GAIN_RATIOS_LUT_LUN"),
120  "VIIRS-SDR-DNB-LGS-GAINS-LUT":(27664,"SDR_DNB_LGS_GAINS_LUT_LUN"),
121  "VIIRS-SDR-DNB-STRAY-LIGHT-CORRECTION-LUT":(487943852,"SDR_DNB_STRAY_LIGHT_CORRECTION_LUT_LUN"),
122  "VIIRS-SDR-RELATIVE-SPECTRAL-RESPONSE-LUT":(240064,"SDR_RELATIVE_SPECTRAL_RESPONSE_LUT_LUN"),
123  "VIIRS-RSBAUTOCAL-BRDF-RTA-VIEW-LUT":(538832,"RSBAUTOCAL_BRDF_RTA_VIEW_LUT_LUN"),
124  "VIIRS-RSBAUTOCAL-BRDF-SDSM-VIEW-LUT":(158080,"RSBAUTOCAL_BRDF_SDSM_VIEW_LUT_LUN"),
125  "VIIRS-RSBAUTOCAL-DNB-DARK-SIGNAL-AUTOMATE-LUT":(147472,"RSBAUTOCAL_DNB_DARK_SIGNAL_AUTOMATE_LUT_LUN"),
126  "VIIRS-RSBAUTOCAL-DNB-GAIN-RATIOS-AUTOMATE-LUT":(41480,"RSBAUTOCAL_DNB_GAIN_RATIOS_AUTOMATE_LUT_LUN"),
127  "VIIRS-RSBAUTOCAL-DNB-LGS-GAIN-AUTOMATE-LUT":(32264,"RSBAUTOCAL_DNB_LGS_GAIN_AUTOMATE_LUT_LUN"),
128  "VIIRS-RSBAUTOCAL-DNB-MOON-ILLUMINATION-LUT":(175200,"RSBAUTOCAL_DNB_MOON_ILLUMINATION_LUT_LUN"),
129  "VIIRS-RSBAUTOCAL-H-AUTOMATE-LUT":(508,"RSBAUTOCAL_H_AUTOMATE_LUT_LUN"),
130  "VIIRS-RSBAUTOCAL-H-LUT":(624,"RSBAUTOCAL_H_LUT_LUN"),
131  "VIIRS-RSBAUTOCAL-ROT-MATRIX-LUT":(72,"RSBAUTOCAL_ROT_MATRIX_LUT_LUN"),
132  "VIIRS-RSBAUTOCAL-RSB-F-AUTOMATE-LUT":(50180,"RSBAUTOCAL_RSB_F_AUTOMATE_LUT_LUN"),
133  "VIIRS-RSBAUTOCAL-RVF-LUT":(7680,"RSBAUTOCAL_RVF_LUT_LUN"),
134  "VIIRS-RSBAUTOCAL-SDSM-SOLAR-SCREEN-TRANS-LUT":(106240,"RSBAUTOCAL_SDSM_SOLAR_SCREEN_TRANS_LUT_LUN"),
135  "VIIRS-RSBAUTOCAL-VOLT-LUT":(1280,"RSBAUTOCAL_VOLT_LUT_LUN"),
136  "VIIRS-RSBAUTOCAL-SDSM-TIME-LUT":(20,"RSBAUTOCAL_SDSM_TIME_LUT_LUN")
137  }
138 
139 
140 iopath_type = {"Sci-RDR-LIST":("#VIIRS_SCIENCE_RDR_LUN","Sci_RDR_List"),
141  "Sci-RDR-IN-PATH":("RDR_INPUT_PATH_LUN","Sci_RDR"),
142  "OBCIP-IN-PATH":("OBC_IP_INPUT_PATH_LUN","OBCIP_INPUT"),
143  "IP-STAGING-PATH":("IP_STAGING_PATH_LUN","STAGING"),
144  "VRDR-OUT-PATH":("VERIFIED_RDR_PATH_LUN","VRDR"),
145  "GEO-OUT-PATH":("GEO_OUTPUT_PATH_LUN","GEO"),
146  "DNB-OUT-PATH":("DAYNIGHT_SDR_OUTPUT_PATH_LUN","SDR_DNB"),
147  "IMG-OUT-PATH":("IMAGERY_SDR_OUTPUT_PATH_LUN","SDR_IMG"),
148  "MOD-OUT-PATH":("MODERATE_SDR_OUTPUT_PATH_LUN","SDR_MOD"),
149  "OBCIP-OUT-PATH":("OBC_IP_OUTPUT_PATH_LUN","OBCIP"),
150  "DGIP-OUT-PATH":("DUAL_GAIN_IP_OUTPUT_PATH_LUN","DGIP"),
151  "SD-OUT-PATH":("SD_OUTPUT_PATH_LUN","SD_HISTORY"),
152  "CAL-HISTORY-PATH":("RSBAUTOCAL_HISTORY_AUX_LUN","HISTORY"),
153  "OBCIP-HISTORY-PATH":("RSBAUTOCAL_OBCIP_HISTORY_AUX_LUN","HISTORY")
154  }
155 
156 
157 
158 class l1_file:
159  def __init__(self, arg1):
160  self.path, self.filename = os.path.split(arg1)
161  self.filepath = arg1
162  self.type = self.parseL1Type(self.filename)
163  self.date = self.parseL1Date(self.filename)
164  self.time = self.parseL1Time(self.filename)
165  self.corename = self.getCorename(self.filename)
166 
167  def display(self):
168  print(self.filepath + "/" + self.filename)
169  print(self.vtype, self.itype)
170  print(self.date, self.time)
171 
172  def getStartYMD(self):
173  y = int(self.date[0:4])
174  m = int(self.date[4:6])
175  d = int(self.date[6:8])
176  return y, m, d
177 
178  def getStartHMS(self):
179  s = self.time % 100
180  m = (self.time - s)/100 % 100
181  h = (self.time - m*100 - s)/10000
182  return h, m, s
183 
184  def getEndHMS(self):
185  s = self.endTime % 100
186  m = (self.endTime - s)/100 % 100
187  h = (self.endTime - m*100 - s)/10000
188  return h, m, s
189 
190  def getCorename(self, str):
191  pos = str.find(".L1B-M")
192  if (pos > 0):
193  return str[0:pos]
194  pos = str.find(".L1A_SNPP")
195  if (pos > 0):
196  return str[0:pos]
197  pos = str.find(".L1A_JPSS1")
198  if (pos > 0):
199  return str[0:pos]
200  pos = str.find(".nc")
201  if (pos > 0):
202  return str[0:pos]
203  return ""
204 
205  def setOutputPath(self, arg):
206  self.outputPath = arg
207  if not os.path.isdir(arg):
208  return False
209  else:
210  return True
211 
212  def getImgFilename(self):
213  self.ImgFilename = self.corename + ".L1B-I_SNPP.nc"
214  return self.ImgFilename
215 
216  def getModFilename(self):
217  self.ModFilename = self.corename + ".L1B-M_SNPP.nc"
218  return self.ModFilename
219 
220  def getDnbFilename(self):
221  self.DnbFilename = self.corename + ".L1B-D_SNPP.nc"
222  return self.DnbFilename
223 
224  def getObcFilename(self):
225  self.ObcFilename = self.corename + ".OBC_SNPP.nc"
226  return self.ObcFilename
227 
228  def getCdgFilename(self):
229  self.CdgFilename = self.corename + ".CDG_SNPP.nc"
230  return self.CdgFilename
231 
232  def getGeoIFilename(self):
233  self.GeoIFilename = self.corename + ".GEO-I_SNPP.nc"
234  return self.GeoIFilename
235 
236  def getGeoMFilename(self):
237  self.GeoMFilename = self.corename + ".GEO-M_SNPP.nc"
238  return self.GeoMFilename
239 
240  def getGeoDFilename(self):
241  self.GeoDFilename = self.corename + ".GEO-D_SNPP.nc"
242  return self.GeoDFilename
243 
244  def getDtFilename(self):
245  self.DtFilename = "DT_" + self.corename + ".nc"
246  return self.DtFilename
247 
248  def getDbFilename(self):
249  self.DbFilename = "DB_" + self.corename + ".nc"
250  return self.DbFilename
251 
252  def parseL1Type(self, str):
253  str_type = str[15:20]
254  if str.find(".nc") < 0:
255  return 0
256  elif str_type not in l1b_type:
257  return 0
258  else:
259  return l1b_type[str_type]
260 
261  def parseL1Date(self, str):
262  if str.startswith("OA"):
263  str_date = str[2:9]
264  elif str.startswith("VL1B"):
265  str_date = str[13:19]
266  elif str.startswith("PACE_OCI_SIM"):
267  str_date = str[13:21]
268  else:
269  str_date = str[1:8]
270  return str_date
271 
272  def parseL1Time(self, str):
273  if str.startswith("OA"):
274  str_time = str[9:15]
275  elif str.startswith("VL1B"):
276  str_time = str[22:28]
277  elif str.startswith("PACE_OCI_SIM"):
278  str_time = str[22:28]
279  else:
280  str_time = str[8:14]
281  return int(str_time)
282 
283 
284 class sdr_file:
285  def __init__(self, arg1):
286  self.path, self.filename = os.path.split(arg1)
287  self.filepath = arg1
288  self.vtype = self.parseVcstType(self.filename)
289  self.itype = self.parseIdpsType(self.filename)
290  self.date = self.parseSdrDate(self.filename)
292  self.endTime = self.parseSdrEndTime(self.filename)
293 
294  def display(self):
295  print(self.filepath + "/" + self.filename)
296  print(self.vtype, self.itype)
297  print(self.date, self.startTime, self.endTime)
298 
299  def getStartHMS(self):
300  s = self.startTime % 1000
301  m = (self.startTime - s)/1000 % 100
302  h = (self.startTime - m*1000 - s)/100000
303  return h, m, s
304 
305  def getEndHMS(self):
306  s = self.endTime % 1000
307  m = (self.endTime - s)/1000 % 100
308  h = (self.endTime - m*1000 - s)/100000
309  return h, m, s
310 
311  def parseVcstType(self, str):
312  if str.find("unscaled") > 0:
313  return 0
314  elif str.find(".h5") < 0:
315  return 0
316  elif str[:6] not in vcst_type:
317  return 0
318  else:
319  return vcst_type[str[:6]]
320 
321  def parseIdpsType(self, str):
322  if str[-3:] != ".h5":
323  return 0
324  elif str[:5] not in idps_type:
325  return 0
326  else:
327  return idps_type[str[:5]]
328 
329  def parseSdrDate(self, str):
330  pos = str.find("_d")
331  return int(str[pos+2:pos+10])
332 
333  def parseSdrStartTime(self, str):
334  pos = str.find("_t")
335  return int(str[pos+2:pos+9])
336 
337  def parseSdrEndTime(self, str):
338  pos = str.find("_e")
339  return int(str[pos+2:pos+9])
340 
341 
342 class lut_file:
343  def __init__(self, arg1,arg2):
344  if os.path.isdir(arg2):
345  self.path = arg2
346  self.filename = ""
347  else:
348  self.path, self.filename = os.path.split(arg2)
349  self.filepath = arg2
350  self.type = arg1
352  self.lptype = lut_type[self.type][1]
353 
354  def display(self):
355  print(self.filepath)
356  print(self.type)
357  print(self.date)
358 
359  def parseLutType(self, str):
360  path,filename = os.path.split(str)
361  pos = str.find("PolarWander")
362  if pos > 0:
363  return "CMNGEO-POLAR-WANDER-LUT"
364  pos = str.find("VIIRS-RSBAUTOCAL-BRDF-SCREEN-TRANSMISSION-PRODUCT-RTA-VIEW-LUT")
365  if pos >= 0:
366  return "VIIRS-RSBAUTOCAL-BRDF-RTA-VIEW-LUT"
367  pos = str.find("VIIRS-RSBAUTOCAL-BRDF-SCREEN-TRANSMISSION-PRODUCT-SDSM-VIEW-LUT")
368  if pos >= 0:
369  return "VIIRS-RSBAUTOCAL-BRDF-SDSM-VIEW-LUT"
370  pos = filename.find("_npp_")
371  if pos > 0:
372  s = filename[:pos]
373  if s in lut_type:
374  return s
375  return ""
376 
377  def parseLutDate(self, str):
378  pos = str.find("PolarWander")
379  if pos > 0:
380  return int(str[pos+35:pos+43])
381  pos = str.find("_npp_")
382  if pos > 0:
383  return int(str[pos+21:pos+29])
384  return 0
385 
386 
387  def parseVcstLutDate(self, str):
388  pos = str.find("_")
389  if pos > 0:
390  return int(str[pos+1:pos+9])
391  return 0
392 
393 
394 class io_path:
395  def __init__(self, arg1, arg2):
396  self.type = arg1
397  self.path = arg2
398  self.lptype = iopath_type[arg1][0]
399 
400  def display(self):
401  print(self.type)
402  print(self.path)
403 
404 
405 
def parseL1Type(self, str)
Definition: viirs_files.py:252
def parseSdrEndTime(self, str)
Definition: viirs_files.py:337
def getStartYMD(self)
Definition: viirs_files.py:172
def parseSdrDate(self, str)
Definition: viirs_files.py:329
def getStartHMS(self)
Definition: viirs_files.py:178
def __init__(self, arg1)
Definition: viirs_files.py:159
def parseVcstType(self, str)
Definition: viirs_files.py:311
def getImgFilename(self)
Definition: viirs_files.py:212
def getCorename(self, str)
Definition: viirs_files.py:190
def getCdgFilename(self)
Definition: viirs_files.py:228
def setOutputPath(self, arg)
Definition: viirs_files.py:205
def getObcFilename(self)
Definition: viirs_files.py:224
def parseLutType(self, str)
Definition: viirs_files.py:359
def getGeoDFilename(self)
Definition: viirs_files.py:240
def parseL1Time(self, str)
Definition: viirs_files.py:272
def getDtFilename(self)
Definition: viirs_files.py:244
def getGeoIFilename(self)
Definition: viirs_files.py:232
def getModFilename(self)
Definition: viirs_files.py:216
def parseVcstLutDate(self, str)
Definition: viirs_files.py:387
def parseIdpsType(self, str)
Definition: viirs_files.py:321
def getDnbFilename(self)
Definition: viirs_files.py:220
def parseL1Date(self, str)
Definition: viirs_files.py:261
def parseSdrStartTime(self, str)
Definition: viirs_files.py:333
def __init__(self, arg1)
Definition: viirs_files.py:285
def __init__(self, arg1, arg2)
Definition: viirs_files.py:395
def getGeoMFilename(self)
Definition: viirs_files.py:236
def __init__(self, arg1, arg2)
Definition: viirs_files.py:343
def parseLutDate(self, str)
Definition: viirs_files.py:377
def getDbFilename(self)
Definition: viirs_files.py:248