Commit a6f1918bf92c655eee66ac28918ea4ff6f7da31c

Authored by Alain Klotz
1 parent 27fdb984
Exists in master

Add the file context type PyROS.fil.1

Showing 1 changed file with 149 additions and 24 deletions   Show diff stats
src/guitastro/filenames.py
... ... @@ -291,13 +291,14 @@ class FileNames(FileNamesException, GuitastroTools):
291 291 VERBOSE_ALL = 8
292 292  
293 293 NAMING_NONE = 0
294   - NAMING_PYROS_IMG1 = 1
295   - NAMING_PYROS_EPH1 = 2
296   - NAMING_PYROS_SEQ1 = 3
297   - NAMING_ROS1 = 4
298   - NAMING_T1M1 = 5
299   - NAMING_INDEXED1 = 6
300   - _naming_list = ["", "PyROS.img.1", "PyROS.eph.1", "PyROS.seq.1", "ROS.1", "T1M.1", "Indexed.1"]
  294 + NAMING_INDEXED1 = 1
  295 + NAMING_ROS1 = 2
  296 + NAMING_T1M1 = 3
  297 + NAMING_PYROS_IMG1 = 4
  298 + NAMING_PYROS_EPH1 = 5
  299 + NAMING_PYROS_SEQ1 = 6
  300 + NAMING_PYROS_FIL1 = 7
  301 + _naming_list = ["", "Indexed.1", "ROS.1", "T1M.1", "PyROS.img.1", "PyROS.eph.1", "PyROS.seq.1", "PyROS.fil.1"]
301 302 _naming_0_stypes = ["C0A", "L0A", "L1A", "L1B", "L1C", "L1D", "L1E", "L2A", "DA0", "DA1", "FL0", "FL1", "BI0", "BI1"]
302 303 _naming_1_stypes = ["AL", "IM", "BI", "DA", "FL"]
303 304 _see_naming_rules = ". See method naming_rules() to get rules"
... ... @@ -488,6 +489,41 @@ class FileNames(FileNamesException, GuitastroTools):
488 489 texte += "CCC is a Channel for L0A, L1A, L1B, L1C ftype levels but should be the Album for L1D level"
489 490 return texte
490 491  
  492 + def __naming_rules_pyros_fil1(self, section):
  493 + name = self._naming_list[self.fcontext_value('naming')]
  494 + texte = ""
  495 + if section == self._NAMING_RULES_SECTION_DATE:
  496 + texte += "2023-09-13T21:05:13"
  497 + elif section == self._NAMING_RULES_SECTION_INTRO:
  498 + texte +=f"{name} is a file name format for the flats of Python Robotic Observatory Software.\n"
  499 + texte += "Specific terminology:\n"
  500 + texte += "* Unit: The set of Mount and Channels that define a 'telescope'.\n"
  501 + texte += "* Channel: An optical path + camera of a Unit. A unit can have many Channels.\n"
  502 + texte += "* Album: A set of Channels for which data can be combined by post processing.\n"
  503 + texte += "* Sequence: A set of Albums. A sequence is a hierarchy Channels/Planes/Frames.\n"
  504 + texte += "* Plane: A set of Frames. A Plane is composed by Frames.\n"
  505 + texte += "* Filter: A symbol of a filter (e.g. 'rp').\n"
  506 + elif section == self._NAMING_RULES_SECTION_FORMAT:
  507 + texte += " 1 2 3 4 5\n"
  508 + texte += "0123456789 123456789 123456789 123456789 123456789 123\n"
  509 + texte += "TTT_YYYYMMDD_hhmmsscccccc_V_UUU_CCC_IIIIIIIIII_PPP_f*\n"
  510 + texte += "\n"
  511 + texte +=f"TTT = 'ftype' = file type amongst {self._naming_0_stypes}\n"
  512 + texte += "YYYYMMDD = 'date' = Year Month Day. e.g. 20221109\n"
  513 + texte += "hhmmsscccccc = 'time' = Hours Minutes Seconds Microseconds. e.g. 235604123456\n"
  514 + texte += "V = 'version' = Version of the naming rule. e.g. 1\n"
  515 + texte += "UUU = 'unit' = Telescope unit. e.g. TNC\n"
  516 + texte += "CCC = 'channel' = Optical channel designation. e.g. CH1\n"
  517 + texte += "IIIIIIIIII = 'id_seq' = ID of the file in the database. e.g. 0000001234\n"
  518 + texte += "PPP = 'plane' = index of the plane. e.g. 001\n"
  519 + texte += "f* = 'filter' = Filter symbol. e.g. rp\n"
  520 + elif section == self._NAMING_RULES_SECTION_REMARKS:
  521 + texte += "Example: FL1_20221109_235406123456_1_TNC_CH1_0123456789_001_rp\n"
  522 + texte += "UUU, CCC are accronyms (string)\n"
  523 + texte += "V, IIIIIIIIII, PPP, are digits (int)\n"
  524 + texte += "f* is a string (string)\n"
  525 + return texte
  526 +
