# Assign the monthly gridded DOT anomaly to the array dot_anom_ts[:, :, t] = nc.variables[ 'dynamic_ocean_topography_anomaly'][:] nc.close() # Move the month index along by 1 t += 1 ## Cycle through each grid cell and calculate the trend of the data dot_anom_regress = np.full((59, 361), fill_value=np.NaN) for ilat in range(len(lat)): for ilon in range(len(lon)): # If there are nans in the data if np.any(np.isfinite(dot_anom_ts[ilat, ilon, :])): regress = stats.linregress( time, funct.inpaint_nans(dot_anom_ts[ilat, ilon, :])) dot_anom_regress[ilat, ilon] = (regress[0] * 1000) ## Calculate the mean circumpolar trend # Calculate the grid size for each cell grid_lon, grid_lat = np.meshgrid(lon, lat) # Calculate the surface area of each cell S = funct.surface_area(grid_lat, grid_lon, 0.5, 1.0) total_area = np.nansum(np.nansum(~np.isnan(dot_anom_regress) * S)) total_trend = np.nansum(dot_anom_regress * S) / total_area print('The total trend is:', total_trend, 'mm / year')
nc = Dataset(altimetry_file, 'r') lat = nc.variables['latitude'][:] lon = nc.variables['longitude'][:] dot_anom_ts[:, :, t] = nc.variables['dynamic_ocean_topography_anomaly'][:] nc.close() # Calculate the correlation between the time series and the altimetry data dot_anom_xcorr = np.full((59, 361), fill_value=np.NaN) dot_anom_xcorr_pvalues = np.full((59, 361), fill_value=np.NaN) for ilat in range(len(lat)): for ilon in range(len(lon)): # If there are nans in the altimetry data if np.any(np.isfinite(dot_anom_ts[ilat, ilon, :])): xcorr = stats.spearmanr(funct.inpaint_nans(dot_anom_ts[ilat, ilon, :]), bpr) dot_anom_xcorr[ilat, ilon] = xcorr[0] dot_anom_xcorr_pvalues[ilat, ilon] = xcorr[1] pl.figure() pl.clf() m = Basemap(projection='spstere', boundinglat=-50, lon_0=180, resolution='l') m.drawmapboundary() m.drawcoastlines(zorder=10) m.fillcontinents(zorder=10) m.drawparallels(np.arange(-80., 81., 20.), labels=[1, 0, 0, 0]) m.drawmeridians(np.arange(-180., 181., 20.), labels=[0, 0, 0, 1]) grid_lats, grid_lons = np.meshgrid(lat, lon) stereo_x, stereo_y = m(grid_lons, grid_lats)
lat = nc.variables['latitude'][:] lon = nc.variables['longitude'][:] # Assign the monthly gridded DOT anomaly to the array ssh_anom_ts[:, :, t] = nc.variables['sea_surface_height_anomaly'][:] nc.close() # Move the month index along by 1 t += 1 ## Cycle through each grid cell and calculate the trend of the data ssh_anom_regress = np.full((59, 361), fill_value=np.NaN) for ilat in range(len(lat)): for ilon in range(len(lon)): # If there are nans in the data if np.any(np.isfinite(ssh_anom_ts[ilat, ilon, :])): regress = stats.linregress(time, funct.inpaint_nans(ssh_anom_ts[ilat, ilon, :])) ssh_anom_regress[ilat, ilon] = (regress[0] * 1000) ## Calculate the mean circumpolar trend # Calculate the grid size for each cell grid_lon, grid_lat = np.meshgrid(lon, lat) # Calculate the surface area of each cell S = funct.surface_area(grid_lat, grid_lon, 0.5, 1.0) total_area = np.nansum(np.nansum(~np.isnan(ssh_anom_regress) * S)) total_trend = np.nansum(ssh_anom_regress * S) / total_area print('The total trend is:', total_trend, 'mm / year')