Exemple #1
0
 def test_config_file_does_not_exist(self):
     config_obj = dict(config_files=[
         'bibo.yaml',
     ])
     with self.assertRaises(ValueError) as cm:
         get_config_dict(**config_obj)
     self.assertEqual("Cannot find configuration 'bibo.yaml'",
                      f'{cm.exception}')
Exemple #2
0
    def test_output_size_option(self):
        config_obj = _get_config_obj(output_size='120, 140')
        config = get_config_dict(config_obj)
        self.assertIn('output_size', config)
        self.assertEqual([120, 140], config['output_size'])

        config_obj = _get_config_obj(output_size='120,abc')
        with self.assertRaises(ValueError) as cm:
            get_config_dict(config_obj)
        self.assertEqual(
            "output_size must have the form <width>,<height>, where both values must be positive integer numbers",
            f'{cm.exception}')
Exemple #3
0
def gen_cube_wrapper(input_paths, output_path, sort_mode=False, input_processor_name=None) \
        -> Tuple[bool, Optional[str]]:
    output = None

    def output_monitor(msg):
        nonlocal output
        if output is None:
            output = msg + '\n'
        else:
            output += msg + '\n'

    config = get_config_dict(
        input_paths=input_paths,
        input_processor_name=input_processor_name,
        output_path=output_path,
        output_size='320,180',
        output_region='-4,47,12,56',
        output_resampling='Nearest',
        output_variables='analysed_sst',
        sort_mode=sort_mode,
    )

    output_metadata = dict(
        title='Test Cube',
        project='xcube',
    )

    return gen_cube(dry_run=False, monitor=output_monitor, output_metadata=output_metadata, **config), output
Exemple #4
0
    def test_output_variables_option(self):
        config_obj = _get_config_obj(output_variables='hanni, nanni, pfanni')
        config = get_config_dict(config_obj)
        self.assertIn('output_variables', config)
        self.assertEqual([('hanni', None), ('nanni', None), ('pfanni', None)],
                         config['output_variables'])

        config_obj = _get_config_obj(output_variables='')
        with self.assertRaises(ValueError) as cm:
            get_config_dict(config_obj)
        self.assertEqual("output_variables must be a list of existing variable names",
                         f'{cm.exception}')

        config_obj = _get_config_obj(output_variables='a*,')
        with self.assertRaises(ValueError) as cm:
            get_config_dict(config_obj)
        self.assertEqual("output_variables must be a list of existing variable names",
                         f'{cm.exception}')
Exemple #5
0
    def test_output_region_option(self):
        config_obj = _get_config_obj(output_region='-10.5, 5., 10.5, 25.')
        config = get_config_dict(config_obj)
        self.assertIn('output_region', config)
        self.assertEqual([-10.5, 5., 10.5, 25.], config['output_region'])

        config_obj = _get_config_obj(output_region='50,_2,55,21')
        with self.assertRaises(ValueError) as cm:
            get_config_dict(config_obj)
        self.assertEqual("output_region must have the form <lon_min>,<lat_min>,<lon_max>,<lat_max>,"
                         " where all four numbers must be floating point numbers in degrees",
                         f'{cm.exception}')

        config_obj = _get_config_obj(output_region='50, 20, 55')
        with self.assertRaises(ValueError) as cm:
            get_config_dict(config_obj)
        self.assertEqual("output_region must have the form <lon_min>,<lat_min>,<lon_max>,<lat_max>,"
                         " where all four numbers must be floating point numbers in degrees",
                         f'{cm.exception}')
Exemple #6
0
def gen_cube_wrapper(input_paths, output_path, append_mode):
    config = get_config_dict(locals())
    return gen_cube(input_processor='default',
                    output_size=(320, 180),
                    output_region=(-4., 47., 12., 56.),
                    output_resampling='Nearest',
                    output_variables=[('analysed_sst', dict(name='SST'))],
                    dry_run=False,
                    monitor=None,
                    **config)
Exemple #7
0
 def test_config_file_overwritten_by_config_obj(self):
     try:
         _create_temp_yaml(TEMP_PATH_FOR_YAML, CONFIG_2_NAME, CONFIG_1_YAML)
         config_obj = _get_config_obj(config_file=CONFIG_1_FILE_LIST,
                                      output_variables='a,b')
         _create_temp_yaml(TEMP_PATH_FOR_YAML, CONFIG_1_NAME, config_obj)
         config = get_config_dict(config_obj)
         self.assertIn('output_variables', config)
         self.assertIsNotNone(['a', 'b'], config['output_variables'])
     finally:
         if os.path.exists(TEMP_PATH_FOR_YAML):
             shutil.rmtree(TEMP_PATH_FOR_YAML)
             print('Successfully removed folder')