491 527 def __naming_rules_pyros_eph1(self, section):
492 528 name = self._naming_list[self.fcontext_value('naming')]
493 529 texte = ""
... ... @@ -657,6 +693,8 @@ class FileNames(FileNamesException, GuitastroTools):
657 693 dat = self.__naming_rules_t1m1(self._NAMING_RULES_SECTION_DATE)
658 694 elif self.fcontext_value('naming') == self.NAMING_INDEXED1:
659 695 dat = self.__naming_rules_indexed1(self._NAMING_RULES_SECTION_DATE)
  696 + elif self.fcontext_value('naming') == self.NAMING_PYROS_FIL1:
  697 + dat = self.__naming_rules_pyros_fil1(self._NAMING_RULES_SECTION_DATE)
660 698 if dat != "":
661 699 texte +=f"Updated on {dat}\n"
662 700 texte +=f"Written on {date_iso}\n"
... ... @@ -678,6 +716,8 @@ class FileNames(FileNamesException, GuitastroTools):
678 716 texte += self.__naming_rules_t1m1(self._NAMING_RULES_SECTION_INTRO)
679 717 elif self.fcontext_value('naming') == self.NAMING_INDEXED1:
680 718 texte += self.__naming_rules_indexed1(self._NAMING_RULES_SECTION_INTRO)
  719 + elif self.fcontext_value('naming') == self.NAMING_PYROS_FIL1:
  720 + texte += self.__naming_rules_pyros_fil1(self._NAMING_RULES_SECTION_INTRO)
681 721 # ---
682 722 h1 = "2. Format of the file names"
683 723 texte +=f"\n{h1}\n" + "="*len(h1) + "\n\n"
... ... @@ -693,6 +733,8 @@ class FileNames(FileNamesException, GuitastroTools):
693 733 texte += self.__naming_rules_t1m1(self._NAMING_RULES_SECTION_FORMAT)
694 734 elif self.fcontext_value('naming') == self.NAMING_INDEXED1:
695 735 texte += self.__naming_rules_indexed1(self._NAMING_RULES_SECTION_FORMAT)
  736 + elif self.fcontext_value('naming') == self.NAMING_PYROS_FIL1:
  737 + texte += self.__naming_rules_pyros_fil1(self._NAMING_RULES_SECTION_FORMAT)
696 738 # ---
697 739 h1 = "3. Remarks"
698 740 texte +=f"\n{h1}\n" + "="*len(h1) + "\n\n"
... ... @@ -708,6 +750,8 @@ class FileNames(FileNamesException, GuitastroTools):
708 750 texte += self.__naming_rules_t1m1(self._NAMING_RULES_SECTION_REMARKS)
709 751 elif self.fcontext_value('naming') == self.NAMING_INDEXED1:
710 752 texte += self.__naming_rules_indexed1(self._NAMING_RULES_SECTION_REMARKS)
  753 + elif self.fcontext_value('naming') == self.NAMING_PYROS_FIL1:
  754 + texte += self.__naming_rules_pyros_fil1(self._NAMING_RULES_SECTION_REMARKS)
