예제 #1
0
    def __init__(self, filename, contents=None):
        '''
        Takes:
            * filename : input filename (.azr)
            * contents : list of strings (generated from the input file)
        '''
        # If contents is provided, don't try to read the input file.
        if contents is not None:
            self.contents = contents.copy()
        else:
            self.contents = utility.read_input_file(filename)

        i = self.contents.index('<segmentsTest>') + 1
        j = self.contents.index('</segmentsTest>')

        self.all_segments = []  #  all segments in the .azr file
        for row in self.contents[i:j]:
            if row != '':
                self.all_segments.append(TestSegment(row))

        self.segments = [
        ]  #  only the segments to be included in the calculation
        for seg in self.all_segments:
            if seg.include:
                self.segments.append(seg)

        self.output_files = []
        for seg in self.segments:
            self.output_files.append(seg.output_filename)
        self.output_files = list(np.unique(self.output_files))
예제 #2
0
    def __init__(self, filename):
        self.contents = utility.read_input_file(filename)
        i = self.contents.index('<segmentsData>') + 1
        j = self.contents.index('</segmentsData>')

        # All segments listed in the file.
        self.all_segments = []
        k = 0
        for row in self.contents[i:j]:
            if row != '':
                self.all_segments.append(Segment(row, k))
                k += 1

        # All segments included in the calculation.
        self.segments = []
        for seg in self.all_segments:
            if seg.include:
                self.segments.append(seg)

        # Indices of segments with varied normalization constants.
        self.norm_segment_indices = []
        for (i, seg) in enumerate(self.all_segments):
            if seg.include and seg.vary_norm_factor:
                self.norm_segment_indices.append(i)

        # Number of data points for each included segment.
        self.ns = [seg.n for seg in self.segments]

        # Output files that need to be read.
        self.output_files = []
        for seg in self.segments:
            self.output_files.append(seg.output_filename)
        # Eliminates repeated output files AND SORTS them:
        # (1, 2, 3, ..., TOTAL_CAPTURE)
        self.output_files = list(np.unique(self.output_files))
예제 #3
0
    color_index = 0
    for file_name in mag_file_name_lst:
        with open(folder_name + "/" + file_name) as csvfile:
            if (not file_name.__contains__(".csv")):
                continue
            if (not file_name.__contains__("mag")):
                continue

            # if (not file_name.__contains__("180-180") and not file_name.__contains__(
            # 		"135-135") and not file_name.__contains__("45-45") and not file_name.__contains__("0-0")):
            # 	continue
            if (not file_name.__contains__("l0r0")):
                continue

            time, raw = ut.read_input_file(csvfile)
            raw = raw - np.mean(raw[200:-1, :], axis=0)

            all_data.append(raw)

            if (file_name.__contains__("45-45")
                    or file_name.__contains__("0-0")):
                label = "left"
            if (file_name.__contains__("135-135")
                    or file_name.__contains__("180-180")):
                label = "right"

            # all_label.append(label)
            all_label.append(file_name)

# import pywt
from utility import read_input_file
from problem import Problem
from algorithms import ucs, bfs, a_star

if __name__ == '__main__':
    input_dict = read_input_file()
    for key, value in input_dict.items():
        print(key, value, sep=':')
    for target in input_dict['targets']:
        problem = Problem(
            init_state=input_dict['state_grid'][input_dict['landing_site'][1]][
                input_dict['landing_site'][0]],
            state_space=input_dict['state_grid'],
            goal_state=input_dict['state_grid'][target[1]][target[0]],
            actions=['E', 'W', 'N', 'S', 'NE', 'SE', 'SW', 'NW'],
            max_elev_diff=input_dict['max_elevation_diff'])
        # print(problem)
        if input_dict['algorithm'].lower() == 'bfs':
            print(bfs(problem))
        elif input_dict['algorithm'].lower() == 'ucs':
            print(ucs(problem))
        else:
            print(a_star(problem))
예제 #5
0
    def __init__(self, input_filename, parameters=None):
        self.input_filename = input_filename
        self.input_filename = input_filename
        self.input_file_contents = utility.read_input_file(input_filename)
        self.initial_levels = utility.read_levels(input_filename)
        self.data = Data(self.input_filename)
        self.test = Test(self.input_filename)

        if parameters is None:
            self.parameters = []
            jpis = []
            for group in self.initial_levels:
                # grab the J^pi from the first row in the group
                jpi = group[0].spin * group[0].parity
                # add it to the list
                jpis.append(jpi)
                for (i, sublevel) in enumerate(group):
                    spin = sublevel.spin
                    parity = sublevel.parity
                    rank = jpis.count(jpi)
                    if i == 0:
                        if not sublevel.energy_fixed:
                            self.parameters.append(
                                Parameter(spin,
                                          parity,
                                          'energy',
                                          i + 1,
                                          rank=rank))
                    if not sublevel.width_fixed:
                        if sublevel.energy < sublevel.separation_energy:
                            self.parameters.append(
                                Parameter(spin,
                                          parity,
                                          'width',
                                          i + 1,
                                          rank=rank,
                                          is_anc=True))
                        else:
                            self.parameters.append(
                                Parameter(spin,
                                          parity,
                                          'width',
                                          i + 1,
                                          rank=rank))
        else:
            self.parameters = parameters

        Jpi = [l[0].spin * l[0].parity for l in self.initial_levels]
        self.addresses = []
        for p in self.parameters:
            jpi = p.spin * p.parity
            i = Jpi.index(jpi)
            i += p.rank - 1  # convert from one-based count to zero-based index
            j = p.channel - 1  # convert from one-based count to zero-based index
            self.addresses.append([i, j, p.kind])

        self.n1 = len(self.parameters)
        self.n2 = len(self.data.norm_segment_indices)
        # number of free parameters
        self.nd = self.n1 + self.n2

        self.labels = []
        for i in range(self.n1):
            self.labels.append(self.parameters[i].label)
        for i in self.data.norm_segment_indices:
            self.labels.append(self.data.all_segments[i].nf.label)