diff --git a/docs/examples/ts2img.ipynb b/docs/examples/ts2img.ipynb index 389d151..89b583c 100644 --- a/docs/examples/ts2img.ipynb +++ b/docs/examples/ts2img.ipynb @@ -27,21 +27,13 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 25, "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/home/wpreimes/shares/home/code/repurpose/src/repurpose/process.py:6: UserWarning: Numpy is already imported. Environment variables set in repurpose.utils wont have any effect!\n", - " warnings.warn(\"Numpy is already imported. Environment variables set in \"\n" - ] - }, { "data": { - "text/plain": "" + "text/plain": "" }, - "execution_count": 9, + "execution_count": 25, "metadata": {}, "output_type": "execute_result" }, @@ -63,7 +55,8 @@ "import numpy as np\n", "from repurpose.process import rootdir\n", "\n", - "source_grid = load_grid(os.path.join(rootdir(), \"docs\", \"examples\", \"assets\", \"warp_subgrid_AUT.nc\"))\n", + "source_grid = load_grid(os.path.join(rootdir(), \"docs\", \"examples\",\n", + " \"assets\", \"warp_subgrid_AUT.nc\"))\n", "y = np.arange(46.3, 49.2, 0.1)\n", "x = np.arange(9.2, 17.4, 0.1)\n", "z = np.full((y.size-1, x.size-1), np.nan)\n", @@ -76,7 +69,8 @@ "plt.ylabel('Latitude [°N]')\n", "\n", "legend = [Line2D([0], [0], color='k', label='Target (image) Grid, Regular 0.1°'),\n", - " Line2D([0], [0], marker='o', color='w', markerfacecolor='c', label='Source (timeseries) Grid, Irregular 12.5 km')]\n", + " Line2D([0], [0], marker='o', color='w', markerfacecolor='c',\n", + " label='Source (timeseries) Grid, Irregular 12.5 km')]\n", "plt.legend(handles=legend, loc='upper left')" ], "metadata": { @@ -101,7 +95,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 26, "id": "406f83ff-7725-4710-8048-1a2311b23963", "metadata": { "tags": [] @@ -112,7 +106,9 @@ "\n", "class Reader:\n", " def __init__(self):\n", - " self.df = pd.read_csv(os.path.join(rootdir(), \"docs\", \"examples\", \"assets\", \"SM_AUT.csv\"), index_col=[0, 1], parse_dates=True)\n", + " self.df = pd.read_csv(\n", + " os.path.join(rootdir(), \"docs\", \"examples\", \"assets\", \"SM_AUT.csv\"),\n", + " index_col=[0, 1], parse_dates=True)\n", " self.grid: CellGrid = source_grid\n", "\n", " def read(self, lon, lat):\n", @@ -139,13 +135,13 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 27, "outputs": [ { "data": { - "text/plain": "" + "text/plain": "" }, - "execution_count": 11, + "execution_count": 27, "metadata": {}, "output_type": "execute_result" }, @@ -198,16 +194,22 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 28, "outputs": [], "source": [ "from repurpose.ts2img import Ts2Img\n", "from pygeogrids.grids import gridfromdims\n", "\n", "target_grid = gridfromdims(x, y)\n", - "timestamps = pd.date_range('2010-06-01T00:00:00', '2010-06-10T12:00:00', freq='12H')\n", + "timestamps = pd.date_range('2010-06-01T00:00:00',\n", + " '2010-06-10T12:00:00', freq='12H')\n", "\n", - "converter = Ts2Img(ts_reader=source_reader, img_grid=target_grid, timestamps=timestamps, variables=['sm'], max_dist=10000, time_collocation=True)\n" + "converter = Ts2Img(ts_reader=source_reader,\n", + " img_grid=target_grid,\n", + " timestamps=timestamps,\n", + " variables=['sm'],\n", + " max_dist=10000,\n", + " time_collocation=True)\n" ], "metadata": { "collapsed": false, @@ -240,21 +242,21 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 29, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Images are stored in /tmp/tmp72x9hsa2\n" + "Images are stored in /tmp/tmp6_mbnlrl\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "Processed: 100%|██████████| 3/3 [00:10<00:00, 3.52s/it]\n", - "Processed: 100%|██████████| 14/14 [00:00<00:00, 109.31it/s]\n" + "Processed: 100%|██████████| 3/3 [00:07<00:00, 2.50s/it]\n", + "Processed: 100%|██████████| 14/14 [00:00<00:00, 106.15it/s]\n" ] } ], @@ -267,7 +269,11 @@ "var_attrs = {'sm': {'unit': 'percent saturation', 'long_name': 'soil moisture'}}\n", "encoding = {'sm': {'scale_factor': 0.01, 'dtype': 'int32', '_FillValue': -9999}}\n", "\n", - "converter.calc(path_out=path_out, format_out='slice', fn_template='ascat_0.1deg_{datetime}.nc',glob_attrs=glob_attrs, var_attrs=var_attrs,encoding=encoding, img_buffer=100, n_proc=1, drop_empty=True)" + "converter.calc(path_out=path_out, format_out='slice',\n", + " fn_template='ascat_0.1deg_{datetime}.nc',\n", + " glob_attrs=glob_attrs, var_attrs=var_attrs,\n", + " encoding=encoding, img_buffer=100, n_proc=1,\n", + " drop_empty=True)" ], "metadata": { "collapsed": false, @@ -291,13 +297,13 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 30, "outputs": [ { "data": { - "text/plain": "" + "text/plain": "" }, - "execution_count": 14, + "execution_count": 30, "metadata": {}, "output_type": "execute_result" }, @@ -328,7 +334,9 @@ "source": [ "import xarray as xr\n", "\n", - "ds = xr.open_dataset(os.path.join(path_out, \"2010\", \"ascat_0.1deg_20100601120000.nc\"))\n", + "ds = xr.open_dataset(os.path.join(\n", + " path_out, \"2010\", \"ascat_0.1deg_20100601120000.nc\"))\n", + "\n", "ds['sm'].plot(figsize=(10,5), cmap='RdBu')\n", "\n", "plt.figure()\n", @@ -355,7 +363,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 31, "outputs": [ { "name": "stdout", @@ -382,13 +390,13 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 32, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Value and time stamp in image (after applying the timedetal_seconds to the image wide time stamp\n", + "Value and time stamp in image (after adding `timedelta_seconds` to the image wide time stamp\n", "\n", "sm: 5.64\n", "timestamp+offset: 2010-06-01 19:23:48.750000\n" @@ -403,7 +411,7 @@ "img_timestamp = pd.to_datetime(img['time'].values[0]).to_pydatetime()\n", "timedelta = timedelta(seconds=float(img['timedelta_seconds'].values[0]))\n", "\n", - "print(\"Value and time stamp in image (after applying the timedetal_seconds to the image wide time stamp\\n\")\n", + "print(\"Value and time stamp in image (after adding `timedelta_seconds` to the image wide time stamp\\n\")\n", "print(\"sm:\", sm)\n", "print(\"timestamp+offset:\", img_timestamp + timedelta)\n" ],