711 755 # ---
712 756 texte += "\n\n=== End of the Document ==="
713 757 return texte
... ... @@ -869,6 +913,30 @@ class FileNames(FileNamesException, GuitastroTools):
869 913 except:
870 914 pass
871 915 self.fcontext_value('naming', old_naming)
  916 + # --- Try NAMING_PYROS_FIL1
  917 + if n >= 9:
  918 + param = {}
  919 + param['ftype'] = words[0]
  920 + param['date'] = words[1]
  921 + param['time'] = words[2]
  922 + param['version'] = words[3]
  923 + param['unit'] = words[4]
  924 + param['channel'] = words[5]
  925 + param['id_seq'] = words[6]
  926 + param['plane'] = words[7]
  927 + k8 = 0
  928 + for k in range(8):
  929 + k8 += len(words[k]) + 1
  930 + param['filter'] = fname[k8:]
  931 + old_naming = self.fcontext_value('naming')
  932 + self.fcontext_value('naming', self.NAMING_PYROS_FIL1)
  933 + try:
  934 + fname_verified = self.naming_set(**param)
  935 + if fname == fname_verified:
  936 + naming = self.NAMING_PYROS_FIL1
  937 + except:
  938 + pass
  939 + self.fcontext_value('naming', old_naming)
872 940 if naming == self.NAMING_NONE:
873 941 # Any other formats can reasch the indexed rules
874 942 naming = self.NAMING_INDEXED1
... ... @@ -930,6 +998,33 @@ class FileNames(FileNamesException, GuitastroTools):
930 998 fname_verified = self.naming_set(**param)
931 999 if fname != fname_verified:
932 1000 raise FileNamesException(FileNamesException.BAD_FILENAME_RULE)
  1001 + elif self.fcontext_value('naming') == self.NAMING_PYROS_FIL1:
  1002 + n = len(fname)
  1003 + nn = 52
  1004 + if n < nn:
  1005 + texte =f"File name '{fname}' must be a string of at less {nn} characters" + see_rules
  1006 + raise FileNamesException(FileNamesException.BAD_FILENAME_RULE, texte)
  1007 + words = fname.split("_")
  1008 + n = len(words)
  1009 + nn = 9
  1010 + if n < nn:
  1011 + texte =f"File name '{fname}' must contain at less {nn-1} underscore characters" + see_rules
  1012 + raise FileNamesException(FileNamesException.BAD_FILENAME_RULE, texte)
  1013 + param['ftype'] = words[0]
  1014 + param['date'] = words[1]
  1015 + param['time'] = words[2]
  1016 + param['version'] = words[3]
  1017 + param['unit'] = words[4]
  1018 + param['channel'] = words[5]
  1019 + param['id_seq'] = words[6]
  1020 + param['plane'] = words[7]
  1021 + k8 = 0
  1022 + for k in range(8):
  1023 + k8 += len(words[k]) + 1
  1024 + param['filter'] = fname[k8:]
  1025 + fname_verified = self.naming_set(**param)
  1026 + if fname != fname_verified:
  1027 + raise FileNamesException(FileNamesException.BAD_FILENAME_RULE)
933 1028 elif self.fcontext_value('naming') == self.NAMING_PYROS_EPH1:
934 1029 n = len(fname)
935 1030 nn = 20
... ... @@ -1137,6 +1232,8 @@ class FileNames(FileNamesException, GuitastroTools):
1137 1232 wildcard = "*"
1138 1233 elif self.fcontext_value('naming') == self.NAMING_PYROS_IMG1:
1139 1234 wildcard = "???_????????_????????????_?_???_???_??????????_???_???"
  1235 + elif self.fcontext_value('naming') == self.NAMING_PYROS_FIL1:
  1236 + wildcard = "???_????????_????????????_?_???_???_??????????_???_*"
1140 1237 elif self.fcontext_value('naming') == self.NAMING_PYROS_EPH1:
1141 1238 wildcard = "????_????????_?_???_*"
1142 1239 elif self.fcontext_value('naming') == self.NAMING_PYROS_SEQ1:
... ... @@ -1191,7 +1288,7 @@ class FileNames(FileNamesException, GuitastroTools):
1191 1288 if self.fcontext_value('naming') == self.NAMING_NONE:
1192 1289 if na > 0:
1193 1290 fname = args[0]
1194   - if self.fcontext_value('naming') == self.NAMING_PYROS_IMG1:
  1291 + if self.fcontext_value('naming') == self.NAMING_PYROS_IMG1 or self.fcontext_value('naming') == self.NAMING_PYROS_FIL1:
