Update README.md
Browse files
README.md
CHANGED
@@ -5,62 +5,72 @@ language:
|
|
5 |
tags:
|
6 |
- climate
|
7 |
---
|
8 |
-
# Convection Parameterization in CAM
|
9 |
|
10 |
-
|
11 |
-
Once a useable release is produced it will be tagged.
|
12 |
|
13 |
-
|
14 |
-
This repository contains code as part of an effort to deploy machine learning (ML) models of geophysical parameterisations into the [Community Earth System Model (CESM)](https://www.cesm.ucar.edu/).
|
15 |
-
This work is part of the [M<sup>2</sup>LInES](https://m2lines.github.io/) project aiming to improve performance of climate models using ML models for subgrid parameterizations.
|
16 |
|
17 |
-
|
18 |
-
The
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
|
25 |
-
|
|
|
|
|
|
|
|
|
26 |
|
27 |
-
|
28 |
-
We plan to evaluate performance using SCAM in the gateIII configuration for tropical convection in a similar manner described by the [SCAM6 pulication in JAMES](https://agupubs.onlinelibrary.wiley.com/doi/10.1029/2018MS001578).
|
29 |
-
This will compare model performance to data from an intense observation period (IOP) described in an [AMS publication](https://journals.ametsoc.org/view/journals/atsc/36/1/1520-0469_1979_036_0053_saposs_2_0_co_2.xml).
|
30 |
|
31 |
-
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
```
|
37 |
-
βββ NN_module
|
38 |
-
βΒ Β βββ ...
|
39 |
-
βββ torch_nets
|
40 |
-
βββ ...
|
41 |
```
|
42 |
|
|
|
43 |
|
|
|
|
|
|
|
44 |
|
45 |
-
|
|
|
46 |
|
47 |
-
|
48 |
-
|
|
|
|
|
49 |
|
50 |
-
|
|
|
|
|
|
|
51 |
|
52 |
-
|
53 |
|
54 |
-
|
55 |
-
The directory contains the PyTorch versions of the neural networks we are interested in.
|
56 |
|
|
|
|
|
|
|
|
|
57 |
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
-
|
61 |
-
|
62 |
|
63 |
-
|
64 |
-
|
65 |
-
Once ready assign a reviewer and request a code review.
|
66 |
-
Merging should _only_ be performed once a code review has taken place.
|
|
|
5 |
tags:
|
6 |
- climate
|
7 |
---
|
|
|
8 |
|
9 |
+
# CAM-ML-YOG-v0: Machine Learning-based Convection Parameterization
|
|
|
10 |
|
11 |
+
This repository contains a machine learning-based implementation of the convection parameterization in CAM (Community Atmosphere Model), leveraging PyTorch.
|
|
|
|
|
12 |
|
13 |
+
## Model Overview
|
14 |
+
The model is a PyTorch adaptation of the original Fortran-based convection parameterization in CAM. It simulates subgrid-scale convection processes within a climate model and was developed to improve accuracy and efficiency.
|
15 |
|
16 |
+
### Key Features:
|
17 |
+
- **Architecture**: The model is built with custom neural network layers as seen in [torch_nets/models.py](https://github.com/m2lines/convection-parameterization-in-CAM/blob/main/torch_nets/models.py).
|
18 |
+
- **Data Handling**: Fortran-derived model weights are seamlessly converted to PyTorch, ensuring compatibility with existing CAM configurations.
|
19 |
+
- **Training and Fine-tuning**: The model can be retrained or fine-tuned using custom climate data.
|
20 |
|
21 |
+
## Model Conversion and Upload
|
22 |
+
This model was converted from the original CAM implementation by extracting the weights from Fortran and converting them into a PyTorch-compatible format. This conversion process involved the following steps:
|
23 |
+
1. **Extract Fortran Weights**: Weights were extracted from the original CAM Fortran implementation.
|
24 |
+
2. **Convert to PyTorch**: Using custom scripts, the weights were converted into a format compatible with PyTorch models.
|
25 |
+
3. **Upload to Hugging Face**: The model was validated and uploaded to the Hugging Face Model Hub.
|
26 |
|
27 |
+
## Usage
|
|
|
|
|
28 |
|
29 |
+
To use the model in PyTorch, first install the necessary dependencies:
|
30 |
|
31 |
+
```bash
|
32 |
+
pip install torch huggingface_hub
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
```
|
34 |
|
35 |
+
Then, download and load the model as follows:
|
36 |
|
37 |
+
```python
|
38 |
+
from huggingface_hub import hf_hub_download
|
39 |
+
import torch
|
40 |
|
41 |
+
# Download model weights
|
42 |
+
model_path = hf_hub_download(repo_id="ICCS/cam-ml-yog-v0", filename="model.pth")
|
43 |
|
44 |
+
# Load model (replace 'YourModel' with the appropriate model class from torch_nets/models.py)
|
45 |
+
model = YourModel()
|
46 |
+
model.load_state_dict(torch.load(model_path))
|
47 |
+
model.eval()
|
48 |
|
49 |
+
# Use the model for predictions
|
50 |
+
input_data = ... # Prepare your climate input data
|
51 |
+
output = model(input_data)
|
52 |
+
```
|
53 |
|
54 |
+
### Fine-tuning
|
55 |
|
56 |
+
The model is designed to be easily fine-tuned using domain-specific climate data:
|
|
|
57 |
|
58 |
+
```python
|
59 |
+
# Fine-tune the model
|
60 |
+
optimizer = torch.optim.Adam(model.parameters(), lr=1e-4)
|
61 |
+
loss_fn = torch.nn.MSELoss()
|
62 |
|
63 |
+
# Example training loop
|
64 |
+
for epoch in range(epochs):
|
65 |
+
optimizer.zero_grad()
|
66 |
+
output = model(input_data)
|
67 |
+
loss = loss_fn(output, target_data)
|
68 |
+
loss.backward()
|
69 |
+
optimizer.step()
|
70 |
+
```
|
71 |
|
72 |
+
## Weight Updates
|
73 |
+
Please note that weight updates may be necessary as improvements are made to the model (see [Issue #66](https://github.com/m2lines/convection-parameterization-in-CAM/issues/66)).
|
74 |
|
75 |
+
## References
|
76 |
+
For more details on the original implementation and how to contribute to the modelβs development, see the [GitHub repository](https://github.com/m2lines/convection-parameterization-in-CAM).
|
|
|
|