def runSimulation(self):
        """ Run the ablation model and srote results. """


        # Run the erosion simulation
        results_list, wake_results = runSimulationErosion(self.const, compute_wake=False)

        # Store simulation results
        self.simulation_results = SimulationResults(self.const, results_list, wake_results)


        ### Sort saved files into a directory structure split by velocity and density ###

        # Extract the velocity part
        split_file = self.file_name.split("_")
        vel = float(split_file[2].strip("v"))

        # Make velocity folder name
        vel_folder = "v{:02d}".format(int(vel))
        vel_folder_path = os.path.join(self.output_dir, vel_folder)

        # Create the velocity folder if it doesn't already exist
        if not os.path.isdir(vel_folder_path):
            os.makedirs(vel_folder_path)


        # Extract the density part
        dens = 100*int(float(split_file[4].strip("rho"))/100)

        # Make density folder name
        dens_folder = "rho{:04d}".format(dens)
        dens_folder_path = os.path.join(vel_folder_path, dens_folder)

        # Make the density folder
        if not os.path.isdir(dens_folder_path):
            os.makedirs(dens_folder_path)


        ###


        # # Save results as a JSON file
        # self.saveJSON()

        # Save results as a pickle file
        savePickle(self, dens_folder_path, self.file_name + ".pickle")
Exemplo n.º 2
0
    def saveTrajectoryResults(self, traj, save_plots):
        """ Save trajectory results to the disk. """

        # Generate the name for the output directory (add list of country codes at the end)
        output_dir = self.generateTrajOutputDirectoryPath(traj, make_dirs=True)

        # Save the report
        traj.saveReport(output_dir,
                        traj.file_name + '_report.txt',
                        uncertainties=traj.uncertainties,
                        verbose=False)

        # Save the picked trajectory structure
        savePickle(traj, output_dir, traj.file_name + '_trajectory.pickle')

        # Save the plots
        if save_plots:
            traj.save_results = True
            traj.savePlots(output_dir, traj.file_name, show_plots=False)
            traj.save_results = False
Exemplo n.º 3
0
    def saveTrajectoryResults(self, traj, save_plots):
        """ Save trajectory results to the disk. """

        # Generate the name for the output directory (add list of country codes at the end)
        output_dir = os.path.join(self.dir_path, OUTPUT_TRAJ_DIR, \
            jd2Date(traj.jdt_ref, dt_obj=True).strftime("%Y%m%d_%H%M%S.%f")[:-3] + "_" \
            + "_".join(list(set([obs.station_id[:2] for obs in traj.observations]))))

        # Save the report
        traj.saveReport(output_dir,
                        traj.file_name + '_report.txt',
                        uncertainties=traj.uncertainties,
                        verbose=False)

        # Save the picked trajectory structure
        savePickle(traj, output_dir, traj.file_name + '_trajectory.pickle')

        # Save the plots
        if save_plots:
            traj.save_results = True
            traj.savePlots(output_dir, traj.file_name, show_plots=False)
            traj.save_results = False
    def _solve(self, form, format):
        """
        Run wmpg trajectory solver and return the directory path of the output files

        :param form: (UploadForm) the form object submitted by the user
        :param format: (str) supported input data format (MILIG, CAMS and RMSJSON currently)
        :return: (str) directory of output
        """

        dir_path = os.path.join(self.temp_dir, uuid.uuid4().hex)
        max_toffset = float(form.max_toffset.data)
        v_init_part = float(form.v_init_part.data)
        v_init_ht = float(
            form.v_init_ht.data) if form.v_init_ht.data != -1 else None

        os.mkdir(dir_path)

        if format == "MILIG":
            filenames = self._save_files_from_form(form.upload_methods,
                                                   dir_path)
            try:
                traj = solveTrajectoryMILIG(dir_path,
                                            filenames['file_input'],
                                            max_toffset=max_toffset,
                                            v_init_part=v_init_part,
                                            v_init_ht=v_init_ht,
                                            monte_carlo=False,
                                            save_results=False,
                                            show_plots=False,
                                            verbose=False)
                traj.saveReport(dir_path, "report.txt")
                savePickle(traj, dir_path, "trajectory.pickle")
            except:
                self.remove_saved_files(dir_path)
                raise Exception("Input files incorrect")

        elif format == "CAMS":
            filenames = self._save_files_from_form(form.upload_methods,
                                                   dir_path)

            try:
                # Get locations of stations
                stations = loadCameraSites(
                    os.path.join(dir_path, filenames["file_camera_sites"]))

                time_offsets = None
                if 'file_camera_time_offsets' in filenames:
                    # Get time offsets of cameras
                    time_offsets = loadCameraTimeOffsets(
                        os.path.join(dir_path,
                                     filenames["file_camera_time_offsets"]))

                # Get the meteor data
                meteor_list = loadFTPDetectInfo(os.path.join(
                    dir_path, filenames["file_FTP_detect_info"]),
                                                stations,
                                                time_offsets=time_offsets)

                traj = solveTrajectoryCAMS(meteor_list,
                                           dir_path,
                                           max_toffset=max_toffset,
                                           v_init_part=v_init_part,
                                           v_init_ht=v_init_ht,
                                           monte_carlo=False,
                                           save_results=False,
                                           show_plots=False,
                                           verbose=False)
                traj.saveReport(dir_path, "report.txt")
                savePickle(traj, dir_path, "trajectory.pickle")
            except:
                self.remove_saved_files(dir_path)
                raise Exception("Input files incorrect")

        elif format == "RMSJSON":
            filenames = self._save_files_from_form(form.upload_methods,
                                                   dir_path)

            # Load all json files
            json_list = []
            for json_file in filenames.values():
                with open(os.path.join(dir_path, json_file)) as f:
                    data = json.load(f)
                    json_list.append(data)

            try:
                traj = solveTrajectoryRMS(json_list,
                                          dir_path,
                                          max_toffset=max_toffset,
                                          v_init_part=v_init_part,
                                          v_init_ht=v_init_ht,
                                          monte_carlo=False,
                                          show_plots=False,
                                          save_results=False,
                                          verbose=False)
                traj.saveReport(dir_path, "report.txt")
                savePickle(traj, dir_path, "trajectory.pickle")
            except:
                self.remove_saved_files(dir_path)
                raise Exception("Input files incorrect")
        else:
            assert "Format not found"

        return dir_path
                # Solve trajectory
                traj = traj.run()

                # Calculate orbit of an intersecting planes solution
                if traj_solver == 'planes':

                    # Use the average velocity of the first half of the trajectory for the initial velocity
                    v_init_fh = calcVelocityOfFirstHalf(traj)

                    # Calculate the orbit
                    traj.orbit = calcOrbit(traj.avg_radiant, v_init_fh, traj.v_avg, traj.state_vect_avg, \
                        traj.jd_avg, stations_fixed=True, reference_init=False)

                    # Save the intersecting planes solution
                    savePickle(traj, output_dir,
                               traj.file_name + '_planes.pickle')

                # Calculate the LoS with the average velocity of the first half
                elif traj_solver == 'milig':

                    # Use the average velocity of the first half of the trajectory for the initial velocity
                    v_init_fh = calcVelocityOfFirstHalf(traj)

                    # Calculate the orbit with the average velocity
                    traj.orbit = calcOrbit(traj.radiant_eci_mini, v_init_fh, traj.v_avg, traj.state_vect_mini, \
                        traj.rbeg_jd, stations_fixed=False, reference_init=True)

                    # Save the simulated milig solution
                    savePickle(traj, output_dir,
                               traj.file_name + '_milig.pickle')