Esempio n. 1
0
    def __init__(self, gp):
        """
        Constructor
        """

        binaryfile = gp.binaryfile

        length = read_half(binaryfile)
        actual_position = binaryfile.tell()
        p_end_offset = actual_position + length - 2

        logger.debug("Packet 24: SCIT Forecast Position Data")
        logger.debug("Length of Data Block (in bytes) = %hd" % length)

        while (actual_position < p_end_offset):
            p_packet_code = read_half(binaryfile)
            if (p_packet_code == 6):  # TODO also posible 2 or 25
                if gp.pdb.MH_msg_code == 141:
                    package = Package_6(gp, gp.mesocyclone.set_line_forecast)
                if gp.pdb.MH_msg_code == 58:
                    package = Package_6(gp, gp.storm.set_line_forecast)
            else:
                binaryfile.seek(read_half(binaryfile), 1)
                logger.warning("Packet code %i not handled yet!!!" %
                               p_packet_code)

            actual_position = binaryfile.tell()
Esempio n. 2
0
    def __init__(self, gp):
        '''
        Constructor
        '''
        length = read_half(gp.binaryfile)
        num = length >> 3

        # in this packet there are 4 fields (8 bytes) to be
        # written for each symbol
        for i in range(num):
            ipos = read_half(gp.binaryfile)
            jpos = read_half(gp.binaryfile)
            FeatureType = read_half(gp.binaryfile)
            attribute = read_half(gp.binaryfile)

            logger.debug("Packet 20: Generic Point Feature")
            logger.debug("Packet 20: Length=%4hd  Number Included=%hd" %
                         (length, num))
            logger.debug("""  I Pos: %4hd  J Pos: %4hd  Feature Type: %hd                              
                                             Attribute: %hd""" % \
                        (ipos,jpos,FeatureType,attribute))

        if gp.pdb.MH_msg_code != 141:
            logger.warning(
                "This package is intended for product 141 by now!!!")

        gp.mesocyclone = Mesocyclone(ipos, jpos, FeatureType, attribute, gp)
Esempio n. 3
0
    def __init__(self, gp):
        '''
        Constructor
        '''
        binaryfile = gp.binaryfile
        self.length = read_half(binaryfile)

        #         if DEBUG:
        #             print ("Packet 12: Tornado Vortex Signature")
        #
        self.num = self.length / 4
        if self.num != 1:
            logger.warning("More than one symbol in packet. Not handled.")
#
#             print ("TVS Block Length %hd  Number Included %hd\n" %(self.length,self.num))
#
#              in this packet there are 2 fields (4 bytes) to be
#              written for each symbol
#
#             for i in range(self.num):
#                 self.ipos=read_half(binaryfile)
#                 self.jpos=read_half(binaryfile)
#                 print ("  I Pos: %4hd  J Pos: %4hd\n" %(self.ipos,self.jpos))
#         else:
        self.ipos = read_half(binaryfile)
        self.jpos = read_half(binaryfile)
        gp.tornado = Tornado(self.ipos, self.jpos, False, gp)

        logger.debug("Packet 12: Tornado Vortex Signature")
        logger.debug("TVS Block Length %hd  Number Included %hd" %
                     (self.length, self.num))
        logger.debug("  I Pos: %4hd  J Pos: %4hd" % (self.ipos, self.jpos))
Esempio n. 4
0
    def __init__(self, gp, set_line=None):
        '''
        Constructor
        '''

        binaryfile = gp.binaryfile

        length = read_half(binaryfile)
        num_vectors = length / 4

        logger.debug("Packet 6: Linked Vector Packet (no value)")
        logger.debug("Packet 6 Length of Data Block (in bytes) = %hd" % length)
        logger.debug("Number of Vectors: %i" % num_vectors)

        tmp = []
        for i in range(0, length, 4):
            u = read_half(binaryfile)
            v = read_half(binaryfile)
            logger.debug("  I Starting Point: %hd   J Starting Point: %hd" %
                         (u, v))
            u *= 250  # m
            v *= 250  # m
            tmp.append([u, v])

        if set_line != None:
            set_line(tmp)

        logger.debug("Packet 6 Complete")
Esempio n. 5
0
 def plot(self, axes, plt):
     logger.debug('Color Level: %i' % self.color)
     cl = plt.color(self.color)
     for i in range(self.num_vectors):
         begI = read_half(self.binaryfile)
         begJ = read_half(self.binaryfile)
         endI = read_half(self.binaryfile)
         endJ = read_half(self.binaryfile)
         logger.debug(
             'Vector: %i\tbegI: %3i\tbegJ: %3i\tendI: %3i\tendJ: %3i' %
             (i + 1, begI, begJ, endI, endJ))
         l = pylab.Line2D([begI, endI], [begJ, endJ], color=cl)
         axes.add_line(l)
