Skip to content

Commit

Permalink
Merge pull request #13 from gregory-halverson-jpl/main
Browse files Browse the repository at this point in the history
tile name parameter to generate grid or affine
  • Loading branch information
gregory-halverson-jpl authored Dec 4, 2024
2 parents 8e620b6 + 4c17852 commit 40b9ceb
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 5 deletions.
113 changes: 113 additions & 0 deletions Sinusoidal Tile Grid.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from modland import generate_modland_grid"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{\n",
" \"dimensions\": {\n",
" \"rows\": 1200,\n",
" \"cols\": 1200\n",
" },\n",
" \"bbox\": {\n",
" \"xmin\": -11119505.197665555,\n",
" \"ymin\": 3335851.5592996655,\n",
" \"xmax\": -10007554.677899,\n",
" \"ymax\": 4447802.079066221\n",
" },\n",
" \"crs\": \"+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +R=6371007.181 +units=m +no_defs +type=crs\",\n",
" \"resolution\": {\n",
" \"cell_width\": 926.6254331387962,\n",
" \"cell_height\": -926.6254331387962\n",
" }\n",
"}"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"generate_modland_grid(tile_size=1200, tile=\"h08v05\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{\n",
" \"dimensions\": {\n",
" \"rows\": 1200,\n",
" \"cols\": 1200\n",
" },\n",
" \"bbox\": {\n",
" \"xmin\": -11119505.197665555,\n",
" \"ymin\": 3335851.5592996655,\n",
" \"xmax\": -10007554.677899,\n",
" \"ymax\": 4447802.079066221\n",
" },\n",
" \"crs\": \"+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +R=6371007.181 +units=m +no_defs +type=crs\",\n",
" \"resolution\": {\n",
" \"cell_width\": 926.6254331387962,\n",
" \"cell_height\": -926.6254331387962\n",
" }\n",
"}"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"generate_modland_grid(8, 5, 1200)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "modland",
"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.11.10"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
37 changes: 34 additions & 3 deletions modland/modland_affine.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,24 @@

from .projection import *
from .dimensions import MODLAND_TILE_SIZES
from .parsehv import parsehv

def calculate_modland_affine(h: int = None, v: int = None, tile_size: int = None, tile: str = None, spatial_resolution: int = None):
if tile_size is None and spatial_resolution is not None:
tile_size = MODLAND_TILE_SIZES[spatial_resolution]

if tile_size is None:
raise ValueError("tile size not given")

if h is None or v is None and tile is not None:
h, v = parsehv(tile)

if tile is None and h is not None and v is not None:
tile = f"h{h:02d}v{v:02d}"

if tile is None and h is None and v is None:
raise ValueError("tile not given")

def calculate_modland_affine(h, v, tile_size):
# boundaries of sinusodial projection
UPPER_LEFT_X_METERS = -20015109.355798
UPPER_LEFT_Y_METERS = 10007554.677899
Expand Down Expand Up @@ -46,8 +62,23 @@ def calculate_global_modland_affine(spatial_resolution):

return affine

def generate_modland_grid(h, v, tile_size):
affine = calculate_modland_affine(h, v, tile_size)
def generate_modland_grid(h: int = None, v: int = None, tile_size: int = None, tile: str = None, spatial_resolution: int = None):
if tile_size is None and spatial_resolution is not None:
tile_size = MODLAND_TILE_SIZES[spatial_resolution]

if tile_size is None:
raise ValueError("tile size not given")

if h is None or v is None and tile is not None:
h, v = parsehv(tile)

if tile is None and h is not None and v is not None:
tile = f"h{h:02d}v{v:02d}"

if tile is None and h is None and v is None:
raise ValueError("tile not given")

affine = calculate_modland_affine(h=h, v=v, tile_size=tile_size)
grid = RasterGrid.from_affine(affine, tile_size, tile_size, crs=SINUSOIDAL_PROJECTION)

return grid
2 changes: 1 addition & 1 deletion modland/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.3
1.1.0
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requires = ["setuptools>=60", "setuptools-scm>=8.0", "wheel"]

[project]
name = "modland"
version = "1.0.3"
version = "1.1.0"
description = "georeferencing for MODIS/VIIRS sinusoidal tiles"
readme = "README.md"
authors = [
Expand Down

0 comments on commit 40b9ceb

Please sign in to comment.