Ejemplo n.º 1
0
    def _apply_sens_correction(self, band_num, band_wns, band_data, gain):

        if self.sens_corr_data == None:
            return band_data

        band_index = SWIR_BANDS.index(band_num)

        corr_obj = self.sens_corr_data[band_index]

        unit_col_idx = corr_obj.labels.index(RAD_CNV_UNIT_COL)

        for pol_idx, pol_name in enumerate(POL_ORDER):
            corr_col_name = RAD_CNV_SENS_COL_TMPL % (band_num, pol_name, gain[pol_idx])

            try:
                corr_col_idx = corr_obj.labels.index(corr_col_name)
            except:
                raise IOError('Could not find column named: %s in sensitivity file: %s' % (corr_col_name, corr_obj.filename))


            # Retrieve correction data
            resampled_corr_data = numpy.zeros(band_data.shape[0], dtype=float)

            src_corr_data = corr_obj.data[:,corr_col_idx]
            resampled_corr_data = OCO_MathUtil.linear_interpol(src_corr_data, corr_obj.data[:, unit_col_idx], band_wns[:,pol_idx], extrapolate=False, extrap_err=False)
            
            valid_points = numpy.where(abs(resampled_corr_data) > 0.0)[0]
            band_data[valid_points, pol_idx] *= resampled_corr_data[valid_points]

        return band_data
def calculate_aod_values(in_press, out_press, aer_profiles, name_prefix, use_sub_types=None):

    if type(aer_profiles) == numpy.ndarray and len(aerosol.shape) == 2:
        resampled_profiles = numpy.zeros((len(out_press), aer_profiles.shape[1]), dtype=float)
    else:
        resampled_profiles = numpy.zeros((len(out_press), len(aer_profiles)), dtype=float)
        
    for prof_idx in range(resampled_profiles.shape[1]):
        if type(aer_profiles) == numpy.ndarray and len(aerosol.shape) == 2:
            curr_profile = aer_profiles[:,prof_idx]
        else:
            curr_profile = numpy.array(aer_profiles[prof_idx])

        # Check for log values
        if numpy.any(curr_profile < 0):
            curr_profile = numpy.exp(curr_profile)
            
        resampled_profiles[:, prof_idx] = OCO_MathUtil.resample_profile(in_press, curr_profile, out_press)

    layer_aod, layer_press = OCO_MathUtil.total_aod( out_press, resampled_profiles, return_layers=True )

    if use_sub_types == None:
        use_sub_types = AOD_TYPE_ORDER

    aod_vals_ret = []
    aod_vals_chk = {}
    for type_name in AOD_TYPE_ORDER:
        type_range = AOD_SUB_TYPES[type_name]
        
        press_high = numpy.where(layer_press >= type_range[0])
        press_low  = numpy.where(layer_press <= type_range[1])
        press_range = list(set.intersection(set(press_high[0]), set(press_low[0])))

        calc_aod = numpy.sum(layer_aod[press_range])

        # Place variables with same name as type name for checking after loop
        aod_vals_chk[type_name] = calc_aod

        # Put calculated values in format needed for table
        if type_name in use_sub_types:
            aod_vals_ret.append( ('%s_%s' % (name_prefix, type_name), calc_aod) )

    check_eval = AOD_CHECK_EVAL.format(**aod_vals_chk)
    if not eval(check_eval):
        raise Exception('Check on aod values "%s" evaluated as: "%s" has failed.' % (AOD_CHECK_EVAL, check_eval))

    return aod_vals_ret
Ejemplo n.º 3
0
    def get_value(self, time_struct):
        year, month, doy = (time_struct.tm_year, time_struct.tm_mon, time_struct.tm_yday)
        year_frac = float(doy) / float(time.strftime('%j', datetime.datetime(year, 12, 31).utctimetuple()))
        curr_dec_date = year + year_frac

        trend_value = OCO_MathUtil.linear_interpol(self.values, self.dates, [curr_dec_date], extrapolate=True, extrap_err=False)

        # Resulting trend value should be in first element of matrix
        return trend_value[0]
Ejemplo n.º 4
0
    def get_value(self, time_struct):
        year, month, doy = (time_struct.tm_year, time_struct.tm_mon,
                            time_struct.tm_yday)
        year_frac = float(doy) / float(
            time.strftime('%j',
                          datetime.datetime(year, 12, 31).utctimetuple()))
        curr_dec_date = year + year_frac

        trend_value = OCO_MathUtil.linear_interpol(self.values,
                                                   self.dates, [curr_dec_date],
                                                   extrapolate=True,
                                                   extrap_err=False)

        # Resulting trend value should be in first element of matrix
        return trend_value[0]
def calculate_file_xco2(ts_obj, file_obj, curr_dir, psurf_file, ak_file, data_label):
    logger = logging.getLogger(LOGGING_NAME)

    # See if extra files are available
    psurf_obj = ts_obj.get_cached_file(curr_dir, psurf_file)
    ak_obj = ts_obj.get_cached_file(curr_dir, ak_file)

    if ak_obj == None:
        ak_data = None
    else:
        ak_data = ak_obj.data

    try:
        in_press_profile = file_obj[PRESSURE_COLUMN]
    except LookupError:
        logger.error('For file "%s" LookupError: %s' % (file_obj.filename,traceback.format_exception_only(*sys.exc_info()[0:2])))
        return None

    if in_press_profile == None or in_press_profile.shape[0] == 0:
        logger.error('Could not calculate xco2 from file: "%s" for run dir "%s" due to missing pressure column' % (file_obj.filename. curr_dir))

    if psurf_obj != None:
        out_press_profile = apply_psurf_to_pressures(in_press_profile[:,0], psurf_obj[PSURF_COLUMN][0,0])
    else:
        out_press_profile = in_press_profile[:,0]


    # Get desired atmosphere profiles for calculation
    try:
        co2_profile = file_obj[CO2_COLUMN]
    except LookupError:
        logger.error('Could not find column named: %s' % CO2_COLUMN)
        return None
    
    if co2_profile == None or co2_profile.shape[0] == 0:
        logger.error('Could not calculate xco2 from file: "%s" for run dir "%s" due to missing CO2 column' % (file_obj.filename. curr_dir))
        return None
    
    try:
        co2_profile = OCO_MathUtil.resample_profile(in_press_profile, co2_profile[:,0], out_press_profile)
    except ValueError:
        logger.error('Could not resample profile with inputs: in_pressure_profile = %s, co2_profile = %s, out_pressure_profile = %s' % (in_press_profile, co2_profile[:,0], out_press_profile))
        return None

    # Get temperature and water profiles, if results are empty make sure we
    # pass None to compute_xco2
    temp_profile = file_obj[TEMPERATURE_COLUMN]
    if temp_profile != None and temp_profile.shape[0] == 0:
        temp_profile = None
    else:
        temp_profile = OCO_MathUtil.resample_profile(in_press_profile, temp_profile[:,0], out_press_profile)

    h2o_profile = file_obj[H2O_COLUMN]
    if h2o_profile != None and h2o_profile.shape[0] == 0:
        h2o_profile = None
    else:
        h2o_profile = OCO_MathUtil.resample_profile(in_press_profile, h2o_profile[:,0], out_press_profile)

    calc_xco2 = OCO_MathUtil.compute_xco2(co2_profile, out_press_profile, temp_profile, h2o_profile, ak_data)

    return [ (data_label, calc_xco2) ]