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


Python OCO_Matrix.data方法代码示例

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


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

示例1: scale_cov_by_corr

# 需要导入模块: from OCO_Matrix import OCO_Matrix [as 别名]
# 或者: from OCO_Matrix.OCO_Matrix import data [as 别名]
def scale_cov_by_corr(input_file, output_file, scale_factor):

    # Load existing file
    matrix_obj = OCO_Matrix(input_file)

    rows = range(matrix_obj.dims[0])
    cols = range(matrix_obj.dims[1])

    data_new = numpy.zeros((matrix_obj.dims[0], matrix_obj.dims[1]), dtype=float)

    for row_idx in rows:
        for col_idx in cols:
            rho_old = matrix_obj.data[row_idx, col_idx] / \
                      (math.sqrt(matrix_obj.data[row_idx, row_idx]) * math.sqrt(matrix_obj.data[col_idx, col_idx]))

            if rho_old < 0.0:
                sign = -1.0
            else:
                sign = 1.0
                
            fact_new = float(scale_factor) * (1.0 - abs(rho_old))
            if abs(rho_old) < 1e-40:
                rho_new = 0.0
            elif fact_new > 1.0:
                rho_new = 0.0
            else:
                rho_new = 1.0 - fact_new

            data_new[row_idx, col_idx] = sign * rho_new * \
                                         (math.sqrt(matrix_obj.data[row_idx, row_idx]) * math.sqrt(matrix_obj.data[col_idx, col_idx]))
            
    matrix_obj.data = data_new
    matrix_obj.write(output_file)
开发者ID:E-LLP,项目名称:RtRetrievalFramework,代码行数:35,代码来源:scale_cov_by_corr.py

示例2: average_profiles

# 需要导入模块: from OCO_Matrix import OCO_Matrix [as 别名]
# 或者: from OCO_Matrix.OCO_Matrix import data [as 别名]
def average_profiles(input_file_list, output_file):

    input_file_obj = open(input_file_list)
    first_file = input_file_obj.readline()
    input_file_obj.close()

    first_obj = OCO_Matrix(first_file.strip())
    dst_data = zeros((first_obj.dims[0], first_obj.dims[1]), dtype=float)
    pres_col = first_obj.labels_lower.index("pressure")
    dst_data[:, pres_col] = first_obj.data[:, pres_col]
    
    input_file_obj = open(input_file_list)

    count = 0
    for curr_atm_file in input_file_obj.readlines():
        curr_atm_file = curr_atm_file.strip()
        
        # Load existing file
        print "Loading %s" % curr_atm_file
        file_obj = OCO_Matrix(curr_atm_file)

        for col in range(file_obj.dims[1]):
            if col != pres_col:
                dst_data[:, col] += file_obj.data[:, col]

        count += 1
    
    for col in range(dst_data.shape[1]):
        if col != pres_col:        
            dst_data[:, col] /= count

    first_obj.data = dst_data
    first_obj.write(output_file)
开发者ID:E-LLP,项目名称:RtRetrievalFramework,代码行数:35,代码来源:average_profiles.py

示例3: create_mean_psurf

# 需要导入模块: from OCO_Matrix import OCO_Matrix [as 别名]
# 或者: from OCO_Matrix.OCO_Matrix import data [as 别名]
def create_mean_psurf(runlog_file, psurf_file):

    print 'runlog_file = ', runlog_file
    print 'psurf_file = ', psurf_file
    
    runlog_fobj = open(runlog_file, "r")

    header_cols = runlog_fobj.readline().split()

    pout_col = header_cols.index('pout')

    pouts = []
    for runlog_line in runlog_fobj.readlines():
        runlog_parts = runlog_line.split()
        pouts.append(float(runlog_parts[pout_col]))
        
    runlog_fobj.close()
    
    avg_psurf = mean(pouts) * 1e2

    out_mat_obj = OCO_Matrix()
    out_mat_obj.file_id = "Mean surface pressure from runlog file: %s" % runlog_file
    out_mat_obj.labels = ['LEVEL', 'PSURF']
    out_mat_obj.data = ones((1, 2), dtype=float)
    out_mat_obj.data[0, 1] = avg_psurf
    out_mat_obj.write(psurf_file)
开发者ID:E-LLP,项目名称:RtRetrievalFramework,代码行数:28,代码来源:create_runlog_mean_psurf.py

示例4: write_xco2_file

# 需要导入模块: from OCO_Matrix import OCO_Matrix [as 别名]
# 或者: from OCO_Matrix.OCO_Matrix import data [as 别名]
def write_xco2_file(log_sounding_dict, xco2_filename):
    xco2_fileobj = OCO_Matrix()
    xco2_fileobj.file_id = 'True xco2 from orbit simulator'
    xco2_fileobj.labels = [XCO2_LABEL_NAME]
    xco2_fileobj.data = numpy.zeros((1,1), dtype=float)
    xco2_fileobj.data[0,0] = log_sounding_dict[XCO2_COL_NAME]
    xco2_fileobj.write(xco2_filename)