1195 1292 if na > 0:
1196 1293 # case the dict is not **kwargs but *args
1197 1294 if isinstance(args[0], dict):
... ... @@ -1213,7 +1310,10 @@ class FileNames(FileNamesException, GuitastroTools):
1213 1310 param['channel'] = wildcards[5]
1214 1311 param['id_seq'] = wildcards[6]
1215 1312 param['plane'] = wildcards[7]
1216   - param['frame'] = wildcards[8]
  1313 + if self.fcontext_value('naming') == self.NAMING_PYROS_IMG1:
  1314 + param['frame'] = wildcards[8]
  1315 + else:
  1316 + param['filter'] = wildcards[8]
1217 1317 if nk > 0:
1218 1318 for key, val in kwargs.items():
1219 1319 if key in param.keys():
... ... @@ -1319,19 +1419,34 @@ class FileNames(FileNamesException, GuitastroTools):
1319 1419 raise FileNamesException(FileNamesException.BAD_PARAM, texte)
1320 1420 # --- verify frame
1321 1421 valid = False
1322   - if isinstance(param['frame'],str):
1323   - if param['frame'] == wildcards[8]:
1324   - valid = True
1325   - elif len(param['frame']) == 3:
  1422 + if self.fcontext_value('naming') == self.NAMING_PYROS_IMG1:
  1423 + if isinstance(param['frame'],str):
  1424 + if param['frame'] == wildcards[8]:
  1425 + valid = True
  1426 + elif len(param['frame']) == 3:
  1427 + valid = True
  1428 + elif isinstance(param['frame'],int):
  1429 + param['frame'] = f"{param['frame']:03d}"
1326 1430 valid = True
1327   - elif isinstance(param['frame'],int):
1328   - param['frame'] = f"{param['frame']:03d}"
1329   - valid = True
1330   - if valid == False:
1331   - texte = f"Frame {param['frame']} must be a string of 3 characters or an integer" + see_rules
1332   - raise FileNamesException(FileNamesException.BAD_PARAM, texte)
  1431 + if valid == False:
  1432 + texte = f"Frame {param['frame']} must be a string of 3 characters or an integer" + see_rules
  1433 + raise FileNamesException(FileNamesException.BAD_PARAM, texte)
  1434 + else:
  1435 + if isinstance(param['filter'],int):
  1436 + param['filter'] = str(param['filter'])
  1437 + if isinstance(param['filter'],str):
  1438 + if param['filter'] == wildcards[8]:
  1439 + valid = True
  1440 + elif len(param['filter']) >= 1:
  1441 + valid = True
  1442 + if valid == False:
  1443 + texte = f"Frame {param['frame']} must be a string of at less 1 character or an integer" + see_rules
  1444 + raise FileNamesException(FileNamesException.BAD_PARAM, texte)
1333 1445 # --- form final file name
1334   - fname = param['ftype']+"_"+param['date']+"_"+param['time']+"_"+param['version']+"_"+param['unit']+"_"+param['channel']+"_"+param['id_seq']+"_"+param['plane']+"_"+param['frame']
  1446 + if self.fcontext_value('naming') == self.NAMING_PYROS_IMG1:
  1447 + fname = param['ftype']+"_"+param['date']+"_"+param['time']+"_"+param['version']+"_"+param['unit']+"_"+param['channel']+"_"+param['id_seq']+"_"+param['plane']+"_"+param['frame']
  1448 + else:
  1449 + fname = param['ftype']+"_"+param['date']+"_"+param['time']+"_"+param['version']+"_"+param['unit']+"_"+param['channel']+"_"+param['id_seq']+"_"+param['plane']+"_"+param['filter']
1335 1450 if self.fcontext_value('naming') == self.NAMING_PYROS_EPH1:
1336 1451 if na > 0:
1337 1452 # case the dict is not **kwargs but *args
... ... @@ -2312,10 +2427,12 @@ class FileNames(FileNamesException, GuitastroTools):
2312 2427 self.fcontext_value('naming', self.fcontext_value('pathnaming'))
2313 2428 if self.fcontext_value('pathnaming') == self.NAMING_PYROS_IMG1:
2314 2429 self.fcontext_value('pathing', self.PATHING_YYYYMMDD)
2315   - if self.fcontext_value('pathnaming') == self.NAMING_PYROS_EPH1:
  2430 + elif self.fcontext_value('pathnaming') == self.NAMING_PYROS_EPH1:
