Exemplo n.º 1
0
    def get_cov(cls, only_time=False, save_coverage=False, in_memory=False, inline_data_writes=True, brick_size=None, make_empty=False, nt=None, auto_flush_values=True):
        """
        Construct coverage
        """
        pname_filter = ['time']
        pdict = get_parameter_dict(parameter_list=pname_filter)

        # Construct temporal and spatial Coordinate Reference System objects
        tcrs = CRS([AxisTypeEnum.TIME])
        scrs = CRS([AxisTypeEnum.LON, AxisTypeEnum.LAT])

        # Construct temporal and spatial Domain objects
        tdom = GridDomain(GridShape('temporal', [0]), tcrs, MutabilityEnum.EXTENSIBLE) # 1d (timeline)
        sdom = GridDomain(GridShape('spatial', [0]), scrs, MutabilityEnum.IMMUTABLE) # 0d spatial topology (station/trajectory)

        if brick_size is not None:
            bricking_scheme = {'brick_size':brick_size, 'chunk_size':True}
        else:
            bricking_scheme = None

        # Instantiate the SimplexCoverage providing the ParameterDictionary, spatial Domain and temporal Domain
        scov = SimplexCoverage(cls.working_dir, create_guid(), 'sample coverage_model', parameter_dictionary=pdict, temporal_domain=tdom, spatial_domain=sdom, inline_data_writes=inline_data_writes, in_memory_storage=in_memory, bricking_scheme=bricking_scheme, auto_flush_values=auto_flush_values)

        # Insert some timesteps (automatically expands other arrays)
        if (nt is None) or (nt == 0) or (make_empty is True):
            return scov, 'TestOneParamCovInt'
        else:
            # Add data for the parameter
            scov.set_parameter_values(make_parameter_data_dict({'time': np.arange(nt)}))

        if in_memory and save_coverage:
            SimplexCoverage.pickle_save(scov, os.path.join(cls.working_dir, 'sample.cov'))

        return scov, 'TestOneParamCovInt'
    def get_cov(cls, only_time=False, param_filter=None, save_coverage=False, in_memory=False, inline_data_writes=True, brick_size=None, make_empty=False, nt=None, auto_flush_values=True):
        # Instantiate a ParameterDictionary
        pname_filter = ['time',
                            'lat',
                            'lon',
                            'temp',
                            'conductivity']
        if only_time:
            pname_filter = ['time']
        pdict = get_parameter_dict(parameter_list=pname_filter)

        # Construct temporal and spatial Coordinate Reference System objects
        tcrs = CRS([AxisTypeEnum.TIME])
        scrs = CRS([AxisTypeEnum.LON, AxisTypeEnum.LAT])

        # Construct temporal and spatial Domain objects
        tdom = GridDomain(GridShape('temporal', [0]), tcrs, MutabilityEnum.EXTENSIBLE) # 1d (timeline)
        sdom = GridDomain(GridShape('spatial', [0]), scrs, MutabilityEnum.IMMUTABLE) # 0d spatial topology (station/trajectory)

        if brick_size is not None:
            bricking_scheme = {'brick_size':brick_size, 'chunk_size':True}
        else:
            bricking_scheme = None

        # Instantiate the SimplexCoverage providing the ParameterDictionary, spatial Domain and temporal Domain
        scov = SimplexCoverage(cls.working_dir, create_guid(), 'sample coverage_model', parameter_dictionary=pdict, temporal_domain=tdom, spatial_domain=sdom, inline_data_writes=inline_data_writes, in_memory_storage=in_memory, bricking_scheme=bricking_scheme, auto_flush_values=auto_flush_values)

        if in_memory and save_coverage:
            SimplexCoverage.pickle_save(scov, os.path.join(cls.working_dir, 'sample.cov'))

        return scov, 'TestEmptySampleCovInt'
