コード例 #1
0
    def init_generators(self, CloudGenerator, AirGenerator):
        """
        Initialize the medium generators. The cloud generator also loads the Mie scattering
        tables for the given wavelengths at this point.

        Parameters
        -------
        CloudGenerator: a shdom.Generator class object.
            Creates the cloudy medium.
        AirGenerator: a shdom.Air class object
            Creates the scattering due to air molecules

        Returns
        -------
        cloud_generator: a shdom.CloudGenerator object.
            Creates the cloudy medium. The loading of Mie tables takes place at this point.
        air_generator: a shdom.AirGenerator object
            Creates the scattering due to air molecules
        """
        cloud_generator = CloudGenerator(self.args)
        for wavelength in self.args.wavelength:
            table_path = self.args.mie_base_path.replace('<wavelength>', '{}'.format(shdom.int_round(wavelength)))
            cloud_generator.add_mie(table_path)

        air_generator = None
        if self.args.add_rayleigh:
            air_generator = AirGenerator(self.args)
        return cloud_generator, air_generator
コード例 #2
0
def get_file_paths(wavelength, args):
    """
    Retrieve the file paths according to the wavelength and base path argument.
    
    Parameters
    ----------
    wavelength: float
            Wavelength in microns
    args: arguments from argparse.ArgumentParser()
        Arguments required for this function
    
    Returns
    -------
    mono_path: str
        Path to the monodisperse table
    poly_path: str
        Path to the polydisperse table
    """
    if not os.path.exists(args.mono_dir):
        os.makedirs(args.mono_dir)
    if not os.path.exists(args.poly_dir):
        os.makedirs(args.poly_dir)

    file_name = args.mie_base_name.replace(
        '<wavelength>', '{}'.format(shdom.int_round(wavelength)))
    if args.polarized:
        file_name += 'pol'
    mono_path = os.path.join(args.mono_dir, file_name)
    poly_path = os.path.join(args.poly_dir, file_name)
    return mono_path, poly_path
コード例 #3
0
    def average_scatterers(self, scatterer_list):
        first = True
        for scatterer in scatterer_list:
            if first:
                lwc = scatterer.lwc
                reff = scatterer.reff
                veff = scatterer.veff
                wavelength = scatterer.wavelength
                first = False
            else:
                assert wavelength == scatterer.wavelength
                lwc = lwc + scatterer.lwc
                reff = reff + scatterer.reff
                veff = veff + scatterer.veff

        lwc._data /= len(scatterer_list)
        reff._data /= len(scatterer_list)
        veff._data /= len(scatterer_list)

        scatterer = shdom.MicrophysicalScatterer(lwc, reff, veff)
        mie = shdom.MiePolydisperse()
        table_path = 'mie_tables/polydisperse/Water_{}nm.scat'.format(
            shdom.int_round(wavelength))
        mie.read_table(table_path)
        reff._data[reff._data < mie.size_distribution.reff.min(
        )] = mie.size_distribution.reff.min()
        veff._data[veff._data < mie.size_distribution.veff.min(
        )] = mie.size_distribution.veff.min()
        scatterer.add_mie(mie)
        return scatterer.get_optical_scatterer(wavelength)
コード例 #4
0
    def get_medium_estimator(self, measurements):
        """
        Generate the medium estimator for optimization.

        Parameters
        ----------
        measurements: shdom.AirMSPIMeasurements
            The acquired measurements.
        ground_truth: shdom.Scatterer
            The ground truth scatterer


        Returns
        -------
        medium_estimator: shdom.MediumEstimator
            A medium estimator object which defines the optimized parameters.
        """
        wavelength = measurements.wavelength
        # if not isinstance(wavelength, list):
        #     wavelength = [wavelength]

        # Define the grid for reconstruction

        extinction_grid = albedo_grid = phase_grid = shdom.Grid(
            bounding_box=measurements.bb,
            nx=self.args.nx,
            ny=self.args.ny,
            nz=self.args.nz)
        grid = extinction_grid + albedo_grid + phase_grid

        # Find a cloud mask for non-cloudy grid points

        carver = shdom.SpaceCarver(measurements)
        mask = carver.carve(grid,
                            agreement=0.7,
                            thresholds=self.args.radiance_threshold)

        # show_mask = 1
        # if show_mask:
        #     a = (mask.data).astype(int)
        #     shdom.cloud_plot(a)

        # Define the known albedo and phase: either ground-truth or specified, but it is not optimized.
        if self.args.use_forward_albedo is False or self.args.use_forward_phase is False:
            table_path = self.args.mie_base_path.replace(
                '<wavelength>', '{}'.format(shdom.int_round(wavelength)))
            self.cloud_generator.add_mie(table_path)

        albedo = self.cloud_generator.get_albedo(wavelength, albedo_grid)
        phase = self.cloud_generator.get_phase(wavelength, phase_grid)

        extinction = shdom.GridDataEstimator(
            self.cloud_generator.get_extinction(grid=grid),
            min_bound=1e-3,
            max_bound=2e2)
        cloud_estimator = shdom.OpticalScattererEstimator(
            wavelength, extinction, albedo, phase)
        cloud_estimator.set_mask(mask)

        # Create a medium estimator object (optional Rayleigh scattering)
        medium_estimator = shdom.MediumEstimator()
        if self.args.add_rayleigh:
            air = self.air_generator.get_scatterer(wavelength)
            medium_estimator.set_grid(cloud_estimator.grid + air.grid)
            medium_estimator.add_scatterer(air, 'air')
        else:
            medium_estimator.set_grid(cloud_estimator.grid)

        medium_estimator.add_scatterer(cloud_estimator, self.scatterer_name)

        return medium_estimator
