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


Python OCO_Matrix.write方法代码示例

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


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

示例1: create_log_p_profile

# 需要导入模块: from OCO_Matrix import OCO_Matrix [as 别名]
# 或者: from OCO_Matrix.OCO_Matrix import write [as 别名]
def create_log_p_profile(input_file, output_file, column, val0, lapse_rate):

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

    val0 = float(val0)
    lapse_rate = float(lapse_rate)

    # Find existing pressure bounds
    src_pres_col = file_obj.labels_lower.index("pressure")
    pressure = numpy.zeros(num_rows, dtype=float)

    for row in range(0, num_rows):
        pressure[row] = float(file_obj.data[row][src_pres_col])
   
    if column.isdigit():
        dest_prof_col = column
    else:
        dest_prof_col = file_obj.labels_lower.index(column.lower())

    # create log p profile
    for row in range(num_rows-1,0,-1):
       file_obj.data[row, dest_prof_col] = val0 - lapse_rate * (math.log(pressure[num_rows-1])-math.log(pressure[row]))

    file_obj.write(output_file)
开发者ID:E-LLP,项目名称:RtRetrievalFramework,代码行数:28,代码来源:create_log_p_profile.py

示例2: write_xco2_file

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

示例3: offset_column

# 需要导入模块: from OCO_Matrix import OCO_Matrix [as 别名]
# 或者: from OCO_Matrix.OCO_Matrix import write [as 别名]
def offset_column(input_file, output_file, columns, offset, method, pressure_range=None):

    # Load existing file
    matrix_obj = OCO_Matrix(input_file)
   
    # Add ability to specify cols individually or using a * to goto end
    cols = index_range_list(columns)

    if offset.isdigit():
        offset = float(offset)
    else:
        offset = eval(offset)

    if pressure_range != None:
        pres_col = matrix_obj.labels_lower.index("pressure")

        pres_range_arr = pressure_range.split(',')
        pres_val_beg = float(pres_range_arr[0])
        pres_val_end = float(pres_range_arr[1])

        pres_idx_beg = 0
        pres_idx_end = matrix_obj.dims[0]

        pres_column = []
        [ pres_column.append(float(val[pres_col])) for val in matrix_obj.data ]

        pres_idx_curr = 0
        beg_found = False
        for pres_val in pres_column:            
            if pres_val >= pres_val_beg and not beg_found:
                pres_idx_beg = pres_idx_curr
                beg_found = True
        
            if pres_val <= pres_val_end:
                pres_idx_end = pres_idx_curr + 1

            pres_idx_curr += 1

        target_rows = range(pres_idx_beg, pres_idx_end)

    else:
        target_rows = range(matrix_obj.dims[0])

    for rowIdx in target_rows:
        for colIdx in cols:

            #print 'old_val[%d][%d] = %f' % (rowIdx, colIdx, matrix_obj.data[rowIdx][colIdx])
            
            if method == '/':
                matrix_obj.data[rowIdx][colIdx] = matrix_obj.data[rowIdx][colIdx] / offset
            elif method == '-':
                matrix_obj.data[rowIdx][colIdx] = matrix_obj.data[rowIdx][colIdx] - offset
            elif method == '*':
                matrix_obj.data[rowIdx][colIdx] = matrix_obj.data[rowIdx][colIdx] * offset
            else:
                matrix_obj.data[rowIdx][colIdx] = matrix_obj.data[rowIdx][colIdx] + offset

            #print 'new_val[%d][%d] = %f' % (rowIdx, colIdx, matrix_obj.data[rowIdx][colIdx])

    matrix_obj.write(output_file)
开发者ID:E-LLP,项目名称:RtRetrievalFramework,代码行数:62,代码来源:offset_column.py

示例4: average_profiles

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

示例5: remove_bad_data_all

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

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

示例7: create_mean_psurf

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

示例8: noisify_spectra_file

# 需要导入模块: from OCO_Matrix import OCO_Matrix [as 别名]
# 或者: from OCO_Matrix.OCO_Matrix import write [as 别名]
def noisify_spectra_file(input_radiance_file, output_radiance_file, **kwarg):

    # Load existing file
    matrix_obj = OCO_Matrix(input_radiance_file)

    noisify_spectra_obj(matrix_obj, **kwargs)

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

示例9: write_soundinginfo_file

# 需要导入模块: from OCO_Matrix import OCO_Matrix [as 别名]
# 或者: from OCO_Matrix.OCO_Matrix import write [as 别名]
def write_soundinginfo_file(hdf_sounding_dict, sounding_info_filename, sounding_id):
    sounding_info_fileobj = OCO_Matrix()
    sounding_info_fileobj.file_id = 'Sounding info from orbit simulator for sounding id: %s' % sounding_id

    sounding_info_fileobj.header = hdf_sounding_dict
    
    sounding_info_fileobj.header['sounding_id'] = sounding_id

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

示例10: resample_levels

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

示例11: extract_ils_from_hdf

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

示例12: Process_File

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

    matrix_obj = OCO_Matrix(source)
    for noisifySect in moduleSections:       
        noise_cut_off = Apply_Template(noisifySect.Get_Keyword_Value('noise_cut_off'), valuesDict, mapDict=mapDict)
        pixel_rows    = Apply_Template(noisifySect.Get_Keyword_Value('pixel_rows'), valuesDict, mapDict=mapDict)

        noisify_spectra_obj(matrix_obj, row_range_spec=pixel_rows, noise_cut_off=noise_cut_off)
        
    matrix_obj.write(destination, auto_size_cols=False)
开发者ID:E-LLP,项目名称:RtRetrievalFramework,代码行数:12,代码来源:noisify_spectra_module.py

示例13: write_albedo_file

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

示例14: write_total_aod_file

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

示例15: write_psurf_file

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


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