Commit b3c1d90b authored by vertighel's avatar vertighel
Browse files

Simplified parsing. Still an issue with OPC because it is BITPIX -32

parent 8cd7bd65
Loading
Loading
Loading
Loading
Loading
+10 −27
Original line number Diff line number Diff line
@@ -120,7 +120,7 @@ class Noche:
                    val, comment = value, None

                val = self._parse(val)
                log.debug(f"{k:<11}: initializing with: {val} / {comment}")
                log.info(f"{k:<11}: initializing with: {val} / {comment}")
                self.header[k] = val, comment
                # Filling the header dict with format info too.
                self._header_dict[k] = (val, typ, fmt, comment)
@@ -148,15 +148,14 @@ class Noche:
        # default val (_) and comment( __) are not used.
        _, typ, fmt, __ = self._header_dict[k.lower()]

        val = self._parse(val)
        #val = self._parse(val)
            
        if typ.strip() == "float":
            with custom_float():
                if val:
                    val = header_round(val, int(fmt))
                elif val == 0.0:
                    val = header_round(val, int(fmt))                
                else:
                    if val == None:
                        val = None
         
        self.header[k] = val
@@ -654,7 +653,9 @@ class Noche:
        except AttributeError as e:
            pass
        
        if not val:
        if val == "":
            val = None
        elif val == None:
            val = None            
        else:
            try:
@@ -676,21 +677,3 @@ class Noche:
        return val


    def _parse2(self, val, typ, fmt):
        type_mapping = {
            "bool": bool,
            "float": float,
            "int": int,
            "str": str,
        }

        if typ in type_mapping:
            the_type = type_mapping[typ.strip()]
            val = the_type(val)
            if typ.strip() == "float":
                val = header_round(val, fmt)
        else:
            log.error(f"Not supported type: {typ}")

        return val
+2 −1
Original line number Diff line number Diff line
@@ -118,6 +118,7 @@ class TestNoche(unittest.TestCase):
    """
    pass


# Popolamento dinamico della classe TestNoche con i metodi di test
for obs_name, file_path in TEST_FILES:
    test_func = create_test_for_file(obs_name, file_path)