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
import xarray as xr | |
from pathlib import Path | |
from tqdm import tqdm | |
import xesmf as xe | |
def convert_to_same_grid(reference_ds: xr.Dataset, ds: xr.Dataset, method: str="nearest_s2d") -> xr.Dataset: | |
""" Use xEMSF package to regrid ds to the same grid as reference_ds """ | |
assert ("lat" in reference_ds.dims) & ( | |
"lon" in reference_ds.dims |
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
import geopandas as gpd | |
import xarray as xr | |
from pathlib import Path | |
import matplotlib.pyplot as plt | |
def load_latlon_points(data_dir: Path) -> gpd.GeoSeries: | |
static = xr.open_dataset(data_dir / "camels_static.nc") | |
d = static[["gauge_lat", "gauge_lon"]].to_dataframe() | |
points = gpd.GeoSeries( |
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
time | vci | |
---|---|---|
2001-10-10 | 24.559374350223557 | |
2001-10-20 | 20.51960470075651 | |
2001-10-31 | 19.518919914072242 | |
2001-11-10 | 20.878032524608127 | |
2001-11-20 | 24.47625265366251 | |
2001-11-30 | 28.31497249158752 | |
2001-12-10 | 44.594910789294936 | |
2001-12-20 | 65.47588757067652 | |
2001-12-31 | 81.7176422592538 |
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
conda create -n gpy --yes | |
conda install -c conda-forge pytorch xarray=0.16 pytorch torchvision cudatoolkit --yes | |
conda install -c conda-forge netcdf4 numba tqdm jupyterlab tensorboard ipython pip ruamel.yaml descartes statsmodels scikit-learn black mypy --yes | |
pip install gpytorch |
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
from typing import Dict | |
import xarray as xr | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import seaborn as sns | |
from pathlib import Path | |
def scatter_plot(obs: np.ndarray, sim: np.ndarray, ax = None, scatter_kwargs: Dict = {"marker": "x", "color": "C0", "alpha": 0.3}): | |
if ax is None: | |
f, ax = plt.subplots(figsize=(6, 6)) |
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
from typing import Tuple, Any, Union, List | |
import pandas as pd | |
import datetime as dt | |
from pathlib import Path | |
import numpy as np | |
def find_nearest(array: Union[np.ndarray, List[float]], value: float) -> Tuple[Any, int]: | |
# https://stackoverflow.com/a/2566508/9940782 | |
array = np.asarray(array) |
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
# conda install -c conda-forge xarray --yes | |
import xarray as xr | |
import pandas as pd | |
from pathlib import Path | |
import matplotlib.pyplot as plt | |
data_dir = Path("path/to/data") | |
# open the data | |
dynamic = xr.open_dataset(data_dir / "ALL_dynamic_ds.nc") |
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
import napari | |
import xarray as xr | |
from pathlib import Path | |
data_dir = Path("/path/to/data") | |
# open data | |
ds = xr.open_dataset(data_dir / "data.nc") | |
da = ds["VARIABLE_NAME"] |
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
conda create -n napari python=3.8 --yes | |
conda activate napari | |
conda install -c conda-forge napari xarray netcdf4 ipython pip | |
pip install 'napari[all]' |
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
frmo typing import Dict, Union | |
import xarray as xr | |
import pandas as pd | |
from pathlib import Path | |
def save_scaler(scaler: Dict[str, Union[xr.Dataset, pd.DataFrame]], run_dir: Path) -> None: | |
"""Save scaler to disk as separate netcdf files""" | |
scaler_dir = run_dir / "train_data" | |
for k, v in scaler.items(): |