Initial commit

This commit is contained in:
Zhongwei Li
2025-11-30 08:35:28 +08:00
commit 3073463598
13 changed files with 735 additions and 0 deletions

View File

@@ -0,0 +1,125 @@
---
name: hydro-forecast
description:
---
# 1 运行环境说明
- 在Julia中运行
- 在julia中首先加载包`using HydroTools`
- 若没有包加载出错,则安装之,`using Pkg; Pkg.add("HydroTools")`
## 说明
先不要立即执行该skills提醒用户输入的数据的格式。用户需要整理好的数据路径即可。
```
```
`model`模型选择
+ MarrMot
+ XAJ
+ TCN
+ LSTM
+ KAN
如果复杂、参数比较多的模型:要求用户输入模型参数`json`文件。
按照如下示例
```json
{
"clumping_index": 0.62,
"LAI_max_o": 4.5,
"LAI_max_u": 2.4,
"z00": 1.33,
"mass_overstory": 35,
"mass_understory": 10,
"root_depth": 0.6,
"α_canopy_vis": 0.035,
"α_canopy_nir": 0.23,
"r_root_decay": 0.95,
"minimum_stomatal_resistance": 150,
"z_canopy_o": 20,
"z_canopy_u": 3,
"g1_w": 8,
"VCmax25": 62.5,
"leaf_resp_co": 0.0015,
"stem_resp_co": 0.0020,
"root_resp_co": 0.0020,
"fine_root_resp_co": 0.003,
"N_leaf": 4.45,
"slope_Vc": 0.33152
}
```
## 1.1 任务说明
### 1.1.1 `framework`
```julia
function hydro_forecast(f; model, outdir)
res = ...
fwrite(res.output, ...)
fwrite(res.gof, ...)
fwrite(res.info_flood, ...)
fwrite(res.dat_flood, ...)
fwrite(res.evaluation, ...)
end
function hydro_forecast(X::AbstractArray, Y::AbstractArray; model::Function, outdir = "OUTPUT")
mkpath(outdir)
res; # return a NamedTuple
end
```
**输入**X, Y, model
**输出**Qsim, GOF, Pass_rate
+ `output`: 三类数据集的输出A DataFrame with columns of `date`, `Qsim`,
+ `gof`: 三类数据的拟合优度
+ `info_flood`: 洪水场次信息,`id`, `time_beg`, `time_end`, `duration`, `Q_peak`, `Q_min`
+ `dat_flood`:洪水场次的驱动数据,
+ `evaluation`: 每个洪水场次上的模拟优度, csv
**绘图**
+ 交给他绘图的函数,数据
**总结**
+ `evaluation`总结模型预报精度 `AI执行`
**内部模块设计**
+ `flood_division`: 采用R语言划分洪水场次
+ `划分数据集`train, test, valid
+ `loss`: 根据拟合优度指标去设计loss例如KGE, NSE, RMSE注意loss越小越优。根据loss去优选模型参数。
+ `evaluation`: 在三种数据集train, test, valid。每个洪水场次的洪峰、峰现时间合格率。
### 1.1.2 `model`水文模型、LSTM、TCN、KAN
```julia
Ysim = Model(X, Y; params, state) # Lux的设计哲学
```
### 1.1.3 文件保存
文件保存采用Julia包`DataFrames``RTableTools`
```julia
using RTableTools
fwrite(df, "out.csv") # df is a DataFrame
```

View File

@@ -0,0 +1,22 @@
using HydroTools
using Dates
lat = 20.0
doy = 120
ws = HourAngleSunSet(lat, doy)
# doy
cal_Rsi_toa(lat, doy)
# date
date = Date(2010, 6, 12)
doy = dayofyear(date)
cal_Rsi_toa(lat, doy)
# datetime
time = DateTime(2010, 6, 12)
doy = dayofyear(date)
Rsi = cal_Rsi_toa(lat, doy) # [MJ d-1 m-2]
MJ2W(Rsi) # [MJ d-1 m-2] to [W m-2]

View File