开发者ID:E-LLP,项目名称:RtRetrievalFramework,代码行数:9,代码来源:extract_orbit_sim_data.py

示例5: remove_bad_data_all

# 需要导入模块: from OCO_Matrix import OCO_Matrix [as 别名]
# 或者: from OCO_Matrix.OCO_Matrix import data [as 别名]
def remove_bad_data_all(input_file, output_file, check_col, check_val):

    # Load existing file
    file_obj = OCO_Matrix(input_file)
    num_rows = file_obj.dims[0]

    if check_col.isdigit():
        check_col = int(check_col)
    else:
        check_col = file_obj.labels_lower.index(check_col.lower())
    
    good_mask = []

    for row_idx in range(num_rows):
        if not re.search(str(check_val).lower(), str(file_obj.data[row_idx, check_col]).lower()):
            good_mask.append(row_idx)

    cleaned_data = numpy.zeros((len(good_mask), file_obj.dims[1]), dtype=float)

    new_data_idx = 0
    for good_row in good_mask:
        cleaned_data[new_data_idx, :] = file_obj.data[good_row, :]
        new_data_idx += 1
    
    file_obj.data = cleaned_data
    file_obj.write(output_file)
开发者ID:E-LLP,项目名称:RtRetrievalFramework,代码行数:28,代码来源:remove_bad_data.py

示例6: resample_levels

# 需要导入模块: from OCO_Matrix import OCO_Matrix [as 别名]
# 或者: from OCO_Matrix.OCO_Matrix import data [as 别名]
def resample_levels(input_file, output_file, resample_to, val_extrapolate=False):

    # Load existing file
    file_obj = OCO_Matrix(input_file)

    try:
        src_pres_col = file_obj.labels_lower.index("pressure")
    except:
        raise IOError('Could not find pressure column in input file: "%s"' % input_file)

    try:
        src_temp_col = file_obj.labels_lower.index("t")
    except:
        src_temp_col = -1

    ## Do nothing except write output file if input and desired levels already match
    if resample_to.isdigit() and file_obj.dims[0] == int(resample_to):
        file_obj.write(output_file)
        return

    elif resample_to.isdigit():
        resample_to = int(resample_to)
        dst_data = numpy.zeros((resample_to, file_obj.dims[1]), dtype=float)
        
    elif os.path.exists(resample_to):
        dest_pressure_file = resample_to
        pres_obj = OCO_Matrix(dest_pressure_file)

        dst_pres_col = pres_obj.labels_lower.index("pressure")

        dst_data = numpy.zeros((pres_obj.dims[0], file_obj.dims[1]), dtype=float)

        resample_to = pres_obj.data[:, dst_pres_col]
        
    else:
        raise ValueError('Resample to argument "%s" is neither an integer nor a file that exists' % resample_to)


    for col_idx in range(file_obj.dims[1]):
        # Interpolate all but temperature in log space
        if col_idx == src_temp_col:
            log_data=False
        else:
            log_data=True

        if col_idx == src_pres_col:
            do_extrapolate = True
        else:
            do_extrapolate = val_extrapolate
            
        dst_data[:, col_idx] = resample_profile( file_obj.data[:, src_pres_col],
                                                 file_obj.data[:, col_idx], 
                                                 resample_to,
                                                 log_data=log_data,
                                                 extrapolate=do_extrapolate )
    file_obj.data = dst_data
    file_obj.write(output_file)
开发者ID:E-LLP,项目名称:RtRetrievalFramework,代码行数:59,代码来源:resample_levels.py

示例7: extract_ils_from_hdf

