corems.transient.input.midasDatFile

  1from os import path
  2
  3from numpy import dtype, fromfile
  4
  5
  6__author__ = "Yuri E. Corilo"
  7__date__ = "Jun 19, 2019"
  8
  9
 10class ReadMidasDatFile:
 11    """[Not Implemented] Reads MIDAS .dat files (binary transient data)
 12
 13    This class will read .dat binary format transient data, e.g. midas format from Predator or Thermo datastations
 14    This code is not yet implemented and is not fully functional.
 15
 16    Parameters
 17    ----------
 18    filename_path : str
 19        The path to the .dat file
 20
 21    Attributes
 22    ----------
 23    filename_path : str
 24        The path to the .dat file
 25    d_params : dict
 26        A dictionary with the parameters of the .dat file
 27    transient_data : numpy.ndarray
 28        The transient data
 29
 30    Methods
 31    -------
 32    * read_file().
 33        Reads the .dat file and returns the transient data and the parameters
 34    * get_transient_data(data_file, d_params).
 35        Reads the transient data from the .dat file
 36    * parse_parameter(f).
 37        Parses the parameters from the .dat file
 38
 39    Raises
 40    ------
 41    NotImplementedError
 42        This class is not yet implemented.
 43
 44    """
 45
 46    def __init__(self, filename_path):
 47        raise NotImplementedError(
 48            "This class is not yet implemented, if you want to use it please contact the author at corilo@pnnl.gov or feel free to implement it"
 49        )
 50        if not path.isfile(filename_path):
 51            raise Exception("File does not exist: " + filename_path)
 52
 53        self.filename_path = filename_path
 54
 55    def read_file(self):
 56        """Reads the .dat file and returns the transient data and the parameters
 57
 58        Returns
 59        -------
 60        transient_data : numpy.ndarray
 61            The transient data
 62        d_params : dict
 63            A dictionary with the parameters of the .dat file
 64
 65        """
 66        data_file = open(self.filename_path, "rb")
 67
 68        # modo_de_ions = "POSITIVE ION MODE"
 69        d_params = self.parse_parameters(self.parameter_filename_location)
 70
 71        transient_data = self.get_transient_data(data_file, d_params, d_params)
 72
 73        return transient_data, d_params
 74
 75    def get_transient_data(self, data_file, d_params):
 76        """Reads the transient data from the .dat file
 77
 78        Parameters
 79        ----------
 80        data_file : file
 81            The .dat file
 82        d_params : dict
 83            A dictionary with the parameters of the .dat file
 84
 85        Returns
 86        -------
 87        myarray : numpy.ndarray
 88            The transient data
 89        """
 90
 91        # dt = np.dtype('<f')
 92        if d_params.get("storage_type").split()[0] == "int":
 93            dt = dtype("i2")
 94
 95        else:
 96            dt = dtype("<f")
 97        # dt = np.dtype(int)
 98
 99        myarray = fromfile(data_file, dtype=dt)
