File size: 3,013 Bytes
b8eeb77 ec86bf7 c9a76e6 ec86bf7 c9a76e6 ec86bf7 c9a76e6 ec86bf7 c9a76e6 ec86bf7 c9a76e6 ec86bf7 c9a76e6 ec86bf7 c9a76e6 ec86bf7 c9a76e6 ec86bf7 c9a76e6 ec86bf7 c9a76e6 ec86bf7 c9a76e6 ec86bf7 c9a76e6 ec86bf7 c9a76e6 ec86bf7 c9a76e6 ec86bf7 c9a76e6 ec86bf7 c9a76e6 ec86bf7 c9a76e6 ec86bf7 c9a76e6 ec86bf7 c9a76e6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
---
license: mit
language:
- en
tags:
- climate
---
# CAM-ML-YOG-v0: Machine Learning-based Convection Parameterization
This repository contains a machine learning-based implementation of the convection parameterization in CAM (Community Atmosphere Model), leveraging PyTorch.
## Model Overview
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.
### Key Features:
- **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).
- **Data Handling**: Fortran-derived model weights are seamlessly converted to PyTorch, ensuring compatibility with existing CAM configurations.
- **Training and Fine-tuning**: The model can be retrained or fine-tuned using custom climate data.
## Model Conversion and Upload
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:
1. **Extract Fortran Weights**: Weights were extracted from the original CAM Fortran implementation.
2. **Convert to PyTorch**: Using custom scripts, the weights were converted into a format compatible with PyTorch models.
3. **Upload to Hugging Face**: The model was validated and uploaded to the Hugging Face Model Hub.
## Usage
To use the model in PyTorch, first install the necessary dependencies:
```bash
pip install torch huggingface_hub
```
Then, download and load the model as follows:
```python
from huggingface_hub import hf_hub_download
import torch
# Download model weights
model_path = hf_hub_download(repo_id="ICCS/cam-ml-yog-v0", filename="model.pth")
# Load model (replace 'YourModel' with the appropriate model class from torch_nets/models.py)
model = YourModel()
model.load_state_dict(torch.load(model_path))
model.eval()
# Use the model for predictions
input_data = ... # Prepare your climate input data
output = model(input_data)
```
### Fine-tuning
The model is designed to be easily fine-tuned using domain-specific climate data:
```python
# Fine-tune the model
optimizer = torch.optim.Adam(model.parameters(), lr=1e-4)
loss_fn = torch.nn.MSELoss()
# Example training loop
for epoch in range(epochs):
optimizer.zero_grad()
output = model(input_data)
loss = loss_fn(output, target_data)
loss.backward()
optimizer.step()
```
## Weight Updates
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)).
## References
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).
|