Changeset 6808525 in ammosreader


Ignore:
Timestamp:
05/05/22 16:00:45 (3 years ago)
Author:
Enrico Schwass <ennoausberlin@…>
Branches:
AmmosSource, guix
Children:
94f7c24
Parents:
bfab5ea
Message:

import script improved

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • sample_scripts/import_signal.py

    rbfab5ea r6808525  
    55from pathlib import Path
    66from ammosreader.AmmosIFReader import AmmosIFReader
    7 from ammosreader.PDW import PDW
     7from ammosreader.PPDWReader import PPDWReader
    88
    99parser = argparse.ArgumentParser()
     
    5959ammos_reader.read_all_frames_left()
    6060print(ammos_reader.container)
     61
     62ppdw_reader = PPDWReader(ppdw_file)
     63ppdw_reader.read_all_frames_left()
     64print(ppdw_reader.container)
  • src/_version.py

    rbfab5ea r6808525  
    22# file generated by setuptools_scm
    33# don't change, don't track in version control
    4 version = '0.1.dev33+gcaee9d8.d20220504'
    5 version_tuple = (0, 1, 'dev33', 'gcaee9d8.d20220504')
     4version = '0.1.dev57+gbfab5ea.d20220505'
     5version_tuple = (0, 1, 'dev57', 'gbfab5ea.d20220505')
  • src/ammosreader.egg-info/PKG-INFO

    rbfab5ea r6808525  
    11Metadata-Version: 2.1
    22Name: ammosreader
    3 Version: 0.1.dev33+gcaee9d8.d20220504
     3Version: 0.1.dev57+gbfab5ea.d20220505
    44Summary: ammosreader: tool to parse R&S Ammos files
    55Home-page: http://gitlab.kid.local/kidzg/ammosreader
     
    1919Classifier: Programming Language :: Python :: 3.10
    2020Classifier: Topic :: Utilities
    21 Requires-Python: >=3.8
     21Requires-Python: >=3.10
    2222Description-Content-Type: text/text
    2323Provides-Extra: testing
  • src/ammosreader.egg-info/SOURCES.txt

    rbfab5ea r6808525  
    115115sample_scripts/audio_socket_reader_test.py
    116116sample_scripts/audio_socket_reader_test_streamer.py
     117sample_scripts/import_signal.py
    117118sample_scripts/iqdw_reader.py
    118119sample_scripts/pdw_reader.py
     
    134135src/ammosreader/PDW.py
    135136src/ammosreader/PPDWContainer.py
     137src/ammosreader/PPDWReader.py
    136138src/ammosreader/__init__.py
    137139src/ammosreader.egg-info/PKG-INFO
  • src/ammosreader/PDW.py

    rbfab5ea r6808525  
     1"""I store the information of a single PDW block."""
     2
    13import struct
    24import math
    35import numpy as np
    46
    5 # TODO: Use BitArray module in future versions
    6 
    77
    88class PDW():
     
    1111
    1212    .. automethod:: __init__
    13 
    1413    """
    1514
    1615    @classmethod
    1716    def from_bytes(cls, byte_string):
    18 
    19         """
    20 
    21         I create an instance of class PDW from data body (8 * 32 bits)
     17        """
     18        I create an instance of class PDW from data body (8 * 32 bits).
    2219
    2320        :param byte_string: a byte string containing a single data body read from a ppdw file
     
    2623        :return: an instance of class PDW with attributes set according to the data of a data body
    2724        :rtype: PDW
    28 
    29         """
    30 
     25        """
    3126        assert(len(byte_string) == 32)
    3227
     
    165160
    166161    def __str__(self):
     162        """
     163        I return the string representation of myself.
     164
     165        :rtype: str
     166        """
    167167        output = ("Time of arrival: " + str(self.time_of_arrival) + "\n" +
    168168                  "PDW Format identifier: " + str(self.pdw_format_identifier) + "\n" +
  • src/ammosreader/PPDWContainer.py

    rbfab5ea r6808525  
    1212            self.signals = signals
    1313
     14    def __str__(self):
     15        return "\n".join(["Number of pulses:" + str(len(self.signals)),
     16                          "Start time:" + str(self.start_time()),
     17                          "End time:" + str(self.end_time())])
     18
    1419    def add(self, a_pdw):
    1520        self.signals.append(a_pdw)
    1621
     22    def start_time(self):
     23        return min([each.time_of_arrival for each in self.signals])
     24
     25    def end_time(self):
     26        return max([each.time_of_arrival for each in self.signals])
    1727
    1828if __name__ == '__main__':
  • src/ammosreader/PPDWReader.py

    rbfab5ea r6808525  
    66class PPDWReader():
    77
    8     def __init__(self, file_name):
     8    def __init__(self, a_file):
    99
    10         self.file = Path(file_name)
     10        self.file = a_file
    1111        assert self.file.is_file()
     12        self.content = self.file.read_bytes()
     13        self.cursor = 0
    1214        self.container = PPDWContainer(self.file.stem)
    1315
    1416    def read_all_frames_left(self):
    15         with self.file.open() as f:
    16             while True:
    17                 current_bytes = f.read(32)
    18                 if current_bytes == '':
    19                     print('End of file detected')
    20                     break
    21                 if len(current_bytes) != 32:
    22                     print('Can not read all 32 bytes of next PDW')
    23                     break
    24                 self.container.add(PDW.from_bytes(current_bytes))
     17        while self.cursor <= len(self.content) - 32:
     18            current_bytes = self.content[self.cursor:self.cursor+32]
     19            assert len(current_bytes) == 32
     20            if not current_bytes:
     21                print('End of file detected')
     22                break
     23            if self.cursor + 32 >= len(self.content):
     24                print('Can not read all 32 bytes of next PDW')
     25                break
     26            self.container.add(PDW.from_bytes(current_bytes))
     27            self.cursor += 32
     28        return self.container
Note: See TracChangeset for help on using the changeset viewer.