Example #1
0
    def generate_xml_from_all_seq(self):
        clear_scene_file_startswith(self.seq_name)
        SceneGenerate.write_range_num_for_RT(self._cfgFile)
        self.readParameterFileList()
        for filename in self.parameter_file_list:
            tcfgfile = os.path.join(session.get_input_dir(), filename)
            prifix = os.path.splitext(filename)[0] + "_"
            SceneGenerate.terr_generate(tcfgfile, prifix)
            SceneGenerate.generate_objects_file(tcfgfile, prifix)
            SceneGenerate.forest_generate(tcfgfile, prifix)

        # if len(self.parameter_file_list) > 0:
        # SceneGenerate.generate_objects_file(self._cfgFile, self.seq_name + "_")
        # SceneGenerate.forest_generate(self._cfgFile, self.seq_name + "_")
        # log("INFO: Generating view and illuminations.")

        # 输出irridiance
        fi = open(
            os.path.join(session.get_output_dir(),
                         self.seq_name + "_" + irradiance_file), 'w')
        sp = SceneParser()
        for filename in self.parameter_file_list:
            tcfgfile = os.path.join(session.get_input_dir(), filename)
            prifix = os.path.splitext(filename)[0] + "_"
            irrstr = sp.parse(tcfgfile, prifix, prifix)
            fi.write(os.path.splitext(filename)[0] + "\n" + irrstr + "\n")
        log("INFO: view and illuminations generated.")
        fi.close()
Example #2
0
    def parse_seq(self):
        clear_param_file_startswith(self.seq_name)
        # write seq info
        finfo = open(
            os.path.join(session.get_output_dir(),
                         self.seq_name + BATCH_INFO_FILE), 'w')

        params = []
        f = open(self.seqPath, 'r')

        seq = json.load(f, object_pairs_hook=OrderedDict)
        groupNames = []
        for groupName in seq:
            groupParam = dict()
            groupNames.append(groupName)
            for paramName in seq[groupName]:  # in each group
                paramValue = seq[groupName][paramName]
                if paramValue.startswith(batch_List_name):
                    arr = paramValue.split(":", 1)
                    arr = arr[1].split("/")
                    index = 0
                    for data in arr:
                        if index not in groupParam:
                            groupParam[index] = dict()
                        groupParam[index][paramName] = data
                        index += 1
            # print groupParam
            params.append(groupParam)

        # mixture between group
        indexList = []
        for i in range(0, len(params)):
            groupLen = len(params[i])
            indexList.append(range(0, groupLen))
        totalIndex = 0
        combinations = list(itertools.product(*indexList))
        for combination in combinations:
            if len(combination) > 0:
                groupIndex = 0
                seq_input_file = os.path.join(
                    session.get_input_dir(),
                    self.seq_name + "_" + str(totalIndex) + ".json")
                finfo.write(self.seq_name + "_" + str(totalIndex) + " ")
                cfg = self.read_config_file()
                totalIndex += 1
                for paramValueIndex in combination:
                    for paramName in params[groupIndex][paramValueIndex]:
                        paraVal = params[groupIndex][paramValueIndex][
                            paramName]
                        print("INFO: --", paramName)
                        self.writeKey(cfg, paramName,
                                      self.getTypedValue(paramName, paraVal))
                        finfo.write(paramName + " " + paraVal + " ")
                    groupIndex += 1
                # write batch config file
                self.writeCfgFile(cfg, seq_input_file)
                finfo.write("\n")
        finfo.close()
