当前位置: 首页>>代码示例>>Python>>正文


Python OCO_Matrix.units方法代码示例

本文整理汇总了Python中OCO_Matrix.OCO_Matrix.units方法的典型用法代码示例。如果您正苦于以下问题:Python OCO_Matrix.units方法的具体用法?Python OCO_Matrix.units怎么用?Python OCO_Matrix.units使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OCO_Matrix.OCO_Matrix的用法示例。


在下文中一共展示了OCO_Matrix.units方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: write_psurf_file

# 需要导入模块: from OCO_Matrix import OCO_Matrix [as 别名]
# 或者: from OCO_Matrix.OCO_Matrix import units [as 别名]
def write_psurf_file(psurf, out_filename):

    out_psurf_data = numpy.zeros((1, 1), dtype=float)

    out_psurf_data[0, 0] = psurf

    out_mat_obj = OCO_Matrix()
    out_mat_obj.file_id = 'True surface pressure from orbit simulator'
    out_mat_obj.data = out_psurf_data
    out_mat_obj.labels = ['PSURF']
    out_mat_obj.units =  ['Pa']

    out_mat_obj.write(out_filename)
开发者ID:E-LLP,项目名称:RtRetrievalFramework,代码行数:15,代码来源:extract_orbit_sim_data.py

示例2: write_windspeed_file

# 需要导入模块: from OCO_Matrix import OCO_Matrix [as 别名]
# 或者: from OCO_Matrix.OCO_Matrix import units [as 别名]
def write_windspeed_file(sounding_data, out_filename):

    out_windspeed_data = numpy.zeros((1, 1), dtype=float)

    ws_data = sounding_data['surface_windspeed']
    if hasattr(ws_data, '__iter__'):
        out_windspeed_data[0, 0] = ws_data[0]
    else:
        out_windspeed_data[0, 0] = ws_data
        
    out_mat_obj = OCO_Matrix()
    out_mat_obj.file_id = 'True windspeed from orbit simulator'
    out_mat_obj.data = out_windspeed_data
    out_mat_obj.labels = ['WINDSPEED']
    out_mat_obj.units =  ['m/s']

    out_mat_obj.write(out_filename)
开发者ID:E-LLP,项目名称:RtRetrievalFramework,代码行数:19,代码来源:extract_orbit_sim_data.py

示例3: write_windspeed_file

# 需要导入模块: from OCO_Matrix import OCO_Matrix [as 别名]
# 或者: from OCO_Matrix.OCO_Matrix import units [as 别名]
def write_windspeed_file(sounding_id, apriori_out_dir, ws_value, header_values=None, windspeed_f=False):

   windspeed_obj = OCO_Matrix()

   windspeed_obj.data = numpy.zeros((1,1), dtype=float)
   windspeed_obj.data[:,:] = ws_value
   windspeed_obj.labels = WINDSPEED_LABELS
   windspeed_obj.units  = WINDSPEED_UNITS
   windspeed_obj.file_id = 'Windspeed for sounding: %s' % sounding_id

   if header_values != None:
      windspeed_obj.header.update(header_values)

   if windspeed_f:
      windspeed_obj.header['Windspeed_F'] = True
      windspeed_obj.write(WINDSPEED_F_FILE_TMPL % (apriori_out_dir, sounding_id))
   else:
      windspeed_obj.write(WINDSPEED_FILE_TMPL % (apriori_out_dir, sounding_id))
开发者ID:E-LLP,项目名称:RtRetrievalFramework,代码行数:20,代码来源:create_surface_apriori.py

示例4: create_simple_cov

