Пример #1
0
 def filter_months(data_array, month_list):
     # To define in GeoDataArray !!!!and GeoDS!!!!
     if month_list is not None:
         condition = xr.zeros_like(data_array.t)
         for i in range(len(data_array.t)):
             condition[i] = data_array.t[i].values[()].month in util.months_to_number(month_list)
         data_array = data_array.where(condition, drop=True)
     return data_array
Пример #2
0
 def crop_months(self, new_month_list):
     condition = xr.zeros_like(self.data.t)
     for i in range(len(self.data.t)):
         condition[i] = self.data.t[i].values[()].month in util.months_to_number(new_month_list)
     self.data = self.data.where(condition, drop=True)
     self.months = new_month_list
     print("____ Data cropped to the new month list.")
     return self
Пример #3
0
    def __init__(self, experiment, start_year, end_year, month_list, verbose,
                 logger):
        super(NorESMDS, self).__init__(verbose, logger)

        self.t = None
        self.lsm = None
        self.start_year = start_year
        self.end_year = end_year
        self.experiment = experiment
        if month_list is None:
            self.months = None
        elif month_list == "full":
            self.months = util.months_to_number(self.MONTHS)
        else:
            self.months = util.months_to_number(month_list)

        self.import_data()
        self.import_coordinates()
Пример #4
0
    def import_coordinates(self):
        self.lon, self.lat = sort_coordinates(self.grid.plon.values,
                                              self.grid.plat.values)
        self.lon_p, self.lat_p = cycle_coordinates(self.lon, self.lat)
        self.transform_matrix = get_transform_matrix(self.grid.plon.values)

        self.z = np.sort(self.sample_data.depth.values)
        self.z_p = self.z

        self.t = [
            cftime.Datetime360Day(year, month, 1)
            for year in np.arange(int(self.start_year),
                                  int(self.end_year) + 1)
            for month in util.months_to_number(self.months)
        ]

        super(OCNMDS, self).import_coordinates()
Пример #5
0
    def get(self,
            data,
            zone=zones.NoZone(),
            mode_lon=None,
            value_lon=None,
            mode_lat=None,
            value_lat=None,
            mode_z=None,
            value_z=None,
            mode_t=None,
            value_t=None,
            new_start_year=None,
            new_end_year=None,
            new_month_list=None):
        """
        TO FACTORISE
        """

        geo_da = proc.GeoDataArray(
            data, ds=self,
            process=self.process)  # add the GeoDataArray wrapper
        geo_da = zone.compact(geo_da)

        if any([
                new_start_year is not None, new_end_year is not None,
                new_month_list is not None
        ]):
            print("____ Truncation to new time coordinates.")

        try:
            if new_start_year is not None and new_start_year < self.start_year:
                raise ValueError(
                    "**** The new start year is smaller than the imported one."
                )
            elif new_end_year is not None and new_end_year > self.end_year:
                raise ValueError(
                    "**** The new end year is larger than the imported one.")
            elif new_start_year is None and new_end_year is not None:
                geo_da.crop_years(self.start_year, new_end_year)
            elif new_start_year is not None and new_end_year is None:
                geo_da.crop_years(new_start_year, self.end_year)
            elif new_start_year is not None and new_end_year is not None:
                geo_da.crop_years(new_start_year, new_end_year)
            else:
                pass

            if new_month_list is not None and self.months is None:
                raise ValueError(
                    f"**** The month cropping is not available with {type(self)}."
                )
            elif new_month_list is not None and \
                    not all(
                        month in util.months_to_number(self.months) for month in util.months_to_number(new_month_list)):
                raise ValueError(
                    "**** The new month list includes months not yet imported."
                )
            elif new_month_list is not None:
                geo_da.crop_months(new_month_list)
            else:
                pass

        except ValueError as error:
            print(error)
            print("____ The crop was not performed.")

        geo_da.get_lon(mode_lon, value_lon)
        geo_da.get_lat(mode_lat, value_lat)
        geo_da.get_z(mode_z, value_z)
        geo_da.get_t(mode_t, value_t)

        return geo_da