Exemplo n.º 3
0
    def get_cov(cls, only_time=False, save_coverage=False, in_memory=False, inline_data_writes=True, brick_size=None, make_empty=False, nt=None, auto_flush_values=True):
        # Instantiate a ParameterDictionary
        pname_filter = ['time',
                        'lat',
                        'lon',
                        'temp',
                        'conductivity']
        if only_time:
            pname_filter = ['time']

        pdict = get_parameter_dict(parameter_list=pname_filter)

        # Construct temporal and spatial Coordinate Reference System objects
        tcrs = CRS([AxisTypeEnum.TIME])
        scrs = CRS([AxisTypeEnum.LON, AxisTypeEnum.LAT])

        # Construct temporal and spatial Domain objects
        tdom = GridDomain(GridShape('temporal', [0]), tcrs, MutabilityEnum.EXTENSIBLE) # 1d (timeline)
        sdom = GridDomain(GridShape('spatial', [0]), scrs, MutabilityEnum.IMMUTABLE) # 0d spatial topology (station/trajectory)

        if brick_size is not None:
            bricking_scheme = {'brick_size':brick_size, 'chunk_size':True}
        else:
            bricking_scheme = None

        # Instantiate the SimplexCoverage providing the ParameterDictionary, spatial Domain and temporal Domain
        scov = SimplexCoverage(cls.working_dir, create_guid(), 'sample coverage_model', parameter_dictionary=pdict, temporal_domain=tdom, spatial_domain=sdom, inline_data_writes=inline_data_writes, in_memory_storage=in_memory, bricking_scheme=bricking_scheme, auto_flush_values=auto_flush_values)

        # Insert some timesteps (automatically expands other arrays)
        if (nt is None) or (nt == 0) or (make_empty is True):
            return scov, 'TestSampleCovInt'
        else:
            params = {}
            params['time'] = np.arange(nt)
            if not only_time:
                params['lat'] = np.empty(nt)
                params['lat'].fill(45)
                params['lon'] = np.empty(nt)
                params['lon'].fill(-71)
                params['temp'] = utils.get_random_sample(nt, 23, 26)
                params['conductivity'] = utils.get_random_sample(nt, 90, 110)
            scov.set_parameter_values(params)
            # Add data for each parameter
            # scov.set_parameter_values({'time': np.arange(nt)})
            # if not only_time:
            #     scov.set_parameter_values('lat', value=45)
            #     scov.set_parameter_values('lon', value=-71)
            #     # make a random sample of 10 values between 23 and 26
            #     # Ref: http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.random_sample.html#numpy.random.random_sample
            #     # --> To sample  multiply the output of random_sample by (b-a) and add a
            #     tvals = utils.get_random_sample(nt, 23, 26)
            #     scov.set_parameter_values('temp', value=tvals)
            #     scov.set_parameter_values('conductivity', value=utils.get_random_sample(nt, 90, 110))

        if in_memory and save_coverage:
            SimplexCoverage.pickle_save(scov, os.path.join(cls.working_dir, 'sample.cov'))

        return scov, 'TestSampleCovInt'