@@ -0,0 +1,32 @@
---
name: julia-hydrotools
description: 计算短波辐射、长波辐射、潜在蒸散发、日出日落时间、湿度的基本变量处理。
---
# 1 运行环境说明
- 在Julia中运行
- 在julia中首先加载包`using HydroTools`
- 若没有包加载出错,则安装之,`using Pkg; Pkg.add("HydroTools")`
## 1.1 函数说明
- `cal_Rsi_toa(lat, J)`: daily extraterrestrial radiation in MJ m-2 day-1
+ `lat`: latitude in deg
+ `J`: doy of year
> 注意lat和J是scalar
> 如果是vector按照Julia的语法采用`cal_Rsi_toa.(lat, J)`调用
+ 默认返回单位是`MJ d-1`,若想转为`W m-2`,需要调用[MJ2W]函数,告诉用户返回的数字单位
## 1.2 文件保存
文件保存采用Julia包`DataFrames``RTableTools`
```julia
using RTableTools
fwrite(df, "out.csv") # df is a DataFrame
```

View File

@@ -0,0 +1,22 @@
using HydroTools
using Dates
lat = 20.0
doy = 120
ws = HourAngleSunSet(lat, doy)
# doy
cal_Rsi_toa(lat, doy)
# date
date = Date(2010, 6, 12)
doy = dayofyear(date)
cal_Rsi_toa(lat, doy)
# datetime
time = DateTime(2010, 6, 12)
doy = dayofyear(date)
Rsi = cal_Rsi_toa(lat, doy) # [MJ d-1 m-2]
MJ2W(Rsi) # [MJ d-1 m-2] to [W m-2]

View File

@@ -0,0 +1,120 @@
---
name: julia-numerical
description: Execute numerical calculations and mathematical computations using Julia. Use this skill for matrix operations, linear algebra, numerical integration, optimization, statistics, and scientific computing tasks.
---
# Julia Numerical Calculation Skill
This skill enables you to execute numerical calculations using Julia, a high-performance programming language designed for numerical and scientific computing.
## When to Use
Use this skill when you need to:
- Perform matrix operations and linear algebra
- Solve differential equations
- Execute numerical integration or optimization
- Calculate statistical measures
- Handle large-scale numerical computations
- Work with complex mathematical operations
## Setup
Before using this skill, ensure Julia is installed on your system:
```bash
# On macOS (using Homebrew)
brew install julia
# On Linux (Ubuntu/Debian)
sudo apt-get install julia
# On Windows (using Chocolatey)
choco install julia
# Or download from https://julialang.org/downloads/
```
## Basic Examples
### Linear Algebra
```julia
using LinearAlgebra
# Create matrices
A = [1 2; 3 4]
B = [5 6; 7 8]
# Matrix multiplication
C = A * B
# Eigenvalues and eigenvectors
eigenvals, eigenvecs = eigen(A)
# Matrix inverse
A_inv = inv(A)
```
### Numerical Integration
```julia
using QuadGK
# Define a function
f(x) = sin(x) * exp(-x)
# Integrate from 0 to ∞
result, error = quadgk(f, 0, Inf)
```
### Optimization
```julia
using Optim
# Define objective function
f(x) = (x[1] - 2)^2 + (x[2] - 3)^2
# Minimize
result = optimize(f, [0.0, 0.0])
```
### Statistics
```julia
using Statistics
data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# Statistical measures
mean_val = mean(data)
std_val = std(data)
var_val = var(data)
median_val = median(data)
```
## How to Use This Skill
When you ask me to perform a numerical calculation:
1. I'll identify the appropriate Julia packages needed
2. Write Julia code to solve the problem
3. Execute the code
4. Return results and explanations
## Common Julia Packages
- **LinearAlgebra**: Matrix operations and linear algebra
- **Statistics**: Statistical functions
- **QuadGK**: Numerical integration
- **Optim**: Optimization algorithms
- **DifferentialEquations**: Solving differential equations
- **Plots**: Visualization
- **Distributions**: Probability distributions
- **Random**: Random number generation
## Notes
- Julia is JIT-compiled, so first runs may include compilation time
- Use `.jl` files for organizing longer scripts
- Install packages with `using Pkg; Pkg.add("PackageName")`
- Results are returned as Julia objects that are converted to readable format

View File

