气象折线图bug修改

This commit is contained in:
hekaiyu 2025-12-19 09:48:13 +08:00
parent b2a591e366
commit 059c52615e
3 changed files with 32 additions and 13 deletions

View File

@ -4,6 +4,8 @@ public class LatLonSizeConstants {
// 网格参数 // 网格参数
public static final int LAT_SIZE = 721; // 纬度方向网格数 public static final int LAT_SIZE = 721; // 纬度方向网格数
public static final int LON_SIZE = 1440; // 经度方向网格数 public static final int LON_SIZE = 1440; // 经度方向网格数
public static final int LAT_SIZE_181 = 181; // 纬度方向网格数
public static final int LON_SIZE_360 = 360; // 经度方向网格数
public static final double LAT_START = 90.0; // 纬度起始值(北纬) public static final double LAT_START = 90.0; // 纬度起始值(北纬)
public static final double LAT_END = -90.0; // 纬度结束值(南纬) public static final double LAT_END = -90.0; // 纬度结束值(南纬)
public static final double LON_START = 0.0; // 经度起始值 public static final double LON_START = 0.0; // 经度起始值

View File

@ -15,7 +15,7 @@ import java.util.concurrent.TimeoutException;
@Slf4j @Slf4j
public class ExecutePyUtils { public class ExecutePyUtils {
private static final int PROCESS_TIMEOUT_SECONDS = 3600; // 30分钟超时 private static final int PROCESS_TIMEOUT_SECONDS = 36000;
/** /**
* 执行Python进程 * 执行Python进程
*/ */

View File

@ -166,7 +166,7 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
List<String> windSpeedList = new ArrayList<>(); List<String> windSpeedList = new ArrayList<>();
// 获取网格索引 // 获取网格索引
int[] gridIndex = getGridIndex(latitude, longitude); int[] gridIndex = null;
int hourInterval = 6; int hourInterval = 6;
// 循环处理每个时间点的数据 // 循环处理每个时间点的数据
@ -175,6 +175,9 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
String filePath = getWeatherFilePath(weatherDataList, currentTime); String filePath = getWeatherFilePath(weatherDataList, currentTime);
if (isFileValid(filePath)) { if (isFileValid(filePath)) {
try { try {
if(null == gridIndex){
gridIndex = getGridIndex(latitude, longitude, filePath);
}
processCommonData(filePath, gridIndex, currentTime, timeList, temperatureList, processCommonData(filePath, gridIndex, currentTime, timeList, temperatureList,
pressureList, humidityList, windSpeedList, dataType); pressureList, humidityList, windSpeedList, dataType);
} catch (Exception e) { } catch (Exception e) {
@ -250,7 +253,7 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
throw new IllegalArgumentException("时间范围内没有气象数据"); throw new IllegalArgumentException("时间范围内没有气象数据");
} }
int[] gridIndex = getGridIndex(latitude, longitude); int[] gridIndex = null;
Map<String, String> variables = getVariableNames(dataType); Map<String, String> variables = getVariableNames(dataType);
List<Double> uValues = new ArrayList<>(); List<Double> uValues = new ArrayList<>();
List<Double> vValues = new ArrayList<>(); List<Double> vValues = new ArrayList<>();
@ -263,6 +266,9 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
String filePath = getWeatherFilePath(weatherDataList, currentTime); String filePath = getWeatherFilePath(weatherDataList, currentTime);
if (isFileValid(filePath)) { if (isFileValid(filePath)) {
if(null == gridIndex){
gridIndex = getGridIndex(latitude, longitude, filePath);
}
try (NetcdfFile ncFile = NetcdfFile.open(filePath)) { try (NetcdfFile ncFile = NetcdfFile.open(filePath)) {
uValues.add(getNcValueByIndex(ncFile, variables.get("windU"), gridIndex[0], gridIndex[1])); uValues.add(getNcValueByIndex(ncFile, variables.get("windU"), gridIndex[0], gridIndex[1]));
vValues.add(getNcValueByIndex(ncFile, variables.get("windV"), gridIndex[0], gridIndex[1])); vValues.add(getNcValueByIndex(ncFile, variables.get("windV"), gridIndex[0], gridIndex[1]));
@ -1106,18 +1112,29 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
* @param longitude 经度(-180到180) * @param longitude 经度(-180到180)
* @return 包含纬度和经度下标的数组 [latIndex, lonIndex] * @return 包含纬度和经度下标的数组 [latIndex, lonIndex]
*/ */
public static int[] getGridIndex(double latitude, double longitude) { public static int[] getGridIndex(double latitude, double longitude, String filePath) {
// 计算纬度下标 (从北到南)
double latStep = (LAT_START - LAT_END) / (LAT_SIZE - 1);
int latIndex = (int) Math.round((LAT_START - latitude) / latStep);
latIndex = Math.max(0, Math.min(latIndex, LAT_SIZE - 1));
// 计算经度下标 (从西到东) try (NetcdfFile ncFile = NetcdfFile.open(filePath)) {
double lonStep = (LON_END - LON_START) / (LON_SIZE - 1); Integer lat = ncFile.findDimension("lat").getLength();
int lonIndex = (int) Math.round((longitude - LON_START) / lonStep); Integer lon = ncFile.findDimension("lon").getLength();
lonIndex = Math.max(0, Math.min(lonIndex, LON_SIZE - 1));
return new int[]{latIndex, lonIndex}; Integer latSize = lat < LAT_SIZE ? LAT_SIZE_181 : LAT_SIZE;
Integer lonSize = lon < LON_SIZE ? LON_SIZE_360 : LON_SIZE;
// 计算纬度下标 (从北到南)
double latStep = (LAT_START - LAT_END) / (latSize - 1);
int latIndex = (int) Math.round((LAT_START - latitude) / latStep);
latIndex = Math.max(0, Math.min(latIndex, latSize - 1));
// 计算经度下标 (从西到东)
double lonStep = (LON_END - LON_START) / (lonSize - 1);
int lonIndex = (int) Math.round((longitude - LON_START) / lonStep);
lonIndex = Math.max(0, Math.min(lonIndex, lonSize - 1));
return new int[]{latIndex, lonIndex};
} catch (Exception e) {
throw new RuntimeException(e);
}
} }
/** /**