Exemple #8
0
    def test_config_file_alone(self):
        try:
            _create_temp_yaml(TEMP_PATH_FOR_YAML, CONFIG_2_NAME, CONFIG_1_YAML)
            config_obj = _get_config_obj(config_file=CONFIG_1_FILE_LIST)
            _create_temp_yaml(TEMP_PATH_FOR_YAML, CONFIG_1_NAME, config_obj)

            config = get_config_dict(config_obj)
            self.assertIsNotNone(config)
            self.assertEqual([2000, 1000], config['output_size'])
            self.assertEqual([0, 20, 20, 30], config['output_region'])
            self.assertEqual([('x', None), ('y', None), ('z*', None)], config['output_variables'])
        finally:
            if os.path.exists(TEMP_PATH_FOR_YAML):
                shutil.rmtree(TEMP_PATH_FOR_YAML)
                print('Successfully removed folder')
Exemple #9
0
def gen(input: Sequence[str], proc: str, config: Sequence[str], output: str,
        format: str, size: str, region: str, variables: str, resampling: str,
        append: bool, prof: bool, dry_run: bool, info: bool, sort: bool):
    """
    Generate xcube dataset.
    Data cubes may be created in one go or successively for all given inputs.
    Each input is expected to provide a single time slice which may be appended, inserted or which may replace an
    existing time slice in the output dataset.
    The input paths may be one or more input files or a pattern that may contain wildcards '?', '*', and '**'.
    The input paths can also be passed as lines of a text file. To do so, provide exactly one input file with
    ".txt" extension which contains the actual input paths to be used.
    """
    dry_run = dry_run
    info_mode = info

    from xcube.api.gen.config import get_config_dict
    from xcube.api.gen.gen import gen_cube
    # Force loading of plugins
    __import__('xcube.util.plugin')

    if info_mode:
        print(_format_info())
        return 0

    config = get_config_dict(
        input_paths=input,
        input_processor_name=proc,
        config_files=config,
        output_path=output,
        output_writer_name=format,
        output_size=size,
        output_region=region,
        output_variables=variables,
        output_resampling=resampling,
        profile_mode=prof,
        append_mode=append,
        sort_mode=sort,
    )

    gen_cube(dry_run=dry_run, monitor=print, **config)

    return 0
Exemple #10
0
def gen_cube_wrapper(input_paths, output_path, sort_mode=False, input_processor_name='default') \
        -> Tuple[bool, Optional[str]]:
    output = None

    def output_monitor(msg):
        nonlocal output
        if output is None:
            output = msg + '\n'
        else:
            output += msg + '\n'

    config = get_config_dict(dict(input_paths=input_paths, output_path=output_path))
    return gen_cube(input_processor_name=input_processor_name,
                    output_size=(320, 180),
                    output_region=(-4., 47., 12., 56.),
                    output_resampling='Nearest',
                    output_variables=[('analysed_sst', dict(name='SST'))],
                    sort_mode=sort_mode,
                    dry_run=False,
                    monitor=output_monitor,
                    **config), output
Exemple #11
0
def gen(input: str, proc: str, config: tuple, output: str, format: str,
        size: str, region: str, variables: str, resampling: str, append: bool,
        prof: bool, dry_run: bool, info: bool, sort: bool):
    """
    Generate xcube dataset.
    Data cubes may be created in one go or successively in append mode, input by input.
    The input paths may be one or more input files or a pattern that may contain wildcards '?', '*', and '**'.
    The input paths can also be passed as lines of a text file. To do so, provide exactly one input file with
    ".txt" extension which contains the actual input paths to be used.
    """
    input_paths = input
    input_processor_name = proc
    config_file = config
    output_path = output
    output_writer_name = format
    output_size = size
    output_region = region
    output_variables = variables
    output_resampling = resampling
    profile_mode = prof
    dry_run = dry_run
    info_mode = info
    sort_mode = sort

    from xcube.api.gen.config import get_config_dict
    from xcube.api.gen.gen import gen_cube
    # Force loading of plugins
    __import__('xcube.util.plugin')

    if info_mode:
        print(_format_info())
        return 0

    config = get_config_dict(locals())

    gen_cube(dry_run=dry_run, monitor=print, **config)

    return 0