def get_example_method_plot_params(): #Whole European shelf params = get_baseline_params(); params.pixelRes = (0.25, 0.25); params.timeRes = "monthly"; params.originLon = -12.0; #at (0,0) params.maxLon = 1.0; params.originLat = 62.5; #at (0,0) params.maxLat = 51.0; params.contourPathFile = "method_example_contour_paths.p"; params.contourPathFileDeep = "method_example_contour_paths_deep.p"; params.paramsetName = "method_example"; originLon, originLat = su.convert_lonlat_to_index(params.originLon, params.originLat, params.pixelRes); maxLon, maxLat = su.convert_lonlat_to_index(params.maxLon, params.maxLat, params.pixelRes); params.ilonRange = (originLon, maxLon); #(600, 850) params.ilatRange = (originLat, maxLat); #(50, 225) params.shallowDepth = 500.0; params.deepDepth = params.shallowDepth+100.0; params.contourPathsShallow = [1]; params.contourPathsDeep = [2]; params.numberOfBoundryApproximationLines = [8]; #how many lines should be used to approximate the shelf edge boundry params.start_year = 2014; params.end_year = 2015; params.start_month = 0; params.end_month = 12; params.contourMaskFunc = mf.empty_mask_function; return params;
def get_global_test_params(): params = get_baseline_params(); params.pixelRes = (0.25, 0.25); params.timeRes = "monthly"; params.originLon = -180.0; #at (0,0) params.maxLon = 179.75; params.originLat = 89.75; #at (0,0) params.maxLat = -90.0; originLon, originLat = su.convert_lonlat_to_index(params.originLon, params.originLat, params.pixelRes); maxLon, maxLat = su.convert_lonlat_to_index(params.maxLon, params.maxLat, params.pixelRes); params.ilonRange = (originLon, maxLon); #(600, 850) params.ilatRange = (originLat, maxLat); #(50, 225) params.shallowDepth = 500.0; params.deepDepth = params.shallowDepth+100.0; # params.contourPathsShallow = [13, 15, 39, 68, 75, 101, 107, 110, 113, 115, 136, 175, 257, 177, 180]; # params.contourPathsDeep = [2, 3, 21, 41, 45, 67, 66, 74, 77, 79, 97, 129, 168, 131, 133]; # params.numberOfBoundryApproximationLines = [32, 16, 32, 16, 4, 8, 8, 32, 16, 8, 32, 32, 8, 8, 8]; #how many lines should be used to approximate the shelf edge boundry params.contourMaskFunc = mf.global_shelf_mask_func; params.start_year = 1993; params.end_year = 1993; params.start_month = 0; params.end_month = 12; params.contourPathFile = "global_test_shelf_contour_paths.p"; params.contourPathFileDeep = "global_test_shelf_contour_paths_deep.p"; params.paramsetName = "global_test"; return params
def generic_area_mask(allowedAreas, data, params): keep = np.empty(len(data), dtype=bool) for pointIndex in range(0, len(data)): px = data[pointIndex].indexX py = data[pointIndex].indexY #Check each area to see if the point falls into one of them passed = False for area in allowedAreas: #convert lon/lat to coordinates llx, lly = su.convert_lonlat_to_index(area[0][0], area[0][1], params.pixelRes, lon0=params.originLon, lat0=params.originLat) urx, ury = su.convert_lonlat_to_index(area[1][0], area[1][1], params.pixelRes, lon0=params.originLon, lat0=params.originLat) if point_in_area(llx, lly, urx, ury, px, py) == True: passed = True break keep[pointIndex] = passed #Only keep points that fell into one of the above areas keep = np.array(keep) data = list(np.array(data)[keep]) return data
def get_European_shelf_params(): #Whole European shelf params = get_baseline_params(); params.pixelRes = (0.25, 0.25); params.timeRes = "monthly"; params.originLon = -25.0; #at (0,0) params.maxLon = 0.0; params.originLat = 62.0; #at (0,0) params.maxLat = 40.0; params.contourPathFile = "european_shelf_contour_paths.p"; params.contourPathFileDeep = "european_shelf_contour_paths_deep.p"; params.paramsetName = "europeanshelf"; originLon, originLat = su.convert_lonlat_to_index(params.originLon, params.originLat, params.pixelRes); maxLon, maxLat = su.convert_lonlat_to_index(params.maxLon, params.maxLat, params.pixelRes); params.ilonRange = (originLon, maxLon); #(600, 850) params.ilatRange = (originLat, maxLat); #(50, 225) params.shallowDepth = 500.0; params.deepDepth = params.shallowDepth+100.0; params.contourPathsShallow = [1]; params.contourPathsDeep = [1]; #params.numberOfBoundryApproximationLines = [64]; #how many lines should be used to approximate the shelf edge boundry params.numLineApproximationFunction = lambda x, y : 64; #Function to determine the number of line segments to use #params.start_year = 2014; #params.end_year = 2015; #params.start_month = 0; #params.end_month = 12; params.start_year = 2011; params.end_year = 2012; params.start_month = 9; params.end_month = 9; params.contourMaskFunc = mf.empty_mask_function; params.yeariMonths = [(params.start_year, imonth) for imonth in range(params.start_month, 12)] + [(params.end_year, imonth) for imonth in range(0, params.end_month)]; return params;
def calculate_km_subsection_bounds_along_shelf(wholeShelfX, wholeShelfY, wholeShelfDistances, subsectionBounds, params, testPlot=False): #Calculate subset mask subsetMask = [False] * len(wholeShelfX) for pointIndex in range(0, len(wholeShelfX)): px = wholeShelfX[pointIndex] py = wholeShelfY[pointIndex] #convert lon/lat to coordinates llx, lly = su.convert_lonlat_to_index(subsectionBounds[0][0], subsectionBounds[0][1], params.pixelRes, lon0=params.originLon, lat0=params.originLat) urx, ury = su.convert_lonlat_to_index(subsectionBounds[1][0], subsectionBounds[1][1], params.pixelRes, lon0=params.originLon, lat0=params.originLat) #Check each area to see if the point falls into one of them and set the mask if point_in_area(llx, lly, urx, ury, px, py) == True: subsetMask[pointIndex] = True #find the first and last instance of 'True' for each contiguous span of 'True' ifirsts = [] ilasts = [] prev = False for i in range(0, len(subsetMask)): if subsetMask[i] == True and prev == False: ifirsts.append(i) if subsetMask[i] == False and prev == True: ilasts.append(i - 1) prev = subsetMask[i] if prev == True: #last one won't trigger an end of a contiguous block ilasts.append(i) if len(ilasts) != len(ifirsts): #sanity check raise RuntimeError( "Unequal starts and ends of contiguous blocks in subset filter.") #convert mask to array subsetMask = np.array(subsetMask) cumulativeDists = np.cumsum(wholeShelfDistances) #calculate intercept distances for each contiguous span distances = [] for i in range(0, len(ifirsts)): dist1 = cumulativeDists[ifirsts[i]] dist2 = cumulativeDists[ilasts[i]] distances.append((dist1, dist2)) #plot to perform manual sanity check if testPlot: import matplotlib.pyplot as plt from netCDF4 import Dataset depth = np.flipud( Dataset("data/GEBCO_bathymetry_0.25x0.25deg.nc", 'r').variables["mean_depth"][:]) plt.figure() plt.imshow(depth) for i in range(len(distances)): plt.plot(wholeShelfX[ifirsts[i]:ilasts[i] + 1], wholeShelfY[ifirsts[i]:ilasts[i] + 1], 'y', linewidth=5, alpha=1.0) #plot just subsection with thicker line #plt.plot(wholeShelfX[iFirst:iLast+1], wholeShelfY[iFirst:iLast+1], 'y', linewidth=5, alpha=1.0); #plot just subsection with thicker line plt.plot(wholeShelfX, wholeShelfY, 'r') plt.xlim(wholeShelfX.min(), wholeShelfX.max()) plt.ylim(wholeShelfY.max(), wholeShelfY.min()) #return the intercept distances along the shelf boundary return distances, subsetMask
def global_shelf_mask_func(data, params): allowedAreas = [] #((llLon, llLat), (urLon, urLat)) allowedAreas.append(area_EuropeanShelf) #European shelf allowedAreas.append(area_LabradorSea) #Labrador Sea allowedAreas.append(area_MidAtlanticBight) #Mid-Atlantic Bight allowedAreas.append(area_CoastOfJapan) #Coast of Japan allowedAreas.append(area_Patagonia) #Patagonia allowedAreas.append(area_Tasmania) #Tasmania allowedAreas.append(area_BarentsSea) #Barents Sea allowedAreas.append(area_SouthAtlanticBight) #South Atlantic Bight allowedAreas.append(area_SouthGreenland) #South Greenland allowedAreas.append(area_AntarcticPeninsula) #Antarctic Peninsula allowedAreas.append(area_BeringSeaWest) #Bering Sea (West) allowedAreas.append(area_BeringSeaEast) #Bering Sea (East) allowedAreas.append(area_IrmingerSea) #Irminger Sea allowedAreas.append(area_CascianShelf) #Cascian Shelf # allowedAreas.append( ((141.0, -45.0), (151.0, -39.0)) ); #Tasmania # allowedAreas.append( ((0.0, 60.0), (75.0, 90.0)) ); #Barents Sea # allowedAreas.append( ((-82.0, 26.0), (-74.0, 36.5)) ); #South Atlantic Bight # allowedAreas.append( ((-57.0, 59.0), (-18.5, 67.5)) ); #South Greenland # allowedAreas.append( ((-80.0, -75.0), (-50.0, -61.0)) ); #Antarctic Peninsula # allowedAreas.append( ((-180.0, 45.0), (-150.0, 61.0)) ); #Bering Sea (West) # allowedAreas.append( ((178.0, 45.0), (180.0, 61.0)) ); #Bering Sea (East) # allowedAreas.append( ((-57.0, 59.0), (-18.5, 67.5)) ); #Irminger Sea # allowedAreas.append( ((-140.0, 40.0), (-120.0, 54.0)) ); #Cascian Shelf keep = np.empty(len(data), dtype=bool) for pointIndex in range(0, len(data)): px = data[pointIndex].indexX py = data[pointIndex].indexY #Check each area to see if the point falls into one of them passed = False for area in allowedAreas: #convert lon/lat to coordinates llx, lly = su.convert_lonlat_to_index(area[0][0], area[0][1], params.pixelRes) urx, ury = su.convert_lonlat_to_index(area[1][0], area[1][1], params.pixelRes) if point_in_area(llx, lly, urx, ury, px, py) == True: passed = True break keep[pointIndex] = passed #Only keep points that fell into one of the above areas keep = np.array(keep) data = list(np.array(data)[keep]) return data