コード例 #5
0
    def get_medium_estimator(self, measurements):
        """
        """

        num_of_mediums = self.args.num_mediums
        cv_index = self.args.use_cross_validation
        time_list = measurements.time_list
        if cv_index >= 0:
            time_list = np.delete(time_list, cv_index)

        assert isinstance(num_of_mediums, int) and num_of_mediums <= len(time_list)

        wavelength = measurements.wavelength
        if not isinstance(wavelength,list):
            wavelength = [wavelength]

        # Define the grid for reconstruction
        grid = albedo_grid = phase_grid = shdom.Grid(bounding_box=measurements.bb,nx=self.args.nx,ny=self.args.ny,nz=self.args.nz)

        if self.args.assume_moving_cloud:
            cloud_velocity = None
        else:
            cloud_velocity = [0,0,0]


        # Find a cloud mask for non-cloudy grid points
        dynamic_carver = shdom.DynamicSpaceCarver(measurements)
        mask_list, dynamic_grid, cloud_velocity = dynamic_carver.carve(grid, agreement=0.70,
                            time_list = measurements.time_list, thresholds=self.args.radiance_threshold,
                            vx_max = 10, vy_max=10, gt_velocity = cloud_velocity)
        mask = mask_list[0]
        show_mask=1
        if show_mask:
            a = mask.data.astype(int)
            shdom.cloud_plot(a)
            print(cloud_velocity)
            print(sum(sum(sum(a))))
        table_path = self.args.mie_base_path.replace('<wavelength>', '{}'.format(shdom.int_round(wavelength[0])))
        self.cloud_generator.add_mie(table_path)
        albedo = self.cloud_generator.get_albedo(wavelength[0], [albedo_grid] * num_of_mediums)
        phase = self.cloud_generator.get_phase(wavelength[0], [phase_grid] * num_of_mediums)

        # cv_index = self.args.use_cross_validation
        # if cv_index >= 0:
        #     # del dynamic_grid[cv_index]
        #     # del mask_list[cv_index]
        #     # del albedo[cv_index]
        #     # del phase[cv_index]
        #     time_list = np.delete(measurements.time_list, cv_index)
        time_list = np.mean(np.split(time_list, num_of_mediums), 1)


        extinction = shdom.DynamicGridDataEstimator(self.cloud_generator.get_extinction(wavelength, [grid] * num_of_mediums),
                                                    min_bound=1e-5,
                                                    max_bound=2e2)
        kw_optical_scatterer = {"extinction": extinction, "albedo": albedo, "phase": phase}
        cloud_estimator = shdom.DynamicScattererEstimator(wavelength=wavelength, time_list=time_list, **kw_optical_scatterer)
        cloud_estimator.set_mask([mask] * num_of_mediums)

        # Create a medium estimator object (optional Rayleigh scattering)
        air = self.air_generator.get_scatterer(wavelength)
        medium_estimator = shdom.DynamicMediumEstimator(cloud_estimator, air, cloud_velocity)

        return medium_estimator
コード例 #6
0
    def get_medium_estimator(self, measurements, ground_truth):
        """
        Generate the medium estimator for optimization.

        Parameters
        ----------
        measurements: shdom.Measurements
            The acquired measurements.
        ground_truth: shdom.Scatterer
            The ground truth scatterer


        Returns
        -------
        medium_estimator: shdom.MediumEstimator
            A medium estimator object which defines the optimized parameters.
        """
        wavelength = ground_truth.wavelength

        # Define the grid for reconstruction
        if self.args.use_forward_grid:
            extinction_grid = ground_truth.extinction.grid
            albedo_grid = ground_truth.albedo.grid
            phase_grid = ground_truth.phase.grid
        else:
            extinction_grid = albedo_grid = phase_grid = self.cloud_generator.get_grid(
            )
        grid = extinction_grid + albedo_grid + phase_grid

        # Find a cloud mask for non-cloudy grid points
        if self.args.use_forward_mask:
            mask = ground_truth.get_mask(threshold=1.0)
        else:
            carver = shdom.SpaceCarver(measurements)
            mask = carver.carve(grid,
                                agreement=0.9,
                                thresholds=self.args.radiance_threshold)

        # Define the known albedo and phase: either ground-truth or specified, but it is not optimized.
        if self.args.use_forward_albedo is False or self.args.use_forward_phase is False:
            table_path = self.args.mie_base_path.replace(
                '<wavelength>', '{}'.format(shdom.int_round(wavelength)))
            self.cloud_generator.add_mie(table_path)

        if self.args.use_forward_albedo:
            albedo = ground_truth.albedo
        else:
            albedo = self.cloud_generator.get_albedo(wavelength, albedo_grid)

        if self.args.use_forward_phase:
            phase = ground_truth.phase
        else:
            phase = self.cloud_generator.get_phase(wavelength, phase_grid)

        extinction = shdom.GridDataEstimator(
            self.cloud_generator.get_extinction(grid=grid),
            min_bound=1e-3,
            max_bound=2e2)
        cloud_estimator = shdom.OpticalScattererEstimator(
            wavelength, extinction, albedo, phase)
        cloud_estimator.set_mask(mask)

        # Create a medium estimator object (optional Rayleigh scattering)
        medium_estimator = shdom.MediumEstimator()
        if self.args.add_rayleigh:
            air = self.air_generator.get_scatterer(wavelength)
            medium_estimator.set_grid(cloud_estimator.grid + air.grid)
            medium_estimator.add_scatterer(air, 'air')
        else:
            medium_estimator.set_grid(cloud_estimator.grid)

        medium_estimator.add_scatterer(cloud_estimator, self.scatterer_name)

        return medium_estimator