# 需要导入模块: from OCO_Matrix import OCO_Matrix [as 别名]
# 或者: from OCO_Matrix.OCO_Matrix import units [as 别名]
def create_simple_cov(input_file, output_file, scaling, columns):
    logger = logging.getLogger(os.path.basename(__file__))

    # Load source file
    src_obj = OCO_Matrix(input_file)

    scaling = [float(v) for v in scaling.split(',')]
    if len(scaling) < src_obj.dims[0]:
        last_val = scaling[len(scaling)-1]
        [ scaling.append(last_val) for nada in range(src_obj.dims[0] - len(scaling)) ]

    try:
        columns = index_range_list(columns, max_value=src_obj.dims[1])
    except:
        if not type(columns) is ListType:
            col_name_list = [columns]
        else:
            col_name_list = columns

        columns = []
        for curr_name in col_name_list:
            if curr_name.lower() not in src_obj.labels_lower:
                raise IOError('Column named %s not found in file: %s' % (curr_name, input_file))
            columns.append( src_obj.labels_lower.index(curr_name.lower()) )
                                    
    logger.info('cols = ', columns)

    num_diags = len(columns) * src_obj.dims[0]
    logger.info('num_diags = ', num_diags)
    dst_data = numpy.zeros((num_diags, num_diags), dtype=float)

    diag_index = 0
    for col_index in columns:
        for row_index in range(src_obj.dims[0]):
            #print '%d, %d => %d, %d' % (row_index, col_index, diag_index, diag_index)
            dst_data[diag_index, diag_index] = (src_obj.data[row_index, col_index] * scaling[row_index])**2
            diag_index += 1

    logger.info('Writing: %s' % input_file)
    src_obj.file_id = 'Simple Covariance Created from "%s", scaling: "%s"' % (input_file, ', '.join([str(sc) for sc in scaling]))
    src_obj.labels = []
    src_obj.data = dst_data
    src_obj.units = []
    src_obj.write(output_file, auto_size_cols=False, verbose=True)
开发者ID:E-LLP,项目名称:RtRetrievalFramework,代码行数:46,代码来源:create_simple_cov.py

示例5: write_spectra_files

# 需要导入模块: from OCO_Matrix import OCO_Matrix [as 别名]
# 或者: from OCO_Matrix.OCO_Matrix import units [as 别名]
def write_spectra_files(output_dir, ids, data):
    for curr_id, curr_data in zip(ids, data):
        out_filename = '%s/%s.dat' % (output_dir, curr_id)
        used_data = []
        
        out_obj = OCO_Matrix()
        out_obj.labels = FILE_LABELS
        out_obj.units  = FILE_UNITS
        out_obj.file_id = FILE_ID_TMPL % (curr_id)

        out_obj.data = numpy.zeros((curr_data['Num_Points'], len(FILE_LABELS)), dtype=float)
        used_data.append('Num_Points')
        for column_idx, column_name in enumerate(FILE_LABELS):
            if curr_data.has_key(column_name):
                out_obj.data[:, column_idx] = curr_data[column_name]
                used_data.append(column_name)

        header_dict = copy.copy(curr_data)
        header_dict.update(HEADER_FILL_VALUES)
        for data_name, data_values in header_dict.items():
            if data_name in used_data:
                continue

            out_name = translate_header_name(data_name)

            try:
                if len(data_values.shape) == 0:
                    out_obj.header[out_name] = str(data_values)
                else:
                    out_obj.header[out_name] = ' '.join([ str(item) for item in iter(data_values)])
            except:
                try:
                    out_obj.header[out_name] = str(data_values)
                except:
                    print >>sys.stderr, 'Barfed on parsing %s with values: %s for header of file %s' % (data_name, data_values, out_filename)

        print 'Writing: %s' % out_filename
        out_obj.write(out_filename)
开发者ID:E-LLP,项目名称:RtRetrievalFramework,代码行数:40,代码来源:extract_gosat_spectra.py

示例6: write_atmosphere_file

# 需要导入模块: from OCO_Matrix import OCO_Matrix [as 别名]
# 或者: from OCO_Matrix.OCO_Matrix import units [as 别名]
def write_atmosphere_file(sounding_data, out_filename, pressure_in, pressure_out, profile_mass_densities=False):
    gas_names = sounding_data['gas_names']
    num_cols = len(gas_names) + 2
    
    out_atm_data = numpy.zeros((len(pressure_out), num_cols), dtype=float)

    out_atm_data[:, 0] = resample_profile(pressure_in, pressure_in, pressure_out, log_data=True, extrapolate=True)               
    out_atm_data[:, 1] = resample_profile(pressure_in, sounding_data['temperature'][LEV_BEG:], pressure_out, log_data=False, extrapolate=True)

    for gas_idx in range(len(gas_names)):
        curr_gas = sounding_data['gas_names'][gas_idx]

        # Ensure data is a numpy array 
        source_data = numpy.array(sounding_data['gas_mix_ratio'][curr_gas]) 

        if profile_mass_densities and curr_gas.find("AIR") != 0:
            # Convert H2O from mol/m^2 to VMR
            # The profiles in the Simulation structure are layer mass densities in mol/m^2
            # They are converted to volume mixing ratios by dividing by the mass density of dry air, also in mol/m^2
            source_data = source_data/sounding_data['gas_mix_ratio'][DRY_AIR_NAME]

        elif curr_gas == 'H2O':
            # Convert H2O from specific humidity%
            source_data = source_data/(1.0 - source_data)/H2O_CONVERT_EPSILON
                
        out_atm_data[:, gas_idx+2] = resample_profile(pressure_in, source_data[LEV_BEG:], pressure_out, log_data=True, extrapolate=False)
        

    out_mat_obj = OCO_Matrix()
    out_mat_obj.file_id = 'True atmospheric profiles from orbit simulator'
    out_mat_obj.data = out_atm_data
    out_mat_obj.labels = ['Pressure', 'T'] + list(gas_names)
    out_mat_obj.units =  ['Pa', 'K'] + [ 'VMR' for x in range(len(gas_names)) ]

    out_mat_obj.write(out_filename)

    return out_atm_data
