def create_extended_parsed_contexts(self):
        contexts, funcs = self.create_parsed_params()
        expr, expr_id = funcs['density_L2']
        
        density_lookup_map = {'conductivity':'conductivity_L1', 'temp':'temp_L1', 'pressure':'pressure_L1', 'lat':'lat_lookup', 'lon':'lon_lookup'}
        expr.param_map = density_lookup_map
        density_lookup_ctxt = ParameterContext('density_lookup', param_type=ParameterFunctionType(expr), variability=VariabilityEnum.TEMPORAL)
        density_lookup_ctxt.uom = 'kg m-3'
        density_lookup_ctxt_id = self.dataset_management.create_parameter_context(name='density_lookup', parameter_context=density_lookup_ctxt.dump(), parameter_function_id=expr_id)
        self.addCleanup(self.dataset_management.delete_parameter_context, density_lookup_ctxt_id)
        contexts['density_lookup'] = density_lookup_ctxt, density_lookup_ctxt_id


        lat_lookup_ctxt = ParameterContext('lat_lookup', param_type=ConstantType(QuantityType(value_encoding=np.dtype('float32'))), fill_value=-9999)
        lat_lookup_ctxt.axis = AxisTypeEnum.LAT
        lat_lookup_ctxt.uom = 'degree_north'
        lat_lookup_ctxt.lookup_value = 'lat'
        lat_lookup_ctxt.document_key = ''
        lat_lookup_ctxt_id = self.dataset_management.create_parameter_context(name='lat_lookup', parameter_context=lat_lookup_ctxt.dump())
        self.addCleanup(self.dataset_management.delete_parameter_context, lat_lookup_ctxt_id)
        contexts['lat_lookup'] = lat_lookup_ctxt, lat_lookup_ctxt_id
        

        lon_lookup_ctxt = ParameterContext('lon_lookup', param_type=ConstantType(QuantityType(value_encoding=np.dtype('float32'))), fill_value=-9999)
        lon_lookup_ctxt.axis = AxisTypeEnum.LON
        lon_lookup_ctxt.uom = 'degree_east'
        lon_lookup_ctxt.lookup_value = 'lon'
        lon_lookup_ctxt.document_key = ''
        lon_lookup_ctxt_id = self.dataset_management.create_parameter_context(name='lon_lookup', parameter_context=lon_lookup_ctxt.dump())
        self.addCleanup(self.dataset_management.delete_parameter_context, lon_lookup_ctxt_id)
        contexts['lon_lookup'] = lon_lookup_ctxt, lon_lookup_ctxt_id

        return contexts, funcs
    def create_lookup_contexts(self):
        contexts = {}
        t_ctxt = ParameterContext('time', param_type=QuantityType(value_encoding=np.dtype('float64')))
        t_ctxt.uom = 'seconds since 1900-01-01'
        t_ctxt_id = self.dataset_management.create_parameter_context(name='time', parameter_context=t_ctxt.dump())
        contexts['time'] = (t_ctxt, t_ctxt_id)
        
        temp_ctxt = ParameterContext('temp', param_type=QuantityType(value_encoding=np.dtype('float32')), fill_value=fill_value)
        temp_ctxt.uom = 'deg_C'
        temp_ctxt_id = self.dataset_management.create_parameter_context(name='temp', parameter_context=temp_ctxt.dump())
        contexts['temp'] = temp_ctxt, temp_ctxt_id

        offset_ctxt = ParameterContext(name='offset_a', param_type=SparseConstantType(base_type=ConstantType(value_encoding='float64'), fill_value=fill_value))
        offset_ctxt.uom = ''
        offset_ctxt.lookup_value = 'offset_a'
        offset_ctxt.document_key = ''
        offset_ctxt_id = self.dataset_management.create_parameter_context(name='offset_a', parameter_context=offset_ctxt.dump())
        self.addCleanup(self.dataset_management.delete_parameter_context, offset_ctxt_id)
        contexts['offset_a'] = offset_ctxt, offset_ctxt_id

        offsetb_ctxt = ParameterContext('offset_b', param_type=SparseConstantType(base_type=ConstantType(value_encoding='float64'), fill_value=fill_value))
        offsetb_ctxt.uom = ''
        offsetb_ctxt.lookup_value = 'offset_b'
        offsetb_ctxt.document_key = 'coefficient_document'
        offsetb_ctxt_id = self.dataset_management.create_parameter_context(name='offset_b', parameter_context=offsetb_ctxt.dump())
        self.addCleanup(self.dataset_management.delete_parameter_context, offsetb_ctxt_id)
        contexts['offset_b'] = offsetb_ctxt, offsetb_ctxt_id
        
        offsetc_ctxt = ParameterContext('offset_c', param_type=SparseConstantType(base_type=ConstantType(value_encoding='float64'), fill_value=fill_value))
        offsetc_ctxt.uom = ''
        offsetc_ctxt.lookup_value = 'offset_c'
        offsetc_ctxt.document_key = '$designator_OFFSETC'
        offsetc_ctxt_id = self.dataset_management.create_parameter_context(name='offset_c', parameter_context=offsetc_ctxt.dump())
        self.addCleanup(self.dataset_management.delete_parameter_context, offsetc_ctxt_id)
        contexts['offset_c'] = offsetc_ctxt, offsetc_ctxt_id

        func = NumexprFunction('calibrated', 'temp + offset', ['temp','offset'], param_map={'temp':'temp', 'offset':'offset_a'})
        func.lookup_values = ['LV_offset']
        calibrated = ParameterContext('calibrated', param_type=ParameterFunctionType(func, value_encoding='float32'), fill_value=fill_value)
        calibrated.uom = 'deg_C'
        calibrated_id = self.dataset_management.create_parameter_context(name='calibrated', parameter_context=calibrated.dump())
        self.addCleanup(self.dataset_management.delete_parameter_context, calibrated_id)
        contexts['calibrated'] = calibrated, calibrated_id

        func = NumexprFunction('calibrated_b', 'temp + offset_a + offset_b', ['temp','offset_a', 'offset_b'], param_map={'temp':'temp', 'offset_a':'offset_a', 'offset_b':'offset_b'})
        func.lookup_values = ['LV_offset_a', 'LV_offset_b']
        calibrated_b = ParameterContext('calibrated_b', param_type=ParameterFunctionType(func, value_encoding='float32'), fill_value=fill_value)
        calibrated_b.uom = 'deg_C'
        calibrated_b_id = self.dataset_management.create_parameter_context(name='calibrated_b', parameter_context=calibrated_b.dump())
        self.addCleanup(self.dataset_management.delete_parameter_context, calibrated_b_id)
        contexts['calibrated_b'] = calibrated_b, calibrated_b_id

        return contexts
Esempio n. 3
0
 def get_lookup_value(self,value):
     placeholder = value.replace('LV_','')
     document_key = ''
     if '||' in placeholder:
         document_key, placeholder = placeholder.split('||')
     document_val = placeholder
     placeholder = '%s_%s' % (placeholder, uuid4().hex)
     pc = ParameterContext(name=placeholder, param_type=SparseConstantType(base_type=ConstantType(value_encoding='float64'), fill_value=-9999.))
     pc.lookup_value = document_val
     pc.document_key = document_key
     ctxt_id = self.dataset_management.create_parameter_context(name=placeholder, parameter_context=pc.dump())
     return ctxt_id, placeholder