{ "cells": [ { "cell_type": "markdown", "metadata": { "pycharm": { "name": "#%% md\n" } }, "source": [ "# Working with dask and xarray" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false, "jupyter": { "outputs_hidden": false }, "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "from pyhdf.SD import SD\n", "import numpy\n", "import pystare\n", "import xarray\n", "import dask.distributed\n", "import dask.dataframe\n", "import datetime" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2022-09-15T05:04:05.790079Z", "iopub.status.busy": "2022-09-15T05:04:05.789842Z", "iopub.status.idle": "2022-09-15T05:04:07.005682Z", "shell.execute_reply": "2022-09-15T05:04:07.004909Z" }, "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "client = dask.distributed.Client(n_workers=4)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2022-09-15T05:04:07.008305Z", "iopub.status.busy": "2022-09-15T05:04:07.008034Z", "iopub.status.idle": "2022-09-15T05:04:07.019864Z", "shell.execute_reply": "2022-09-15T05:04:07.019368Z" }, "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "file_path = '../tests/data/granules/MOD05_L2.A2019336.0000.061.2019336211522.hdf'\n", "hdf = SD(file_path)\n", "lon = hdf.select('Longitude').get().astype(numpy.double)\n", "lat = hdf.select('Latitude').get().astype(numpy.double)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2022-09-15T05:04:07.022532Z", "iopub.status.busy": "2022-09-15T05:04:07.022195Z", "iopub.status.idle": "2022-09-15T05:04:08.014397Z", "shell.execute_reply": "2022-09-15T05:04:08.013807Z" }, "pycharm": { "name": "#%%\n" }, "is_executing": true }, "outputs": [], "source": [ "start = datetime.datetime.now()\n", "stare = pystare.from_latlon_2d(lat=lat, \n", " lon=lon, \n", " adapt_level=True)\n", "print(datetime.datetime.now()-start)" ] }, { "cell_type": "markdown", "metadata": { "pycharm": { "name": "#%% md\n" } }, "source": [ "## Dask" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2022-09-15T05:04:08.017246Z", "iopub.status.busy": "2022-09-15T05:04:08.017013Z", "iopub.status.idle": "2022-09-15T05:04:08.034405Z", "shell.execute_reply": "2022-09-15T05:04:08.033890Z" }, "pycharm": { "name": "#%%\n" } }, "outputs": [ { "data": { "text/html": [ "
\n",
"
| \n",
" \n", " \n", " | \n", "
| \n", " | band1 | \n", "
|---|---|
| npartitions=4 | \n", "\n", " |
| 3604081108103418377 | \n", "float64 | \n", "
| 3618019075911588075 | \n", "... | \n", "
| 3661533202196794217 | \n", "... | \n", "
| 3736859491218877322 | \n", "... | \n", "
| 4298544093115426153 | \n", "... | \n", "