开发者ID:E-LLP,项目名称:RtRetrievalFramework,代码行数:39,代码来源:extract_orbit_sim_data.py

示例7: write_aerosol_file

# 需要导入模块: from OCO_Matrix import OCO_Matrix [as 别名]
# 或者: from OCO_Matrix.OCO_Matrix import units [as 别名]
def write_aerosol_file(sounding_data, out_filename, pressure_in, pressure_out):
    aer_names = sounding_data['aerosol_names']

    # If there are no aerosols for this sounding then just make an empty list
    if aer_names == None:
        aer_names = []
    
    num_cols = len(aer_names) + 1
   
    out_aer_data = numpy.zeros((len(pressure_out), num_cols), dtype=float)
   
    out_aer_data[:, 0] = resample_profile(pressure_in, pressure_in, pressure_out, log_data=True, extrapolate=True)               

    aer_src_data = numpy.zeros((len(pressure_in), len(aer_names)), dtype=float)
    
    for aer_idx in range(len(aer_names)):
        curr_aer = sounding_data['aerosol_names'][aer_idx]
        for lev_idx in range(len(pressure_in)):
            aer_src_data[lev_idx, aer_idx] = abs(sounding_data['aerosol_extinction'][curr_aer][LEV_BEG+lev_idx])

    if tuple(pressure_in) == tuple(pressure_out):
        aer_dst_data = aer_src_data.transpose()
    else:
        aer_dst_data = resample_aerosol(pressure_in, aer_src_data, pressure_out, debug=True)

    for aer_idx in range(len(aer_names)):
        out_aer_data[:, aer_idx+1] = aer_dst_data[aer_idx, :]

    out_mat_obj = OCO_Matrix()
    out_mat_obj.file_id = 'True aerosol profiles from orbit simulator'
    out_mat_obj.data = out_aer_data
    out_mat_obj.labels = ['Pressure'] + list(aer_names)
    out_mat_obj.header['Retrieval_Mode'] = 'linear'
    out_mat_obj.units =  ['Pa'] + [ '1/Pa' for x in range(len(aer_names)) ]

    out_mat_obj.write(out_filename)
开发者ID:E-LLP,项目名称:RtRetrievalFramework,代码行数:38,代码来源:extract_orbit_sim_data.py

示例8: Process_File