# 需要导入模块: from OCO_Matrix import OCO_Matrix [as 别名]
# 或者: from OCO_Matrix.OCO_Matrix import data [as 别名]
def extract_ils_from_hdf(hdf_file, output_dir, reverse=False):
    print 'Opening HDF file: %s' % hdf_file
    with contextlib.closing(h5py.File(hdf_file, 'r')) as hdf_obj:

        reported_soundings = []
        for snd_idx, rep_val in enumerate(hdf_obj['Metadata']['ReportedSoundings']):
            if rep_val > 0:
                reported_soundings.append( snd_idx + 1 )

        ils_delta_lambda      = hdf_obj['InstrumentHeader']['ils_delta_lambda']
        ils_relative_response = hdf_obj['InstrumentHeader']['ils_relative_response']

        num_bands          = ils_delta_lambda.shape[0]
        num_ils_parameters = ils_delta_lambda.shape[2]
        num_ils_wndepend   = ils_delta_lambda.shape[3]

        labels = [ 'ILS_PIXELS' ]
        for band_num in range(1, num_bands+1):
            labels.append('ILS_DELTA_LAMBDA_%d' % band_num)
            labels.append('ILS_RESPONSE_%d' % band_num)

        for snd_idx, sounding_id in enumerate(reported_soundings):
            output_filename = os.path.join(output_dir, 'ils_%d.dat' % sounding_id)
            print 'Extracting data for sounding %d into %s' % (sounding_id, output_filename)

            ils_file = OCO_Matrix()
            ils_file.data = numpy.zeros((num_ils_parameters * num_ils_wndepend, num_bands*2+1), dtype=float)

            row_beg = 0
            for color_index in range(num_ils_parameters):
                print 'Extracting color %d' % (color_index+1)
                row_end = row_beg+num_ils_wndepend
                ils_file.data[row_beg:row_end, 0] = color_index + 1

                for band_idx, col_idx in zip(range(num_bands), range(1,1+2*num_bands,2)):
                    ils_file.data[row_beg:row_end, col_idx]   = ils_delta_lambda[band_idx, snd_idx, color_index, :]

                    if reverse:
                        ils_file.data[row_beg:row_end, col_idx+1] = ils_relative_response[band_idx, snd_idx, color_index, :][::-1]
                    else:
                        ils_file.data[row_beg:row_end, col_idx+1] = ils_relative_response[band_idx, snd_idx, color_index, :]

                row_beg = row_end


            ils_file.file_id = 'Instrument Line Shape parameters for sounding posistion %d' % sounding_id

            ils_file.labels = labels

            ils_file.header['function_type'] = 'TABLE'
            ils_file.header['interpolation'] = '100 100 100'
            ils_file.header['num_ils_parameters'] = num_ils_parameters
            ils_file.header['num_ils_wndepend']   = num_ils_wndepend

            print 'Writing to %s' % output_filename
            ils_file.write(output_filename, verbose=True)
开发者ID:E-LLP,项目名称:RtRetrievalFramework,代码行数:58,代码来源:extract_ils_from_hdf.py

示例8: write_albedo_file

# 需要导入模块: from OCO_Matrix import OCO_Matrix [as 别名]
# 或者: from OCO_Matrix.OCO_Matrix import data [as 别名]
def write_albedo_file(output_file, albedo_data, header_values=None):
   albedo_obj = OCO_Matrix()
   if header_values != None:
      albedo_obj.header.update(header_values)

   albedo_obj.header['center_wavelengths'] = ' '.join([str(wl) for wl in ALBEDO_CENTER_WAVELENGTHS])
   albedo_obj.labels = [ ALBEDO_COL_TMPL % (idx+1) for idx in range(albedo_data.shape[1]) ]
   albedo_obj.data = albedo_data
   albedo_obj.file_id = 'Surface albedo data'
   albedo_obj.write(output_file)
开发者ID:E-LLP,项目名称:RtRetrievalFramework,代码行数:12,代码来源:create_surface_apriori.py

示例9: get_data_object

# 需要导入模块: from OCO_Matrix import OCO_Matrix [as 别名]
# 或者: from OCO_Matrix.OCO_Matrix import data [as 别名]
def get_data_object(data_filename):

    # Try to load data using OCO_Matrix class
    try:
        data_obj = OCO_Matrix(data_filename)
        return data_obj
    except:
        pass

    # Now load file as tabled data
    table_file_obj = open(data_filename, 'r')
    file_lines = table_file_obj.readlines()
    table_file_obj.close()

    # Seperate each line by spaces. Keep count of maximum
    # number of columns seen for when file is added so we can
    # know how to size the resultng matrix
    max_cols = 0
    file_rows = []
    for line in file_lines:
        if line.find('#') < 0 and len(line.strip()) != 0:
            line_cols = line.strip().split()
            file_rows.append(line_cols)
            max_cols = max(max_cols, len(line_cols))

#    data_mat = numpy.zeros((len(file_rows), max_cols), dtype=float)
    data_mat = numpy.zeros((len(file_rows), max_cols), dtype=numpy.chararray)

    for row_idx in range(len(file_rows)):
        num_cols = len(file_rows[row_idx])
        for col_idx in range(num_cols):
            col_value = file_rows[row_idx][col_idx]
            data_mat[row_idx][col_idx] = col_value
#            try:
#                data_mat[row_idx][col_idx] = float(col_value)
#            except:
#                data_mat[row_idx][col_idx] = fill_value

    # Create label names based on filename and index or else can
    # not select specific columns
    label_base = os.path.basename(data_filename)
    label_base = label_base[0:label_base.rfind('.')] # Remove extension

    data_labels = []    
    for col_idx in range(max_cols):
        data_labels.append( get_column_format(max_cols) % (label_base, col_idx) )
    
    # Save data into OCO Matrix object
    data_obj = OCO_Matrix()
    data_obj.dims = [len(file_rows), max_cols]
    data_obj.labels = data_labels
    data_obj.data = data_mat
    
    return data_obj