Exemplo n.º 4
0
    def get_cov(cls,
                only_time=False,
                save_coverage=False,
                in_memory=False,
                inline_data_writes=True,
                brick_size=None,
                make_empty=False,
                nt=None,
                auto_flush_values=True):
        """
        Construct coverage
        """
        pname_filter = ['time']
        pdict = get_parameter_dict(parameter_list=pname_filter)

        # Construct temporal and spatial Coordinate Reference System objects
        tcrs = CRS([AxisTypeEnum.TIME])
        scrs = CRS([AxisTypeEnum.LON, AxisTypeEnum.LAT])

        # Construct temporal and spatial Domain objects
        tdom = GridDomain(GridShape('temporal', [0]), tcrs,
                          MutabilityEnum.EXTENSIBLE)  # 1d (timeline)
        sdom = GridDomain(GridShape('spatial',
                                    [0]), scrs, MutabilityEnum.IMMUTABLE
                          )  # 0d spatial topology (station/trajectory)

        if brick_size is not None:
            bricking_scheme = {'brick_size': brick_size, 'chunk_size': True}
        else:
            bricking_scheme = None

        # Instantiate the SimplexCoverage providing the ParameterDictionary, spatial Domain and temporal Domain
        scov = SimplexCoverage(cls.working_dir,
                               create_guid(),
                               'sample coverage_model',
                               parameter_dictionary=pdict,
                               temporal_domain=tdom,
                               spatial_domain=sdom,
                               inline_data_writes=inline_data_writes,
                               in_memory_storage=in_memory,
                               bricking_scheme=bricking_scheme,
                               auto_flush_values=auto_flush_values)

        # Insert some timesteps (automatically expands other arrays)
        if (nt is None) or (nt == 0) or (make_empty is True):
            return scov, 'TestOneParamCovInt'
        else:
            scov.insert_timesteps(nt)

            # Add data for the parameter
            scov.set_parameter_values('time', value=np.arange(nt))

        if in_memory and save_coverage:
            SimplexCoverage.pickle_save(
                scov, os.path.join(cls.working_dir, 'sample.cov'))

        return scov, 'TestOneParamCovInt'
Exemplo n.º 5
0
    def get_cov(cls,
                only_time=False,
                param_filter=None,
                save_coverage=False,
                in_memory=False,
                inline_data_writes=True,
                brick_size=None,
                make_empty=False,
                nt=None,
                auto_flush_values=True):
        # Instantiate a ParameterDictionary
        pname_filter = ['time', 'lat', 'lon', 'temp', 'conductivity']
        if only_time:
            pname_filter = ['time']
        pdict = get_parameter_dict(parameter_list=pname_filter)

        # Construct temporal and spatial Coordinate Reference System objects
        tcrs = CRS([AxisTypeEnum.TIME])
        scrs = CRS([AxisTypeEnum.LON, AxisTypeEnum.LAT])

        # Construct temporal and spatial Domain objects
        tdom = GridDomain(GridShape('temporal', [0]), tcrs,
                          MutabilityEnum.EXTENSIBLE)  # 1d (timeline)
        sdom = GridDomain(GridShape('spatial',
                                    [0]), scrs, MutabilityEnum.IMMUTABLE
                          )  # 0d spatial topology (station/trajectory)

        if brick_size is not None:
            bricking_scheme = {'brick_size': brick_size, 'chunk_size': True}
        else:
            bricking_scheme = None

        # Instantiate the SimplexCoverage providing the ParameterDictionary, spatial Domain and temporal Domain
        scov = SimplexCoverage(cls.working_dir,
                               create_guid(),
                               'sample coverage_model',
                               parameter_dictionary=pdict,
                               temporal_domain=tdom,
                               spatial_domain=sdom,
                               inline_data_writes=inline_data_writes,
                               in_memory_storage=in_memory,
                               bricking_scheme=bricking_scheme,
                               auto_flush_values=auto_flush_values)

        if in_memory and save_coverage:
            SimplexCoverage.pickle_save(
                scov, os.path.join(cls.working_dir, 'sample.cov'))

        return scov, 'TestEmptySampleCovInt'
    def create_cov(cls, only_time=False, in_memory=False, inline_data_writes=True, brick_size=None, auto_flush_values=True):
        # Construct temporal and spatial Coordinate Reference System objects
        tcrs = CRS([AxisTypeEnum.TIME])
        scrs = CRS([AxisTypeEnum.LON, AxisTypeEnum.LAT])

        # Construct temporal and spatial Domain objects
        tdom = GridDomain(GridShape('temporal', [0]), tcrs, MutabilityEnum.EXTENSIBLE) # 1d (timeline)
        sdom = GridDomain(GridShape('spatial', [0]), scrs, MutabilityEnum.IMMUTABLE) # 0d spatial topology (station/trajectory)

        pname_filter = ['time',
                            'boolean',
                            'const_int',
                            'const_rng_flt',
                            'const_rng_int',
                            'numexpr_func',
                            'category',
                            'record',
                            'sparse',
                            'lat',
                            'lon',
                            'depth',
                            'salinity']

        if only_time:
            pname_filter = ['time']

        pdict = get_parameter_dict(parameter_list=pname_filter)

        if brick_size is not None:
            bricking_scheme = {'brick_size':brick_size, 'chunk_size':True}
        else:
            bricking_scheme = None

        # Instantiate the SimplexCoverage providing the ParameterDictionary, spatial Domain and temporal Domain
        cov = SimplexCoverage(cls.working_dir, create_guid(), 'sample coverage_model', parameter_dictionary=pdict, temporal_domain=tdom, spatial_domain=sdom, inline_data_writes=inline_data_writes, in_memory_storage=in_memory, bricking_scheme=bricking_scheme, auto_flush_values=auto_flush_values)
        cls.coverages.add(cov.persistence_guid)
        return cov