Esempio n. 6
0
    def __init__(self, gp):
        '''
        Constructor
        '''

        self.binaryfile = gp.binaryfile
        self.length = read_half(self.binaryfile)
        self.color = read_half(self.binaryfile)

        if (self.color < 1) | (self.color > 16):
            logger.error("Data Error: Color level was out of range")

        self.length -= 2  # account for the color&length values
        self.num_vectors = self.length >> 3
Esempio n. 7
0
    def __init__(self, gp):
        '''
        Constructor
        '''

        binaryfile = gp.binaryfile
        self.gp = gp

        halves = struct.unpack('>10h', binaryfile.read(20))

        num_rows = halves[8]

        self.rows = []
        for i in range(num_rows):
            # read the row header
            num_bytes = read_half(binaryfile)

            s = binaryfile.read(num_bytes)
            data = struct.unpack(str(num_bytes) + 'B', s)

            row = []
            for j in range(num_bytes):
                c = data[j]
                run = c >> 4  # Amount of cells
                val = c & 0xf  # Value of cells
                print(run, val)
                # for k in range(run): row.append(val)
                # should be more efficient concatenate
                row = np.concatenate((row, val * np.ones(run)))

            self.rows.append(row)
Esempio n. 8
0
    def __init__(self, gp):
        self.gp = gp
        binaryfile = gp.binaryfile
        binaryfile.seek(OFFSET + gp.pdb.gra_off * 2, 0)
        self.time = []
        self.cells = []

        # Leyendo las horas
        block_len = read_half(binaryfile)
        num_vols = read_byte(binaryfile)
        self.lts_vol_ptr_time = read_byte(binaryfile)
        for i in range(num_vols):
            minutes = read_half(binaryfile)
            self.time.append(minutes)

        # Leyendo los datos de las celdas
        while True:
            try:
                s = binaryfile.read(2)
                if len(s) == 0: break  # Fin del fichero
                packet_code = struct.unpack('>h', s)[0]
                block_len = read_half(
                    binaryfile)  # Number of bytes to follow in
                # this packet
                if packet_code == 21:
                    trend_data = Package_21(binaryfile)
                else:
                    logger.error(
                        """Error in packet_code (21 expected, %i found). 
                                    Prod 62""" % packet_code)
                    break
                self.cells.append(trend_data.cell)
            except:

                class Myfile:
                    def __init__(self):
                        pass

                    def write(self, txt):
                        logger.error(txt)

                logger_file = Myfile()
                traceback.print_exc(file=logger_file)
                break
Esempio n. 9
0
    def __init__(self, gp):
        '''
        Constructor
        '''
        binaryfile = gp.binaryfile

        length = read_half(binaryfile)
        logger.debug("Packet 19: HDA Hail Data")
        logger.debug(
            "Value of -999 indicates that the cell is beyond the maximum")
        logger.debug("  range for algorithm processing")

        num = length / 10
        logger.debug(
            "Length of Data Block (in bytes) = %hd Number included=%d" %
            (length, num))

        if (length == 10):  # only one symbol
            ipos = read_half(binaryfile)
            jpos = read_half(binaryfile)
            prob = read_half(binaryfile)
            prob_sevr = read_half(binaryfile)
            m_size = read_half(binaryfile)

            logger.debug("""  I Pos: %4hd  J Pos: %4hd  Prob of Hail: %hd
                    \t\t\t\t\t\t of Severe Hail: %hd  Max Size (in): %hd""" %
                         (ipos, jpos, prob, prob_sevr, m_size))

            if (prob != -999) & (prob_sevr != -999):
                if (prob != 0) or (prob_sevr != 0):
                    gp.hail = Hail(ipos, jpos, prob, prob_sevr, m_size, gp)
        else:
            logger.warning("More than one symbol in packet. Not handled.")
Esempio n. 10
0
    def __init__(self, gp):
        '''
        Constructor
        '''
        self.length = read_half(gp.binaryfile)

        self.color = read_half(gp.binaryfile)
        self.ipos = read_half(gp.binaryfile)
        self.jpos = read_half(gp.binaryfile)

        self.length -= 6  # account for the color/I/J Pos values

        self.text = gp.binaryfile.read(self.length).decode(
            "utf-8")  # Leyendo cadena

        logger.debug(
            "Packet 8: Length=%4i  Text Color=%3i  I Pos: %4i  J Pos: %4i" %
            (self.length, self.color, self.ipos, self.jpos))
        logger.debug("  Text: %s\n" % self.text)

        if (gp.pdb.MH_msg_code == 141):
            gp.mesocyclone.set_id(self.text, self.ipos, self.jpos)