100
101        data_file.close()
102
103        if d_params.get("storage_type").split()[0] == "int":
104            return myarray * d_params.get("VoltageScale")
105
106        else:
107            return myarray
108
109    def parse_parameter(self, f):
110        """Parses the parameters from the .dat file
111
112        Parameters
113        ----------
114        f : file
115            The .dat file
116
117        Returns
118        -------
119        output_parameters : dict
120            A dictionary with the parameters of the .dat file
121        """
122
123        output_parameters = {}
124        output_parameters["filename_path"] = self.d_directory_location
125
126        line = f.readline()
127
128        while line != "Data:\n":
129            if line[0:8] == "highfreq":
130                final_frequency = float(line.split(":")[1])
131                output_parameters["exc_high_freq"] = final_frequency
132
133            elif line[0:7] == "lowfreq":
134                initial_frequency = float(line.split(":")[1])
135                output_parameters["exc_low_freq"] = initial_frequency
136
137            elif line[0:9] == "sweeprate":
138                sweeprate = float(line.split(":")[1])
139
140                output_parameters["sweeprate"] = sweeprate
141
142            elif line[0:13] == "Source Coeff0":
143                Acoef = float(line.split(":")[1])
144                output_parameters["Aterm"] = Acoef
145                # print f.readline()
146            elif line[0:13] == "Source Coeff1":
147                output_parameters["Bterm"] = "Bcoef"
148
149            elif line[0:13] == "Voltage Scale":
150                voltage_scale = float(line.split(":")[1])
151                output_parameters["VoltageScale"] = voltage_scale
152
153            elif line[0:9] == "Bandwidth":
154                bandwidth = float(line.split(":")[1])
155                output_parameters["bandwidth"] = bandwidth
156
157            elif line[0:11] == "Data Points":
158                datapoints = float(line.split(":")[1])
159                output_parameters["number_data_points"] = datapoints
160
161            elif line[0:12] == "Storage Type":
162                storage_type = line.split(":")[1]
163                output_parameters["storage_type"] = storage_type
164
165            elif line[0:12] == "Trap Voltage":
166                trap_voltage = float(line.split(":")[1])
167                # Bcoef = Bcoef*trap_voltage
168                output_parameters["trap_voltage"] = trap_voltage
169
170            line = f.readline()
171
172        return output_parameters
class ReadMidasDatFile:
 11class ReadMidasDatFile:
 12    """[Not Implemented] Reads MIDAS .dat files (binary transient data)
 13
 14    This class will read .dat binary format transient data, e.g. midas format from Predator or Thermo datastations
 15    This code is not yet implemented and is not fully functional.
 16
 17    Parameters
 18    ----------
 19    filename_path : str
 20        The path to the .dat file
 21
 22    Attributes
 23    ----------
 24    filename_path : str
 25        The path to the .dat file
 26    d_params : dict
 27        A dictionary with the parameters of the .dat file
 28    transient_data : numpy.ndarray
 29        The transient data
 30
 31    Methods
 32    -------
 33    * read_file().
 34        Reads the .dat file and returns the transient data and the parameters
 35    * get_transient_data(data_file, d_params).
 36        Reads the transient data from the .dat file
 37    * parse_parameter(f).
 38        Parses the parameters from the .dat file
 39
 40    Raises
 41    ------
 42    NotImplementedError
 43        This class is not yet implemented.
 44
 45    """
 46
 47    def __init__(self, filename_path):
 48        raise NotImplementedError(
 49            "This class is not yet implemented, if you want to use it please contact the author at corilo@pnnl.gov or feel free to implement it"
 50        )
 51        if not path.isfile(filename_path):
 52            raise Exception("File does not exist: " + filename_path)
 53
 54        self.filename_path = filename_path
 55
 56    def read_file(self):
 57        """Reads the .dat file and returns the transient data and the parameters
 58
 59        Returns
 60        -------
 61        transient_data : numpy.ndarray
 62            The transient data
 63        d_params : dict
 64            A dictionary with the parameters of the .dat file
 65
 66        """
 67        data_file = open(self.filename_path, "rb")
 68
 69        # modo_de_ions = "POSITIVE ION MODE"
 70        d_params = self.parse_parameters(self.parameter_filename_location)
 71
 72        transient_data = self.get_transient_data(data_file, d_params, d_params)
 73
 74        return transient_data, d_params
 75
 76    def get_transient_data(self, data_file, d_params):
 77        """Reads the transient data from the .dat file
 78
 79        Parameters
 80        ----------
 81        data_file : file
 82            The .dat file
 83        d_params : dict
 84            A dictionary with the parameters of the .dat file
 85
 86        Returns
 87        -------
 88        myarray : numpy.ndarray
 89            The transient data
 90        """
 91
 92        # dt = np.dtype('<f')
 93        if d_params.get("storage_type").split()[0] == "int":
 94            dt = dtype("i2")
 95
 96        else:
 97            dt = dtype("<f")
 98        # dt = np.dtype(int)
 99