Example #3
0
    def run_seq(self):
        currdir = os.path.split(os.path.realpath(__file__))[0]
        os.environ[
            'PATH'] = currdir + '/bin/rt/' + current_rt_program + os.pathsep + os.environ[
                'PATH']
        self.readParameterFileList()
        for filename in self.parameter_file_list:
            log("INFO: " + filename)
            tcfgfile = os.path.join(session.get_input_dir(), filename)
            prifix = os.path.splitext(filename)[0]
            f = open(tcfgfile, 'r')
            cfg = json.load(f)
            excuable = "lessrt"
            scene_path = session.get_scenefile_path()

            distFile = os.path.join(session.get_output_dir(), prifix)
            # parameter = " -o " + distFile
            scene_file_path = os.path.join(scene_path,
                                           prifix + "_" + main_scene_xml_file)
            # cmd = excuable + " " + os.path.join(scene_path, prifix+"_"+main_scene_xml_file) + parameter
            # os.system(cmd)
            cores = cfg["Advanced"]["number_of_cores"]
            if cfg["Advanced"]["network_sim"]:
                subprocess.call([
                    excuable, scene_file_path, "-o", distFile, "-p",
                    str(cores), "-s",
                    os.path.join(session.get_input_dir(), "server.txt")
                ])
            else:
                subprocess.call([
                    excuable, scene_file_path, "-o", distFile, "-p",
                    str(cores)
                ])
                # os.system(excuable + " " + scene_file_path + " " + "-o " + distFile + " -p " + str(cores))
                time.sleep(0.5)
            if output_format not in ("npy", "NPY"):
                if os.path.exists(distFile + ".npy"):
                    self.convert_npy_to_envi(cfg, distFile, output_format)
                if os.path.exists(distFile + "_downwelling.npy"):
                    self.convert_npy_to_envi(cfg, distFile + "_downwelling",
                                             output_format)
                if os.path.exists(distFile + "_upwelling.npy"):
                    self.convert_npy_to_envi(cfg, distFile + "_upwelling",
                                             output_format)
                if os.path.exists(distFile + "_4Components.npy"):
                    data = np.load(distFile + "_4Components.npy")
                    dshape = data.shape
                    if len(dshape) == 3:
                        if dshape[2] <= 4:
                            data = data[:, :, 0]
                        else:
                            data = data[:, :, 0:5]
                    bandlist = []
                    RasterHelper.saveToHdr_no_transform(
                        data, distFile + "_4Components", bandlist,
                        output_format)
                    os.remove(distFile + "_4Components.npy")
Example #4
0
def read_irr_for_seq(seq_name):
    irr_map = dict()  # [seq_name->[boa_band1, boa_band2,...]]
    f = open(
        os.path.join(session.get_output_dir(),
                     seq_name + "_" + irradiance_file))
    current_seq = ""
    for line in f:
        if line.startswith(seq_name):  #
            current_seq = line.strip()
            irr_map[current_seq] = []
        else:
            arr = line.replace("\n", "").strip().split(" ")
            irr = list(map(lambda x: float(x), arr[1:]))
            if len(irr_map[current_seq]) == 0:
                irr_map[current_seq] = irr
            else:
                irr_map[current_seq] = list(
                    map(lambda x, y: x + y, irr, irr_map[current_seq]))
    return irr_map
Example #5
0
                irr_map[current_seq] = irr
            else:
                irr_map[current_seq] = list(
                    map(lambda x, y: x + y, irr, irr_map[current_seq]))
    return irr_map


parser = argparse.ArgumentParser()
parser.add_argument('-t', '--type', help="Product Type.", type=str)
parser.add_argument('-f', '--file', help="info filename.", type=str)
args = parser.parse_args()
# processing thermal products
if args.type in ("T", "BT", "thermal"):
    # read wavelengths
    ft = open(
        os.path.join(session.get_output_dir(), wavelength_file_for_thermal))
    wavelengths = list(map(lambda x: float(x), ft.readline().split(",")))
    ft.close()
    seq_info_files = glob.glob(
        os.path.join(session.get_output_dir(), "*" + BATCH_INFO_FILE))
    for seq_file in seq_info_files:
        seq_name = os.path.splitext(os.path.basename(seq_file))[0].rsplit(
            "_", 1)[0]
        log("INFO: Processing Batch: " + seq_name)
        f = open(seq_file)
        fbt = open(
            os.path.join(session.get_output_dir(), seq_name + "_BT.txt"), 'w')
        for line in f:
            arr = line.strip().split()
            radiance_file = arr[0]  # 实际上为当个模拟的名称
            radiance_path = os.path.join(session.get_output_dir(),