예제 #1
0
def get_geo_ts_collection(datasets_config, data_dir):
    """Return a collection of geo-ts repos in datasets config file."""
    geo_ts_repos = []
    for source in datasets_config.sources:
        station_file = source["params"]["stations_met"]
        if not os.path.isabs(station_file):
            # Relative paths will be prepended the data_dir
            station_file = os.path.join(data_dir, station_file)
        geo_ts_repos.append(GeoTsRepository(source["params"], station_file,
                                            ""))
    return geo_ts_repository_collection.GeoTsRepositoryCollection(geo_ts_repos)
예제 #2
0
 def construct_geots_repo(datasets_config, epsg=None):
     geo_ts_repos = []
     src_types_to_extract = []
     for source in datasets_config.sources:
         if epsg is not None:
             source['params'].update({'epsg': epsg})
         # geo_ts_repos.append(geo_ts_repo_constructor(source['repository'], source['params'], self.region_config))
         geo_ts_repos.append(source['repository'](**source['params']))
         src_types_to_extract.append(source['types'])
     return geo_ts_repository_collection.GeoTsRepositoryCollection(
         geo_ts_repos, src_types_per_repo=src_types_to_extract)
예제 #3
0
def geots_repo_from_config(datasets_config_file, epsg=None):
    datasets_config = YamlContent(datasets_config_file)
    # Construct GeoTsRepository
    geo_ts_repos = []
    src_types_to_extract = []
    for source in datasets_config.sources:
        if epsg is not None:
            source['params'].update({'epsg': epsg})
        # geo_ts_repos.append(geo_ts_repo_constructor(source['repository'], source['params'], self.region_config))
        geo_ts_repos.append(
            geo_ts_repo_constructor(source['repository'], source['params']))
        src_types_to_extract.append(source['types'])
    return geo_ts_repository_collection.GeoTsRepositoryCollection(
        geo_ts_repos, src_types_per_repo=src_types_to_extract)
예제 #4
0
    def construct_repos(self, overrides):
        """
        Construct repositories
        """
        # Read region, model and datasets config files
        region_config_file = os.path.join(self.config_dir,
                                          self.region_config_file)
        region_config = RegionConfig(region_config_file)

        model_config_file = os.path.join(self.config_dir,
                                         self.model_config_file)
        model_config = ModelConfig(model_config_file,
                                   overrides=overrides.get("model", {}))

        datasets_config_file = os.path.join(self.config_dir,
                                            self.datasets_config_file)
        datasets_config = YamlContent(datasets_config_file)

        interpolation_config_file = os.path.join(
            self.config_dir, self.interpolation_config_file)
        interpolation_config = InterpolationConfig(interpolation_config_file)

        # Construct RegionModelRepository
        self.region_model = r_m_repo_constructors[cls_path(
            region_config.repository()['class'])](region_config, model_config,
                                                  self.region_model_id)
        # Construct InterpolationParameterRepository
        self.interp_repos = InterpolationParameterRepository(
            interpolation_config)
        # Construct GeoTsRepository
        geo_ts_repos = []
        for source in datasets_config.sources:
            geo_ts_repos.append(geo_ts_repo_constructors[cls_path(
                source['repository'])](source['params'], region_config))
        self.geo_ts = geo_ts_repository_collection.GeoTsRepositoryCollection(
            geo_ts_repos)
        # Construct destination repository
        self.dst_repo = []
        if hasattr(datasets_config, 'destinations'):
            for repo in datasets_config.destinations:
                repo['repository'] = target_repo_constructors[cls_path(
                    repo['repository'])](repo['params'])
                #[dst['time_axis'].update({'start_datetime': utctime_from_datetime(dst['time_axis']['start_datetime'])})
                # for dst in repo['1D_timeseries'] if dst['time_axis'] is not None]
                [
                    dst.update({'time_axis': self.time_axis})
                    if dst['time_axis'] is None else dst.update({
                        'time_axis':
                        api.Timeaxis(
                            utctime_from_datetime(
                                dst['time_axis']['start_datetime']),
                            dst['time_axis']['time_step_length'],
                            dst['time_axis']['number_of_steps'])
                    }) for dst in repo['1D_timeseries']
                ]
                self.dst_repo.append(repo)

        # Construct StateRepository
        if hasattr(self, 'initial_state'):
            self.initial_state_repo = self.initial_state['repository'][
                'class'](**self.initial_state['repository']['params'])
        if hasattr(self, 'end_state'):
            self.end_state_repo = self.end_state['repository']['class'](
                **self.end_state['repository']['params'])