Esempio n. 11
0
    def __init__(self, gp):
        '''
        Constructor
        '''

        binaryfile = gp.binaryfile
        logger.debug("Packet 15: Storm ID Data")

        length = read_half(binaryfile)  # length in bytes

        num = length / 6

        logger.debug("Packet 15: Length=%4hd  Number Included=%hd" %
                     (length, num))

        if (length == 6):  # only one symbol
            ipos = read_half(binaryfile)
            jpos = read_half(binaryfile)
            cell_id = binaryfile.read(2).decode("utf-8")

            logger.debug("  I Pos: %4hd  J Pos: %4hd  Storm ID: %s\n" %
                         (ipos, jpos, cell_id))
        else:
            logger.warning("More than one symbol in packet. Not handled.")

        if gp.pdb.MH_msg_code == 58:
            try:
                if not (gp.storm.commited):
                    gp.storm.commit()
            except:
                pass
            gp.storm = StormCell(ipos, jpos, cell_id, gp)

        if gp.pdb.MH_msg_code == 59:
            gp.hail.set_id(cell_id, ipos, jpos)

        if gp.pdb.MH_msg_code == 61:
            gp.tornado.set_id(cell_id)
Esempio n. 12
0
    def __init__(self, gp):
        '''
        Constructor
        '''

        binaryfile = gp.binaryfile

        length = read_half(binaryfile)

        logger.debug(
            "Packet 2: Write Special Symbols (No Value) Summary Information")
        logger.debug("Length of Data Block (in bytes) = %i" % length)
        i = read_half(binaryfile)
        j = read_half(binaryfile)
        logger.debug("I Starting Point: %i" % i)
        logger.debug("J Starting Point: %i" % j)

        length -= 4

        logger.debug("Message Begins at next line:")

        logger.debug(binaryfile.read(length))
        logger.debug("Message Complete\n")
    def scan_data(self):
        self.gp.data = ''
        self.gp.adata = ''
        is_adata = False
        u = 0
        count = 0
        self.cell_location = {}  # cell_id -> [azimut, range]
        for i in range(self.number_of_pages):
            while True:
                num = read_half(
                    self.gp.binaryfile)  # num of chars in current line
                if num == -1:  # Romper si llega al final
                    break
                line = self.gp.binaryfile.read(num).decode("utf-8")
                if (line.find("ADAPTATION") != -1 or is_adata):
                    is_adata = True
                    self.gp.adata += line + "\n"
                else:
                    if (line.find("STORM STRUCTURE") != -1):
                        u = 0
                    if u < 6:
                        u += 1
                    else:
                        if (line.find("/") == -1):
                            u = 10
                        if u != 10:
                            a = line.split('    ')
                            b = a[2].split('/')
                            try:
                                self.cell_location.setdefault(
                                    a[1].split()[0],
                                    [int(b[0]), int(b[1])])
                            except:
                                self.cell_location.setdefault(
                                    a[1].split()[0], [0, 0])
                    self.gp.data += line + "\n"

        f = open("adata.txt", 'w')
        f.write(self.gp.adata)
        f.close()
        f = open("data.txt", 'w')
        f.write(self.gp.data)
        f.close()
Esempio n. 14
0
    def __init__(self, gp):
        '''
        Constructor
        '''

        self.length = read_half(gp.binaryfile)
        self.color  = read_half(gp.binaryfile)
        
        self.i_start = read_half(gp.binaryfile)
        self.j_start = read_half(gp.binaryfile)
        
        self.length -= 4 # account for the starting points 
        num_vectors = self.length/4
        
        self.i_ends = []
        self.j_ends = []
        
        for i in range(num_vectors):
            self.i_ends.append(read_half(gp.binaryfile))
            self.j_ends.append(read_half(gp.binaryfile))
        
        self.i_ends.insert(0, self.i_start)
        self.j_ends.insert(0, self.j_start)
Esempio n. 15
0
    def __init__(self, gp):
        '''
        Constructor
        '''
        self.length = read_half(gp.binaryfile)
        self.color_level = read_half(gp.binaryfile)

        if (self.color_level < 1) | (self.color_level > 5):
            logger.error("Data Error: Color level of %hd was out of range",
                         self.color_level)

        self.x = read_half(gp.binaryfile)
        self.y = read_half(gp.binaryfile)
        self.dir = read_half(gp.binaryfile)
        self.spd = read_half(gp.binaryfile)

        self.u = self.spd * pylab.sin(pylab.pi / 180 * (self.dir - 180))
        self.v = self.spd * pylab.cos(pylab.pi / 180 * (self.dir - 180))

        logger.debug(
            "Packet 4: Length=%4i Barb Color=%3i X Pos: %4i Y Pos: %4i Dir: %3i Speed: %3i"
            % (self.length, self.color_level, self.x, self.y, self.dir,
               self.spd))