in analysis/webservice/algorithms/CorrelationMap.py [0:0]
def calc(self, computeOptions, **args):
minLat = computeOptions.get_min_lat()
maxLat = computeOptions.get_max_lat()
minLon = computeOptions.get_min_lon()
maxLon = computeOptions.get_max_lon()
ds = computeOptions.get_dataset()
startTime = computeOptions.get_start_time()
endTime = computeOptions.get_end_time()
resolution = computeOptions.get_decimal_arg("res", default=1.0)
if not len(ds) == 2:
raise Exception("Requires two datasets for comparison. Specify request parameter ds=Dataset_1,Dataset_2")
ds1tiles = self._get_tile_service().find_tiles_in_polygon(box(minLon, minLat, maxLon, maxLat), ds[0], startTime,
endTime)
ds2tiles = self._get_tile_service().find_tiles_in_polygon(box(minLon, minLat, maxLon, maxLat), ds[1], startTime,
endTime)
matches = self._match_tiles(ds1tiles, ds2tiles)
if len(matches) == 0:
raise NexusProcessingException(reason="Could not find any data temporally co-located")
results = [[{
'cnt': 0,
'slope': 0,
'intercept': 0,
'r': 0,
'p': 0,
'stderr': 0,
'lat': float(lat),
'lon': float(lon)
} for lon in np.arange(minLon, maxLon, resolution)] for lat in
np.arange(minLat, maxLat, resolution)]
for stats in results:
for stat in stats:
values_x = []
values_y = []
for tile_matches in matches:
tile_1_list = tile_matches[0]
value_1 = get_approximate_value_for_lat_lon(tile_1_list, stat["lat"], stat["lon"])
tile_2_list = tile_matches[1]
value_2 = get_approximate_value_for_lat_lon(tile_2_list, stat["lat"], stat["lon"])
if not (math.isnan(value_1) or math.isnan(value_2)):
values_x.append(value_1)
values_y.append(value_2)
if len(values_x) > 2 and len(values_y) > 2:
stats = linregress(values_x, values_y)
stat["slope"] = stats[0] if not math.isnan(stats[0]) and not math.isinf(stats[0]) else str(stats[0])
stat["intercept"] = stats[1] if not math.isnan(stats[1]) and not math.isinf(stats[1]) else str(
stats[1])
stat["r"] = stats[2] if not math.isnan(stats[2]) and not math.isinf(stats[2]) else str(stats[2])
stat["p"] = stats[3] if not math.isnan(stats[3]) and not math.isinf(stats[3]) else str(stats[3])
stat["stderr"] = stats[4] if not math.isnan(stats[4]) and not math.isinf(stats[4]) else str(
stats[4])
stat["cnt"] = len(values_x)
return CorrelationResults(results)