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'
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'