@@ -0,0 +1,155 @@
# Julia Numerical Calculation Examples
# This file contains common numerical computation patterns
# ============================================================================
# Linear Algebra Examples
# ============================================================================
function linear_algebra_examples()
using LinearAlgebra
println("=== Linear Algebra Examples ===")
# Matrix creation and basic operations
A = [1 2 3; 4 5 6; 7 8 10]
b = [1, 2, 3]
println("Matrix A:")
println(A)
# Solve linear system Ax = b
x = A \ b
println("\nSolution to Ax = b:")
println(x)
# Eigenvalues
eigenvals, eigenvecs = eigen(A)
println("\nEigenvalues:")
println(eigenvals)
# Singular value decomposition
U, S, V = svd(A)
println("\nSingular values:")
println(S)
# Determinant and norm
println("\nDeterminant: ", det(A))
println("Frobenius norm: ", norm(A))
end
# ============================================================================
# Numerical Integration Examples
# ============================================================================
function integration_examples()
using QuadGK
println("\n=== Numerical Integration Examples ===")
# Integrate sin(x) from 0 to π
f1(x) = sin(x)
result1, error1 = quadgk(f1, 0, π)
println("∫sin(x)dx from 0 to π = ", result1)
println("Estimated error: ", error1)
# Integrate exp(-x^2) from -∞ to ∞ (Gaussian)
f2(x) = exp(-x^2)
result2, error2 = quadgk(f2, -Inf, Inf)
println("\n∫exp(-x²)dx from -∞ to ∞ = ", result2)
println("Theoretical value: ", sqrt(π))
# Integrate 1/(1+x^2) from 0 to 1
f3(x) = 1/(1 + x^2)
result3, error3 = quadgk(f3, 0, 1)
println("\n∫1/(1+x²)dx from 0 to 1 = ", result3)
println("Theoretical value (π/4): ", π/4)
end
# ============================================================================
# Optimization Examples
# ============================================================================
function optimization_examples()
using Optim
println("\n=== Optimization Examples ===")
# Simple quadratic function
f(x) = (x[1] - 2)^2 + (x[2] - 3)^2
result = optimize(f, [0.0, 0.0])
println("Minimize f(x,y) = (x-2)² + (y-3)²")
println("Minimum found at: ", Optim.minimizer(result))
println("Minimum value: ", Optim.minimum(result))
# Rosenbrock function (more challenging)
rosenbrock(x) = (1 - x[1])^2 + 100(x[2] - x[1]^2)^2
result2 = optimize(rosenbrock, [0.0, 0.0])
println("\nMinimize Rosenbrock function")
println("Minimum found at: ", Optim.minimizer(result2))
println("Minimum value: ", Optim.minimum(result2))
end
# ============================================================================
# Statistics Examples
# ============================================================================
function statistics_examples()
using Statistics
println("\n=== Statistics Examples ===")
data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20]
println("Data: ", data)
println("\nStatistical measures:")
println("Mean: ", mean(data))
println("Median: ", median(data))
println("Standard deviation: ", std(data))
println("Variance: ", var(data))
println("Minimum: ", minimum(data))
println("Maximum: ", maximum(data))
println("Range: ", maximum(data) - minimum(data))
# Quantiles
println("\nQuantiles:")
println("25th percentile: ", quantile(data, 0.25))
println("50th percentile: ", quantile(data, 0.50))
println("75th percentile: ", quantile(data, 0.75))
end
# ============================================================================
# Root Finding Examples
# ============================================================================
function root_finding_examples()
using Roots
println("\n=== Root Finding Examples ===")
# Find root of f(x) = x^3 - 2
f(x) = x^3 - 2
root = find_zero(f, 1.0)
println("Root of x³ - 2 = 0: ", root)
println("Verification: f(root) = ", f(root))
# Find root of f(x) = sin(x) - 0.5
f2(x) = sin(x) - 0.5
root2 = find_zero(f2, 0.5)
println("\nRoot of sin(x) - 0.5 = 0: ", root2)
println("Verification: f(root) = ", f2(root2))
end
# ============================================================================
# Main execution
# ============================================================================
if abspath(PROGRAM_FILE) == @__FILE__
linear_algebra_examples()
integration_examples()
optimization_examples()
statistics_examples()
root_finding_examples()
end

View File

@@ -0,0 +1,34 @@
# Basic Julia numerical test
using LinearAlgebra
using Statistics
println("Testing Julia Numerical Calculation Skill")
println("==========================================\n")
# Test 1: Basic arithmetic
println("Test 1: Basic Arithmetic")
result = 2 + 2 * 3
println("2 + 2 * 3 = ", result)
# Test 2: Vector operations
println("\nTest 2: Vector Operations")
v1 = [1, 2, 3]
v2 = [4, 5, 6]
dot_product = dot(v1, v2)
println("dot([1,2,3], [4,5,6]) = ", dot_product)
# Test 3: Matrix operations
println("\nTest 3: Matrix Operations")
A = [1 2; 3 4]
println("Matrix A:")
println(A)
println("det(A) = ", det(A))
# Test 4: Statistics
println("\nTest 4: Statistics")
data = [10, 20, 30, 40, 50]
println("Data: ", data)
println("mean = ", mean(data))
println("std = ", std(data))
println("\n✓ All basic tests passed!")