Exemplo n.º 7
0
    def construct_cov(
        cls,
        only_time=False,
        save_coverage=False,
        in_memory=False,
        inline_data_writes=True,
        brick_size=None,
        make_empty=False,
        nt=None,
        auto_flush_values=True,
    ):
        """
        Construct coverage
        """
        # Construct temporal and spatial Coordinate Reference System objects
        tcrs = CRS([AxisTypeEnum.TIME])
        scrs = CRS([AxisTypeEnum.LON, AxisTypeEnum.LAT])

        # Construct temporal and spatial Domain objects
        tdom = GridDomain(GridShape("temporal", [0]), tcrs, MutabilityEnum.EXTENSIBLE)  # 1d (timeline)
        sdom = GridDomain(
            GridShape("spatial", [0]), scrs, MutabilityEnum.IMMUTABLE
        )  # 0d spatial topology (station/trajectory)

        pname_filter = [
            "time",
            "boolean",
            "const_float",
            "const_int",
            "const_str",
            "const_rng_flt",
            "const_rng_int",
            "numexpr_func",
            "category",
            "quantity",
            "array",
            "record",
            "fixed_str",
            "sparse",
            "lat",
            "lon",
            "depth",
        ]

        if only_time:
            pname_filter = ["time"]

        pdict = get_parameter_dict(parameter_list=pname_filter)

        if brick_size is not None:
            bricking_scheme = {"brick_size": brick_size, "chunk_size": True}
        else:
            bricking_scheme = None

        # Instantiate the SimplexCoverage providing the ParameterDictionary, spatial Domain and temporal Domain
        scov = SimplexCoverage(
            cls.working_dir,
            create_guid(),
            "sample coverage_model",
            parameter_dictionary=pdict,
            temporal_domain=tdom,
            spatial_domain=sdom,
            inline_data_writes=inline_data_writes,
            in_memory_storage=in_memory,
            bricking_scheme=bricking_scheme,
            auto_flush_values=auto_flush_values,
        )

        # Insert some timesteps (automatically expands other arrays)
        if (nt is None) or (nt == 0) or (make_empty is True):
            return scov, "TestTestSpanUnit"
        else:
            # Add data for each parameter
            if only_time:
                scov.set_parameter_values(
                    make_parameter_data_dict({scov.temporal_parameter_name: np.arange(1000, 10000, nt + 1)})
                )
            else:
                parameter_values = {}
                # scov.set_parameter_values('sparse', [[[2, 4, 6], [8, 10, 12]]])
                # scov.insert_timesteps(nt/2)
                #
                # scov.set_parameter_values('sparse', [[[4, 8], [16, 20]]])
                # scov.insert_timesteps(nt/2)
                scov.append_parameter(ParameterContext("m_lon"))
                scov.append_parameter(ParameterContext("m_lat"))
                scov.append_parameter(ParameterContext("depth"))

                parameter_values["time"] = np.arange(1000, 1000 + nt)
                parameter_values["depth"] = 1000 * np.random.random_sample(nt)
                parameter_values["m_lon"] = 160 * np.random.random_sample(nt)
                parameter_values["m_lat"] = 70 * np.random.random_sample(nt)
                scov.set_parameter_values(make_parameter_data_dict(parameter_values))

        cls.coverages.add(scov.persistence_guid)
        return scov, "TestSpanInt"
    def get_cov(cls, only_time=False, save_coverage=False, in_memory=False, inline_data_writes=True, brick_size=None, make_empty=False, nt=None, auto_flush_values=True):
        """
        Construct coverage
        """
        # Construct temporal and spatial Coordinate Reference System objects
        tcrs = CRS([AxisTypeEnum.TIME])
        scrs = CRS([AxisTypeEnum.LON, AxisTypeEnum.LAT])

        # Construct temporal and spatial Domain objects
        tdom = GridDomain(GridShape('temporal', [0]), tcrs, MutabilityEnum.EXTENSIBLE) # 1d (timeline)
        sdom = GridDomain(GridShape('spatial', [0]), scrs, MutabilityEnum.IMMUTABLE) # 0d spatial topology (station/trajectory)

        pname_filter = ['time',
                            'boolean',
                            'const_float',
                            'const_int',
                            'const_str',
                            'const_rng_flt',
                            'const_rng_int',
                            'numexpr_func',
                            'category',
                            'quantity',
                            'array',
                            'record',
                            'fixed_str',
                            'sparse']

        if only_time:
            pname_filter = ['time']

        pdict = get_parameter_dict(parameter_list=pname_filter)

        if brick_size is not None:
            bricking_scheme = {'brick_size':brick_size, 'chunk_size':True}
        else:
            bricking_scheme = None

        # Instantiate the SimplexCoverage providing the ParameterDictionary, spatial Domain and temporal Domain
        scov = SimplexCoverage(cls.working_dir, create_guid(), 'sample coverage_model', parameter_dictionary=pdict, temporal_domain=tdom, spatial_domain=sdom, inline_data_writes=inline_data_writes, in_memory_storage=in_memory, bricking_scheme=bricking_scheme, auto_flush_values=auto_flush_values)

        # Insert some timesteps (automatically expands other arrays)
        if (nt is None) or (nt == 0) or (make_empty is True):
            return scov, 'TestPtypesCovInt'
        else:
            # Add data for each parameter
            print nt
            if only_time:
                scov.insert_timesteps(nt)
                scov.set_parameter_values('time', value=np.arange(nt))
            else:
                scov.set_parameter_values('sparse', [[[2, 4, 6], [8, 10, 12]]])
                scov.insert_timesteps(nt/2)

                scov.set_parameter_values('sparse', [[[4, 8], [16, 20]]])
                scov.insert_timesteps(nt/2)

                scov.set_parameter_values('time', value=np.arange(nt))
                scov.set_parameter_values('boolean', value=[True, True, True], tdoa=[[2,4,14]])
                scov.set_parameter_values('const_float', value=-71.11) # Set a constant with correct data type
                scov.set_parameter_values('const_int', value=45.32) # Set a constant with incorrect data type (fixed under the hood)
                scov.set_parameter_values('const_str', value='constant string value') # Set with a string
                scov.set_parameter_values('const_rng_flt', value=(12.8, 55.2)) # Set with a tuple
                scov.set_parameter_values('const_rng_int', value=[-10, 10]) # Set with a list

                scov.set_parameter_values('quantity', value=np.random.random_sample(nt)*(26-23)+23)

                arrval = []
                recval = []
                catval = []
                fstrval = []
                catkeys = EXEMPLAR_CATEGORIES.keys()
                letts='abcdefghijklmnopqrstuvwxyz'
                while len(letts) < nt:
                    letts += 'abcdefghijklmnopqrstuvwxyz'
                for x in xrange(nt):
                    arrval.append(np.random.bytes(np.random.randint(1,20))) # One value (which is a byte string) for each member of the domain
                    d = {letts[x]: letts[x:]}
                    recval.append(d) # One value (which is a dict) for each member of the domain
                    catval.append(random.choice(catkeys))
                    fstrval.append(''.join([random.choice(letts) for x in xrange(8)])) # A random string of length 8
                scov.set_parameter_values('array', value=arrval)
                scov.set_parameter_values('record', value=recval)
                scov.set_parameter_values('category', value=catval)
                scov.set_parameter_values('fixed_str', value=fstrval)

        if in_memory and save_coverage:
            SimplexCoverage.pickle_save(scov, os.path.join(cls.working_dir, 'sample.cov'))

        return scov, 'TestPtypesCovInt'