100        myarray = fromfile(data_file, dtype=dt)
101
102        data_file.close()
103
104        if d_params.get("storage_type").split()[0] == "int":
105            return myarray * d_params.get("VoltageScale")
106
107        else:
108            return myarray
109
110    def parse_parameter(self, f):
111        """Parses the parameters from the .dat file
112
113        Parameters
114        ----------
115        f : file
116            The .dat file
117
118        Returns
119        -------
120        output_parameters : dict
121            A dictionary with the parameters of the .dat file
122        """
123
124        output_parameters = {}
125        output_parameters["filename_path"] = self.d_directory_location
126
127        line = f.readline()
128
129        while line != "Data:\n":
130            if line[0:8] == "highfreq":
131                final_frequency = float(line.split(":")[1])
132                output_parameters["exc_high_freq"] = final_frequency
133
134            elif line[0:7] == "lowfreq":
135                initial_frequency = float(line.split(":")[1])
136                output_parameters["exc_low_freq"] = initial_frequency
137
138            elif line[0:9] == "sweeprate":
139                sweeprate = float(line.split(":")[1])
140
141                output_parameters["sweeprate"] = sweeprate
142
143            elif line[0:13] == "Source Coeff0":
144                Acoef = float(line.split(":")[1])
145                output_parameters["Aterm"] = Acoef
146                # print f.readline()
147            elif line[0:13] == "Source Coeff1":
148                output_parameters["Bterm"] = "Bcoef"
149
150            elif line[0:13] == "Voltage Scale":
151                voltage_scale = float(line.split(":")[1])
152                output_parameters["VoltageScale"] = voltage_scale
153
154            elif line[0:9] == "Bandwidth":
155                bandwidth = float(line.split(":")[1])
156                output_parameters["bandwidth"] = bandwidth
157
158            elif line[0:11] == "Data Points":
159                datapoints = float(line.split(":")[1])
160                output_parameters["number_data_points"] = datapoints
161
162            elif line[0:12] == "Storage Type":
163                storage_type = line.split(":")[1]
164                output_parameters["storage_type"] = storage_type
165
166            elif line[0:12] == "Trap Voltage":
167                trap_voltage = float(line.split(":")[1])
168                # Bcoef = Bcoef*trap_voltage
169                output_parameters["trap_voltage"] = trap_voltage
170
171            line = f.readline()
172
173        return output_parameters

[Not Implemented] Reads MIDAS .dat files (binary transient data)

This class will read .dat binary format transient data, e.g. midas format from Predator or Thermo datastations This code is not yet implemented and is not fully functional.

Parameters
  • filename_path (str): The path to the .dat file
Attributes
  • filename_path (str): The path to the .dat file
  • d_params (dict): A dictionary with the parameters of the .dat file
  • transient_data (numpy.ndarray): The transient data
Methods
  • read_file(). Reads the .dat file and returns the transient data and the parameters
  • get_transient_data(data_file, d_params). Reads the transient data from the .dat file
  • parse_parameter(f). Parses the parameters from the .dat file
Raises
  • NotImplementedError: This class is not yet implemented.
ReadMidasDatFile(filename_path)
47    def __init__(self, filename_path):
48        raise NotImplementedError(
49            "This class is not yet implemented, if you want to use it please contact the author at corilo@pnnl.gov or feel free to implement it"
50        )
51        if not path.isfile(filename_path):
52            raise Exception("File does not exist: " + filename_path)
53
54        self.filename_path = filename_path
filename_path
def read_file(self):
56    def read_file(self):
57        """Reads the .dat file and returns the transient data and the parameters
58
59        Returns
60        -------
61        transient_data : numpy.ndarray
62            The transient data
63        d_params : dict
64            A dictionary with the parameters of the .dat file
65
66        """
67        data_file = open(self.filename_path, "rb")
68
69        # modo_de_ions = "POSITIVE ION MODE"
70        d_params = self.parse_parameters(self.parameter_filename_location)
71
72        transient_data = self.get_transient_data(data_file, d_params, d_params)
73
74        return transient_data, d_params

