Esempio n. 1
0
    def test_collocate_collapse_expand(self):
        """Test whether collocating, collapsing and expanding work"""
        collocator = Collocator()

        test = xr.Dataset({
            "time": ("time", np.arange("2000", "2010", dtype="M8[Y]")),
            "lat": ("time", np.arange(10)),
            "lon": ("time", np.arange(10)),
        })

        collocations = collocator.collocate(test,
                                            test,
                                            max_interval="30 days",
                                            max_distance="150 miles")

        collapsed = collapse(collocations)
        expanded = expand(collocations)
Esempio n. 2
0
    def test_flat_to_main_coord(self):
        """Tests Collocator._flat_to_main_coord

        This method is crucial since it stacks the whole input datasets for the
        collocating routine and makes them collocateable.
        """
        collocator = Collocator()

        test = xr.Dataset({
            "time": ("time", np.arange(10)),
            "lat": ("time", np.arange(10)),
            "lon": ("time", np.arange(10)),
        })
        check = xr.Dataset({
            "time": ("collocation", np.arange(10)),
            "lat": ("collocation", np.arange(10)),
            "lon": ("collocation", np.arange(10)),
        })
        results = collocator._flat_to_main_coord(test)
        assert check.equals(results)

        test = xr.Dataset({
            "time": ("main", np.arange(10)),
            "lat": ("main", np.arange(10)),
            "lon": ("main", np.arange(10)),
        })
        check = xr.Dataset({
            "time": ("collocation", np.arange(10)),
            "lat": ("collocation", np.arange(10)),
            "lon": ("collocation", np.arange(10)),
        })
        results = collocator._flat_to_main_coord(test)
        assert check.equals(results)

        test = xr.Dataset({
            "time": ("scnline", np.arange(5)),
            "lat": (("scnline", "scnpos"), np.arange(10).reshape(5, 2)),
            "lon": (("scnline", "scnpos"), np.arange(10).reshape(5, 2)),
        })
        check = test.stack(collocation=("scnline", "scnpos"))
        results = collocator._flat_to_main_coord(test)
        assert check.equals(results)
Esempio n. 3
0
    def __init__(self,
                 file=None,
                 collocator=None,
                 processes=10,
                 verbose=0,
                 sea_mask_file=None,
                 elevation_file=None):
        """Initialize a SPAREICE object

        Args:
            file: A JSON file with the coefficients of SPAREICE. If not given,
                the standard configuration will be loaded.
            collocator: SPARE-ICE requires a collocator when it should be
                generated from filesets. You can pass your own
                :class:`Collocator` object here if you want.
            processes: Number of processes to parallelize the training or
                collocation search. 10 is the default. Best value depends on
                your machine.
            verbose (int): Control ``GridSearchCV`` verbosity. The higher the
            value, the more debug messages are printed.
        """

        self.verbose = verbose
        self.processes = processes
        self.name = "SPARE-ICE"

        if sea_mask_file is None:
            self.sea_mask = None
        else:
            self.sea_mask = np.flip(
                np.array(imageio.imread(sea_mask_file) == 255), axis=0)

        if elevation_file is None:
            self.elevation_grid = None
        else:
            ds = xr.open_dataset(elevation_file, decode_times=False)
            self.elevation_grid = ds.data.squeeze().values

        if collocator is None:
            self.collocator = Collocator()
        else:
            self.collocator = collocator

        # SPARE-ICE consists of two retrievals: one neural network for the IWP
        # and one decision tree classifier for the ice cloud flag
        self._iwp = None
        self._ice_cloud = None

        # The users can load SPARE-ICE from their own training or the standard
        # parameters:
        if file is None:
            try:
                self.load(STANDARD_FILE)
            except Exception as e:
                warnings.warn(
                    "Could not load the standard parameters of SPARE-ICE!\n"
                    "You need to train SPARE-ICE by yourself.")
                warnings.warn(str(e))
                self._iwp = RetrievalProduct()
                self._ice_cloud = RetrievalProduct()
        else:
            self.load(file)