Exemplo n.º 9
0
    def construct_cov(cls, only_time=False, save_coverage=False, in_memory=False, inline_data_writes=True, brick_size=None, make_empty=False, nt=None, auto_flush_values=True):
        """
        Construct coverage
        """
        # Construct temporal and spatial Coordinate Reference System objects
        tcrs = CRS([AxisTypeEnum.TIME])
        scrs = CRS([AxisTypeEnum.LON, AxisTypeEnum.LAT])

        # Construct temporal and spatial Domain objects
        tdom = GridDomain(GridShape('temporal', [0]), tcrs, MutabilityEnum.EXTENSIBLE) # 1d (timeline)
        sdom = GridDomain(GridShape('spatial', [0]), scrs, MutabilityEnum.IMMUTABLE) # 0d spatial topology (station/trajectory)

        pname_filter = ['time',
                            'boolean',
                            'const_float',
                            'const_int',
                            # 'const_str',
                            'const_rng_flt',
                            'const_rng_int',
                            'numexpr_func',
                            'category',
                            'quantity',
                            'array',
                            'record',
                            'fixed_str',
                            'sparse',
                            'lat',
                            'lon',
                            'depth']

        if only_time:
            pname_filter = ['time']

        pdict = get_parameter_dict(parameter_list=pname_filter)

        if brick_size is not None:
            bricking_scheme = {'brick_size':brick_size, 'chunk_size':True}
        else:
            bricking_scheme = None

        # Instantiate the SimplexCoverage providing the ParameterDictionary, spatial Domain and temporal Domain
        scov = SimplexCoverage(cls.working_dir, create_guid(), 'sample coverage_model', parameter_dictionary=pdict, temporal_domain=tdom, spatial_domain=sdom, inline_data_writes=inline_data_writes, in_memory_storage=in_memory, bricking_scheme=bricking_scheme, auto_flush_values=auto_flush_values)


        # Insert some timesteps (automatically expands other arrays)
        if (nt is None) or (nt == 0) or (make_empty is True):
            return scov, 'TestSpanValidationUnit'
        else:
            np_dict = {}
            # Add data for each parameter
            time_array = np.arange(10000, 10000+nt)
            np_dict[scov.temporal_parameter_name] = NumpyParameterData(scov.temporal_parameter_name, time_array, time_array)
            if not only_time:
                scov.append_parameter(ParameterContext('depth', fill_value=9999.0))
                # scov.append_parameter(ParameterContext('lon'))
                # scov.append_parameter(ParameterContext('lat'))
                scov.append_parameter(ParameterContext('const_str', fill_value='Nope'))
                np_dict['depth'] = NumpyParameterData('depth', np.random.uniform(0,200,[nt]), time_array)
                np_dict['lon'] = NumpyParameterData('lon', np.random.uniform(-180,180,[nt]), time_array)
                np_dict['lat'] = NumpyParameterData('lat', np.random.uniform(-90,90,[nt]), time_array)
                np_dict['const_float'] = ConstantOverTime('const_float', 88.8, time_start=10000, time_end=10000+nt)
                np_dict['const_str'] = ConstantOverTime('const_str', 'Jello', time_start=10000, time_end=10000+nt)

                scov.set_parameter_values(np_dict)

        cls.coverages.add(scov.persistence_guid)
        return scov, 'TestSpanValidationInt'