View File

@@ -0,0 +1,53 @@
---
name: typst-physica
description: typst公式中的微分、偏微分方程编写latex公式转typst。
---
# 引用包
应在typst文档的开头引用包。公式编写、文档排版依赖`modern-cug-report`
用于如果已经引用了`modern-cug-report`,则无需再重复添加了。
```typst
#import "@local/modern-cug-report:0.1.3": *
#show: doc => template(doc, footer: "CUG水文气象学2025", header: "")
```
# 偏微分方程
- `(∂ theta) / (∂ t)`
`\frac{\partial \theta}{\partial t}`采用typst编写会非常简单`pdv(theta, t)`
```typst
(partial.diff theta) / (partial.diff t) // 是错误写法
pdv(theta, t) // 正确写法
```
- `(d theta) / (d t)`则是:`dv(theta, t)`
# text
typst公式中的本文需要使用引号
```typst
q_(infiltration) // 错误
q_("infiltration") // 正确
```
# fraction
- latex的`\frac{y}{x}`写成typst则是`y/x`
若分子、分母有多个变量则用括号括起来。例如latex的`\frac{y z}{x}`写成typst则是`(y z) / x`
# 排版
- 一级标题之前空两行,凸显章节的层次感。
- 第一个一级标题,不用空两行。

View File

@@ -0,0 +1,40 @@
// Copyright 2023 Leedehai
// Use of this code is governed by a MIT license in the LICENSE.txt file.
// For a manual on this package, see physica-manual.pdf.
#import "@local/modern-cug-report:0.1.3": *
#show: doc => template(doc, footer: "CUG水文气象学2025", header: "")
// #import "physica.typ": *
#show: super-T-as-transpose // Render "..^T" as transposed matrix
$
A^T, curl vb(E) = - pdv(vb(B), t),
quad
tensor(Lambda, +mu, -nu) = dmat(1, RR),
quad
f(x,y) dd(x, y),
quad
dd(vb(x), y, [3]),
quad
dd(x, y, 2, d: Delta, p: and),
quad
dv(phi, t, d: upright(D)) = pdv(phi, t) + vb(u) grad phi \
H(f) = hmat(f; x, y; delim: "[", big: #true),
quad
vb(v^a) = sum_(i=1)^n alpha_i vu(u^i),
quad
Set((x, y), pdv(f, x, y, [2,1]) + pdv(f, x, y, [1,2]) < epsilon) \
-1/c^2 pdv(, t, 2)psi + laplacian psi = (m^2c^2) / hbar^2 psi,
quad
ket(n^((1))) = sum_(k in.not D) mel(k^((0)), V, n^((0))) / (E_n^((0)) - E_k^((0))) ket(k^((0))),
quad
integral_V dd(V) (pdv(cal(L), phi) - partial_mu (pdv(cal(L), (partial_mu phi)))) = 0 \
dd(s, 2) = -(1-(2G M)/r) dd(t, 2) + (1-(2G M)/r)^(-1) dd(r, 2) + r^2 dd(Omega, 2)
$
$
"clk:" & signals("|1....|0....|1....|0....|1....|0....|1....|0..", step: #0.5em) \
"bus:" & signals(" #.... X=... ..... ..... X=... ..... ..... X#.", step: #0.5em)
$

View File

@@ -0,0 +1,36 @@
#import "@local/modern-cug-report:0.1.3": *
#show: doc => template(doc, footer: "CUG水文气象学2025", header: "")
== 1 Richards方程
Richards方程
$ pdv(theta, t) = nabla dot [K(theta) nabla H] + S $
其中:
- $theta$:体积含水量 [L^3/L^3]
- $t$:时间 [T]
- $S$:源汇项 [1/T]
总水头 $H$ 由基质势 $h$ 和重力势 $z$ 组成:
$ H = h + z $
== 2 质量守恒定律
对于土壤控制体积,质量守恒方程为:
$ pdv(rho theta, t) + nabla dot (rho q) = rho S $
假设水密度 $rho$ 为常数,简化为:
$ pdv(theta, t) + nabla dot q = S $
== 3 上边界层条件
上边界通常受大气条件控制,主要包括:
*降雨入渗条件:*
$ -K(theta) pdv(H, z) |_(z=0) = q_("infiltration") $
*蒸发条件:*
$ -K(theta) pdv(H, z) |_(z=0) = q_("evaporation") $