Changeset 4180d6a in ammosreader


Ignore:
Timestamp:
05/06/22 11:23:51 (3 years ago)
Author:
Enrico Schwass <ennoausberlin@…>
Branches:
AmmosSource, guix
Children:
1d0974d, a574a93
Parents:
94f7c24
Message:

Add pymongo import script

Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • sample_scripts/import_signal.py

    r94f7c24 r4180d6a  
    33import sqlite3
    44import argparse
     5import numpy as np
     6from datetime import datetime
    57from pathlib import Path
     8from pymongo import MongoClient
    69from ammosreader.AmmosIFReader import AmmosIFReader
    710from ammosreader.PPDWReader import PPDWReader
     
    1619args = parser.parse_args()
    1720
     21source = args.source.upper()
    1822code = args.code.upper()
    1923signal_number = args.signal_number
    2024input_dir = Path(args.input_dir)
    2125sqlite3_file = Path(args.output_file)
     26
     27if not re.match('[A-Z0-9]{2}', source):
     28    print("Source identifier", source, "invalid")
     29    sys.exit()
    2230
    2331if not re.match('[A-Z][0-9]{3}[A-Z]', code):
     
    4957#    sys.exit(1)
    5058
    51 try:
    52     connection = sqlite3.connect(str(sqlite3_file))
    53     cursor = connection.cursor()
    54 except Exception:
    55     print("Can not connect to database file", str(sqlite3_file))
    56     # sys.exit(1)
     59# try:
     60#    connection = sqlite3.connect(str(sqlite3_file))
     61#    cursor = connection.cursor()
     62# except Exception:
     63#    print("Can not connect to database file", str(sqlite3_file))
     64     # sys.exit(1)
    5765
    58 ammos_if_reader = AmmosIFReader(str(iqdw_file))
    59 ammos_if_reader.read_all_frames_left()
     66#ammos_if_reader = AmmosIFReader(str(iqdw_file))
     67#ammos_if_reader.read_all_frames_left()
    6068# for each_frame in ammos_if_reader.container.global_frames:
    6169#    print(each_frame)
     
    6371ppdw_reader = PPDWReader(ppdw_file)
    6472ppdw_reader.read_all_frames_left()
    65 print(ppdw_reader.container)
     73
     74client = MongoClient('hackathon.kid.local', 27017)
     75
     76database = client['ELINT']
     77ts = (ppdw_reader.container.start_time() - np.datetime64('1970-01-01T00:00:00')) / np.timedelta64(1, 's')
     78time_tuple = datetime.utcfromtimestamp(ts).timetuple()
     79julian_date_string = str(time_tuple.tm_year)[2:] + str(time_tuple.tm_yday).zfill(3)
     80code_collection = database[code]
     81year_collection = code_collection[str(time_tuple.tm_year)]
     82source_collection = year_collection[source]
     83
     84
     85for each in ppdw_reader.container.signals:
     86    each_json = each.to_json()
     87    each_json['SIGNALNUMBER'] = signal_number
     88    each_json['JULIANDATE'] = julian_date_string
     89    # each_json['SOURCEFILE'] = str(ppdw_file)
     90    source_collection.insert_one(each_json)
  • sample_scripts/iqdw_reader.py

    r94f7c24 r4180d6a  
    1818    dat_file.read_all_frames_left()
    1919    print(dat_file.container)
     20
     21    for each in dat_file.container.global_frames:
     22        print(each)
  • src/_version.py

    r94f7c24 r4180d6a  
    22# file generated by setuptools_scm
    33# don't change, don't track in version control
    4 version = '0.1.dev57+gbfab5ea.d20220505'
    5 version_tuple = (0, 1, 'dev57', 'gbfab5ea.d20220505')
     4version = '0.1.dev59+g94f7c24.d20220506'
     5version_tuple = (0, 1, 'dev59', 'g94f7c24.d20220506')
  • src/ammosreader.egg-info/PKG-INFO

    r94f7c24 r4180d6a  
    11Metadata-Version: 2.1
    22Name: ammosreader
    3 Version: 0.1.dev57+gbfab5ea.d20220505
     3Version: 0.1.dev59+g94f7c24.d20220506
    44Summary: ammosreader: tool to parse R&S Ammos files
    55Home-page: http://gitlab.kid.local/kidzg/ammosreader
  • src/ammosreader/PDW.py

    r94f7c24 r4180d6a  
    138138        :rtype: PDW
    139139        """
    140         self.time_of_arrival = time_of_arrival
     140        self.time_of_arrival = time_of_arrival #
    141141        self.pdw_format_identifier = pdw_format_identifier
    142         self.center_frequency = center_frequency
    143         self.is_valid = is_valid
    144         self.is_pulse = is_pulse
    145         self.level_unit = level_unit
     142        self.center_frequency = center_frequency #
     143        self.is_valid = is_valid #
     144        self.is_pulse = is_pulse #
     145        self.level_unit = level_unit #
    146146        self.signal_start_missing = signal_start_missing
    147147        self.signal_end_missing = signal_end_missing
    148         self.pulse_width = pulse_width
    149         self.frequency_shift_or_bandwidth = frequency_shift_or_bandwidth
    150         self.pulse_level_or_pulse_field_strength = pulse_level_or_pulse_field_strength
     148        self.pulse_width = pulse_width #
     149        self.frequency_shift_or_bandwidth = frequency_shift_or_bandwidth #
     150        self.pulse_level_or_pulse_field_strength = pulse_level_or_pulse_field_strength #
    151151        self.region_of_interest = region_of_interest
    152152        self.azimuth_confidence = azimuth_confidence
    153         self.modulation = modulation
     153        self.modulation = modulation #
    154154        self.sector = sector
    155155        self.polarity = polarity
    156         self.df_quality = df_quality
    157         self.elevation = elevation
     156        self.df_quality = df_quality #
     157        self.elevation = elevation #
    158158        self.azimuth = azimuth
    159         self.channel = channel
     159        self.channel = channel #
    160160
    161161    def __str__(self):
     
    222222        return output
    223223
     224    def to_json(self):
     225        return {'TIMEOFARRIVAL': self.time_of_arrival.item(),
     226                'CENTERFREQUENCY': self.center_frequency,
     227                'VALID': self.is_valid,
     228                'PULSE': self.is_pulse,
     229                'PULSEWIDTH': self.pulse_width,
     230                'LEVELUNIT': self.level_unit,
     231                'FREQUENCYSHIFTORBANDWIDTH': self.frequency_shift_or_bandwidth,
     232                'PULSELEVELORFIELDSTRENGTH': self.pulse_level_or_pulse_field_strength,
     233                'MODULATION': self.modulation,
     234                'ELEVATION': self.elevation,
     235                'AZIMUTH': self.azimuth,
     236                'CHANNEL': self.channel
     237                }
    224238
    225239if __name__ == '__main__':
Note: See TracChangeset for help on using the changeset viewer.