Exemplo n.º 10
0
    def get_cov(cls,
                only_time=False,
                save_coverage=False,
                in_memory=False,
                inline_data_writes=True,
                brick_size=None,
                make_empty=False,
                nt=None,
                auto_flush_values=True):
        """
        Construct coverage
        """
        # Construct temporal and spatial Coordinate Reference System objects
        tcrs = CRS([AxisTypeEnum.TIME])
        scrs = CRS([AxisTypeEnum.LON, AxisTypeEnum.LAT])

        # Construct temporal and spatial Domain objects
        tdom = GridDomain(GridShape('temporal', [0]), tcrs,
                          MutabilityEnum.EXTENSIBLE)  # 1d (timeline)
        sdom = GridDomain(GridShape('spatial',
                                    [0]), scrs, MutabilityEnum.IMMUTABLE
                          )  # 0d spatial topology (station/trajectory)

        pname_filter = [
            'time', 'boolean', 'const_float', 'const_int', 'const_str',
            'const_rng_flt', 'const_rng_int', 'numexpr_func', 'category',
            'quantity', 'array', 'record', 'fixed_str', 'sparse'
        ]

        if only_time:
            pname_filter = ['time']

        pdict = get_parameter_dict(parameter_list=pname_filter)

        if brick_size is not None:
            bricking_scheme = {'brick_size': brick_size, 'chunk_size': True}
        else:
            bricking_scheme = None

        # Instantiate the SimplexCoverage providing the ParameterDictionary, spatial Domain and temporal Domain
        scov = SimplexCoverage(cls.working_dir,
                               create_guid(),
                               'sample coverage_model',
                               parameter_dictionary=pdict,
                               temporal_domain=tdom,
                               spatial_domain=sdom,
                               inline_data_writes=inline_data_writes,
                               in_memory_storage=in_memory,
                               bricking_scheme=bricking_scheme,
                               auto_flush_values=auto_flush_values)

        # Insert some timesteps (automatically expands other arrays)
        if (nt is None) or (nt == 0) or (make_empty is True):
            return scov, 'TestPtypesCovInt'
        else:
            # Add data for each parameter
            print nt
            if only_time:
                scov.insert_timesteps(nt)
                scov.set_parameter_values('time', value=np.arange(nt))
            else:
                scov.set_parameter_values('sparse', [[[2, 4, 6], [8, 10, 12]]])
                scov.insert_timesteps(nt / 2)

                scov.set_parameter_values('sparse', [[[4, 8], [16, 20]]])
                scov.insert_timesteps(nt / 2)

                scov.set_parameter_values('time', value=np.arange(nt))
                scov.set_parameter_values('boolean',
                                          value=[True, True, True],
                                          tdoa=[[2, 4, 14]])
                scov.set_parameter_values(
                    'const_float',
                    value=-71.11)  # Set a constant with correct data type
                scov.set_parameter_values(
                    'const_int', value=45.32
                )  # Set a constant with incorrect data type (fixed under the hood)
                scov.set_parameter_values(
                    'const_str',
                    value='constant string value')  # Set with a string
                scov.set_parameter_values('const_rng_flt',
                                          value=(12.8,
                                                 55.2))  # Set with a tuple
                scov.set_parameter_values('const_rng_int',
                                          value=[-10, 10])  # Set with a list

                scov.set_parameter_values('quantity',
                                          value=np.random.random_sample(nt) *
                                          (26 - 23) + 23)

                arrval = []
                recval = []
                catval = []
                fstrval = []
                catkeys = EXEMPLAR_CATEGORIES.keys()
                letts = 'abcdefghijklmnopqrstuvwxyz'
                while len(letts) < nt:
                    letts += 'abcdefghijklmnopqrstuvwxyz'
                for x in xrange(nt):
                    arrval.append(
                        np.random.bytes(np.random.randint(1, 20))
                    )  # One value (which is a byte string) for each member of the domain
                    d = {letts[x]: letts[x:]}
                    recval.append(
                        d
                    )  # One value (which is a dict) for each member of the domain
                    catval.append(random.choice(catkeys))
                    fstrval.append(''.join([
                        random.choice(letts) for x in xrange(8)
                    ]))  # A random string of length 8
                scov.set_parameter_values('array', value=arrval)
                scov.set_parameter_values('record', value=recval)
                scov.set_parameter_values('category', value=catval)
                scov.set_parameter_values('fixed_str', value=fstrval)

        if in_memory and save_coverage:
            SimplexCoverage.pickle_save(
                scov, os.path.join(cls.working_dir, 'sample.cov'))

        return scov, 'TestPtypesCovInt'
