-
Notifications
You must be signed in to change notification settings - Fork 1
Ubc wrf inclusion #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8f6ebbb
UBC WRF config
SBeairsto fb67897
add handling for UBC WRF hr fields
SBeairsto 348336a
correct variable name
SBeairsto 742bea1
update logging
SBeairsto 99ee681
fix pr time coordinate handling
SBeairsto 3a8cf77
save hr target grid
SBeairsto 453e600
update config
SBeairsto 52d5e10
remove unnecessary variable
SBeairsto 4026633
finish precipitation update for climatexwrf
SBeairsto 63f7d2f
merge main
SBeairsto 51d8ee1
fix accidental deletion
SBeairsto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
|
|
||
| _target_: nc2pt.climatedata.ClimateVariable | ||
| name: "ps" | ||
| alternative_names: ["PSFC"] | ||
| path: ${internal.paths.hr.ps} | ||
| is_west_negative: true | ||
| apply_standardize: false | ||
| apply_normalize: true | ||
| invariant: false | ||
| transform: [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # Land mask used in WRF simulations (HR Model) | ||
|
|
||
| _target_: nc2pt.climatedata.ClimateVariable | ||
| name: "land_mask" | ||
| alternative_names: ["LANDMASK"] | ||
| path: ${internal.paths.hr_invariant} | ||
| is_west_negative: false | ||
| invariant: true | ||
| apply_standardize: false | ||
| apply_normalize: true | ||
| transform: [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # Topography used in WRF simulations (HR Model) | ||
|
|
||
| _target_: nc2pt.climatedata.ClimateVariable | ||
| name: "land_use" | ||
| alternative_names: ["LU_INDEX"] | ||
| path: ${internal.paths.hr_invariant} | ||
| is_west_negative: false | ||
| invariant: true | ||
| apply_standardize: false | ||
| apply_normalize: true | ||
| transform: [] |
11 changes: 11 additions & 0 deletions
11
nc2pt/conf/climate_models/hr_invariant/surface_roughness.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # Topography used in WRF simulations (HR Model) | ||
|
|
||
| _target_: nc2pt.climatedata.ClimateVariable | ||
| name: "surface_roughness" | ||
| alternative_names: ["VAR_SSO"] | ||
| path: ${internal.paths.hr_invariant} | ||
| is_west_negative: false | ||
| invariant: true | ||
| apply_standardize: false | ||
| apply_normalize: true | ||
| transform: [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| _target_: nc2pt.climatedata.ClimateVariable | ||
| name: "ps" | ||
| alternative_names: ["PSFC"] | ||
| path: ${internal.paths.lr.ps} | ||
| is_west_negative: false | ||
| apply_standardize: false | ||
| apply_normalize: true | ||
| invariant: false | ||
| transform: [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| """UBC WRF-specific data loading utilities.""" | ||
|
|
||
| import xarray as xr | ||
| import pandas as pd | ||
| import re | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| def get_ubc_wrf_file_list(pattern: str) -> list: | ||
| """Get file list""" | ||
| import glob | ||
|
|
||
| print("Scanning for files (this may take ~30s over NFS)...") | ||
| files = sorted(glob.glob(pattern, recursive=True)) | ||
| print(f"Found {len(files)} files") | ||
|
|
||
| return files | ||
|
|
||
|
|
||
| def add_ubc_wrf_timesteps(ds): | ||
| """ | ||
| Preprocess WRF metgrid files with dummy Time coordinate. | ||
| Extracts date from filename and creates proper time axis. | ||
| Drops last timestep (corresponding to next month's 00:00:00). | ||
| """ | ||
| # Get filename from dataset encoding | ||
| filepath = ds.encoding.get('source', '') | ||
|
|
||
| # Extract year and month: metgrid_YYYY_MM.nc | ||
| match = re.search(r'metgrid_(\d{4})_(\d{2})\.nc$', filepath) | ||
|
|
||
| if match: | ||
| year, month = match.groups() | ||
| start_date = f"{year}-{month}-01" | ||
|
|
||
| # Drop last timestep (spin-up for next month) | ||
| ds = ds.isel(Times=slice(None, -1)) | ||
|
|
||
| # Create time coordinates for remaining timesteps | ||
| n_times = ds.sizes['Times'] | ||
| time_coords = pd.date_range(start=start_date, periods=n_times, freq='h') | ||
| ds = ds.assign_coords(Times=time_coords) | ||
| else: | ||
| # For invariant fields or unparseable files, drop Time if it's dummy | ||
| if 'Times' in ds.dims and len(ds.Times) <= 2: | ||
| ds = ds.isel(Times=0, drop=True) | ||
|
|
||
| return ds | ||
|
|
||
|
|
||
| def load_ubc_wrf(path: str, engine: str = "netcdf4", chunks: str = "auto") -> xr.Dataset: | ||
| """Load WRF metgrid files with proper time coordinate handling.""" | ||
|
|
||
| if "*" in path or isinstance(path, list): | ||
| if isinstance(path, str): | ||
| file_list = get_ubc_wrf_file_list(path) | ||
| else: | ||
| file_list = path | ||
|
|
||
| print(f"Opening {len(file_list)} files...") | ||
| print("Note: Dropping last timestep of each month (corresponds to M+1 00:00:00)") # Log once here | ||
|
|
||
| ds = xr.open_mfdataset( | ||
| file_list, | ||
| engine=engine, | ||
| parallel=True, | ||
| chunks='auto', | ||
| preprocess=add_ubc_wrf_timesteps, | ||
| combine='nested', | ||
| concat_dim='Times', | ||
| combine_attrs='override', | ||
| data_vars='minimal', | ||
| coords='minimal', | ||
| compat='override' | ||
| ) | ||
| return ds | ||
| else: | ||
| ds = xr.open_dataset(path, engine=engine, chunks=chunks) | ||
| return add_ubc_wrf_timesteps(ds) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a note, but the time coordinate in the COMPRESSED_RAIN ubc wrf files is just 'time', as opposed to the COMPRESSED_SUBSETTED and COMPRESSED_SNOW files where the time coordinate is 'Times'. Maybe it's possible to check the name of the time coordinate and adjust accordingly, so that it can process ubc wrf precip?
(Note that the precip and snow variables sometimes found in COMPRESSED_SUBSETTED are not necessarily correct and are to be ignored, as per chatting with Tim.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just another quick note on the precip files should we choose to consider them--they have a different number of time steps per file than the SUBSETTED files.
For instance, COMPRESSED_RAIN_d03_metgrid_1999_09.nc has 720 timesteps, ranging from 1999-09-01_01:00:00 to 1999-10-01_00:00:00 (no Sept 00:00:00 time step!). As per Tim, this is because the precipitation values are valid for the preceding hour.