Skip to content

Commit

Permalink
fix(doc): improve python/resampling/resampling_hads.py documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
spool committed Feb 2, 2024
1 parent 15cab81 commit 896f843
Showing 1 changed file with 39 additions and 24 deletions.
63 changes: 39 additions & 24 deletions python/resampling/resampling_hads.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,31 @@
import os
from os import cpu_count

import netCDF4
import pandas as pd
import scipy
import xarray as xr # requires rioxarray extension
from tqdm import tqdm


def enforce_date_dropping(
raw_data: xr.Dataset, converted_data: xr.Dataset
) -> xr.Dataset:
"""
Workaround to avoid convert_calendar misbehavior with monthly data files.
For leap years, the conversion assigns dropped data to the previous date instead of deleting it.
Here we manually delete those dates to avoid duplicates later in the pipeline.
Args:
raw_data (xr.Dataset): The original data.
converted_data (xr.Dataset): The data after conversion.
Returns:
xr.Dataset: The converted data with specific dates dropped.
"""Workaround convert_calendar misbehavior with monthly data files.
For leap years, the conversion assigns dropped data to the previous
date instead of deleting it. Here we manually delete those dates to
avoid duplicates later in the pipeline.
Parameters
----------
raw_data
The original data.
converted_data
The data after conversion.
Returns
-------
xr.Dataset
The converted data with specific dates dropped.
"""
month_day_drop = {(1, 31), (4, 1), (6, 1), (8, 1), (10, 1), (12, 1)}
time_values = pd.DatetimeIndex(raw_data.coords["time"].values)
Expand All @@ -56,16 +59,28 @@ def enforce_date_dropping(
return converted_data


def resample_hadukgrid(x):
"""
Resamples the UKHADs data to match UKCP18 data both spatially and temporally
and saves the resampled data to the output directory.
inputs:
x: list of inputs
x[0]: file to be resampled
x[1]: x_grid
x[2]: y_grid
x[3]: output_dir
def resample_hadukgrid(x: list) -> int:
"""Resample UKHADs data to match UKCP18 spatially and temporally.
Results are saved to the output directory.
Parameters
----------
x
x[0]: file to be resampled
x[1]: x_grid
x[2]: y_grid
x[3]: output_dir
Returns
-------
bool
Whether function was a success (True) or not (False).
Raises
------
Exception
Generic execption for any errors raised.
"""
try:
# due to the multiprocessing implementations inputs come as list
Expand Down

0 comments on commit 896f843

Please sign in to comment.