Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
67a043a
rename daily notebooks
rogerkuou Jul 15, 2026
5b3d0df
add draft example notebook for watervapor
rogerkuou Jul 15, 2026
5545f1f
check empty dataset in prediction
rogerkuou Jul 16, 2026
0deab33
update hourly watervapor notebook
rogerkuou Jul 16, 2026
1dea21d
initiate loss as zero tensor
rogerkuou Jul 16, 2026
3ac2df4
update notebook
rogerkuou Jul 16, 2026
3e55c64
changed loss to float
rogerkuou Jul 21, 2026
c5a9337
Merge branch 'main' into 73_water_vapor_notebook
rogerkuou Aug 4, 2026
9e289e3
rename patch with crop in dataset and predict module
SarahAlidoost Aug 26, 2026
9c523e5
fix geo_embeding in the model
SarahAlidoost Aug 26, 2026
83a0a20
remove spatial transfomer from the model
SarahAlidoost Aug 26, 2026
63ba353
add some model improvemnets
SarahAlidoost Aug 27, 2026
222f2e5
uncomment groupnorm in decoder
SarahAlidoost Aug 27, 2026
0ff075f
improve docstring
SarahAlidoost Aug 28, 2026
1fb8ba0
remove patch from dataset, adjust api in source modules
SarahAlidoost Aug 28, 2026
09c55db
fix linters
SarahAlidoost Aug 28, 2026
814f151
fix tests
SarahAlidoost Aug 28, 2026
76842bd
fix docstring and comments
SarahAlidoost Aug 28, 2026
e9cdd56
fix nbs
SarahAlidoost Aug 28, 2026
628507b
add model.train in train loop (a bug)
SarahAlidoost Aug 31, 2026
88382ce
Merge branch 'main' into fix_geo_embeding
SarahAlidoost Sep 2, 2026
078121f
update scripts
SarahAlidoost Sep 2, 2026
b59ad45
fix run_best_tuned_model script
SarahAlidoost Sep 2, 2026
eb53bef
rerun example_tuning nb
SarahAlidoost Sep 2, 2026
d5000e9
Merge branch 'main' into 73_water_vapor_notebook
rogerkuou Sep 2, 2026
6e3a31d
Merge branch 'fix_geo_embeding' into 73_water_vapor_notebook
rogerkuou Sep 7, 2026
45ccda3
re-structure training
rogerkuou Sep 7, 2026
6ffc51f
rename_notebook
rogerkuou Sep 7, 2026
689c94b
add example notebook for daily watervapor data
rogerkuou Sep 7, 2026
0b28ed6
update unit name
rogerkuou Sep 8, 2026
e04c2f4
init hourly watervapo notebook
rogerkuou Sep 8, 2026
6444772
initial water vapor hourly training
rogerkuou Sep 8, 2026
f0409a7
add commented out code section for generating 0.5 deg lsm
rogerkuou Sep 8, 2026
33795d1
solve confilcts
rogerkuou Sep 10, 2026
54e17d6
95 watervapor lsm util func (#96)
rogerkuou Sep 14, 2026
e0eefad
Apply suggestion from @SarahAlidoost
rogerkuou Sep 14, 2026
8018eff
solve conficts
rogerkuou Sep 14, 2026
6b7dda2
change spatial_patch_size to spatial_crop_size
rogerkuou Sep 15, 2026
1150732
remove duplicated cell
rogerkuou Sep 15, 2026
5963654
remove unuser import
rogerkuou Sep 15, 2026
a06120b
use jan for hourly notebook
rogerkuou Sep 15, 2026
34dc161
update parameters in hourly notebook
rogerkuou Sep 15, 2026
9feec31
rerun hourly notenook
rogerkuou Sep 15, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions climanet/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ def predict_monthly_var(
model.to(device)
model.eval()

# Length of the dataset should >=1
if len(dataset) < 1:
raise ValueError("The dataset is empty. Please provide a non-empty dataset.")

use_cuda = device == "cuda"
dataloader = DataLoader(
dataset,
Expand Down
30 changes: 29 additions & 1 deletion climanet/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,9 @@ def data_preparation(

# rechunk data
input_da = input_da.chunk({"M": 1, "T": -1, "lat": 100, "lon": 100})
input_da_nan_mask = input_da_nan_mask.chunk({"M": 1, "T": -1, "lat": 100, "lon": 100})
input_da_nan_mask = input_da_nan_mask.chunk(
{"M": 1, "T": -1, "lat": 100, "lon": 100}
)
monthly_da = monthly_da.chunk({"M": 1, "lat": 100, "lon": 100})
padded_days_mask = padded_days_mask.chunk({"M": 1})
time_features = time_features.chunk({"M": 1})
Expand Down Expand Up @@ -891,3 +893,29 @@ def read_st_data(data_path=".", var_name="tos"):

# if one of the datasets is None, we need to compute them
return input_da, input_da_nan_mask, monthly_da, padded_days_mask, time_features


def coarsen_land_mask(
input_lsm: xr.DataArray | xr.Dataset, coarse_factor: int = 2, threshold: float = 0.5
):
"""Coarsen spatial resolution of land mask data by coarse_factor.

It also applies a threshold to values outside of [0,1].
see https://confluence.ecmwf.int/spaces/FUG/pages/673550380/Section+2A.1.3.1+Land-Sea+mask

Args:
input_lsm (xarray.DataArray): Land-sea mask from ERA5-Land data.
coarse_factor (int, optional): Factor by which to coarsen the resolution. Defaults to 2.
threshold (float, optional): Threshold for determining mask value. Defaults to 0.5.

Returns:
xarray.DataArray | xarray.Dataset : Coarse land-sea mask.
"""
coarse_lsm = input_lsm.coarsen(
lat=coarse_factor, lon=coarse_factor, boundary="trim"
).mean()

# Apply threshold
coarse_lsm = coarse_lsm >= threshold

return coarse_lsm
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,14 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"id": "ca9b6c44-1f4a-4ff2-b15e-7b330bbc501e",
"metadata": {
"jp-MarkdownHeadingCollapsed": true
},
"outputs": [],
"source": [
"# read data\n",
"# read data \n",
"data_dir = f\"{run_dir}/data_train\"\n",
"input_da, input_da_nan_mask, monthly_da, padded_days_mask, time_features = read_st_data(data_path=data_dir, var_name=var_name)"
]
Expand Down Expand Up @@ -259,12 +259,12 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"id": "d02dace1-c194-49bd-a283-94f7a04e666b",
"metadata": {},
"outputs": [],
"source": [
"# read data\n",
"# read data \n",
"data_dir = f\"{run_dir}/data_validation\"\n",
"input_da, input_da_nan_mask, monthly_da, padded_days_mask, time_features = read_st_data(data_path=data_dir, var_name=var_name)"
]
Expand Down Expand Up @@ -475,19 +475,19 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 18,
"id": "4c30511a-49fc-4a4d-8bfc-61ec3857fde0",
"metadata": {},
"outputs": [],
"source": [
"# read data\n",
"# read data \n",
"data_dir = f\"{run_dir}/data_test\"\n",
"input_da, input_da_nan_mask, monthly_da, padded_days_mask, time_features = read_st_data(data_path=data_dir, var_name=var_name)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 20,
"id": "ac99fdf5-dfd8-44a0-957b-dea177ac92a1",
"metadata": {},
"outputs": [
Expand All @@ -503,7 +503,7 @@
}
],
"source": [
"spatial_crop_size = monthly_da.shape[1:] # the whole dataset\n",
"spatial_patch_size = monthly_da.shape[1:] # the whole dataset \n",
"\n",
"dataset_test = STDataset(\n",
" input_da=input_da,\n",
Expand All @@ -513,7 +513,7 @@
" time_features=time_features,\n",
" land_mask=lsm_subset[\"lsm\"],\n",
" model_patch_size=patch_size,\n",
" crop_size=(1, *spatial_crop_size),\n",
" crop_size=(1, *spatial_crop_size), \n",
" stride=None, # no stride in inference\n",
" sh_embed_dim=96,\n",
" sh_order_L = 10,\n",
Expand Down Expand Up @@ -574,7 +574,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 23,
"id": "7c2deb40-bee8-4973-80f0-9d9485eabf0c",
"metadata": {},
"outputs": [
Expand All @@ -591,7 +591,7 @@
"# inference on test data, verbose is True\n",
"predictions = predict_monthly_var(\n",
" model=f\"{run_dir}/best_model.pth\",\n",
" dataset=dataset_test,\n",
" dataset=dataset_test, \n",
" dataloader_config=dataloader_config,\n",
" prediction_config=prediction_config,\n",
" run_dir=run_dir,\n",
Expand Down Expand Up @@ -647,7 +647,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 27,
"id": "7ba5d204-aefc-4103-8475-c802c603ad3f",
"metadata": {},
"outputs": [
Expand All @@ -668,7 +668,7 @@
"\n",
"ocean = ~lsm_subset[\"lsm\"].values\n",
"masked_err_baseline = err_baseline.where(ocean)\n",
"masked_err_predictions = err_predictions.where(ocean)\n",
"masked_err_predictions = err_predictions.where(ocean) \n",
"\n",
"plot_results(masked_err_baseline, masked_err_predictions, label=\"error K\", title=(\"err_Baseline\", \"err_Prediction\"), error=True)"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -670,9 +670,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "climanet",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "climanet"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -684,7 +684,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.14.6"
"version": "3.11.14"
}
},
"nbformat": 4,
Expand Down
File renamed without changes.
Loading