{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Loading Pystare and Modules"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pystare"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import numpy\n",
"from pyhdf.SD import SD"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Conversions"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([4151504989081014885, 4161865161846704581, 3643626718498217157])"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"lat = numpy.array([30, 45, 60], dtype=numpy.double)\n",
"lon = numpy.array([45, 60, 10], dtype=numpy.double)\n",
"\n",
"indices = pystare.from_latlon(lat, lon, 5)\n",
"indices"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[30.00000012 45.00000003 59.99999986]\n",
"[44.99999991 60.00000013 9.9999999 ]\n",
"[5 5 5]\n"
]
},
{
"data": {
"text/plain": [
"(array([30.00000012, 45.00000003, 59.99999986]),\n",
" array([44.99999991, 60.00000013, 9.9999999 ]),\n",
" array([5, 5, 5], dtype=int32))"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"lat, lon = pystare.to_latlon(indices)\n",
"lat, lon, level = pystare.to_latlonlevel(indices)\n",
"print(lat)\n",
"print(lon)\n",
"print(level)\n",
"pystare.to_latlonlevel(indices)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[4298473764500464809, 4298458168380511209, 4297394569014717897],\n",
" [4298462872969244297, 4298459225563237225, 4297297422977447753],\n",
" [4298462873435275369, 4298459227962358473, 4297297429637206121]])"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"hdf = SD('../tests/data/MOD05_L2.A2019336.0000.061.2019336211522.hdf')\n",
"lats = hdf.select('Latitude')[0:3, 0:3].astype('double')\n",
"lons = hdf.select('Longitude')[0:3, 0:3].astype('double')\n",
"pystare.from_latlon_2d(lats, lons, adapt_level=True)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([0.0014197 , 0.00143268, 0.00130733])"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"area = pystare.to_area(indices)\n",
"area"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Covers"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import geopandas\n",
"path = geopandas.datasets.get_path('naturalearth_lowres')\n",
"world = geopandas.read_file(path)\n",
"de = world[world.name=='Poland']\n",
"geom = de.simplify(1).iloc[0]\n",
"lon, lat = geom.exterior.xy\n",
"lat = lat[::-1]\n",
"lon = lon[::-1]\n",
"geom"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([4251398048237748228, 4255901647865118724, 4258153447678803972,\n",
" 4539628424389459972, 4541880224203145220, 4546383823830515716])"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pystare.cover_from_hull(lat, lon, 4)#.size"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"array([4252523948144590853, 4256464597818540037, 4257590497725382661,\n",
" 4258716397632225285, 4540191374342881285, 4542443174156566533,\n",
" 4543006124109987845, 4543569074063409157, 4546383823830515717,\n",
" 4547509723737358341, 4548072673690779653])"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pystare.cover_from_ring(lat, lon, 5)#.size"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(array([53.89745687, 56.8965353 , 56.93769843]),\n",
" array([ 9.22866958, 13.23186479, 8.07137938]),\n",
" array([55.93005351]),\n",
" array([10.15342841]))"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pystare.to_vertices_latlon([4254212798004854789])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Overlay"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[4151504989081014885 4161865161846704581 3643626718498217157]\n",
"[3643412098542731269 4151192956528754693 4161326055690338309]\n"
]
},
{
"data": {
"text/plain": [
"array([5, 5, 5], dtype=int32)"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"intersected = pystare.intersection(indices, indices, multi_resolution=False)\n",
"print(indices)\n",
"print(intersected)\n",
"set(indices) == set(intersected)\n",
"pystare.to_level(intersected)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([False, True])"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sids = numpy.array([4251398048237748227, 4269412446747230211, 4278419646001971203,])\n",
"pystare.intersects(sids, numpy.array([1251398048237748227, 4269412446747230210]), method=2)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([4251398048237748228, 4255901647865118724, 4258153447678803972,\n",
" 4539628424389459972])"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sids1 = [4251398048237748227, 4269412446747230211, 4278419646001971203, 4539628424389459971]\n",
"sids2 = [4251398048237748228, 4255901647865118724, 4258153447678803972, 4539628424389459972]\n",
"pystare.intersection(sids1, sids2, multi_resolution=False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"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.8.10"
}
},
"nbformat": 4,
"nbformat_minor": 4
}