经度从0-360更改为-180到180

1.经度概念

  • 在参考大圆上,从所采用的零子午线与该参考圆的交点到通过物体的子午线的相似交点的角距。
  • 子午线(从一极到一极的线)连接着同一经度的点。经过英国格林威治皇家天文台附近的本初子午线,按照惯例被定义为经度为0°。正经度在本初子午线的东边,负经度在本初子午线的西边。
    在这里插入图片描述

2.将0-360范围的经度转换为-180-180
方法一:

lon_name = 'longitude'  # whatever name is in the data

# Adjust lon values to make sure they are within (-180, 180)
ds['_longitude_adjusted'] = xr.where(
    ds[lon_name] > 180,
    ds[lon_name] - 360,
    ds[lon_name])

# reassign the new coords to as the main lon coords
# and sort DataArray using new coordinate values
ds = (
    ds
    .swap_dims({lon_name: '_longitude_adjusted'})
    .sel(**{'_longitude_adjusted': sorted(ds._longitude_adjusted)})
    .drop(lon_name))

ds = ds.rename({'_longitude_adjusted': lon_name})

参考资料:
https://blog.csdn.net/weixin_44237337/article/details/119707332

方法二:
https://confluence.ecmwf.int/pages/viewpage.action?pageId=149337515
代码:

long1=mod((long3+180),360)-180
 
# Python:
long1 = (long3 + 180) % 360 - 180
 
# Or:
if long3 <= 180: long1 = long3
else: long1 = long3 - 360
long3: 180, 181, ..., 359, 360/0, 1, ..., 179, 180
long1: -180, -179, ... -1, 0, 1, ..., 179, 180
figure; % 设置地图投影为赤平投影(极地赤平投影),适用于南纬30度到90度 %axesm('LambertAzimEqualArea', 'MapLatLimit', [-90 -30], 'MapLonLimit', [-180 180]); %axesm('LambertAzimEqualArea'); %m_proj('polar','lat',-90,'long',0,'radius',60); m_proj('stereographic','lat',-90,'long',0,'radius',60); %m_proj('mercator','lat',[-90 -30],'long',[-180 180]);%m_proj('mercator','lat',[-10 30],'long',[96 125]); m_coast('patch',[.7 .7 .7],'edgecolor','none');% 绘制海岸线 %m_grid('box','circle','linestyle','-', 'mlabel', 60, 'plabel', 30, 'fontsize', 8);%网格线 %m_grid('box','circle','linestyle','-', 'xtick', [], 'ytick', [], 'mlabel', 10, 'plabel', 10, 'fontsize', 8); %m_grid('linestyle','-','xtick',[0 90 180 270],'ytick',[-60 -70 -80],'fontsize',10,'box','on'); m_grid('box', 'fancy', 'tickdir', 'out','xtick', [-180:90:180], ... % 自定义经度刻度 'ytick', [-90:30:-30]); hold on; % 绘制流速矢量图 p=10; LON_sampled = LON(1:p:end, 1:p:end); LAT_sampled = LAT(1:p:end, 1:p:end); u_sampled = u(1:p:end, 1:p:end); v_sampled = v(1:p:end, 1:p:end); %m_quiver(LON,LAT, u',v',4); %m_quiver( LON_sampled,LAT_sampled, u_sampled', v_sampled', 4); m_quiver( LON_sampled,LAT_sampled, u_sampled', v_sampled' , 5); hold on; %m_grid('box','on','circle','on','linestyle','-', 'xtick', [], 'ytick', []); %m_grid( 'mlabel', 30, 'plabel', 15, 'fontsize', 8,'mlocation', -85, 'plocation', 0) title('南纬30°到南纬90°流速矢量图');有刻度了,但是刻度标签处于图形中央挡住了图形,修改代码,将经度刻度标签设置到圆外,并且对应其经度
03-23
clear all; close all; % 读取NetCDF文件 filename = 'BOA_Argo_2021_02.nc'; lon = ncread(filename, 'lon'); % 360x1 lat = ncread(filename, 'lat'); % 160x1 temp = ncread(filename, 'temp'); % 360x160x58 pres = ncread(filename, 'pres'); % 58x1 ncdisp([filename]) % 选择黑潮区域(东经140°-160°,北纬25°-35°) latIndices = find(lat >= 25 & lat <= 35); lonIndices = find(lon >= 140 & lon <= 160); % 从pres中找到0到300米的深度范围对应索引 depths_10m = 0:10:180; % 0180米,10米间距 depths_20m = 180:20:300; % 180到300米,20米间距 depth_indices = ismember(pres, [depths_10m, depths_20m]); % 匹配pres中的相应深度 % 提取相应经度、纬度范围深度范围下的温度、压力 temp_slice = squeeze(mean(temp(lonIndices,latIndices, depth_indices),3)); temp_slice=permute(temp_slice,[2,1]); pres_slice = pres(depth_indices); % 创建经纬度网格 [Lon, Lat] = meshgrid(lon(lonIndices), lat(latIndices)); % 计算温度梯度 % 假设经度/纬度间隔为1度 [dx, dy] = gradient(temp_slice); % 转置匹配网格方向 grad_mag = hypot(dx, dy); % 梯度幅值 % 创建图形 figure('Position', [100 100 800 600]) contour(Lon, Lat, grad_mag, 40, 'LineColor','none') colormap(jet(256)) % 使用高对比度色图 colorbar title('2021-02 黑潮区域海洋锋面(温度梯度)','FontSize',12) xlabel('经度','FontSize',10) ylabel('纬度','FontSize',10) % 添加海岸线 hold on load coastlines plot(coastlon, coastlat, 'k', 'LineWidth',1) axis([140 160 25 35]) % 设置坐标范围 grid on % 标记高梯度区域(锋面) hold on contour(Lon, Lat, grad_mag, [0.5 0.5], 'r', 'LineWidth',1.5) % 0.5°C/km阈值 legend('温度梯度','海岸线','锋面位置') coastlines文件不存咋,但是我有m_map工具箱,调用m_coast来完成海岸线的绘制,改代码
04-02
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值