2316 2431 self.fcontext_value('pathing', self.PATHING_PPPP_YYYYMMDD)
2317   - if self.fcontext_value('pathnaming') == self.NAMING_PYROS_SEQ1:
  2432 + elif self.fcontext_value('pathnaming') == self.NAMING_PYROS_SEQ1:
2318 2433 self.fcontext_value('pathing', self.PATHING_PPPP_YYYYMMDD)
  2434 + elif self.fcontext_value('pathnaming') == self.NAMING_PYROS_FIL1:
  2435 + self.fcontext_value('pathing', self.PATHING_YYYYMMDD)
2319 2436 return self._naming_list[self.fcontext_value('pathnaming')]
2320 2437  
2321 2438 def pathnaming_set(self, pkw:dict, nkw:dict, extension="") -> str:
... ... @@ -2354,6 +2471,8 @@ class FileNames(FileNamesException, GuitastroTools):
2354 2471  
2355 2472 The answer should be '/tmp\\2021\\10\\26\\L0_20211026_134522999983_1_TNC_CH1_0123456789_001_001.fits'
2356 2473 """
  2474 + path = ""
  2475 + fname = ""
2357 2476 if self.fcontext_value('pathnaming') == self.NAMING_PYROS_IMG1:
2358 2477 path = self.pathing_set(**pkw)
2359 2478 fname = self.naming_set(**nkw)
... ... @@ -2363,6 +2482,9 @@ class FileNames(FileNamesException, GuitastroTools):
2363 2482 if self.fcontext_value('pathnaming') == self.NAMING_PYROS_SEQ1:
2364 2483 path = self.pathing_set(**pkw)
2365 2484 fname = self.naming_set(**nkw)
  2485 + if self.fcontext_value('pathnaming') == self.NAMING_PYROS_FIL1:
  2486 + path = self.pathing_set(**pkw)
  2487 + fname = self.naming_set(**nkw)
2366 2488 fullname = os.path.join(path, fname) + extension
2367 2489 return fullname
2368 2490  
... ... @@ -2389,6 +2511,9 @@ class FileNames(FileNamesException, GuitastroTools):
2389 2511 if self.fcontext_value('pathnaming') == self.NAMING_PYROS_SEQ1:
2390 2512 pkw = self.pathing_get(filename)
2391 2513 nkw = self.naming_get(filename)
  2514 + if self.fcontext_value('pathnaming') == self.NAMING_PYROS_FIL1:
  2515 + pkw = self.pathing_get(filename)
  2516 + nkw = self.naming_get(filename)
2392 2517 return pkw, nkw
2393 2518  
2394 2519 def subdir_from_filename(self, filename:str, outfname:bool = False)->str:
... ... @@ -2416,7 +2541,7 @@ class FileNames(FileNamesException, GuitastroTools):
2416 2541 fname = nkw['fname']
2417 2542 else:
2418 2543 fname = self.naming_set(nkw)
2419   - if self.fcontext_value('pathnaming') == self.NAMING_PYROS_IMG1:
  2544 + if self.fcontext_value('pathnaming') == self.NAMING_PYROS_IMG1 or self.fcontext_value('pathnaming') == self.NAMING_PYROS_FIL1:
2420 2545 d = nkw['date']
2421 2546 t = nkw['time']
2422 2547 date = d[0:4]+"-"+d[4:6]+"-"+d[6:8]+"T"+t[0:2]+":"+t[2:4]+":"+t[4:6]
... ... @@ -2427,7 +2552,7 @@ class FileNames(FileNamesException, GuitastroTools):
2427 2552 fullname = self.pathnaming_set(pparam, nkw)
2428 2553 #print(f"fullname={fullname}")
2429 2554 subdir = os.path.dirname(fullname)
2430   - if self.fcontext_value('pathnaming') == self.NAMING_PYROS_SEQ1:
  2555 + if self.fcontext_value('pathnaming') == self.NAMING_PYROS_SEQ1 or self.fcontext_value('pathnaming') == self.NAMING_PYROS_EPH1:
2431 2556 pparam = {}
2432 2557 pparam['period'] = nkw['period']
2433 2558 pparam['night'] = nkw['date']
... ...