This commit is contained in:
hekaiyu 2024-07-05 17:01:57 +08:00
parent 24f4459247
commit 9ce7aec264
26 changed files with 1717 additions and 932 deletions

View File

@ -66,6 +66,11 @@
<artifactId>grib</artifactId>
<version>4.5.5</version>
</dependency>
<dependency>
<groupId>org.nd4j</groupId>
<artifactId>nd4j-native-platform</artifactId>
<version>1.0.0-M1.1</version>
</dependency>
<!-- 积木报表 mongo redis 支持包
<dependency>
<groupId>org.jeecgframework.jimureport</groupId>

View File

@ -1,5 +1,5 @@
package org.jeecg.modules.constants;
public class RedisConstants {
public static final long TWO_DAYS_SECS = 60 * 60 * 6;
public static final long TWO_DAYS_SECS = 60 * 60 * 12;
}

View File

@ -310,28 +310,6 @@ public class BizFacilityAimController extends JeecgController<BizFacilityAim, IB
return Result.OK("上传成功!");
}
/**
* 图片转base64
*
* @param files
* @return
*/
@ApiOperation(value="设施目标表-图片转base64", notes="设施目标表-图片转base64")
@RequestMapping(value = "/imageToBase64", method = {RequestMethod.POST})
public Result<List<String>> imageToBase64(@RequestParam List<MultipartFile> files) {
List<String> base64s = new ArrayList<>();
try {
for (MultipartFile file : files) {
//图片转base64
base64s.add(Base64.getEncoder().encodeToString(file.getBytes()).trim());
}
}catch (Exception e){
e.printStackTrace();
return Result.error("上传失败!");
}
return Result.OK(base64s);
}
/**
* 导出excel
*

View File

@ -22,6 +22,8 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.multipart.MultipartFile;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
/**
@ -69,7 +71,6 @@ public class BizUpdateFileController extends JeecgController<BizUploadFile, BizU
.body(new InputStreamResource(file.getInputStream()));
}
/**
* 下载并保存文件
*

View File

@ -2,6 +2,7 @@ package org.jeecg.modules.project.baseConfig.bizUploadFile.service;
import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.modules.project.baseConfig.bizUploadFile.entity.BizUploadFile;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import java.io.InputStream;
@ -12,5 +13,6 @@ public interface BizUploadFileService extends IService<BizUploadFile> {
void uploadFiles(String trainingId,String descDir, String type, List<MultipartFile> fileList);
void uploadFile(String trainingId,String descDir, String type, MultipartFile file);
void saveFile(String descDir, String filename, InputStream inputStream) throws Exception;
String imageToBase64(MultipartFile file);
}

View File

@ -10,6 +10,7 @@ import org.jeecg.modules.project.baseConfig.bizUploadFile.service.BizUploadFileS
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
@ -101,4 +102,20 @@ public class BizUploadFileServiceImpl extends ServiceImpl<BizUploadFileMapper, B
inputStream.close();
}
/**
* 图片转base64
*
* @param file
* @return
*/
@Override
public String imageToBase64(MultipartFile file) {
try {
return "data:image/png;base64," + Base64.getEncoder().encodeToString(file.getBytes()).trim();
}catch (Exception e){
e.printStackTrace();
}
return null;
}
}

View File

@ -1,10 +1,12 @@
package org.jeecg.modules.project.baseConfig.equipment.bizEquipmentMotor.controller;
import java.util.Arrays;
import java.util.Base64;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.project.baseConfig.bizUploadFile.service.BizUploadFileService;
import org.jeecg.modules.project.baseConfig.equipment.bizEquipmentMotor.entity.BizEquipmentMotor;
import org.jeecg.modules.project.baseConfig.equipment.bizEquipmentMotor.service.IBizEquipmentMotorService;
@ -16,6 +18,7 @@ import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -35,7 +38,10 @@ import org.apache.shiro.authz.annotation.RequiresPermissions;
public class BizEquipmentMotorController extends JeecgController<BizEquipmentMotor, IBizEquipmentMotorService> {
@Autowired
private IBizEquipmentMotorService bizEquipmentMotorService;
@Autowired
private BizUploadFileService bizUploadFileService;
/**
* 分页列表查询
*
@ -57,7 +63,7 @@ public class BizEquipmentMotorController extends JeecgController<BizEquipmentMot
IPage<BizEquipmentMotor> pageList = bizEquipmentMotorService.page(page, queryWrapper);
return Result.OK(pageList);
}
/**
* 添加
*
@ -71,7 +77,7 @@ public class BizEquipmentMotorController extends JeecgController<BizEquipmentMot
bizEquipmentMotorService.save(bizEquipmentMotor);
return Result.OK("添加成功!");
}
/**
* 编辑
*
@ -85,7 +91,7 @@ public class BizEquipmentMotorController extends JeecgController<BizEquipmentMot
bizEquipmentMotorService.updateById(bizEquipmentMotor);
return Result.OK("编辑成功!");
}
/**
* 通过id删除
*
@ -99,7 +105,7 @@ public class BizEquipmentMotorController extends JeecgController<BizEquipmentMot
bizEquipmentMotorService.removeById(id);
return Result.OK("删除成功!");
}
/**
* 批量删除
*
@ -113,7 +119,7 @@ public class BizEquipmentMotorController extends JeecgController<BizEquipmentMot
this.bizEquipmentMotorService.removeByIds(Arrays.asList(ids.split(",")));
return Result.OK("批量删除成功!");
}
/**
* 通过id查询
*
@ -131,6 +137,29 @@ public class BizEquipmentMotorController extends JeecgController<BizEquipmentMot
return Result.OK(bizEquipmentMotor);
}
/**
* 上传图片
*
* @param file
* @return
*/
@ApiOperation(value="机动装备表-上传图片", notes="机动装备表-上传图片")
@RequestMapping(value = "/imageToBase64", method = {RequestMethod.POST})
public Result<?> imageToBase64(@RequestParam(name="id",required=false) String id,
@RequestParam MultipartFile file) {
try {
String base64 = bizUploadFileService.imageToBase64(file);
BizEquipmentMotor bizEquipmentMotor = new BizEquipmentMotor();
bizEquipmentMotor.setId(id);
bizEquipmentMotor.setImageBase64(base64);
bizEquipmentMotorService.updateById(bizEquipmentMotor);
}catch (Exception e){
e.printStackTrace();
return Result.error("上传失败!");
}
return Result.OK("上传成功!");
}
/**
* 导出excel
*

View File

@ -1,11 +1,19 @@
package org.jeecg.modules.project.baseConfig.equipment.bizEquipmentMotor.service.impl;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.project.baseConfig.equipment.bizEquipmentMotor.entity.BizEquipmentMotor;
import org.jeecg.modules.project.baseConfig.equipment.bizEquipmentMotor.mapper.BizEquipmentMotorMapper;
import org.jeecg.modules.project.baseConfig.equipment.bizEquipmentMotor.service.IBizEquipmentMotorService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import java.util.Base64;
/**
* @Description: 机动装备表
@ -16,4 +24,5 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@Service
public class BizEquipmentMotorServiceImpl extends ServiceImpl<BizEquipmentMotorMapper, BizEquipmentMotor> implements IBizEquipmentMotorService {
}

View File

@ -5,6 +5,8 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.project.baseConfig.bizUploadFile.service.BizUploadFileService;
import org.jeecg.modules.project.baseConfig.equipment.bizEquipmentMotor.entity.BizEquipmentMotor;
import org.jeecg.modules.project.baseConfig.equipment.bizEquipmentProtection.entity.BizEquipmentProtection;
import org.jeecg.modules.project.baseConfig.equipment.bizEquipmentProtection.service.IBizEquipmentProtectionService;
@ -16,6 +18,7 @@ import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -35,7 +38,9 @@ import org.apache.shiro.authz.annotation.RequiresPermissions;
public class BizEquipmentProtectionController extends JeecgController<BizEquipmentProtection, IBizEquipmentProtectionService> {
@Autowired
private IBizEquipmentProtectionService bizEquipmentProtectionService;
@Autowired
private BizUploadFileService bizUploadFileService;
/**
* 分页列表查询
*
@ -57,7 +62,7 @@ public class BizEquipmentProtectionController extends JeecgController<BizEquipme
IPage<BizEquipmentProtection> pageList = bizEquipmentProtectionService.page(page, queryWrapper);
return Result.OK(pageList);
}
/**
* 添加
*
@ -71,7 +76,7 @@ public class BizEquipmentProtectionController extends JeecgController<BizEquipme
bizEquipmentProtectionService.save(bizEquipmentProtection);
return Result.OK("添加成功!");
}
/**
* 编辑
*
@ -85,7 +90,7 @@ public class BizEquipmentProtectionController extends JeecgController<BizEquipme
bizEquipmentProtectionService.updateById(bizEquipmentProtection);
return Result.OK("编辑成功!");
}
/**
* 通过id删除
*
@ -99,7 +104,7 @@ public class BizEquipmentProtectionController extends JeecgController<BizEquipme
bizEquipmentProtectionService.removeById(id);
return Result.OK("删除成功!");
}
/**
* 批量删除
*
@ -113,7 +118,7 @@ public class BizEquipmentProtectionController extends JeecgController<BizEquipme
this.bizEquipmentProtectionService.removeByIds(Arrays.asList(ids.split(",")));
return Result.OK("批量删除成功!");
}
/**
* 通过id查询
*
@ -131,6 +136,29 @@ public class BizEquipmentProtectionController extends JeecgController<BizEquipme
return Result.OK(bizEquipmentProtection);
}
/**
* 上传图片
*
* @param file
* @return
*/
@ApiOperation(value="防护装备表-上传图片", notes="防护装备表-上传图片")
@RequestMapping(value = "/imageToBase64", method = {RequestMethod.POST})
public Result<?> imageToBase64(@RequestParam(name="id",required=false) String id,
@RequestParam MultipartFile file) {
try {
String base64 = bizUploadFileService.imageToBase64(file);
BizEquipmentProtection bizEquipmentProtection = new BizEquipmentProtection();
bizEquipmentProtection.setId(id);
bizEquipmentProtection.setImageBase64(base64);
bizEquipmentProtectionService.updateById(bizEquipmentProtection);
}catch (Exception e){
e.printStackTrace();
return Result.error("上传失败!");
}
return Result.OK("上传成功!");
}
/**
* 导出excel
*
@ -154,10 +182,4 @@ public class BizEquipmentProtectionController extends JeecgController<BizEquipme
return super.importExcel(request, response, BizEquipmentProtection.class);
}
public static void main(String[] args) {
for (int i = 0; i<175;i++){
System.out.println(Math.floor(Math.random() * 1000) / 1000);
}
}
}

View File

@ -65,4 +65,8 @@ public class BizEquipmentProtection implements Serializable {
@Excel(name = "安全时间", width = 15)
@ApiModelProperty(value = "安全时间")
private Double safetyTime;
/**图片base64*/
@Excel(name = "图片base64", width = 15)
@ApiModelProperty(value = "图片base64")
private String imageBase64;
}

View File

