#!/usr/bin/env python # encoding: utf-8 """ Glance config file to compare sfc emissivity output from Geocat to output from FWAIT Created by Graeme Martin 20101119. Copyright (c) 2010 University of Wisconsin SSEC. All rights reserved. """ import glance.filters as filters import glance.data as dataobj import numpy as np Saved_Mask = None # *** filters for loading different variables and making a mask to reuse def load_alternate_file_and_variable (file_path, variable_name) : """ load the data for a variable in a file """ file_object = dataobj.FileInfo(file_path) data = np.array(file_object.file_object[variable_name]) return data def build_mask_by_differences (file_A_name, variable_A_name, file_B_name, variable_B_name, epsilon=0.0) : """ make a mask of where the variables in the two files are too different """ a_data = load_alternate_file_and_variable(file_A_name, variable_A_name) b_data = load_alternate_file_and_variable(file_B_name, variable_B_name) mask = np.abs(a_data - b_data) > epsilon return mask def filter_on_other_variables_profile (data, replace_value, file_A_name, variable_A_name, file_B_name, variable_B_name, dim_size=101, axis=0, epsilon=0.0, do_cache=True) : """ filter the data based on external files, replacing values in data that correspond to values that are too different between variable_A and variable_B with the replace_value if do_cache is true, reuse or save the mask note: if you are cacheing don't use this function with more than one set of external files/variables per config file """ global Saved_Mask mask_to_use = Saved_Mask if do_cache else None if mask_to_use is None : mask_to_use = np.repeat([build_mask_by_differences(file_A_name, variable_A_name, file_B_name, variable_B_name, epsilon=epsilon)], dim_size, axis=axis) data[mask_to_use] = replace_value if do_cache : Saved_Mask = mask_to_use return data # general settings to control how reports are created settings = {} settings['useThreadsToControlMemory'] = True settings['shouldIncludeImages'] = True settings['useSharedRangeForOriginal'] = True settings['doFork'] = False # info on the latitude and longitude variables that will be used lat_lon_info = {} lat_lon_info['longitude'] = 'imager_prof_retr_msg_Lon_reduced' lat_lon_info['latitude'] = 'imager_prof_retr_msg_Lat_reduced' lat_lon_info['longitude_alt_name_in_b'] = 'Longitude' lat_lon_info['latitude_alt_name_in_b'] = 'Latitude' lat_lon_info['lon_lat_epsilon'] = 0.0001 # filter works on (m x n) array, and profiles are (nprof x m x n), so need to apply filter to each # level data[i,:,:] and aggregate output back into a 3D array #numClrPixelsFilter = (lambda data, filterData: np.array([filters.filter_based_on_additional_data_set_min_max_bounds( \ # data[i,:,:], filterData, missingValue=-999.0, minOkFilterValue=9, maxOkFilterValue=9) for i in range(data.shape[0]) ] ) ) numIterFilter3dReal = (lambda data: filter_on_other_variables_profile(data, -999.0, '/data/graemem/sounding_verification_20110427/data/geocatL2.Meteosat-8.2006230.000000_patch_test.nc', 'imager_prof_retr_msg_Num_Iteration', '/data/graemem/sounding_verification_20110427/data/MSG8_SEVIRI_2006213_0600_00_AWG_SOUNDINGS_patch_test.nc', 'NumIter', dim_size=101, axis=0) ) # per variable defaults defaultValues = { 'epsilon': None, 'epsilon_failure_tolerance': None, 'nonfinite_data_tolerance': None, # 'missing_value_alt_in_b': -999.0 # glance should be able to get from variable attributes } # a list of all the variables to analyze # setOfVariables = {} setOfVariables['msg temperature profile'] = { # this entry should correspond to the name in the data file 'variable_name': 'imager_prof_retr_msg_Tprof', 'alternate_name_in_B': 'TempProf', 'data_filter_function_a': numIterFilter3dReal, 'data_filter_function_b': numIterFilter3dReal } setOfVariables['msg water profile'] = { # this entry should correspond to the name in the data file 'variable_name': 'imager_prof_retr_msg_Wprof', 'alternate_name_in_B': 'RHProf', 'data_filter_function_a': numIterFilter3dReal, 'data_filter_function_b': numIterFilter3dReal }