Source code for reader_ionodata
#!/usr/bin/env python
#-------------------------------------------------------------------------------
# Name: reader_ionodata.py
#
# Purpose: This software collects functions to read specific ionosonde data files and returning dictionaries of this data
#
# Input: Please customize the paths in config.py first
# Ionosonde data in the output format of DownloadClient
#
# Output: Ionosonde data in Python dictionaries or SciPy interpolation function
#
# HowToStart: python reader_ionodata.py
#
# Needs: python2.7.8, scipy 0.14.0
#
# Version: $Id: reader_ionodata.py
# $HeadURL: https://svn.dlr.de/GNSSsoft/trunk/UserUtils/CBojarraUtils/Filter/reader_ionodata.py $
#
# Author: Chris Bojarra
#
# Created: 03.11.2014
# Copyright: (c) Chris Bojarra 2014
# Mail: Chris.Bojarra@dlr.de
# Licence: DLR
#-------------------------------------------------------------------------------
import datetime
import os
import scipy.interpolate
import config
[docs]class Reader_IonoData(object):
"""
Main class of reader_ionodata.py
"""
def __init__(self):
pass
def __del__(self):
pass
[docs] def read_iono_data(self, param):
"""
This method creates a dictionary of the files in ``config.path_input`` and returns it
The files should be in the format used with the DownloadClient::
# URSIC Station Name
# Lat:0.0 Lon:0.0
YYYY-MM-DD hh:mm value
:param string param: ionospheric parameter
:return: dictionary of ionosonde data, format dict["station"]["YYYY-MM-DD hh:mm"] = float
:rtype: dict
"""
dict_data = {}
list_files = [filename for filename in os.listdir(config.path_input) if filename.startswith(param)]
for filename in list_files:
fr = open(os.path.join(config.path_input, filename), "r")
filecontent = fr.readlines()
fr.close()
station = filename[len(param)+1:-4]
dict_data[station] = {}
dict_data[station]["Meta"] = {}
for contentline in filecontent:
if("#" in contentline):
if(station in contentline):
line = contentline.split()
name = ' '.join(line[2:])
dict_data[station]["Meta"]["Name"] = name
if("Lat" in contentline):
line = contentline.split()
lat = ""
lon = ""
if(len(line[1]) > 4):
lat = float(line[1][4:])
lon = float(line[2][4:])
dict_data[station]["Meta"]["Lat"] = lat
dict_data[station]["Meta"]["Lon"] = lon
else:
line = contentline.split()
valuedate = line[0]
valuetime = line[1]
valuedatetime = valuedate + " " + valuetime
value = float(line[2])
if(value!=9999.0):
dict_data[station][valuedatetime] = value
return dict_data
[docs] def convert_fof2_nmf2(self):
"""
This method reads foF2 files (using :py:func:`read_iono_data`), converts all values to NmF2 * 10^-12 and returns a dictionary of NmF2 data
:return: dictionary of NmF2 data, format dict["station"]["YYYY-MM-DD hh:mm"] = float
:rtype: dict
"""
dict_nmf2 = {}
dict_fof2 = self.read_iono_data("foF2")
for station in dict_fof2:
dict_nmf2[station] = {}
for data_time in [item for item in dict_fof2[station] if item!="Meta"]:
fof2 = dict_fof2[station][data_time]
nmf2 = 1.24e10*(fof2)**2*1e-12 # NmF2 = 1.24*10^10 * (foF2)^2
dict_nmf2[station][data_time] = nmf2
return dict_nmf2
[docs] def read_F10p7(self):
"""
This method returns a dictionary of F10.7 values read from a file with the format::
YYYY-MM-DD hh:mm value
:return: dictionary of F10.7 data, format dict["YYYY-MM-DD"] = float
:rtype: dict
"""
dict_f10p7 = {}
fr = open(config.path_input_F10p7, "r")
filecontent = fr.readlines()
fr.close()
for contentline in filecontent:
if("#" not in contentline):
line = contentline.split()
valuedate = line[0]
value = float(line[2])
dict_f10p7[valuedate] = value
return dict_f10p7
[docs] def read_Kp(self):
"""
This method returns a dictionary of Kp values read from a file with the format::
YYYY-MM-DD hh:mm value
:return: dictionary of Kp data, format dict["YYYY-MM-DD hh:mm"] = float
:rtype: dict
"""
dict_kp = {}
fr = open(config.path_input_Kp, "r")
filecontent = fr.readlines()
fr.close()
for contentline in filecontent:
if("#" not in contentline):
line = contentline.split()
valuedate = line[0]
valuetime = line[1]
value = float(line[2])
valuedatetime = valuedate + " " + valuetime
dict_kp[valuedatetime] = value
return dict_kp
[docs] def read_Kp_interp(self):
"""
This method reads a Kp file and returns a SciPy interpolation function: interp(hour_of_year) = interpolated Kp value
:return: SciPy interpolation function to interpolate Kp values
:rtype: SciPy interpolation function
"""
dict_Kp = self.read_Kp()
dict_Kp_hoy = {}
for valuedatetime in dict_Kp.keys():
value_yyyy = int(valuedatetime[0:4])
value_mm = int(valuedatetime[5:7])
value_dd = int(valuedatetime[8:10])
value_hh = int(valuedatetime[11:13])
value_doy = datetime.date(value_yyyy, value_mm, value_dd).strftime("%j")
value_hoy = int(value_doy)*24 + value_hh
dict_Kp_hoy[value_hoy] = dict_Kp[valuedatetime]
interp = scipy.interpolate.interp1d(dict_Kp_hoy.keys(), dict_Kp_hoy.values(), assume_sorted=False)
return interp
def main():
pass
if __name__ == "__main__":
main()