Exemplo n.º 11
0
    def get_cov(cls,
                only_time=False,
                save_coverage=False,
                in_memory=False,
                inline_data_writes=True,
                brick_size=None,
                make_empty=False,
                nt=None,
                auto_flush_values=True):
        # Instantiate a ParameterDictionary
        pname_filter = ['time', 'lat', 'lon', 'temp', 'conductivity']
        if only_time:
            pname_filter = ['time']

        pdict = get_parameter_dict(parameter_list=pname_filter)

        # Construct temporal and spatial Coordinate Reference System objects
        tcrs = CRS([AxisTypeEnum.TIME])
        scrs = CRS([AxisTypeEnum.LON, AxisTypeEnum.LAT])

        # Construct temporal and spatial Domain objects
        tdom = GridDomain(GridShape('temporal', [0]), tcrs,
                          MutabilityEnum.EXTENSIBLE)  # 1d (timeline)
        sdom = GridDomain(GridShape('spatial',
                                    [0]), scrs, MutabilityEnum.IMMUTABLE
                          )  # 0d spatial topology (station/trajectory)

        if brick_size is not None:
            bricking_scheme = {'brick_size': brick_size, 'chunk_size': True}
        else:
            bricking_scheme = None

        # Instantiate the SimplexCoverage providing the ParameterDictionary, spatial Domain and temporal Domain
        scov = SimplexCoverage(cls.working_dir,
                               create_guid(),
                               'sample coverage_model',
                               parameter_dictionary=pdict,
                               temporal_domain=tdom,
                               spatial_domain=sdom,
                               inline_data_writes=inline_data_writes,
                               in_memory_storage=in_memory,
                               bricking_scheme=bricking_scheme,
                               auto_flush_values=auto_flush_values)

        # Insert some timesteps (automatically expands other arrays)
        if (nt is None) or (nt == 0) or (make_empty is True):
            return scov, 'TestSampleCovInt'
        else:
            scov.insert_timesteps(nt)

            # Add data for each parameter
            scov.set_parameter_values('time', value=np.arange(nt))
            if not only_time:
                scov.set_parameter_values('lat', value=45)
                scov.set_parameter_values('lon', value=-71)
                # make a random sample of 10 values between 23 and 26
                # Ref: http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.random_sample.html#numpy.random.random_sample
                # --> To sample  multiply the output of random_sample by (b-a) and add a
                tvals = utils.get_random_sample(nt, 23, 26)
                scov.set_parameter_values('temp', value=tvals)
                scov.set_parameter_values('conductivity',
                                          value=utils.get_random_sample(
                                              nt, 90, 110))

        if in_memory and save_coverage:
            SimplexCoverage.pickle_save(
                scov, os.path.join(cls.working_dir, 'sample.cov'))

        return scov, 'TestSampleCovInt'