diff --git a/src/pyfaradaycup/decommutator/ccsds_reader_pipeline.py b/src/pyfaradaycup/decommutator/ccsds_reader_pipeline.py index 2e6b9f7..581a429 100644 --- a/src/pyfaradaycup/decommutator/ccsds_reader_pipeline.py +++ b/src/pyfaradaycup/decommutator/ccsds_reader_pipeline.py @@ -36,7 +36,6 @@ def _read_stdin(ptp: bool = False, verbose: bool = False) -> None: # ruff:ignor def _file2bytestr( path: str | os.PathLike[str], - verbose: bool = False, # ruff:ignore[ARG001, FBT001, FBT002] gzip: bool = False, # ruff:ignore[FBT001, FBT002] ) -> bytes: """ @@ -47,9 +46,6 @@ def _file2bytestr( path : str or path-like Path to the file to read. - verbose : bool, optional - Not currently used. - gzip : bool, optional If `True`, read the file as gzip-compressed. @@ -76,11 +72,7 @@ def _file2bytestr( raise RuntimeError(msg) from exc -def _choose_file( - path: str | os.PathLike[str], - ptp: bool = False, # ruff:ignore[ARG001, FBT001, FBT002] - verbose: bool = False, # ruff:ignore[ARG001, FBT001, FBT002] -) -> str: +def _choose_file(path: str | os.PathLike[str]) -> str: """ Check that a file can be opened and return its path. @@ -89,12 +81,6 @@ def _choose_file( path : str or path-like Path to the file to check. - ptp : bool, optional - Not currently used. - - verbose : bool, optional - Not currently used. - Returns ------- str @@ -121,7 +107,6 @@ def _choose_file( def _wrapper_status( path: str | os.PathLike[str], - verbose: bool = False, # ruff:ignore[ARG001, FBT001, FBT002] gzip: bool = False, # ruff:ignore[FBT001, FBT002] spconly: bool = False, # ruff:ignore[FBT001, FBT002] ) -> dict[str, list[int]]: @@ -133,9 +118,6 @@ def _wrapper_status( path : str or path-like Path to the CCSDS file to read. - verbose : bool, optional - Not currently used. - gzip : bool, optional If `True`, read the file as gzip-compressed. @@ -204,8 +186,6 @@ def _wrapper_status( except: # ruff:ignore[E722] return data - npackets = len(pkt_starts) # ruff:ignore[F841] - # Loop through each packet beginning and decommutate it for i_pointer, pointer in enumerate(pkt_starts): # ruff:ignore[B007] wrap_cchead = _parse_ccsds_head(bytestr[pointer : pointer + 10]) @@ -287,7 +267,7 @@ def read_file( # ruff:ignore[C901] # Loop through each packet beginning and decommutate it for i_pointer, pointer in enumerate(pkt_starts): - foo = _read_bytestr( # ruff:ignore[F841] + _ = _read_bytestr( bytestr, pointer + 12, data, apidformat, pktcnt, verbose=verbose ) @@ -563,7 +543,7 @@ def _read_bytestr( # ruff:ignore[C901, PLR0912, PLR0913] # parse the packet and add decommed values to data variable _parse_pkt( - thispkt, data, apidformat, apid, ccsds_head + thispkt, data, apidformat, apid ) # could send this off to a parallel task? Might try that if too slow this way elif apid in pktcnt[1].keys(): # ruff:ignore[SIM118] @@ -574,7 +554,7 @@ def _read_bytestr( # ruff:ignore[C901, PLR0912, PLR0913] return () -def _parse_ccsds_head(bytestr: bytes, verbose: bool = False) -> dict[str, int]: # ruff:ignore[ARG001, FBT001, FBT002] +def _parse_ccsds_head(bytestr: bytes) -> dict[str, int]: """ Decode a 10-byte CCSDS packet header into its fields. @@ -583,9 +563,6 @@ def _parse_ccsds_head(bytestr: bytes, verbose: bool = False) -> dict[str, int]: bytestr : bytes The header bytes. Only the first 10 bytes are used. - verbose : bool, optional - Not currently used. - Returns ------- dict of str to int @@ -627,13 +604,11 @@ def _parse_ccsds_head(bytestr: bytes, verbose: bool = False) -> dict[str, int]: return head -def _parse_pkt( # ruff:ignore[C901, PLR0912, PLR0913] +def _parse_pkt( # ruff:ignore[C901, PLR0912] bytestr: bytes, data: dict[int, dict[str, list]], apidformat, # ruff:ignore[ANN001] apid: int, - ccsds_head: dict[str, int], # ruff:ignore[ARG001] - verbose: bool = False, # ruff:ignore[ARG001, FBT001, FBT002] ) -> None: """Parse one CCSDS packet""" # ruff:ignore[D400] # The format for this APIDs packet list @@ -697,7 +672,6 @@ def _parse_pkt( # ruff:ignore[C901, PLR0912, PLR0913] thisval = int(thisbin, 2) except: # ruff:ignore[E722] raise RuntimeError # ruff:ignore[B904] - thisval = -999 thisname = form.names[i_bit] # store in our data variable @@ -724,7 +698,6 @@ def _parse_pkt( # ruff:ignore[C901, PLR0912, PLR0913] thisval = int(thisbin, 2) except ValueError: raise ValueError # ruff:ignore[B904] - thisval = -999 thisname = form.sw_data_vars[i] newdat[thisname].append(thisval) @@ -820,10 +793,6 @@ def _get_layout(apid: int, verbose: bool = False) -> apid_obj | None: # ruff:ig "***INFO*** 'sweap_tlm.blk' not found...using the one in src/pyfaradaycup/data" ) try: - # here = os.path.dirname(__file__) - # thisdir = os.path.realpath(__file__) - # thisdir = "\\".join(thisdir.split("\\")[0:-1]) - # print(f"{thisdir = }") file = (data_dir / "sweap_tlm.blk").open() except: # ruff:ignore[E722] # print(here) diff --git a/src/pyfaradaycup/decommutator/swp_spc_l02l1.py b/src/pyfaradaycup/decommutator/swp_spc_l02l1.py index aad4c89..bde2260 100644 --- a/src/pyfaradaycup/decommutator/swp_spc_l02l1.py +++ b/src/pyfaradaycup/decommutator/swp_spc_l02l1.py @@ -131,7 +131,7 @@ def main( # ruff:ignore[C901, PLR0912, PLR0913, PLR0915, PLR0917] msg = f"Could not open log file: {logpath}" raise RuntimeError(msg) from exc # Write some information to the log file - _statusmsg("scriptname = swp_spc_l02l1.py", verbose=verbose) + _statusmsg("filename = swp_spc_l02l1.py", verbose=verbose) _statusmsg("timerun = " + nowdt.isoformat(), verbose=verbose) _statusmsg(f"l0file = {l0file}", verbose=verbose) _statusmsg(f"l1dir = {l1dir}", verbose=verbose) @@ -338,7 +338,7 @@ def main( # ruff:ignore[C901, PLR0912, PLR0913, PLR0915, PLR0917] logfile.close() -def _cdf35e_35f(cdf: pycdf.CDF, dat: dict[str, list], verbose: bool = False) -> None: # ruff:ignore[C901, FBT001, FBT002] +def _cdf35e_35f(cdf: pycdf.CDF, dat: dict[str, list], verbose: bool = False) -> None: # ruff:ignore[ARG001, C901, FBT001, FBT002] """ Fill a CDF with housekeeping data, one row per packet. @@ -356,8 +356,8 @@ def _cdf35e_35f(cdf: pycdf.CDF, dat: dict[str, list], verbose: bool = False) -> each mnemonic. verbose : bool, optional - If `True`, print error messages to the screen as well as to the - log file. + Not currently used. Accepted so that `main` can call each CDF + writer with the same arguments. Notes ----- @@ -425,14 +425,8 @@ def _cdf35e_35f(cdf: pycdf.CDF, dat: dict[str, list], verbose: bool = False) -> if key not in dat.keys(): # ruff:ignore[SIM118] cdf[key] = np.ones(len(dat["Epoch"])) * cdf[key].attrs["FILLVAL"] except: # ruff:ignore[E722] - raise RuntimeError # ruff:ignore[B904] - - _statusmsg( - f"Failed : Key:{key} failed insert into CDF", - screen=True, - verbose=verbose, - ) - _statusmsg(sys.exc_info()) + msg = f"Failed : Key:{key} failed insert into CDF" + raise RuntimeError(msg) # ruff:ignore[B904] def _cdf351_353_354( # ruff:ignore[C901, PLR0912, PLR0915, RET503] @@ -501,9 +495,6 @@ def _cdf351_353_354( # ruff:ignore[C901, PLR0912, PLR0915, RET503] # MET of each NYS scet = _secsubsec2scet(dat["CCSDS_MET"], dat["SW_SPCSUBSEC"]) - # MET of each measurement (to be filled in in the future) - scet_exp = [] # ruff:ignore[F841] - # Same keys as original data dictionary, but will hold one variable per key # instead of one for every NYS for every key dat_exp = {} @@ -822,7 +813,6 @@ def _secsubsec2scet( sec: list[int], subsec: list[int], spacecraft: bool = False, # ruff:ignore[FBT001, FBT002] - verbose: bool = False, # ruff:ignore[ARG001, FBT001, FBT002] ) -> list[float]: """ Convert MET seconds and subseconds to ephemeris time in nanoseconds. @@ -843,9 +833,6 @@ def _secsubsec2scet( spacecraft packets. If `False`, ``subsec`` is in units of 1/65536 second, as used in SWEAP packets. - verbose : bool, optional - Not currently used. - Returns ------- list of float @@ -919,7 +906,6 @@ def _statusmsg( def _get_newest_kernel( tls: bool = False, # ruff:ignore[FBT001, FBT002] sclk: bool = False, # ruff:ignore[FBT001, FBT002] - verbose: bool = False, # ruff:ignore[ARG001, FBT001, FBT002] ) -> str: """ Find the newest NAIF leap second or PSP clock (SCLK) kernel file. @@ -936,9 +922,6 @@ def _get_newest_kernel( If `True`, find the newest PSP clock kernel (``spp_sclk_NNNN.tsc``). - verbose : bool, optional - Not currently used. - Returns ------- str @@ -955,10 +938,9 @@ def _get_newest_kernel( package data directory, ``src/pyfaradaycup/data/``. The version number is read from the digits at the end of the file name. """ - # Make sure we chose exactly one of the options + # Choose exactly one of the options if tls + sclk != 1: raise RuntimeError("Need exactly one of tls or sclk") # ruff:ignore[EM101, TRY003] - return False # TODO: make this less hardcoded to the directory # ruff:ignore[FIX002, TD002, TD003] # Kristoff said that there's a spacepy(.pycdf?) command that regenerates @@ -991,7 +973,7 @@ def _get_newest_kernel( return str(files[maxind]) -def _get_newest_skeleton(apid: int, verbose: bool = False) -> str: # ruff:ignore[ARG001, FBT001, FBT002] +def _get_newest_skeleton(apid: int) -> str: """ Return the path to the skeleton CDF file for an APID. @@ -1000,9 +982,6 @@ def _get_newest_skeleton(apid: int, verbose: bool = False) -> str: # ruff:ignor apid : int The APID of the skeleton file, such as ``0x352``. - verbose : bool, optional - Not currently used. - Returns ------- str @@ -1022,26 +1001,3 @@ def _get_newest_skeleton(apid: int, verbose: bool = False) -> str: # ruff:ignor / "cdf_skeletons" / f"psp_swp_spc_l1_{hex(apid)[2:].zfill(3)}_skeleton.cdf" # ruff:ignore[FURB116] ) - - # The remaining code in this function is from when we used skeleton file numbers with a version # in them - # and we had to search for the most recent (highest) version - - # Search for newest file - # globstr = 'cdf_skeletons/spp_apid_{:}_sweap_00000000t000000_v[0-9][0-9].cdf'.format(hex(apid)[2:].zfill(3)) - # ndigits = 2 - - # files = glob.glob(globstr) - - # isolate version numbers from the file path and find newest - # versions = [int(i[-4-ndigits:-4]) for i in files] - - # try: - # maxind = np.argmax(versions) - # except ValueError: - # _statusmsg('***ERROR*** Could not find skeleton versions') - # return(False) - - # return path to newest file - # path = files[maxind] - - # return(path)