# 需要导入模块: from OCO_Matrix import OCO_Matrix [as 别名]
# 或者: from OCO_Matrix.OCO_Matrix import units [as 别名]
def Process_File(source, destination, fileKeywords, moduleSections, valuesDict, mapDict):
    logger = logging.getLogger(os.path.basename(__file__))

    # Load existing file
    matrix_obj = OCO_Matrix(source)

    for modifySect in moduleSections:

        # Add ability to specify cols individually or using a * to goto end
        columns = Apply_Template(modifySect.Get_Keyword_Value('columns'), valuesDict, mapDict=mapDict)
        rows    = Apply_Template(modifySect.Get_Keyword_Value('rows'), valuesDict, mapDict=mapDict)
        modify  = modifySect.Get_Keyword_Value('modify')
        delete  = evaluate_bool_str( modifySect.Get_Keyword_Value('delete') )
        add_column = evaluate_bool_str( modifySect.Get_Keyword_Value('add_column') )

        if columns != None:
            try:
                columns = index_range_list(columns, max_value=matrix_obj.dims[1])
            except:
                if not type(columns) is ListType:
                    col_name_list = [columns]
                else:
                    col_name_list = columns

                columns = []
                for curr_name in col_name_list:
                    if curr_name.lower() not in matrix_obj.labels_lower:
                        if add_column:
                            matrix_obj.add_column(curr_name)
                            columns.append(  matrix_obj.dims[1] - 1 )
                        else:
                            raise IOError('Column named %s not found in file: %s' % (curr_name, source))
                            
                    columns.append( matrix_obj.labels_lower.index(curr_name.lower()) )
        else:
            columns = range(matrix_obj.dims[1])

        if rows != None:
            rows = index_range_list(rows, max_value=matrix_obj.dims[0])
        else:
            rows = range(matrix_obj.dims[0])

        if delete and modify != None:
            raise ValueError('delete and modify keywords can not be specified together')

        if delete:
            if len(columns) > matrix_obj.dims[1]:
                raise IOError('More columns to be deleted %d than exist %d in input file %s' % (len(columns), matrix_obj.dims[1], source))
            
            new_data = numpy.zeros((matrix_obj.dims[0], matrix_obj.dims[1]-len(columns)), dtype=numpy.double)
            new_labels = []
            new_units  = []

            new_col_idx = 0
            for old_col_idx in range(matrix_obj.dims[1]):
                if old_col_idx not in columns:
                    new_labels.append(matrix_obj.labels[old_col_idx])
                    new_units.append(matrix_obj.units[old_col_idx])

                    new_data[:,new_col_idx] = matrix_obj.data[:,old_col_idx]

                    new_col_idx += 1

            matrix_obj.data = new_data
            matrix_obj.labels = new_labels
            matrix_obj.units  = new_units

        if modify != None and len(modify) > 0:
            
            modifyDict = copy_module.copy(valuesDict)

            Get_Constant_Values(modifySect.Get_Section('->CONSTANTS'), modifyDict)

            for row_idx in rows:
                for col_idx in columns:
                    modifyDict['original'] = str(matrix_obj.data[row_idx][col_idx])

                    modify_str = Apply_Template(modify, modifyDict, mapDict=mapDict)

                    try:
                        matrix_obj.data[row_idx][col_idx] = eval(modify_str)
                    except:
                        raise RuntimeError('Error evaluating modify string: "%s"' % modify_str)

    matrix_obj.write(destination, auto_size_cols=False)
开发者ID:E-LLP,项目名称:RtRetrievalFramework,代码行数:87,代码来源:modify_data.py

示例9: Process_File

# 需要导入模块: from OCO_Matrix import OCO_Matrix [as 别名]
# 或者: from OCO_Matrix.OCO_Matrix import units [as 别名]
def Process_File(source, destination, fileKeywords, moduleSections, valuesDict, mapDict):
    logger = logging.getLogger(os.path.basename(__file__))
    
    if len(moduleSections) > 1:
        raise AttributeError('only one merge_profile allowed per file')
    
    file_obj = OCO_Matrix(source)

    # Make sure not adding logarithmic aerosol data
    in_log = False
    header_keys = [ head_str.lower() for head_str in file_obj.header.keys() ]
    if 'retrieval_mode' in header_keys and file_obj.header[file_obj.header.keys()[header_keys.index('retrieval_mode')]] == 'logarithmic':
        in_log = True
    
    src_data           = file_obj.data
    src_profile_names  = file_obj.labels_lower
    src_units          = file_obj.units

    src_pressure_col   = src_profile_names.index('pressure')
        
    dst_profile_names = moduleSections[0].Get_All_Keyword_Names()

    dst_labels = {}
    dst_units  = {}
    dst_data   = {}

    for dest_profile_name in dst_profile_names:
        source_profiles_srch = Apply_Template(moduleSections[0].Get_Keyword_Value(dest_profile_name), valuesDict, mapDict=mapDict)

        if type(source_profiles_srch) is not ListType:
            source_profiles_srch = [ source_profiles_srch ]

        for source_profile_re in source_profiles_srch:
            for src_profile in src_profile_names:
                if re.search(source_profile_re, src_profile):
                    src_col_idx = src_profile_names.index(src_profile)

                    # Don't ever use the pressure column even if it would match
                    if src_col_idx == src_pressure_col:
                        continue

                    if not dst_data.has_key(dest_profile_name):
                        dst_data[dest_profile_name]   = numpy.zeros(src_data.shape[0], dtype=float)
                        dst_units[dest_profile_name]  = None
                        dst_labels[dest_profile_name] = dest_profile_name

                    if in_log:
                        dst_data[dest_profile_name] += numpy.exp(src_data[:, src_col_idx])
                    else:
                        dst_data[dest_profile_name] += src_data[:, src_col_idx]

                    # Complain if mixing units when adding
                    if src_col_idx < len(src_units):
                        if dst_units[dest_profile_name] == None:
                            dst_units[dest_profile_name] = src_units[src_col_idx]
                        elif dst_units[dest_profile_name].lower() != src_units[src_col_idx].lower():
                            raise Exception('Mixing unit types when merging src profile %s into dst profile %s' % (src_profile, dest_profile_name))

    if 'pressure' in file_obj.labels_lower:
        file_obj.labels = ['pressure']
        file_obj.units  = ['Pa']
        new_data = numpy.zeros((src_data.shape[0], len(dst_data.keys())+1), dtype=float)
        new_data[:, 0] = file_obj.data[:, src_pressure_col]
        beg_col = 1
    else:
        file_obj.labels = []
        file_obj.units  = []
        new_data = numpy.zeros((src_data.shape[0], len(dst_data)), dtype=float)
        beg_col = 0

    for dest_profile_name, dest_col_index in zip(dst_data.keys(), range(beg_col, beg_col+len(dst_data))):
        if in_log:
            new_data[:, dest_col_index] = numpy.log(dst_data[dest_profile_name][:])
        else:
            new_data[:, dest_col_index] = dst_data[dest_profile_name][:]
        file_obj.labels.append( dst_labels[dest_profile_name] )
        file_obj.units.append( dst_units[dest_profile_name] )

    logger.debug('Merged profile names: %s' % file_obj.labels[1:])

    file_obj.data = new_data
    file_obj.write(destination)