开发者ID:E-LLP,项目名称:RtRetrievalFramework,代码行数:56,代码来源:gather_data.py

示例10: write_total_aod_file

# 需要导入模块: from OCO_Matrix import OCO_Matrix [as 别名]
# 或者: from OCO_Matrix.OCO_Matrix import data [as 别名]
def write_total_aod_file(log_sounding_dict, aod_filename):
    # make aerosol_od_<sounding_id>.dat
    
    aod_fileobj = OCO_Matrix()
    aod_fileobj.file_id = 'True aerosol optical depth from orbit simulator'
    aod_fileobj.labels = AOD_LABEL_NAMES
    aod_fileobj.data = numpy.zeros((1,len(AOD_COL_NAMES)), dtype=float)

    for out_idx, aer_col_name in enumerate(AOD_COL_NAMES):
        aod_fileobj.data[0,out_idx] = log_sounding_dict[aer_col_name]

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

示例11: write_psurf_file

# 需要导入模块: from OCO_Matrix import OCO_Matrix [as 别名]
# 或者: from OCO_Matrix.OCO_Matrix import data [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

示例12: Process_File

# 需要导入模块: from OCO_Matrix import OCO_Matrix [as 别名]
# 或者: from OCO_Matrix.OCO_Matrix import data [as 别名]
def Process_File(source, destination, fileKeywords, moduleSections, valuesDict, mapDict):

    if len(moduleSections) > 1:
        raise RuntimeError("Only one input file config set per file")

    if str(source) == str(destination):
        raise ValueError("source and dest filenames must be different. will not overwrite source file")

    spectrum_file = Apply_Template(moduleSections[0].Get_Keyword_Value("spectrum_file"), valuesDict, mapDict=mapDict)

    if type(source) is str and not os.path.exists(source):
        raise IOError("Runlog file %s does not exist" % source)

    base_spec_name = os.path.basename(spectrum_file)

    # Use grep because its faster than doing it outself
    matched_line = None
    if type(source) == str:
        grep_cmd = "grep -E " + base_spec_name + " " + source
        matched_line = os.popen(grep_cmd).readline()

    elif hasattr(source, "read"):
        for curr_line in source.readlines():
            if re.search(base_spec_name, curr_line):
                matched_line = curr_line
                break
    else:
        raise Exception("Unsupported object: %s" % source)

    if matched_line == None or len(matched_line) == 0:
        raise IOError("Could not find spectrum name: %s in run log file: %s" % (base_spec_name, source))

    try:
        matched_columns = matched_line.split()
        psurf_val = float(matched_columns[pout_col_idx]) * convert_factor
    except:
        raise ValueError(
            'Failed to parse psurf value from: "%s" from runlog line: %s'
            % (matched_columns[pout_col_idx], matched_line)
        )

    out_obj = OCO_Matrix()

    out_obj.data = numpy.zeros((1, 1), dtype=float)
    out_obj.data[0, 0] = psurf_val

    out_obj.file_id = "psurf value extracted for spectrum named: %s from runlog file: %s" % (base_spec_name, source)
    out_obj.labels = ["PSURF"]

    out_obj.write(destination)
开发者ID:nasa,项目名称:RtRetrievalFramework,代码行数:52,代码来源:psurf_from_runlog.py

示例13: make_diag_only_cov

# 需要导入模块: from OCO_Matrix import OCO_Matrix [as 别名]
# 或者: from OCO_Matrix.OCO_Matrix import data [as 别名]
def make_diag_only_cov(input_file, output_file):

    # Load existing file
    matrix_obj = OCO_Matrix(input_file)

    rows = range(matrix_obj.dims[0])
    cols = range(matrix_obj.dims[1])

    data_new = numpy.zeros((matrix_obj.dims[0], matrix_obj.dims[1]), dtype=float)

    for row_idx in rows:
        for col_idx in cols:
            if row_idx == col_idx:
                data_new[row_idx, col_idx] = matrix_obj.data[row_idx, col_idx]
            
    matrix_obj.data = data_new
    matrix_obj.write(output_file)
开发者ID:E-LLP,项目名称:RtRetrievalFramework,代码行数:19,代码来源:make_diag_only_cov.py

示例14: write_windspeed_file

# 需要导入模块: from OCO_Matrix import OCO_Matrix [as 别名]
# 或者: from OCO_Matrix.OCO_Matrix import data [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

示例15: write_windspeed_file

# 需要导入模块: from OCO_Matrix import OCO_Matrix [as 别名]
# 或者: from OCO_Matrix.OCO_Matrix import data [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


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