{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Granules" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2022-09-15T05:05:30.956534Z", "iopub.status.busy": "2022-09-15T05:05:30.956216Z", "iopub.status.idle": "2022-09-15T05:05:32.636006Z", "shell.execute_reply": "2022-09-15T05:05:32.635440Z" } }, "outputs": [], "source": [ "import starepandas\n", "import geopandas\n", "import pystare\n", "import matplotlib.pyplot as plt\n", "import importlib\n", "import copy" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2022-09-15T05:05:32.641127Z", "iopub.status.busy": "2022-09-15T05:05:32.640837Z", "iopub.status.idle": "2022-09-15T05:05:32.687997Z", "shell.execute_reply": "2022-09-15T05:05:32.687460Z" } }, "outputs": [], "source": [ "fname = '../tests/data/granules/MOD05_L2.A2019336.0000.061.2019336211522.hdf'\n", "modis = starepandas.read_granule(fname, latlon=True, sidecar=True, xy=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2022-09-15T05:05:32.690910Z", "iopub.status.busy": "2022-09-15T05:05:32.690622Z", "iopub.status.idle": "2022-09-15T05:05:32.696882Z", "shell.execute_reply": "2022-09-15T05:05:32.696361Z" } }, "outputs": [], "source": [ "modis = copy.copy(modis[(modis.y>250) & (modis.x<150)])" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2022-09-15T05:05:32.699420Z", "iopub.status.busy": "2022-09-15T05:05:32.698884Z", "iopub.status.idle": "2022-09-15T05:05:32.718775Z", "shell.execute_reply": "2022-09-15T05:05:32.718268Z" } }, "outputs": [], "source": [ "modis" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2022-09-15T05:05:32.721026Z", "iopub.status.busy": "2022-09-15T05:05:32.720818Z", "iopub.status.idle": "2022-09-15T05:05:36.845440Z", "shell.execute_reply": "2022-09-15T05:05:36.844657Z" } }, "outputs": [], "source": [ "trixels = modis.make_trixels()\n", "modis.set_trixels(trixels, inplace=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2022-09-15T05:05:36.848117Z", "iopub.status.busy": "2022-09-15T05:05:36.847918Z", "iopub.status.idle": "2022-09-15T05:05:37.517162Z", "shell.execute_reply": "2022-09-15T05:05:37.516578Z" } }, "outputs": [], "source": [ "geom = geopandas.points_from_xy(modis.lon, modis.lat)\n", "modis.set_geometry(geom, inplace=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2022-09-15T05:05:37.519722Z", "iopub.status.busy": "2022-09-15T05:05:37.519403Z", "iopub.status.idle": "2022-09-15T05:05:42.287472Z", "shell.execute_reply": "2022-09-15T05:05:42.286836Z" } }, "outputs": [], "source": [ "fig, ax = plt.subplots(figsize=(10, 10), dpi=100)\n", "ax.grid(True)\n", "\n", "modis.plot(trixels=False, ax=ax, marker='.', markersize=20)\n", "modis.plot(trixels=True, color='r', ax=ax, lw=0.5)\n", "\n", "#plt.savefig('modis.png')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Plotting footprints" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2022-09-15T05:05:42.295941Z", "iopub.status.busy": "2022-09-15T05:05:42.295682Z", "iopub.status.idle": "2022-09-15T05:05:42.300568Z", "shell.execute_reply": "2022-09-15T05:05:42.300098Z" } }, "outputs": [], "source": [ "fname = '../tests/data/granules/MOD05_L2.A2019336.0000.061.2019336211522.hdf'\n", "mod05 = starepandas.io.granules.Mod05(fname)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2022-09-15T05:05:42.302499Z", "iopub.status.busy": "2022-09-15T05:05:42.302257Z", "iopub.status.idle": "2022-09-15T05:05:42.308895Z", "shell.execute_reply": "2022-09-15T05:05:42.308435Z" } }, "outputs": [], "source": [ "mod05.read_sidecar_cover()\n", "mod05.stare_cover" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Manually getting the 2D STARE array" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2022-09-15T05:05:42.311096Z", "iopub.status.busy": "2022-09-15T05:05:42.310873Z", "iopub.status.idle": "2022-09-15T05:05:42.313916Z", "shell.execute_reply": "2022-09-15T05:05:42.313252Z" } }, "outputs": [], "source": [ "import netCDF4\n", "from pyhdf.SD import SD\n", "import numpy\n", "import pystare\n", "import datetime" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2022-09-15T05:05:42.316429Z", "iopub.status.busy": "2022-09-15T05:05:42.316087Z", "iopub.status.idle": "2022-09-15T05:05:42.326907Z", "shell.execute_reply": "2022-09-15T05:05:42.326288Z" } }, "outputs": [], "source": [ "hdf = SD(fname)\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:05:42.328999Z", "iopub.status.busy": "2022-09-15T05:05:42.328789Z", "iopub.status.idle": "2022-09-15T05:05:43.318609Z", "shell.execute_reply": "2022-09-15T05:05:43.318110Z" } }, "outputs": [], "source": [ "start = datetime.datetime.now()\n", "sids = pystare.from_latlon_2d(lat=lat, lon=lon, adapt_level=True)\n", "datetime.datetime.now()-start" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2022-09-15T05:05:43.320675Z", "iopub.status.busy": "2022-09-15T05:05:43.320458Z", "iopub.status.idle": "2022-09-15T05:05:43.324440Z", "shell.execute_reply": "2022-09-15T05:05:43.323977Z" } }, "outputs": [], "source": [ "print(pystare.spatial_resolution(sids).min())\n", "print(pystare.spatial_resolution(sids).max())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Intersecting Data " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2022-09-15T05:05:43.326841Z", "iopub.status.busy": "2022-09-15T05:05:43.326468Z", "iopub.status.idle": "2022-09-15T05:05:52.121235Z", "shell.execute_reply": "2022-09-15T05:05:52.120528Z" } }, "outputs": [], "source": [ "world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))\n", "world.sort_values(by='name', inplace=True)\n", "world = starepandas.STAREDataFrame(world)\n", "sids = world.make_sids(level=6)\n", "world.set_sids(sids, inplace=True)\n", "trixels = world.make_trixels()\n", "world.set_trixels(trixels, inplace=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2022-09-15T05:05:52.124371Z", "iopub.status.busy": "2022-09-15T05:05:52.124035Z", "iopub.status.idle": "2022-09-15T05:05:53.221587Z", "shell.execute_reply": "2022-09-15T05:05:53.220388Z" } }, "outputs": [], "source": [ "fig, ax = plt.subplots(figsize=(4,4), dpi=200)\n", "ax.grid(True)\n", "\n", "country = world[world.name=='Iceland']\n", "country.plot(ax=ax, trixels=True, boundary=True, color='y', zorder=1)\n", "country.plot(ax=ax, trixels=False, facecolor=\"none\", edgecolor='blue', zorder=1)\n", "modis.plot(ax=ax, color='red', trixels=False, zorder=0, linewidth=0.1)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2022-09-15T05:05:53.224991Z", "iopub.status.busy": "2022-09-15T05:05:53.224509Z", "iopub.status.idle": "2022-09-15T05:05:53.273310Z", "shell.execute_reply": "2022-09-15T05:05:53.271450Z" } }, "outputs": [], "source": [ "a = modis.stare_intersects(country['sids'].iloc[0])\n", "a.any()" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "execution": { "iopub.execute_input": "2022-09-15T05:05:53.281303Z", "iopub.status.busy": "2022-09-15T05:05:53.277882Z", "iopub.status.idle": "2022-09-15T05:05:53.289147Z", "shell.execute_reply": "2022-09-15T05:05:53.288279Z" } }, "outputs": [ { "data": { "text/plain": "17" }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(country['sids'].iloc[0])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.6" } }, "nbformat": 4, "nbformat_minor": 4 }