开发者ID:E-LLP,项目名称:RtRetrievalFramework,代码行数:84,代码来源:merge_profiles.py

示例10: aggregate_matrix_files

# 需要导入模块: from OCO_Matrix import OCO_Matrix [as 别名]
# 或者: from OCO_Matrix.OCO_Matrix import units [as 别名]
def aggregate_matrix_files(input_files, output_filename, src_column_names=None, dst_column_names=None):

    # Create combined atmosphere file from values in all GAS sections
    # Will overwrite columns of the same name in sequential order

    # First gather contents of various files
    uniq_file_ids = []
    uniq_labels = []
    uniq_units = []
    uniq_filenames = []
    file_objs = []
    max_num_rows = -1
    for curr_input_filename in input_files:
        if curr_input_filename not in uniq_filenames:
            print "%s -> %s" % (curr_input_filename, output_filename)
            uniq_filenames.append(curr_input_filename)
            curr_matobj = OCO_Matrix(curr_input_filename)
            file_objs.append(curr_matobj)

            max_num_rows = max(max_num_rows, curr_matobj.dims[0])

            for (curr_lbl, curr_unit) in itertools.izip_longest(curr_matobj.labels, curr_matobj.units, fillvalue=""):
                if not curr_lbl in uniq_labels:
                    uniq_labels.append(curr_lbl)
                    uniq_units.append(curr_unit)
                    
            if not curr_matobj.file_id in uniq_file_ids:
                uniq_file_ids.append(curr_matobj.file_id)
            
    out_matobj = OCO_Matrix()
    if len(uniq_file_ids) == 1:
        out_matobj.file_id = uniq_file_ids[0]
    else:
        out_matobj.file_id = uniq_file_ids

    if src_column_names == None:
        src_column_names = uniq_labels

    if dst_column_names == None:
        dst_column_names = uniq_labels

    src_column_names = [ curr_col.upper() for curr_col in src_column_names ]
    dst_column_names = [ curr_col.upper() for curr_col in dst_column_names ]

    out_matobj.labels = dst_column_names
    out_matobj.units = uniq_units

    out_matobj.data = numpy.zeros((max_num_rows, len(dst_column_names)), dtype=float)

    # Now aggregate data
    for curr_matobj in file_objs:
        out_matobj.header.update(curr_matobj.header)
        n_src_rows = curr_matobj.dims[0]
        
        for (src_col_idx, col_name) in enumerate(curr_matobj.labels):
            if col_name.upper() in src_column_names:
                dst_col_idx = src_column_names.index(col_name.upper())

                out_matobj.data[:,dst_col_idx] = 0 # make sure not to overlay mismatched row sizes
                out_matobj.data[:n_src_rows, dst_col_idx] = curr_matobj.data[:, src_col_idx]

    out_matobj.write(output_filename)

    if len(uniq_filenames) == 1:
        src_filename = uniq_filenames[0]
    else:
        src_filename = ", ".join(uniq_filenames)

    write_source_into_header(output_filename, src_filename)
开发者ID:E-LLP,项目名称:RtRetrievalFramework,代码行数:71,代码来源:create_dataset_from_inp.py


注:本文中的OCO_Matrix.OCO_Matrix.units方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。