@ -81,7 +81,9 @@ public class BizCmaqController extends JeecgController<BizCmaq, IBizCmaqService>
public Result<?> getGribInfo(){
List<List<List<Double>>> resultAll = new ArrayList<>();
List<List<Double>> results = new ArrayList<>();
String filePath = "C:\\Users\\13673\\Desktop\\fnl_20181101_00_00.grib2";
String filePath = "D:\\wumu\\T1279\\GG_nhgsmout_2024050112.015.grb";
// String filePath = "D:\\wumu\\vmhgfs\\java\\hky\\测试1026结果数据\\fnl_20160629_00_00.grib2";
try {
// 打开grib2文件
@ -91,40 +93,37 @@ public class BizCmaqController extends JeecgController<BizCmaq, IBizCmaqService>
List<Double> latData = new ArrayList<>();
List<Double> lonData = new ArrayList<>();
for (int i = 90; i >= -90; i--) {
for (double i = 90; i >= -90; i=i-0.125) {
latData.add(i + 0.0);
}
// 从0递增到180
for (int i = 0; i <= 180; i++) {
for (double i = 0; i <= 180; i=i+0.125) {
lonData.add(i + 0.0);
}
// 从180递减到-180
for (int i = -180; i < 0; i++) {
for (double i = -180; i < 0; i=i+0.125) {
lonData.add(i + 0.0);
}
// 获取风场数据
// List<List<List<Double>>> u = NcUtil.getNCByName(ncFile, "u-component_of_wind_height_above_ground", 0);
// List<List<List<Double>>> v = NcUtil.getNCByName(ncFile, "v-component_of_wind_height_above_ground", 0);
//
// for (int i = 0; i < latData.length; i++) {
// for (int j = 0; j < lonData.length; j++) {
// // 获取风场数据
// List<List<Double>> u = NcUtil.getNCByName(ncFile, "10_metre_U_wind_component_surface",0).get(0);
// List<List<Double>> v = NcUtil.getNCByName(ncFile, "10_metre_V_wind_component_surface",0).get(0);
////
// for (int i = 0; i < u.size(); i++) {
// for (int j = 0; j < u.get(0).size(); j++) {
// List<Double> values = new ArrayList<>();
// values.add(lonData[j]);
// values.add(latData[i]);
// values.add(u.get(0).get(i).get(j));
// values.add(v.get(0).get(i).get(j));
// values.add(0.0);
// values.add(u.get(i).get(j));
// values.add(v.get(i).get(j));
// results.add(values);
// }
// }
//获取温度数据
List<List<List<Double>>> ts = NcUtil.getNCByName(ncFile, "Temperature_height_above_ground", 0);
List<List<List<Double>>> ts = NcUtil.getNCByName(ncFile, "2_metre_temperature_surface", 0);
for (int i = 0; i < latData.size(); i++) {
for (int j = 0; j < lonData.size(); j++) {

View File

@ -50,6 +50,20 @@ public class BizRunLog implements Serializable {
@Excel(name = "运行程序名称", width = 15)
@ApiModelProperty(value = "运行程序名称")
private String runName;
/**运行程序中文名称*/
@Excel(name = "运行程序中文名称", width = 15)
@ApiModelProperty(value = "运行程序中文名称")
private String runChineseName;
/**运行开始时间*/
@Excel(name = "运行开始时间", width = 15)
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "运行开始时间")
private Date runStartTime;
/**预计时长(秒)*/
@Excel(name = "预计时长(秒)", width = 15)
@ApiModelProperty(value = "预计时长(秒)")
private int estimatedTime;
/**是否运行成功*/
@Excel(name = "是否运行成功", width = 15)
@ApiModelProperty(value = "是否运行成功")
@ -57,7 +71,7 @@ public class BizRunLog implements Serializable {
/**运行进度*/
@Excel(name = "运行进度", width = 15)
@ApiModelProperty(value = "运行进度")
private Integer runPct;
private double runPct;
/**运行程序描述*/
@Excel(name = "运行程序描述", width = 15)
@ApiModelProperty(value = "运行程序描述")

View File

@ -6,11 +6,14 @@ import org.jeecg.modules.project.baseConfig.bizEngineering.mapper.BizEngineering
import org.jeecg.modules.project.calculateResult.bizRunLog.entity.BizRunLog;
import org.jeecg.modules.project.calculateResult.bizRunLog.mapper.BizRunLogMapper;
import org.jeecg.modules.project.calculateResult.bizRunLog.service.IBizRunLogService;
import org.jeecg.modules.project.calculateResult.runProcess.enums.ModeInfoEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.Date;
/**
* @Description: 运行过程日志表
* @Author: jeecg-boot
@ -26,9 +29,14 @@ public class BizRunLogServiceImpl extends ServiceImpl<BizRunLogMapper, BizRunLog
@Override
public void saveRunLog(String engineeringId,String runName){
ModeInfoEnum modeInfoEnum = ModeInfoEnum.valueOf(runName);
String[] titleArray = modeInfoEnum.getTitle().split(",");
BizRunLog bizRunLog = new BizRunLog();
bizRunLog.setEnginId(engineeringId);
bizRunLog.setRunName(runName);
bizRunLog.setRunChineseName(titleArray[1]);
bizRunLog.setEstimatedTime(Integer.valueOf(titleArray[2]));
bizRunLog.setRunStartTime(new Date());
bizRunLog.setRunPct(0);
this.baseMapper.insert(bizRunLog);
}
@ -48,16 +56,16 @@ public class BizRunLogServiceImpl extends ServiceImpl<BizRunLogMapper, BizRunLog
bizEngineering.setEnginStatus(5);
bizEngineeringMapper.updateById(bizEngineering);
}
if(runPct == null){
if("true".equals(succesfully)){
bizRunLog.setRunPct(100);
}else{
bizRunLog.setRunPct(0);
}
}else{
bizRunLog.setRunPct(runPct);
bizRunLog.setRunDescribe(runName + "运行中......");
}
// if(runPct == null){
// if("true".equals(succesfully)){
// bizRunLog.setRunPct(100);
// }else{
// bizRunLog.setRunPct(0);
// }
// }else{
// bizRunLog.setRunPct(runPct);
// bizRunLog.setRunDescribe(runName + "运行中......");
// }
this.baseMapper.update(bizRunLog,new LambdaQueryWrapper<BizRunLog>().eq(BizRunLog::getEnginId,engineeringId).eq(BizRunLog::getRunName,runName));
return bizRunLog;
}

View File

@ -224,12 +224,33 @@ public class RunProcessController extends JeecgController<BizResultDiffuse, IBiz
//工程执行了几个脚本
List<BizRunLog> bizRunLogs = bizRunLogService.list(new LambdaQueryWrapper<BizRunLog>().eq(BizRunLog::getEnginId, engineeringId).orderByAsc(BizRunLog::getId));
Date nowTime = new Date();
bizRunLogs.forEach(runLog -> {
if(100 != runLog.getRunPct() && "WPS".equals(runLog.getRunName())){
runLog.setRunDescribe("WPS运行中...");
runLog.setRunPct(2);
bizRunLogService.update(runLog,new LambdaQueryWrapper<BizRunLog>().eq(BizRunLog::getEnginId,engineering.getId()).eq(BizRunLog::getRunName,"WPS"));
if("true".equals(runLog.getSuccesfully())){
runLog.setRunDescribe(runLog.getRunChineseName() + "运行完成!");
runLog.setRunPct(100);
}else{
if(null != runLog.getRunStartTime()){
double runPct =(double)((nowTime.getTime() - runLog.getRunStartTime().getTime() / 1000) / runLog.getEstimatedTime());
if(runPct <= 50){
runPct = runPct * 1.4;
}else if(runPct < 100){
runPct = 70 + runPct * 0.58 - 29;
}else{
runPct = 99;
}
runLog.setRunDescribe(runLog.getRunChineseName() + "运行中。。。");
runLog.setRunPct(runPct);
}else{
runLog.setRunDescribe(runLog.getRunChineseName() + "等待运行!");
runLog.setRunPct(0);
}
}
// if(100 != runLog.getRunPct() && "WPS".equals(runLog.getRunName())){
// runLog.setRunDescribe("WPS运行中...");
// runLog.setRunPct(2);
// bizRunLogService.update(runLog,new LambdaQueryWrapper<BizRunLog>().eq(BizRunLog::getEnginId,engineering.getId()).eq(BizRunLog::getRunName,"WPS"));
// }
});
// bizRunLogs.forEach(bizRunLog -> {
// try {

View File

@ -1,13 +1,13 @@
package org.jeecg.modules.project.calculateResult.runProcess.enums;
public enum ModeInfoEnum {
WPS("WPS", "WPS,气象数据预处理,run_project_wps.sh"),
WRF("WRF", "WRF,气象数据模拟,run_project_wrf.sh"),
MCIP("MCIP", "MCIP,气象-化学接口处理,run_project_mcip.sh"),
EMIS("EMIS","EMIS,初始排放处理,"),
ICON("ICON", "ICON,初始条件处理,run_project_icon.sh"),
BCON("BCON", "BCON,边界条件处理,run_project_bcon.sh"),
CCTM("CCTM", "CCTM,化学输出模型,run_project_cctm.sh");
WPS("WPS", "WPS,气象数据预处理,100000,run_project_wps.sh"),
WRF("WRF", "WRF,气象数据模拟,10000,run_project_wrf.sh"),
MCIP("MCIP", "MCIP,气象-化学接口处理,10000,run_project_mcip.sh"),
EMIS("EMIS","EMIS,初始排放处理,10000,"),
ICON("ICON", "ICON,初始条件处理,10000,run_project_icon.sh"),
BCON("BCON", "BCON,边界条件处理,10000,run_project_bcon.sh"),
CCTM("CCTM", "CCTM,化学输出模型,10000,run_project_cctm.sh");
String key;
@ -21,4 +21,7 @@ public enum ModeInfoEnum {
public String getKey(){
return this.key;
}
public String getTitle(){
return this.title;
}
}

View File

@ -31,6 +31,8 @@ import org.springframework.stereotype.Service;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import static java.nio.file.Files.readAllBytes;
@ -64,6 +66,8 @@ public class BizRunProcessServiceImpl implements IBizRunProcessService {
private String localFilePrefix;
@Value("${spring.cshTemFielPath}")
private String cshTemFielPath;
@Value("${spring.WRF.fnldataPath}")
private String fnlDataPath;
@Override
public Result<String> runAllExe(Map<String,String> map){
@ -105,6 +109,7 @@ public class BizRunProcessServiceImpl implements IBizRunProcessService {
return wrfResult;
}
//下载wrf文件
for (Integer i = 0; i <= sumDay; i++) {
String newStartTime = DateUtil.format(new Date(startTime.getTime() + oneDaySecs * i), format);
String ncName = "wrfout_d03_" + newStartTime;
@ -112,6 +117,17 @@ public class BizRunProcessServiceImpl implements IBizRunProcessService {
String targetName = "wrfout_d03_" + DateUtil.format(new Date(startTime.getTime() + oneDaySecs * i), "yyyy-MM-dd_HH_mm_ss");
bizSftpAPIService.download(allRunPath + "workdir/WRF/",ncName,targetFilePath + targetName);
}
//下载fnl文件
String fnlStartTime = DateUtil.format(DateUtil.parse(wrf.getStartTime(), "yyyy-MM-dd_HH:mm:ss"), "yyyyMMdd_HH");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd_HH");
LocalDateTime dateTime = LocalDateTime.parse(fnlStartTime, formatter);
for (int t = 0; t < sumDay * 24; t= t+6) {
// 增加t小时
LocalDateTime newDateTime = dateTime.plusHours(t);
String fnlFileName = "fnl_"+ newDateTime.format(formatter) +"_00.grib2";
bizSftpAPIService.download(fnlDataPath,fnlFileName,targetFilePath + fnlFileName);
}
}
if(bizModeLink.getDiffuseModeId() == 1){
@ -129,9 +145,15 @@ public class BizRunProcessServiceImpl implements IBizRunProcessService {
return cmaqResult;
}
//下载cmaq文件
for (Integer i = 1; i <= sumDay; i++) {
String ncName = "CCTM.ACONC.d03."+DateUtil.format(new Date(startTimeSecs + oneDaySecs * i), yyyymdFormat);
String dataString = DateUtil.format(new Date(startTimeSecs + oneDaySecs * i), yyyymdFormat);
String ncName = "CCTM.CONC.d03."+ dataString;
String metcr03dName = "METCRO3D_d03_"+ dataString;
String emisName = "emis_"+ dataString;
bizSftpAPIService.download(allRunPath + "workdir/CCTM/",ncName,targetFilePath + ncName);
bizSftpAPIService.download(mcipPath,metcr03dName,targetFilePath + metcr03dName);
bizSftpAPIService.download(allRunPath + "data/emis/d03/",emisName,targetFilePath + emisName);
}
}else if(bizModeLink.getDiffuseModeId() == 2){
//生成配置文件

View File

@ -16,10 +16,12 @@ import org.jeecg.modules.project.calculateConfig.bizWrf.entity.BizWrf;
import org.jeecg.modules.project.calculateConfig.bizWrf.service.IBizWrfService;
import org.jeecg.modules.project.resultAction.VO.*;
import org.jeecg.modules.project.resultAction.queryResult.service.IResultActionService;
import org.jeecg.modules.util.NcUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ucar.nc2.NetcdfFile;
import java.io.IOException;
import java.util.ArrayList;
@ -175,8 +177,6 @@ public class DosageDataActionController {
CrossResultVO crossResultVO = new CrossResultVO();
List<List<List<Double>>> crossResults = new ArrayList<>();
List<Double> maxMin = (List<Double>)redisUtil.get(String.format("%s_%s_MAXMIN",enginId,keyName));
Double globalMax = maxMin.get(0);
Double globalMin = maxMin.get(1);
if("空中剂量".equals(type)){
List<List<Double>> xlats = (List<List<Double>>)redisUtil.get(enginId + "_WRF_XLAT");
List<List<Double>> xlongs = ((List<List<Double>>)redisUtil.get(enginId + "_WRF_XLONG"));
@ -242,7 +242,6 @@ public class DosageDataActionController {
keyName += "_GK";
}
BizWrf bizWrf = bizWrfService.getOne(new LambdaQueryWrapper<BizWrf>().eq(BizWrf::getEngineeringId,engineeringId));
try {
@ -250,11 +249,6 @@ public class DosageDataActionController {
List<List<Double>> xlongs = ((List<List<Double>>)redisUtil.get(engineeringId + "_WRF_XLONG"));
List<List<Double>> hgts = ((List<List<Double>>)redisUtil.get(engineeringId + "_WRF_HGT"));
int maxLayer = (int)redisUtil.get(engineeringId + "_LAYER");
maxLayer = 14;
CubeResultVO cubeResultVO = new CubeResultVO();
List<List<List<Double>>> results = new ArrayList<>();
List<Double> maxMin = (List<Double>)redisUtil.get(String.format("%s_%s_MAXMIN",engineeringId,keyName));
@ -262,15 +256,8 @@ public class DosageDataActionController {
Double globalMax = maxMin.get(0);
Double globalMin = maxMin.get(1);
if(keyName.indexOf("AERDEP") >= 0){
String key = String.format("%s_%s_LAYER%s_HOUR%s",engineeringId,keyName,0,hour);
results.add(getCubeNCInfo(xlats,xlongs,hgts,key,globalMax,globalMin,null));
}else{
for (int i = 0; i < maxLayer; i++) {
String key = String.format("%s_%s_LAYER%s_HOUR%s",engineeringId,keyName,i,hour);
results.add(getCubeNCInfo(xlats,xlongs,hgts,key,globalMax,globalMin,null));
}
}
String key = String.format("%s_%s_LAYER%s_HOUR%s",engineeringId,keyName,0,hour);
results.add(getCubeNCInfo(xlats,xlongs,hgts,key,globalMax,globalMin,null));
cubeResultVO.setCubeResults(results);
cubeResultVO.setMax(maxMin.get(0) > 200?log100(200):log100(maxMin.get(0)));
@ -430,7 +417,7 @@ public class DosageDataActionController {
}
/**
* 封装立方体数据
* 封装横截面数据
* @param valueKey
* @return
*/
@ -651,5 +638,4 @@ public class DosageDataActionController {
return quadCoordinates;
}
}

View File

@ -19,15 +19,14 @@ import org.jeecg.modules.project.baseConfig.bizEngineering.service.IBizEngineeri
import org.jeecg.modules.project.baseConfig.weather.bizWeatherHistory.entity.BizWeatherHistory;
import org.jeecg.modules.project.calculateConfig.bizWrf.entity.BizWrf;
import org.jeecg.modules.project.calculateConfig.bizWrf.service.IBizWrfService;
import org.jeecg.modules.project.resultAction.VO.AnalysisResultVO;
import org.jeecg.modules.project.resultAction.VO.ActionParamVO;
import org.jeecg.modules.project.resultAction.VO.CrossResultVO;
import org.jeecg.modules.project.resultAction.VO.CubeResultVO;
import org.jeecg.modules.project.resultAction.VO.*;
import org.jeecg.modules.project.resultAction.queryResult.service.IResultActionService;
import org.jeecg.modules.util.NcUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ucar.nc2.NetcdfFile;
import java.io.File;
import java.io.FileInputStream;
@ -152,25 +151,19 @@ public class ResultActionController {
CrossResultVO crossResultVO = new CrossResultVO();
List<List<List<Double>>> crossResults = new ArrayList<>();
List<Double> maxMin = null;
if("风速".equals(type)){
String windSpeedKey = enginId + "_WRF_WINDSPEED_LAYER" + layer + "_HOUR" + hour;
crossResults.add(getCrossNCInfo(xlats,xlongs,hgts,windSpeedKey,0,maxs,mins,null,null,lonlats));
}else if("温度".equals(type)){
String tKey = String.format("%s_WRF_T_LAYER%s_HOUR%s",enginId,layer,hour);
crossResults.add(getCrossNCInfo(xlats,xlongs,hgts,tKey,0,maxs,mins,null,null,lonlats));
}else if("气压".equals(type)){
String pKey = String.format("%s_WRF_P_LAYER%s_HOUR%s",enginId,layer,hour);
crossResults.add(getCrossNCInfo(xlats,xlongs,hgts,pKey,0,maxs,mins,null,null,lonlats));
}else if("空中浓度".equals(type)){
if("空中浓度".equals(type)){
String coKey = String.format("%s_CMAQ_CO_LAYER%s_HOUR%s",enginId,layer,hour);
maxMin = (List<Double>)redisUtil.get(String.format("%s_CMAQ_CO_MAXMIN",enginId));
crossResults.add(getCrossNCInfo(xlats,xlongs,hgts,coKey,1,maxs,mins,maxMin.get(0),maxMin.get(1),lonlats));
} else if("相对湿度".equals(type)){
return Result.ok();
crossResultVO.setCurrentMax(String.format("%.2E",maxs.get(0)));
} else if("地表沉降".equals(type)){
maxMin = (List<Double>)redisUtil.get(enginId + "_SUBSIDE_MAXMIN");
String dryKey = String.format("%s_CMAQ_SUBSIDE_HOUR%s",enginId,hour);
crossResults.add(getCrossNCInfo(xlats,xlongs,hgts,dryKey,1,maxs,mins,null,null,lonlats));
crossResultVO.setCurrentMax(String.format("%.2E",maxs.get(0)));
crossResultVO.setLon(String.format("%.3f",lonlats.get(0)[0]));
crossResultVO.setLat(String.format("%.3f",lonlats.get(0)[1]));
crossResultVO.setHgt(String.format("%.3f",lonlats.get(0)[2]));
}
crossResultVO.setCrossResults(crossResults);
if(null == maxMin){
@ -182,10 +175,6 @@ public class ResultActionController {
}
crossResultVO.setSn(!"空中浓度".equals(type) && !"地表沉降".equals(type) ? Integer.valueOf(bizWrf.getSn()) + 2: Integer.valueOf(bizWrf.getSn()));
crossResultVO.setWe(!"空中浓度".equals(type) && !"地表沉降".equals(type) ? Integer.valueOf(bizWrf.getWe()) + 2: Integer.valueOf(bizWrf.getWe()));
crossResultVO.setCurrentMax(String.format("%.2E",maxs.get(0)));
crossResultVO.setLon(String.format("%.3f",lonlats.get(0)[0]));
crossResultVO.setLat(String.format("%.3f",lonlats.get(0)[1]));
crossResultVO.setHgt(String.format("%.3f",lonlats.get(0)[2]));
return Result.ok(crossResultVO);
}catch (Exception e){
e.printStackTrace();
@ -253,6 +242,199 @@ public class ResultActionController {
}
}
/**
* 获取全球场数据
* @param actionParamVO
* @return
*/
@AutoLog(value = "操作结果-获取全球场数据")
@ApiOperation(value="操作结果-获取全球场数据", notes="操作结果-获取全球场数据")
@GetMapping(value = "/getGribInfo")
public Result<WorldResultVO> getGribInfo(ActionParamVO actionParamVO) {
String enginId = actionParamVO.getEngineeringId();
String type = actionParamVO.getType();
int hour = actionParamVO.getHour();
WorldResultVO worldResultVO = new WorldResultVO();
try {
NetcdfFile ncFile = NetcdfFile.open("D:\\wumu\\T1279\\GG_nhgsmout_2024050112.015_world.grb");
List<List<List<Double>>> dataList = new ArrayList<>();
if("风场".equals(type)){
List<List<Double>> windData = getWindData(ncFile);
worldResultVO.setSn(181);
worldResultVO.setWe(360);
worldResultVO.setDataList(windData);
}else if("温度".equals(type)){
//获取温度数据
dataList = NcUtil.getNCByName(ncFile, "T", 0);
}else if("温度2".equals(type)){
//获取温度数据
String filePath = "D:\\wumu\\vmhgfs\\java\\hky\\测试1026结果数据\\fnl_20160629_00_00.grib2";
NetcdfFile ncFile2 = NetcdfFile.open(filePath);
dataList = NcUtil.getNCByName(ncFile2, "Temperature_height_above_ground", 0);
worldResultVO.setDataList(getWorldData2(dataList));
}else if("气压".equals(type)){
//获取温度数据
dataList = NcUtil.getNCByName(ncFile, "P", 0);
}else if("湿度".equals(type)){
//获取温度数据
dataList = NcUtil.getNCByName(ncFile, "H", 0);
}
ncFile.close();
if(!"风场".equals(type)){
List<Double> flattenedList = new ArrayList<>();
List<List<Double>> worldData = getWorldData(dataList,type);
flattenList(worldData,flattenedList);
List<Double> maxMin = getMaxMin(flattenedList);
worldResultVO.setMax(maxMin.get(0));
worldResultVO.setMin(maxMin.get(1));
worldResultVO.setDataList(worldData);
worldResultVO.setSn(1441);
worldResultVO.setWe(2881);
}
return Result.ok(worldResultVO);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
// 递归地将嵌套列表中的所有 Double 值提取出来
public static void flattenList(List<?> nestedList, List<Double> flattenedList) {
for (Object element : nestedList) {
if (element instanceof List) {
flattenList((List<?>) element, flattenedList);
} else {
flattenedList.add((Double) element);
}
}
}
public List<Double> getMaxMin(List<Double> flattenedList){
List<Double> maxMin = new ArrayList<>();
double maxValue = Collections.max(flattenedList);
double minValue = Collections.min(flattenedList);
maxMin.add(maxValue);
maxMin.add(minValue);
return maxMin;
}
public List<List<Double>> getWindData(NetcdfFile ncFile){
List<List<Double>> results = new ArrayList<>();
try {
// 获取风场数据
List<List<Double>> u = NcUtil.getNCByName(ncFile, "U",0).get(0);
List<List<Double>> v = NcUtil.getNCByName(ncFile, "V",0).get(0);
for (int i = 0; i < u.size(); i=i+8) {
for (int j = 0; j < u.get(0).size(); j=j+8) {
List<Double> values = new ArrayList<>();
values.add(u.get(i).get(j));
values.add(v.get(i).get(j));
results.add(values);
}
}
// 关闭文件
ncFile.close();
} catch (Exception e) {
e.printStackTrace();
}
return results;
}
public List<List<Double>> getWorldData(List<List<List<Double>>> dataList,String type){
List<List<Double>> results = new ArrayList<>();
try {
// 获取经纬度数据
List<Double> latData = new ArrayList<>();
List<Double> lonData = new ArrayList<>();
for (double i = -90; i <= 90; i=i+0.125) {
latData.add(i + 0.0);
}
// 从0递增到180
for (double i = 0; i < 180; i=i+0.125) {
lonData.add(i + 0.0);
}
// 从180递减到-180
for (double i = -180; i <= 0; i=i+0.125) {
lonData.add(i + 0.0);
}
for (int i = 0; i < latData.size(); i++) {
for (int j = 0; j < lonData.size(); j++) {
List<Double> values = new ArrayList<>();
values.add(lonData.get(j));
values.add(latData.get(i));
if(j >= dataList.get(0).get(i).size()){
if("气压".equals(type)){
values.add(dataList.get(0).get(i).get(0) / 1000);
}else if("温度".equals(type)){
values.add(dataList.get(0).get(i).get(0) - 273.15);
}else{
values.add(dataList.get(0).get(i).get(0));
}
}else{
if("气压".equals(type)){
values.add(dataList.get(0).get(i).get(j) / 1000);
}else if("温度".equals(type)){
values.add(dataList.get(0).get(i).get(j) - 273.15);
}else{
values.add(dataList.get(0).get(i).get(j));
}
}
results.add(values);
}
}
return results;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public List<List<Double>> getWorldData2( List<List<List<Double>>> dataList){
List<List<Double>> results = new ArrayList<>();
try {
// 获取经纬度数据
List<Double> latData = new ArrayList<>();
List<Double> lonData = new ArrayList<>();
for (double i = 90; i >= -90; i--) {
latData.add(i + 0.0);
}
// 从0递增到180
for (double i = 0; i <= 180; i++) {
lonData.add(i + 0.0);
}
// 从180递减到-180
for (double i = -180; i < 0; i++) {
lonData.add(i + 0.0);
}
for (int i = 0; i < latData.size(); i++) {
for (int j = 0; j < lonData.size(); j++) {
List<Double> values = new ArrayList<>();
values.add(lonData.get(j));
values.add(latData.get(i));
if(j >= dataList.get(0).get(i).size()){
values.add(dataList.get(0).get(i).get(0));
}else{
values.add(dataList.get(0).get(i).get(j));
}
results.add(values);
}
}
return results;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* 操作结果
* @param actionParamVO
@ -268,24 +450,15 @@ public class ResultActionController {
int layer = resultActionService.getLayerMaxByZF(enginId,actionParamVO.getLayer());
int hour = actionParamVO.getHour();
List<List<Double>> xlatAllList = null;
List<List<Double>> xlongAllList = null;
List<List<Double>> hgtAllList = null;
Integer[] tableByLonLat = new Integer[]{actionParamVO.getLatIndex(),actionParamVO.getLonIndex()}; //获取经纬度对应的网格坐标;
AnalysisResultVO analysisResultVO = new AnalysisResultVO();
if(null == xlatAllList){
xlatAllList = (List<List<Double>>)redisUtil.get(bizEngineering.getId() + "_WRF_XLAT");
xlongAllList = ((List<List<Double>>)redisUtil.get(bizEngineering.getId() + "_WRF_XLONG"));
hgtAllList = (List<List<Double>>)redisUtil.get(bizEngineering.getId() + "_WRF_HGT"); //等高线
}
//获取经纬度对应的网格坐标
List<List<Double>> tAllList = (List<List<Double>>)redisUtil.get(String.format("%s_WRF_T_LAYER%s_HOUR%s",enginId,layer,hour)); //温度
List<List<Double>> pAllList = (List<List<Double>>)redisUtil.get(String.format("%s_WRF_P_LAYER%s_HOUR%s",enginId,layer,hour)); //压强
// List<List<Double>> pAllList = NcUtil.getNCByName(ncfile, "",0); //湿度
List<List<Double>> coAllList = (List<List<Double>>)redisUtil.get(String.format("%s_CMAQ_CO_LAYER%s_HOUR%s",enginId,layer,hour)); //浓度
List<List<Double>> subsideAllList = (List<List<Double>>)redisUtil.get(String.format("%s_CMAQ_SUBSIDE_HOUR%s",enginId,hour)); //干湿沉降
Double tValue = tAllList.get(tableByLonLat[0]).get(tableByLonLat[1]);
Double pValue = pAllList.get(tableByLonLat[0]).get(tableByLonLat[1]);
@ -312,25 +485,6 @@ public class ResultActionController {
Double coValue = coAllList.get(tableByLonLat[0]).get(tableByLonLat[1]);
analysisResultVO.setCo(String.format("%.2E",coValue));
//干湿沉降
Double maxSubside = null;
for (int i = 0; i < subsideAllList.size(); i++) {
List<Double> subsideDep = subsideAllList.get(i);
for (int j = 0; j < subsideDep.size(); j++) {
if(null == maxSubside || subsideDep.get(j) > maxSubside){
maxSubside = subsideDep.get(j);
double lonValue = xlongAllList.get(i + 1).get(j + 1);
analysisResultVO.setLon(lonValue);
double latValue = xlatAllList.get(i + 1).get(j + 1);
analysisResultVO.setLat(latValue);
Double hgtValue = hgtAllList.get(i + 1).get(j + 1);
analysisResultVO.setHeight(hgtValue);
analysisResultVO.setSedimentation(String.format("%.2E",maxSubside));
analysisResultVO.setHumidity("0.76");
}
}
}
return Result.ok(analysisResultVO);
}catch (Exception e){
e.printStackTrace();
@ -535,9 +689,11 @@ public class ResultActionController {
// values.add(value);
if(null != globalMax && value > globalMax){
values.add(globalMax);
}else if(value < 2.5E-3 && null != globalMax){
values.add(1E-20);
}else{
}
// else if(value < 2.5E-3 && null != globalMax){
// values.add(1E-20);
// }
else{
values.add(value);
}
resultAll.add(values);
@ -551,91 +707,4 @@ public class ResultActionController {
}
return resultAll;
}
/**
* 封装地表沉降数据
* @param dryKey
* @param wetKey
* @return
*/
public List<List<Double>> getSedimentationInfo(List<List<Double>> xlats, List<List<Double>> xlongs,String dryKey,String wetKey,List<Double> maxs,List<Double> mins) {
List<List<Double>> resultAll = new ArrayList<>();
List<List<Double>> dryHours = (List<List<Double>>)redisUtil.get(dryKey);
List<List<Double>> wetHours = (List<List<Double>>)redisUtil.get(wetKey);
// for (int i = 0; i < dryHours.size(); i++) {
// for (int j = 0; j < dryHours.get(i).size(); j++) {
// double sedimentation = dryHours.get(i).get(j) + wetHours.get(i).get(j);
// List<Double> values = new ArrayList<>();
// values.add(j - 0.0);
// values.add(i - 0.0);
// values.add(sedimentation);
// resultAll.add(values);
// }
// }
Double max = null;
Double min = null;
for (int i = 0; i < dryHours.size(); i++) {
for (int j = 0; j < dryHours.get(i).size(); j++) {
double sedimentation = dryHours.get(i).get(j) + wetHours.get(i).get(j);
if(null == max){
max = sedimentation;
}else{
if(max < sedimentation){
max = sedimentation;
}
}
if(null == min){
min = sedimentation;
}else{
if(min > sedimentation){
max = sedimentation;
}
}
List<Double> values = new ArrayList<>();
values.add(xlongs.get(i).get(j));
values.add(xlats.get(i).get(j));
values.add(sedimentation);
resultAll.add(values);
}
}
maxs.add(max);
mins.add(min);
return resultAll;
}
/**
* 根据经纬度获取表格中的位置
* @param bizWrf
* @param targetLon
* @param targetLat
* @return
*/
public Integer[] getTableByLonLat (BizWrf bizWrf,double targetLon,double targetLat){
Integer[] lonlat = new Integer[2];
double latticeWidth = Math.abs(Math.round((Double.valueOf(bizWrf.getLon2()) - Double.valueOf(bizWrf.getLon1())) / Integer.valueOf(bizWrf.getWe()) * 10000) / 10000d);
Integer lonLatticeIndex = (int)(Math.abs(Math.ceil((Double.valueOf(targetLon) - Double.valueOf(bizWrf.getLon1()) + (latticeWidth / 2)) / latticeWidth)));
double latticeHeight = Math.abs(Math.round((Double.valueOf(bizWrf.getLat2()) - Double.valueOf(bizWrf.getLat1())) / Integer.valueOf(bizWrf.getSn()) * 10000) / 10000d);
Integer latLatticeIndex = (int)(Math.abs(Math.ceil((targetLat - Double.valueOf(bizWrf.getLat2()) + (latticeHeight / 2)) / latticeHeight)));
if(lonLatticeIndex > Integer.valueOf(bizWrf.getWe())){
lonLatticeIndex = Integer.valueOf(bizWrf.getWe()) - 1;
}
if(latLatticeIndex > Integer.valueOf(bizWrf.getSn())){
latLatticeIndex = Integer.valueOf(bizWrf.getSn()) - 1;
}
lonlat[0] = lonLatticeIndex;
lonlat[1] = latLatticeIndex;
return lonlat;
}
public boolean fileExists(String filePath){
File aconcNcPathFile = new File(filePath);
return aconcNcPathFile.exists();
}
}

View File

@ -0,0 +1,141 @@
package org.jeecg.modules.util;
import org.nd4j.linalg.api.buffer.DataType;
import org.nd4j.linalg.api.ndarray.INDArray;
import org.nd4j.linalg.factory.Nd4j;
import org.nd4j.linalg.indexing.NDArrayIndex;
import org.nd4j.linalg.ops.transforms.Transforms;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import static java.nio.file.Paths.get;
public class DoseCalculatorV3 {
public static void main(String[] args) throws IOException {
String filePath = "D:\\hky_word\\Projectlibrary\\resultFile\\admin\\1113\\csv_s\\";
int NuclearNum = 35;
int GasNum = 13;
int TimeAssessment = 73;
int TimefromCMAQ = 49;
List<String> doseTransFactorPaths = new ArrayList<>();
doseTransFactorPaths.add("source1.txt");
doseTransFactorPaths.add("GAS.txt");
doseTransFactorPaths.add("AERDEP.txt");
doseTransFactorPaths.add("AER.txt");
INDArray Halftime = null;
INDArray CEF = null;
INDArray SEF = null;
INDArray RIF = null;
for (int i = 0; i < doseTransFactorPaths.size(); i++) {
String sourcePath = doseTransFactorPaths.get(i);
List<Double> sourceData = stringAsDouble(Files.readAllLines(get(filePath + sourcePath)));
for (int j = 0; j < sourceData.size(); j++) {
if(sourceData.get(j).isNaN()){
sourceData.set(j,0d);
}
}
if(i == 0){
Halftime = Nd4j.create(sourceData.stream().mapToDouble(Double::doubleValue).toArray());
}else if(i == 1){
CEF = Nd4j.create(sourceData.stream().mapToDouble(Double::doubleValue).toArray()).mul(1000);
}else if(i == 2){
SEF = Nd4j.create(sourceData.stream().mapToDouble(Double::doubleValue).toArray()).mul(1000);
}else if(i == 3){
RIF = Nd4j.create(sourceData.stream().mapToDouble(Double::doubleValue).toArray()).mul(1000);
}
}
INDArray DecayRate = Nd4j.scalar(Math.log(2)).div(Halftime);
int AerosolNum = NuclearNum - GasNum;
INDArray DFfromGas = Nd4j.zeros(GasNum, TimefromCMAQ - 1);
INDArray DFfromAero_air = Nd4j.zeros(AerosolNum, TimefromCMAQ - 1);
INDArray DFfromDep = Nd4j.zeros(AerosolNum, TimeAssessment - 1);
double BreathRate=0.000347;
List<String> sourceDataPaths = new ArrayList<>();
sourceDataPaths.add("facilityData.txt");
List<List<Double>> SourceDataAll = new ArrayList<>();
for (String sourcePath : sourceDataPaths) {
List<Double> sourceData = stringAsDouble(Files.readAllLines(get(filePath + sourcePath)));
for (int i = 0; i < sourceData.size(); i++) {
if(sourceData.get(i).isNaN()){
sourceData.set(i,0d);
}
}
SourceDataAll.add(sourceData);
}
// 遍历每一列
for (int i = 0; i < SourceDataAll.size(); i++) {
// 提取当前列的数据
INDArray SourceData = Nd4j.create(SourceDataAll.get(i).stream().mapToDouble(Double::doubleValue).toArray());
for (int j = 1; j < TimeAssessment; j++) {
if (j < TimefromCMAQ){
INDArray gasPart = SourceData.get(NDArrayIndex.interval(0, GasNum))
.mul(Transforms.exp(DecayRate.get(NDArrayIndex.interval(0, GasNum)).mul(-j * 3600)))
.mul(CEF.get(NDArrayIndex.interval(0, GasNum)));
DFfromGas.putColumn(j - 1, gasPart);
INDArray aeroPart = SourceData.get(NDArrayIndex.interval(GasNum, NuclearNum))
.mul(Transforms.exp(DecayRate.get(NDArrayIndex.interval(GasNum, NuclearNum)).mul(-j * 3600)))
.mul(CEF.get(NDArrayIndex.interval(GasNum, NuclearNum)).add(RIF.get(NDArrayIndex.interval(GasNum, NuclearNum)).mul(BreathRate)));
DFfromAero_air.putColumn(j - 1, aeroPart);
}
INDArray depPart = SourceData.get(NDArrayIndex.interval(GasNum, NuclearNum))
.mul(Transforms.exp(DecayRate.get(NDArrayIndex.interval(GasNum, NuclearNum)).mul(-j * 3600)))
.mul(SEF.get(NDArrayIndex.interval(GasNum, NuclearNum)))
.mul(Nd4j.ones(NuclearNum - GasNum).sub(Transforms.exp(DecayRate.get(NDArrayIndex.interval(GasNum, NuclearNum)).mul(-3600))))
.div(DecayRate.get(NDArrayIndex.interval(GasNum, NuclearNum)));
DFfromDep.putColumn(j - 1, depPart);
}
// 计算每个矩阵的列求和
INDArray FactorforGas = DFfromGas.sum(0);
INDArray FactorforAerosol_air = DFfromAero_air.sum(0);
INDArray FactorforAerosol_dep = DFfromDep.sum(0);
writeArrayToFile(FactorforGas,"D:\\hky_word\\Projectlibrary\\resultFile\\admin\\1113\\csv_s\\aaa.txt");
// 打印结果
System.out.println("FactorforGas:\n" + FactorforGas.toStringFull());
System.out.println("FactorforAerosol_air:\n" + FactorforAerosol_air.toStringFull());
System.out.println("FactorforAerosol_dep:\n" + FactorforAerosol_dep.toStringFull());
}
}
// 写入 INDArray 到文件
private static void writeArrayToFile(INDArray array, String filePath) {
try (FileWriter writer = new FileWriter(filePath)) {
// 获取数组列数
long columns = array.columns();
// 将数组逐行写入文件
StringBuilder sb = new StringBuilder();
for (int j = 0; j < columns; j++) {
sb.append(array.getDouble(j)).append("\n");
}
writer.write(sb.toString());
System.out.println("Results written to file: " + filePath);
} catch (IOException e) {
e.printStackTrace();
}
}
public static List<Double> stringAsDouble(List<String> values){
List<Double> results = new ArrayList<>();
for (String s : values) {
results.add(Double.valueOf(s.trim()));
}
return results;
}
}

View File

@ -0,0 +1,123 @@
package org.jeecg.modules.util;
import org.nd4j.linalg.api.ndarray.INDArray;
import org.nd4j.linalg.factory.Nd4j;
import org.nd4j.linalg.indexing.NDArrayIndex;
import org.nd4j.linalg.ops.transforms.Transforms;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import static java.nio.file.Paths.get;
public class DoseCalculatorV3_Bak {
public static void main(String[] args) throws IOException {
String filePath = "D:\\hky_word\\Projectlibrary\\resultFile\\admin\\1113\\csv_s\\";
int NuclearNum = 35;
int GasNum = 13;
int TimeAssessment = 72;
int TimefromCMAQ = 48;
List<String> doseTransFactorPaths = new ArrayList<>();
doseTransFactorPaths.add("source1.txt");
doseTransFactorPaths.add("GAS.txt");
doseTransFactorPaths.add("AERDEP.txt");
doseTransFactorPaths.add("AER.txt");
INDArray DecayRate = null;
INDArray CEF = null;
INDArray SEF = null;
INDArray RIF = null;
for (int i = 0; i < doseTransFactorPaths.size(); i++) {
String sourcePath = doseTransFactorPaths.get(i);
List<Double> sourceData = stringAsDouble(Files.readAllLines(get(filePath + sourcePath)));
for (int j = 0; j < sourceData.size(); j++) {
if(sourceData.get(j).isNaN()){
sourceData.set(j,0d);
}else{
if(i == 0){
sourceData.set(j,Math.log(2) / sourceData.get(j));
}else{
sourceData.set(j,sourceData.get(j) * 1000);
}
}
}
if(i == 0){
DecayRate = Nd4j.create(sourceData.stream().mapToDouble(Double::doubleValue).toArray());
}else if(i == 1){
CEF = Nd4j.create(sourceData.stream().mapToDouble(Double::doubleValue).toArray());
}else if(i == 2){
SEF = Nd4j.create(sourceData.stream().mapToDouble(Double::doubleValue).toArray());
}else if(i == 3){
RIF = Nd4j.create(sourceData.stream().mapToDouble(Double::doubleValue).toArray());
}
}
int AerosolNum = NuclearNum - GasNum;
INDArray DFfromGas = Nd4j.zeros(GasNum, TimefromCMAQ);
INDArray DFfromAero_air = Nd4j.zeros(AerosolNum, TimefromCMAQ);
INDArray DFfromDep = Nd4j.zeros(AerosolNum, TimeAssessment);
double BreathRate=0.000347;
List<String> sourceDataPaths = new ArrayList<>();
sourceDataPaths.add("facilityData.txt");
List<List<Double>> SourceDataAll = new ArrayList<>();
for (String sourcePath : sourceDataPaths) {
List<Double> sourceData = stringAsDouble(Files.readAllLines(get(filePath + sourcePath)));
for (int i = 0; i < sourceData.size(); i++) {
if(sourceData.get(i).isNaN()){
sourceData.set(i,0d);
}
}
SourceDataAll.add(sourceData);
}
// 遍历每一列
for (int i = 0; i < SourceDataAll.size(); i++) {
// 提取当前列的数据
INDArray SourceData = Nd4j.create(SourceDataAll.get(i).stream().mapToDouble(Double::doubleValue).toArray());
for (int j = 0; j < TimeAssessment; j++) {
if (j < TimefromCMAQ){
INDArray gasPart = SourceData.get(NDArrayIndex.interval(0, GasNum))
.mul(Transforms.exp(DecayRate.get(NDArrayIndex.interval(0, GasNum)).mul(-j * 3600)))
.mul(CEF.get(NDArrayIndex.interval(0, GasNum)));
DFfromGas.putColumn(j, gasPart);
INDArray aeroPart = SourceData.get(NDArrayIndex.interval(GasNum, NuclearNum))
.mul(Transforms.exp(DecayRate.get(NDArrayIndex.interval(GasNum, NuclearNum)).mul(-j * 3600)))
.mul(CEF.get(NDArrayIndex.interval(GasNum, NuclearNum)).add(RIF.get(NDArrayIndex.interval(GasNum, NuclearNum)).mul(BreathRate)));
DFfromAero_air.putColumn(j, aeroPart);
}
INDArray depPart = SourceData.get(NDArrayIndex.interval(GasNum, NuclearNum))
.mul(Transforms.exp(DecayRate.get(NDArrayIndex.interval(GasNum, NuclearNum)).mul(-j * 3600)))
.mul(SEF.get(NDArrayIndex.interval(GasNum, NuclearNum)))
.mul(Nd4j.ones(NuclearNum - GasNum).sub(Transforms.exp(DecayRate.get(NDArrayIndex.interval(GasNum, NuclearNum)).mul(-3600))))
.div(DecayRate.get(NDArrayIndex.interval(GasNum, NuclearNum)));
DFfromDep.putColumn(j, depPart);
}
// 计算每个矩阵的列求和
INDArray FactorforGas = DFfromGas.sum(0);
INDArray FactorforAerosol_air = DFfromAero_air.sum(0);
INDArray FactorforAerosol_dep = DFfromDep.sum(0);
// 打印结果
System.out.println("FactorforGas:\n" + FactorforGas);
System.out.println("FactorforAerosol_air:\n" + FactorforAerosol_air);
System.out.println("FactorforAerosol_dep:\n" + FactorforAerosol_dep);
}
}
public static List<Double> stringAsDouble(List<String> values){
List<Double> results = new ArrayList<>();
for (String s : values) {
results.add(Double.valueOf(s.trim()));
}
return results;
}
}

View File

@ -2,14 +2,17 @@ package org.jeecg.modules.util;
import cn.hutool.core.date.DateUtil;
import ucar.ma2.Array;
import ucar.ma2.ArrayDouble;
import ucar.ma2.DataType;
import ucar.ma2.Index;
import ucar.nc2.*;
import ucar.nc2.dataset.NetcdfDataset;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
@ -94,7 +97,56 @@ public final class NcUtil {
int[] shape = data.getShape();
Index index = data.getIndex();
for (int i = 0; i < 24; i++) {
int time = 24;
if(shape[0] < 24){
time = shape[0];
}
int layer = 14;
if(shape[1] < 14){
layer = shape[1];
}
for (int i = 0; i < time; i++) {
List<List<List<Double>>> resultLayer = new ArrayList<>();
for (int l = 0; l < layer; l++) {
List<List<Double>> resultPiece = new ArrayList<>();
for (int j = 0; j < shape[2]; j++) {
List<Double> strings = new ArrayList<>();
// 按经度
for (int k = 0; k < shape[3]; k++) {
// 按照对应索引获取数据并转换为string类型添加到数组中
if("CO".equals(name) || "ASIJ".equals(name)){
strings.add(data.getDouble(index.set(i,l, j, k)));
}else{
strings.add(Math.ceil(data.getDouble(index.set(i,l, j, k)) * 1000d) / 1000d);
}
}
resultPiece.add(strings);
}
resultLayer.add(resultPiece);
}
resultAll.add(resultLayer);
}
return resultAll;
}
public static List<List<List<List<Double>>>> getNCAllTimeByName(NetcdfFile ncFile, String name){
Variable variable = ncFile.findVariable(name);
List<List<List<List<Double>>>> resultAll = new ArrayList<>();
// 读取nc数据到数组
Array data = null;
try {
data = variable.read();
} catch (IOException e) {
e.printStackTrace();
}
// 获取参数和索引其中shape的前三个参数分别是时间层级纬度经度
int[] shape = data.getShape();
Index index = data.getIndex();
for (int i = 0; i < shape[0]; i++) {
List<List<List<Double>>> resultLayer = new ArrayList<>();
for (int l = 0; l < shape[1]; l++) {
List<List<Double>> resultPiece = new ArrayList<>();
@ -214,8 +266,8 @@ public final class NcUtil {
public static void genNcFile(List<List<List<List<Double>>>> dataList,String newNcFilePath,String variableName){
// 创建NetCDF文件并打开以进行写入
try {
// 创建NetCDF文件写入器
NetcdfFileWriter ncWriter = NetcdfFileWriter.createNew(NetcdfFileWriter.Version.netcdf3, newNcFilePath);
File file = new File(newNcFilePath);
boolean fileExists = file.exists();
// 数据维度
int tstepNum = dataList.size();
@ -223,23 +275,40 @@ public final class NcUtil {
int rowNum = dataList.get(0).get(0).size();
int colNum = dataList.get(0).get(0).get(0).size();
// 定义维度
ncWriter.addDimension(null, "TSTEP", tstepNum);
ncWriter.addDimension(null, "LAY", layNum);
ncWriter.addDimension(null, "ROW", rowNum);
ncWriter.addDimension(null, "COL", colNum);
Variable dataVar;
NetcdfFileWriter ncWriter;
if(fileExists){
ncWriter = NetcdfFileWriter.openExisting(newNcFilePath);
ncWriter.setRedefineMode(true);
}else{
ncWriter = NetcdfFileWriter.createNew(NetcdfFileWriter.Version.netcdf3, newNcFilePath);
// 定义维度
ncWriter.addDimension(null, "TSTEP", tstepNum);
ncWriter.addDimension(null, "LAY", layNum);
ncWriter.addDimension(null, "ROW", rowNum);
ncWriter.addDimension(null, "COL", colNum);
ncWriter.addDimension(null, "LAYER", 1);
}
Variable dataVar = ncWriter.addVariable(null, variableName, DataType.DOUBLE, "TSTEP LAY ROW COL");
if(variableName.indexOf("AERDEP") >= 0){
dataVar = ncWriter.addVariable(null, variableName, DataType.DOUBLE, "TSTEP LAYER ROW COL");
}else{
dataVar = ncWriter.addVariable(null, variableName, DataType.DOUBLE, "TSTEP LAY ROW COL");
}
// 关联维度到变量
ncWriter.addVariableAttribute(dataVar, new Attribute("units", "none"));
ncWriter.addVariableAttribute(dataVar, new Attribute("long_name", variableName));
// 定义数据
ncWriter.create();
if(fileExists){
ncWriter.setRedefineMode(false);
}else{
// 定义数据
ncWriter.create();
}
// 将数据转换为NetCDF数组
Array dataArray = Array.factory(DataType.DOUBLE, new int[]{tstepNum, layNum,rowNum,colNum});
ArrayDouble.D4 dataArray = new ArrayDouble.D4(tstepNum, layNum,rowNum,colNum);
for (int i = 0; i < tstepNum; i++) {
List<List<List<Double>>> layData = dataList.get(i);
for (int j = 0; j < layNum; j++) {
@ -247,6 +316,7 @@ public final class NcUtil {
for (int r = 0; r < rowNum; r++) {
List<Double> colData = rowData.get(r);
for (int c = 0; c < colNum; c++) {
// System.out.print(colData.get(c) + ",");
dataArray.setDouble(dataArray.getIndex().set(i, j, r, c), colData.get(c));
}
}
@ -264,14 +334,31 @@ public final class NcUtil {
}
public static NetcdfFile openFile(String filePath) throws IOException {
return NetcdfDataset.open(filePath);
}
public static void main(String[] args) throws IOException {
// NetcdfFile ncFile = NetcdfDataset.open("D:\\wumu\\vmhgfs\\zyh\\0508\\CCTM.CONC.d03.20181113");
NetcdfFile ncFile = NetcdfDataset.open("D:\\wumu\\java\\resultFile\\admin\\1113\\wrfout_d03_2018-11-13_00_00_00");
Date startTime = new Date();
List<List<List<List<Double>>>> co = getNCByName(ncFile, "U");
Date endTime = new Date();
System.out.println(endTime.getTime() - startTime.getTime());
try{
NetcdfFile ncFile = NetcdfDataset.open("D:\\wumu\\vmhgfs\\zyh\\0508\\CCTM.CONC.d03.20181113");
Date startTime = new Date();
// NetcdfFile ncFile = NetcdfDataset.open("D:\\wumu\\java\\resultFile\\admin\\1113\\METCRO3D_d03_20181113");
List<List<List<List<Double>>>> co = getNCByName(ncFile, "CO");
// List<List<List<List<Double>>>> P = getNCByName(ncFile, "PRES");
Date endTime = new Date();
System.out.println(endTime.getTime() - startTime.getTime());
// NetcdfFile ncFile = openFile("D:\\wumu\\T1279\\GG_nhgsmout_2024050112.015.grb");
// List<List<List<Double>>> us = getNCByName(ncFile, "10_metre_U_wind_component_surface",0);
// List<List<List<Double>>> vs = getNCByName(ncFile, "10_metre_V_wind_component_surface",0);
// List<List<List<Double>>> ps = getNCByName(ncFile, "Surface_pressure_surface",0);
// List<List<List<Double>>> ts = getNCByName(ncFile, "2_metre_temperature_surface",0);
// NetcdfFile ncFile2 = NetcdfDataset.open("D:\\wumu\\T1279\\PL_nhgsmout_2024050112.003.grb");
// List<List<List<Double>>> hs = getNCByName(ncFile2, "Relative_humidity_isobaric",0);
}catch (Exception e){
e.printStackTrace();
}
}
}

View File

@ -8,6 +8,7 @@ import ucar.nc2.dataset.NetcdfDataset;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static java.nio.file.Paths.get;
@ -373,6 +374,10 @@ public class plt_add_hgt_gk {
aerdep_gk.add(aerdep_Slice);
}
List<Double> flattenedList = new ArrayList<>();
flattenList(aerdep_gk,flattenedList);
getMaxMin(flattenedList);
//单时次总和
// 创建一个新的列表 total_gk 来存储结果
List<List<List<List<Double>>>> total_gk = new ArrayList<>();
@ -416,6 +421,10 @@ public class plt_add_hgt_gk {
total_gk.add(totalSlice);
}
List<Double> flattenedList2 = new ArrayList<>();
flattenList(total_gk,flattenedList2);
getMaxMin(flattenedList2);
List<List<List<List<Double>>>> total_acc_gk = new ArrayList<>();
List<List<List<List<Double>>>> gas_acc_gk = new ArrayList<>();
List<List<List<List<Double>>>> aer_acc_gk = new ArrayList<>();
@ -454,6 +463,17 @@ public class plt_add_hgt_gk {
dosageDataVO.setAerAccGk(aer_acc_gk);
dosageDataVO.setAerDepAccGk(aerdep_acc_gk);
dosageDataVO.setTotalAccGk(total_acc_gk);
String dosagePath = "D:\\wumu\\java\\resultFile\\admin\\1113\\";
NcUtil.genNcFile(total_gk,dosagePath,"TOTAL_GK");
NcUtil.genNcFile(gas_gk,dosagePath,"GAS_GK");
NcUtil.genNcFile(aer_gk,dosagePath,"AER_GK");
NcUtil.genNcFile(aerdep_gk,dosagePath,"AERDEP_GK");
NcUtil.genNcFile(total_acc_gk,dosagePath,"TOTAL_ACC_GK");
NcUtil.genNcFile(gas_acc_gk,dosagePath,"GAS_ACC_GK");
NcUtil.genNcFile(aer_acc_gk,dosagePath,"AER_ACC_GK");
NcUtil.genNcFile(aerdep_acc_gk,dosagePath,"AERDEP_ACC_GK");
System.out.println();
}
@ -578,7 +598,36 @@ public class plt_add_hgt_gk {
return cornerCoordinates;
}
// 递归地将嵌套列表中的所有 Double 值提取出来
public static void flattenList(List<?> nestedList, List<Double> flattenedList) {
for (Object element : nestedList) {
if (element instanceof List) {
flattenList((List<?>) element, flattenedList);
} else {
flattenedList.add((Double) element);
}
}
}
public static List<Double> getMaxMin(List<Double> flattenedList){
List<Double> maxMin = new ArrayList<>();
double maxValue = Collections.max(flattenedList);
double minValue = Collections.min(flattenedList);
maxMin.add(maxValue);
maxMin.add(minValue);
return maxMin;
}
public static void main(String[] args) throws IOException {
fun();
// String dosagePath = "D:\\wumu\\java\\resultFile\\admin\\1113\\";
// NetcdfFile totalNcFile = NetcdfDataset.open(dosagePath + "DOSAGE_AER_GK");
// List<List<List<List<Double>>>> totalGk = NcUtil.getNCAllTimeByName(totalNcFile, "AER_GK");
// List<Double> flattenedList3 = new ArrayList<>();
// flattenList(totalGk,flattenedList3);
// List<Double> maxMin = getMaxMin(flattenedList3);
// System.out.println(maxMin.get(0));
// System.out.println(maxMin.get(1));
}
}

View File

@ -0,0 +1,615 @@
package org.jeecg.modules.util;
import org.jeecg.modules.project.resultAction.VO.DosageDataVO;
import org.nd4j.linalg.api.ndarray.INDArray;
import org.nd4j.linalg.factory.Nd4j;
import org.nd4j.linalg.indexing.NDArrayIndex;
import ucar.nc2.NetcdfFile;
import ucar.nc2.dataset.NetcdfDataset;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import static java.nio.file.Paths.get;
public class plt_add_hgt_gk_bak {
public static void fun() throws IOException {
String path = "D:\\hky_word\\Projectlibrary\\resultFile\\admin\\1113\\";
//读取nc文件
NetcdfFile wrfFile = NetcdfDataset.open("D:\\hky_word\\Projectlibrary\\resultFile\\admin\\1113\\wrfout_d03_2018-11-13_00_00_00");
NetcdfFile metcro3dFile = NetcdfDataset.open("D:\\hky_word\\Projectlibrary\\resultFile\\admin\\1113\\METCRO3D_d03_20181113");
NetcdfFile cmaqFile = NetcdfDataset.open("D:\\hky_word\\Projectlibrary\\resultFile\\admin\\1113\\CCTM.CONC.d03.20181113");
NetcdfFile dryFile = NetcdfDataset.open("D:\\hky_word\\Projectlibrary\\resultFile\\admin\\1113\\CCTM.DRYDEP.d03.20181113");
NetcdfFile wetFile = NetcdfDataset.open("D:\\hky_word\\Projectlibrary\\resultFile\\admin\\1113\\CCTM.WETDEP1.d03.20181113");
List<List<List<Double>>> lats = NcUtil.getNCByName(wrfFile, "XLAT", 0);
List<List<List<Double>>> lons = NcUtil.getNCByName(wrfFile, "XLONG", 0);
List<List<List<Double>>> hts = NcUtil.getNCByName(wrfFile, "HGT", 0); // 地形高程
List<List<List<List<Double>>>> uwinds = NcUtil.getNCByNameOrderByTime(wrfFile, "U");
List<List<List<List<Double>>>> vwinds = NcUtil.getNCByNameOrderByTime(wrfFile, "V");
List<List<List<List<Double>>>> tas = NcUtil.getNCByNameOrderByTime(metcro3dFile, "TA"); //温度
List<List<List<List<Double>>>> ps = NcUtil.getNCByNameOrderByTime(metcro3dFile, "PRES"); //气压
int[] uwindShape = NcUtil.getShapeByName(wrfFile, "U");
// 获取 UWIND VWIND 的维度
int nt = uwindShape[0];
int nz = uwindShape[1];
int nx = uwindShape[2];
int ny = uwindShape[3];
// // 计算 水平方向平均值
// double[][][][] UWIND_ca = new double[nt][nz][nx][ny-1];
// double[][][][] VWIND_ca = new double[nt][nz][nx-1][ny];
// for (int i = 0; i < nt; i++) {
// for (int j = 0; j < nz; j++) {
// for (int k = 0; k < nx-1; k++) {
// for (int l = 0; l < ny-1; l++) {
// UWIND_ca[i][j][k][l] = (uwinds.get(i).get(j).get(k).get(l) + uwinds.get(i).get(j).get(k+1).get(l)) / 2.0;
// VWIND_ca[i][j][k][l] = (vwinds.get(i).get(j).get(k).get(l) + vwinds.get(i).get(j).get(k+1).get(l)) / 2.0;
// }
// }
// }
// }
//
// // 计算 垂直方向平均值
// double[][][][] UWIND_cross = new double[nt][nz][nx-1][ny-1];
// double[][][][] VWIND_cross = new double[nt][nz][nx-1][ny-1];
// for (int i = 0; i < nt; i++) {
// for (int j = 0; j < nz; j++) {
// for (int k = 0; k < nx-1; k++) {
// for (int l = 0; l < ny-2; l++) {
// UWIND_cross[i][j][k][l] = (UWIND_ca[i][j][k][l] + UWIND_ca[i][j][k][l+1]) / 2.0;
// VWIND_cross[i][j][k][l] = (VWIND_ca[i][j][k][l] + VWIND_ca[i][j][k][l+1]) / 2.0;
// }
// }
// }
// }
List<List<List<List<Double>>>> emis = new ArrayList<>();
List<List<List<List<Double>>>> emis_aer = new ArrayList<>();
//遍历每一天的nc
// for (int i = 0; i < 3; i++) {
NetcdfFile emisFile = NetcdfDataset.open("D:\\hky_word\\Projectlibrary\\resultFile\\admin\\1113\\emis_20181113");
List<List<List<List<Double>>>> emis0 = NcUtil.getNCByNameOrderByTime(emisFile, "CO");
List<List<List<List<Double>>>> emis1 = NcUtil.getNCByNameOrderByTime(emisFile, "PSI");
emis.addAll(emis0);
emis_aer.addAll(emis1);
// }
// 初始化 CO 排放总量列表
List<Double> co_emis = new ArrayList<>();
// 计算 CO 排放总量
for (List<List<List<Double>>> emisList : emis) {
double sum = 0.0;
for (List<List<Double>> emisList1 : emisList) {
for (List<Double> emisList2 : emisList1) {
for (Double value : emisList2) {
sum += value;
}
}
}
co_emis.add(3600 * sum);
}
// 初始化 SI 排放总量列表
List<Double> si_emis = new ArrayList<>();
// 计算 SI 排放总量
for (List<List<List<Double>>> emisList : emis_aer) {
double sum = 0.0;
for (List<List<Double>> emisList1 : emisList) {
for (List<Double> emisList2 : emisList1) {
for (Double value : emisList2) {
sum += value;
}
}
}
si_emis.add(3600 * sum);
}
// 各时刻已经排放的总量 分之一
int[] taShape = NcUtil.getShapeByName(metcro3dFile, "TA");
// 获取 UWIND VWIND 的维度
nt = taShape[0] - 1;
nz = taShape[1];
nx = taShape[2];
ny = taShape[3];
double[][][][] total_emis = new double[nt][nz][nx][ny];
double[][][][] total_emis_aer = new double[nt][nz][nx][ny];
for (int i = 0; i < nt; i++) {
double te = co_emis.stream().limit(i).mapToDouble(Double::doubleValue).sum();
double te_aer = si_emis.stream().limit(i).mapToDouble(Double::doubleValue).sum();
if(te == 0){
// total_emis 中索引为 i 的切片的所有元素设置为零
for (int j = 0; j < nz; j++) {
for (int k = 0; k < nx; k++) {
for (int l = 0; l < ny; l++) {
total_emis[i][j][k][l] = 0;
}
}
}
}else{
for (int j = 0; j < nz; j++) {
for (int k = 0; k < nx; k++) {
for (int l = 0; l < ny; l++) {
total_emis[i][j][k][l] = 1 / te;
}
}
}
}
if(te_aer == 0){
// total_emis 中索引为 i 的切片的所有元素设置为零
for (int j = 0; j < nz; j++) {
for (int k = 0; k < nx; k++) {
for (int l = 0; l < ny; l++) {
total_emis_aer[i][j][k][l] = 0;
}
}
}
}else{
for (int j = 0; j < nz; j++) {
for (int k = 0; k < nx; k++) {
for (int l = 0; l < ny; l++) {
total_emis_aer[i][j][k][l] = 1 / te_aer;
}
}
}
}
}
//气体
// 计算 gas0 中的每个元素并将 gas total_emis 相乘
List<List<List<List<Double>>>> gas0 = NcUtil.getNCByNameOrderByTime(cmaqFile, "CO");
for (int i = 0; i < nt; i++) {
List<List<List<Double>>> gasSlice = gas0.get(i);
double[][][] totalEmisSlice = total_emis[i];
for (int j = 0; j < gasSlice.size(); j++) {
List<List<Double>> gasGrid = gasSlice.get(j);
double[][] totalEmisGrid = totalEmisSlice[j];
for (int k = 0; k < gasGrid.size(); k++) {
List<Double> gasRow = gasGrid.get(k);
double[] totalEmisRow = totalEmisGrid[k];
for (int l = 0; l < gasRow.size(); l++) {
double value = 3600 * (gasRow.get(l) * ps.get(i).get(j).get(k).get(l) / (8.31 * tas.get(i).get(j).get(k).get(l))) / 1e6;
gasRow.set(l, value * totalEmisRow[l]);
}
}
}
}
//获取excel表格值
List<Double> g1 = stringAsDouble(Files.readAllLines(get("D:\\hky_word\\Projectlibrary\\resultFile\\admin\\1113\\csv_s\\g1.txt")));
// 乘以工况系数
List<List<List<List<Double>>>> gas_gk = new ArrayList<>();
for (int t = 0; t < nt; t++) {
List<List<List<Double>>> gasSlice = gas0.get(t);
List<List<List<Double>>> gasGkSlice = new ArrayList<>();
double g1Value = g1.get(t);
for (int i = 0; i < gasSlice.size(); i++) {
List<List<Double>> gasGrid = gasSlice.get(i);
List<List<Double>> gasGkGrid = new ArrayList<>();
for (int j = 0; j < gasGrid.size(); j++) {
List<Double> gasRow = gasGrid.get(j);
List<Double> gasGkRow = new ArrayList<>();
for (int k = 0; k < gasRow.size(); k++) {
gasGkRow.add(gasRow.get(k) * g1Value);
}
gasGkGrid.add(gasGkRow);
}
gasGkSlice.add(gasGkGrid);
}
gas_gk.add(gasGkSlice);
}
//气溶胶
List<List<List<List<Double>>>> aer0 = NcUtil.getNCByNameOrderByTime(cmaqFile, "ASIJ");
for (int i = 0; i < nt; i++) {
List<List<List<Double>>> aerSlice = aer0.get(i);
double[][][] totalEmisAerSlice = total_emis_aer[i];
// 遍历 sis 中的网格
for (int j = 0; j < aerSlice.size(); j++) {
List<List<Double>> aerGrid = aerSlice.get(j);
double[][] totalEmisAerGrid = totalEmisAerSlice[j];
// 遍历 sis 中的行
for (int k = 0; k < aerGrid.size(); k++) {
List<Double> aerRow = aerGrid.get(k);
double[] totalEmisAerRow = totalEmisAerGrid[k];
// 对每个元素进行计算并更新 sis 中的值
for (int l = 0; l < aerRow.size(); l++) {
aerRow.set(l, 3600 * aerRow.get(l) / 1e6 * totalEmisAerRow[l]);
}
}
}
}
//获取excel表格值
List<Double> a1 = stringAsDouble(Files.readAllLines(get("D:\\hky_word\\Projectlibrary\\resultFile\\admin\\1113\\csv_s\\a1.txt")));
// 乘以工况系数
List<List<List<List<Double>>>> aer_gk = new ArrayList<>();
// 对每个时间步进行计算
for (int t = 0; t < nt; t++) {
List<List<List<Double>>> aerSlice = aer0.get(t);
List<List<List<Double>>> aerGkSlice = new ArrayList<>();
double a1Value = a1.get(t);
// 遍历 aer 时间步中的网格
for (int i = 0; i < aerSlice.size(); i++) {
List<List<Double>> aerGrid = aerSlice.get(i);
List<List<Double>> aerGkGrid = new ArrayList<>();
// 遍历 aer 时间步中的行
for (int j = 0; j < aerGrid.size(); j++) {
List<Double> aerRow = aerGrid.get(j);
List<Double> aerGkRow = new ArrayList<>();
// 遍历 aer 时间步中的列
for (int k = 0; k < aerRow.size(); k++) {
aerGkRow.add(aerRow.get(k) * a1Value);
}
aerGkGrid.add(aerGkRow);
}
aerGkSlice.add(aerGkGrid);
}
aer_gk.add(aerGkSlice);
}
//气溶胶沉降
List<List<List<List<Double>>>> depaer0 = new ArrayList<>();
List<List<List<List<Double>>>> depDatas = NcUtil.getNCByNameOrderByTime(dryFile, "ASIJ");
List<List<List<List<Double>>>> wetDatas = NcUtil.getNCByNameOrderByTime(wetFile, "ASIJ");
for (int i = 0; i < nt; i++) {
List<List<List<Double>>> depLayer = new ArrayList<>();
for (int j = 0; j < depDatas.get(i).size(); j++) {
List<List<Double>> depSn = new ArrayList<>();
for (int k = 0; k < depDatas.get(i).get(j).size(); k++) {
List<Double> depWe = new ArrayList<>();
for (int l = 0; l < depDatas.get(i).get(j).get(k).size(); l++) {
depWe.add(depDatas.get(i).get(j).get(k).get(l) + wetDatas.get(i).get(j).get(k).get(l));
}
depSn.add(depWe);
}
depLayer.add(depSn);
}
depaer0.add(depLayer);
}
List<List<List<List<Double>>>> depaer_c = new ArrayList<>();
for (int i = 0; i < nt; i++) {
List<List<List<Double>>> depaerLayer = new ArrayList<>();
for (int j = 0; j < depaer0.get(i).size(); j++) {
List<List<Double>> depaerSn = new ArrayList<>();
for (int k = 0; k < depaer0.get(i).get(j).size(); k++) {
List<Double> depaerWe = new ArrayList<>();
for (int l = 0; l < depaer0.get(i).get(j).get(k).size(); l++) {
if(i == 0){
depaerWe.add(0.0);
}else{
depaerWe.add(depaer0.get(i-1).get(j).get(k).get(l));
}
}
depaerSn.add(depaerWe);
}
depaerLayer.add(depaerSn);
}
depaer_c.add(depaerLayer);
}
List<List<List<List<Double>>>> depaer = new ArrayList<>();
// 对每个维度进行计算
for (int i = 0; i < nt; i++) {
List<List<List<Double>>> depaerSliceResult = new ArrayList<>();
List<List<List<Double>>> depaerSlice = depaer_c.get(i);
double[][][] totalEmisAerSlice = total_emis_aer[i];
// 遍历 depaer_c 中的网格
for (int j = 0; j < depaerSlice.size(); j++) {
List<List<Double>> depaerGridResult = new ArrayList<>();
List<List<Double>> depaerGrid = depaerSlice.get(j);
double[][] totalEmisAerGrid = totalEmisAerSlice[j];
// 遍历 depaer_c 中的行
for (int k = 0; k < depaerGrid.size(); k++) {
List<Double> depaerResult = new ArrayList<>();
List<Double> depaerRow = depaerGrid.get(k);
double[] totalEmisAerRow = totalEmisAerGrid[k];
// 对每个元素进行计算并更新 depaer_c 中的值
for (int l = 0; l < depaerRow.size(); l++) {
depaerResult.add(depaerRow.get(l) * 1000 / 10000 * totalEmisAerRow[l]);
}
depaerGridResult.add(depaerResult);
}
depaerSliceResult.add(depaerGridResult);
}
depaer.add(depaerSliceResult);
}
INDArray depaerIndArray = convertListToINDArray(depaer);
//获取excel表格值
List<Double> ad1 = stringAsDouble(Files.readAllLines(get("D:\\hky_word\\Projectlibrary\\resultFile\\admin\\1113\\csv_s\\ad1.txt")));
// 乘以工况系数
List<List<List<List<Double>>>> aerdep_gk = initializeList(nt,1,nx,ny);
// 对每个时间步进行计算
for (int t = 0; t < nt; t++) {
// 提取子数组并进行求和
INDArray subArray = depaerIndArray.get(NDArrayIndex.interval(0, t + 1), NDArrayIndex.point(0), NDArrayIndex.all(), NDArrayIndex.all());
INDArray ad_tmp = subArray.sum(0);
// 乘以工况系数
INDArray multiplied = ad_tmp.mul(ad1.get(t));
// 将结果存储回 List
storeResultInList(aerdep_gk, multiplied, t);
}
NcUtil.genNcFile(aerdep_gk,path,"GAS_GK");
//单时次总和
// 创建一个新的列表 total_gk 来存储结果
List<List<List<List<Double>>>> total_gk = new ArrayList<>();
// 遍历 gas_gk aer_gk 的每个元素进行相应位置的求和操作
for (int i = 0; i < nt; i++) {
List<List<List<Double>>> gasSlice = gas_gk.get(i);
List<List<List<Double>>> aerSlice = aer_gk.get(i);
List<List<List<Double>>> aerdepSlice = aerdep_gk.get(i);
// totalSlice 是与 gasSlice aerSlice 维度相同的三维数组用于存储当前时刻的求和结果
List<List<List<Double>>> totalSlice = new ArrayList<>();
// 遍历 gasSlice aerSlice 的每个元素进行相应位置的求和操作
for (int j = 0; j < gasSlice.size(); j++) {
List<List<Double>> gasInnerList = gasSlice.get(j);
List<List<Double>> aerInnerList = aerSlice.get(j);
List<List<Double>> aerdepInnerList = aerdepSlice.get(0);
// totalInnerList 是与 gasInnerList aerInnerList 维度相同的二维数组用于存储当前时刻的求和结果
List<List<Double>> totalInnerList = new ArrayList<>();
// 遍历 gasInnerList aerInnerList 的每个元素进行相应位置的求和操作
for (int k = 0; k < gasInnerList.size(); k++) {
List<Double> gasInnerList2 = gasInnerList.get(k);
List<Double> aerInnerList2 = aerInnerList.get(k);
List<Double> aerdepInnerList2 = aerdepInnerList.get(k);
// totalInnerList2 是与 gasInnerList2 aerInnerList2 维度相同的一维数组用于存储当前时刻的求和结果
List<Double> totalInnerList2 = new ArrayList<>();
// 遍历 gasInnerList2 aerInnerList2 的每个元素进行相应位置的求和操作
for (int l = 0; l < gasInnerList2.size(); l++) {
double totalValue = gasInnerList2.get(l) + aerInnerList2.get(l) + aerdepInnerList2.get(l);
totalInnerList2.add(totalValue);
}
totalInnerList.add(totalInnerList2);
}
totalSlice.add(totalInnerList);
}
total_gk.add(totalSlice);
}
List<List<List<List<Double>>>> total_acc_gk = new ArrayList<>();
List<List<List<List<Double>>>> gas_acc_gk = new ArrayList<>();
List<List<List<List<Double>>>> aer_acc_gk = new ArrayList<>();
List<List<List<List<Double>>>> aerdep_acc_gk = new ArrayList<>();
// total_acc_gk.addAll(total_gk);
// gas_acc_gk.addAll(gas_gk);
// aer_acc_gk.addAll(aer_gk);
// aerdep_acc_gk.addAll(aerdep_gk);
// 逐时次累加结果
sumSlice(total_acc_gk, total_gk, nt);
sumSlice(gas_acc_gk, gas_gk, nt);
sumSlice(aer_acc_gk, aer_gk, nt);
sumSlice(aerdep_acc_gk, aerdep_gk, nt);
DosageDataVO dosageDataVO = new DosageDataVO();
dosageDataVO.setGasGk(gas_gk);
dosageDataVO.setAerGk(aer_gk);
dosageDataVO.setAerDepGk(aerdep_gk);
dosageDataVO.setTotalGk(total_gk);
dosageDataVO.setGasAccGk(gas_acc_gk);
dosageDataVO.setAerAccGk(aer_acc_gk);
dosageDataVO.setAerDepAccGk(aerdep_acc_gk);
dosageDataVO.setTotalAccGk(total_acc_gk);
System.out.println();
// NcUtil.genNcFile(gas_gk,path,"GAS_GK");
// NcUtil.genNcFile(aer_gk,path,"AER_GK");
// NcUtil.genNcFile(aerdep_gk,path,"AERDEP_GK");
// NcUtil.genNcFile(total_gk,path,"TOTAL_GK");
// NcUtil.genNcFile(gas_acc_gk,path,"GAS_ACC_GK");
// NcUtil.genNcFile(aer_acc_gk,path,"AER_ACC_GK");
// NcUtil.genNcFile(aerdep_acc_gk,path,"AERDEP_ACC_GK");
// NcUtil.genNcFile(total_acc_gk,path,"TOTAL_ACC_GK");
}
private static void sumSlice(List<List<List<List<Double>>>> results,List<List<List<List<Double>>>> datas, int nt) {
for (int i = 0; i < nt; i++) {
if(0 == i){
results.add(datas.get(i));
continue;
}
List<List<List<Double>>> resultSliceList = new ArrayList<>();
for (int j = 0; j < datas.get(i).size(); j++) {
List<List<Double>> sliceInnerList = datas.get(i).get(j);
List<List<Double>> resultInnerList = new ArrayList<>();
for (int k = 0; k < sliceInnerList.size(); k++) {
List<Double> slices = sliceInnerList.get(k);
List<Double> accs = results.get(i-1).get(j).get(k);
List<Double> result = new ArrayList<>();
for (int l = 0; l < slices.size(); l++) {
result.add(accs.get(l) + slices.get(l));
}
resultInnerList.add(result);
}
resultSliceList.add(resultInnerList);
}
results.add(resultSliceList);
}
}
public static List<List<List<List<Double>>>> initializeList(int a, int b, int c, int d) {
List<List<List<List<Double>>>> list4D = new ArrayList<>();
for (int i = 0; i < a; i++) {
List<List<List<Double>>> list3D = new ArrayList<>();
for (int j = 0; j < b; j++) {
List<List<Double>> list2D = new ArrayList<>();
for (int k = 0; k < c; k++) {
List<Double> list1D = new ArrayList<>();
for (int l = 0; l < d; l++) {
list1D.add(0.0);
}
list2D.add(list1D);
}
list3D.add(list2D);
}
list4D.add(list3D);
}
return list4D;
}
public static INDArray convertListToINDArray(List<List<List<List<Double>>>> list) {
int a = list.size();
int b = list.get(0).size();
int c = list.get(0).get(0).size();
int d = list.get(0).get(0).get(0).size();
double[] flatArray = new double[a * b * c * d];
int index = 0;
for (List<List<List<Double>>> list3D : list) {
for (List<List<Double>> list2D : list3D) {
for (List<Double> list1D : list2D) {
for (Double value : list1D) {
flatArray[index++] = value;
}
}
}
}
return Nd4j.create(flatArray, new int[]{a, b, c, d});
}
public static void storeResultInList(List<List<List<List<Double>>>> list4D, INDArray array, int t) {
for (int i = 0; i < array.size(0); i++) {
for (int j = 0; j < array.size(1); j++) {
list4D.get(t).get(0).get(i).set(j, array.getDouble(i, j));
}
}
}
// private static List<List<List<Double>>> sumSlice(List<List<List<List<Double>>>> data, int t) {
// List<List<List<Double>>> accSlice = new ArrayList<>();
// for (int i = 0; i <= t; i++) {
// List<List<List<Double>>> slice = data.get(i);
// if (accSlice.isEmpty()) {
// accSlice.addAll(slice); // 第一次直接复制
// } else {
// for (int j = 0; j < slice.size(); j++) {
// List<List<Double>> sliceInnerList = slice.get(j);
// for (int k = 0; k < sliceInnerList.size(); k++) {
// List<Double> slices = sliceInnerList.get(k);
// List<Double> accs = accSlice.get(j).get(k);
// for (int l = 0; l < slices.size(); l++) {
// accs.set(l, accs.get(l) + slices.get(l));
// }
// }
// }
// }
// }
// return accSlice;
// }
// private static List<List<List<Double>>> sumSlice(List<List<List<List<Double>>>> data, int t) {
// List<List<List<Double>>> accSlice = new ArrayList<>();
// for (int i = 0; i <= t; i++) {
// List<List<List<Double>>> slice = data.get(i);
// if (accSlice.isEmpty()) {
// accSlice.addAll(slice); // 第一次直接复制
// } else {
// for (int j = 0; j < slice.size(); j++) {
// List<List<Double>> sliceInnerList = slice.get(j);
// List<List<Double>> accInnerList = accSlice.get(j);
// List<List<Double>> resultInnerList = new ArrayList<>();
// for (int k = 0; k < sliceInnerList.size(); k++) {
// List<Double> slices = sliceInnerList.get(k);
// List<Double> accs = accInnerList.get(k);
// List<Double> result = new ArrayList<>();
// for (int l = 0; l < slices.size(); l++) {
// result.add(accs.get(l) + slices.get(l));
// }
// resultInnerList.add(accs);
// }
// accSlice.set(j,resultInnerList);
// }
// }
// }
// return accSlice;
// }
public static List<Double> stringAsDouble(List<String> values){
List<Double> results = new ArrayList<>();
for (String s : values) {
results.add(Double.valueOf(s.trim()));
}
return results;
}
// 方法用于获取左上角左下角右上角和右下角经纬度
public static double[][] getCornerCoordinates(List<double[]> coordinates) {
double minLat = Double.MAX_VALUE;
double maxLat = Double.MIN_VALUE;
double minLon = Double.MAX_VALUE;
double maxLon = Double.MIN_VALUE;
// 遍历坐标列表
for (double[] coord : coordinates) {
double lon = coord[0];
double lat = coord[1];
// 更新最小和最大经纬度值
if (lat < minLat) {
minLat = lat;
}
if (lat > maxLat) {
maxLat = lat;
}
if (lon < minLon) {
minLon = lon;
}
if (lon > maxLon) {
maxLon = lon;
}
}
// 计算左上角左下角右上角和右下角经纬度
double[][] cornerCoordinates = {
{minLon, maxLat}, // 左上角经纬度
{minLon, minLat}, // 左下角经纬度
{maxLon, maxLat}, // 右上角经纬度
{maxLon, minLat} // 右下角经纬度
};
return cornerCoordinates;
}
public static void main(String[] args) throws IOException {
fun();
}
}

View File

@ -10,10 +10,30 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class testMain {
public class testMain2 {
public static void main(String[] args) {
genNc();
Thread sleepThread = new Thread(() -> {
sleepRunnable();
});
// 启动线程
sleepThread.start();
// 主线程继续执行其他操作
System.out.println("主线程继续执行,不等待线程完成");
// genNc();
}
public static void sleepRunnable (){
try {
// 让当前线程睡眠10秒10000毫秒
System.out.println("子线程开始睡眠10秒...");
Thread.sleep(10000);
System.out.println("子线程睡眠结束");
} catch (InterruptedException e) {
System.err.println("睡眠过程中被中断");
e.printStackTrace();
}
}
public static void genNc(){

View File

@ -151,7 +151,7 @@ spring:
connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
datasource:
master:
url: jdbc:mysql://127.0.0.1:3306/mobileterminalanalysissystem?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
url: jdbc:mysql://127.0.0.1:3306/nucleardispersionsystem?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
username: root
password: root
driver-class-name: com.mysql.cj.jdbc.Driver