Reads the .dat file and returns the transient data and the parameters

Returns
  • transient_data (numpy.ndarray): The transient data
  • d_params (dict): A dictionary with the parameters of the .dat file
def get_transient_data(self, data_file, d_params):
 76    def get_transient_data(self, data_file, d_params):
 77        """Reads the transient data from the .dat file
 78
 79        Parameters
 80        ----------
 81        data_file : file
 82            The .dat file
 83        d_params : dict
 84            A dictionary with the parameters of the .dat file
 85
 86        Returns
 87        -------
 88        myarray : numpy.ndarray
 89            The transient data
 90        """
 91
 92        # dt = np.dtype('<f')
 93        if d_params.get("storage_type").split()[0] == "int":
 94            dt = dtype("i2")
 95
 96        else:
 97            dt = dtype("<f")
 98        # dt = np.dtype(int)
 99
100        myarray = fromfile(data_file, dtype=dt)
101
102        data_file.close()
103
104        if d_params.get("storage_type").split()[0] == "int":
105            return myarray * d_params.get("VoltageScale")
106
107        else:
108            return myarray

Reads the transient data from the .dat file

Parameters
  • data_file (file): The .dat file
  • d_params (dict): A dictionary with the parameters of the .dat file
Returns
  • myarray (numpy.ndarray): The transient data
def parse_parameter(self, f):
110    def parse_parameter(self, f):
111        """Parses the parameters from the .dat file
112
113        Parameters
114        ----------
115        f : file
116            The .dat file
117
118        Returns
119        -------
120        output_parameters : dict
121            A dictionary with the parameters of the .dat file
122        """
123
124        output_parameters = {}
125        output_parameters["filename_path"] = self.d_directory_location
126
127        line = f.readline()
128
129        while line != "Data:\n":
130            if line[0:8] == "highfreq":
131                final_frequency = float(line.split(":")[1])
132                output_parameters["exc_high_freq"] = final_frequency
133
134            elif line[0:7] == "lowfreq":
135                initial_frequency = float(line.split(":")[1])
136                output_parameters["exc_low_freq"] = initial_frequency
137
138            elif line[0:9] == "sweeprate":
139                sweeprate = float(line.split(":")[1])
140
141                output_parameters["sweeprate"] = sweeprate
142
143            elif line[0:13] == "Source Coeff0":
144                Acoef = float(line.split(":")[1])
145                output_parameters["Aterm"] = Acoef
146                # print f.readline()
147            elif line[0:13] == "Source Coeff1":
148                output_parameters["Bterm"] = "Bcoef"
149
150            elif line[0:13] == "Voltage Scale":
151                voltage_scale = float(line.split(":")[1])
152                output_parameters["VoltageScale"] = voltage_scale
153
154            elif line[0:9] == "Bandwidth":
155                bandwidth = float(line.split(":")[1])
156                output_parameters["bandwidth"] = bandwidth
157
158            elif line[0:11] == "Data Points":
159                datapoints = float(line.split(":")[1])
160                output_parameters["number_data_points"] = datapoints
161
162            elif line[0:12] == "Storage Type":
163                storage_type = line.split(":")[1]
164                output_parameters["storage_type"] = storage_type
165
166            elif line[0:12] == "Trap Voltage":
167                trap_voltage = float(line.split(":")[1])
168                # Bcoef = Bcoef*trap_voltage
169                output_parameters["trap_voltage"] = trap_voltage
170
171            line = f.readline()
172
173        return output_parameters

Parses the parameters from the .dat file

Parameters
  • f (file): The .dat file
Returns
  • output_parameters (dict): A dictionary with the parameters of the .dat file