Skip to content

Instantly share code, notes, and snippets.

@rutj3
Last active December 14, 2016 12:39
Show Gist options
  • Save rutj3/70fe9d76d72b0fbfdeebda0568753828 to your computer and use it in GitHub Desktop.
Save rutj3/70fe9d76d72b0fbfdeebda0568753828 to your computer and use it in GitHub Desktop.
Radar_coordinates
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import pyproj\n",
"import numpy as np\n",
"import math"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 1. Corner coordinates approach"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"(0.0, -3649.9991119177544, 700.000903671186, -4415.003881997636)"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# convert corners in lat/lon degrees to provided projection (RD)\n",
"\n",
"# geographic_geo_product_corners\n",
"coords = [[0, 49.362053],\n",
" [0, 55.973602],\n",
" [10.856429, 55.388977],\n",
" [9.0092793, 48.895298]]\n",
"\n",
"lons, lats = list(zip(*coords))\n",
"\n",
"inproj4 = '+proj=stere +lat_0=90 +lon_0=0 +lat_ts=60 +a=6378.14 +b=6356.75 +x_0=0 y_0=0'\n",
"\n",
"crobj = pyproj.Proj(inproj4)\n",
"mapx, mapy = crobj(lons, lats, inverse=False)\n",
"\n",
"ulx = mapx[1]\n",
"lrx = mapx[3]\n",
"uly = mapy[1]\n",
"lry = mapy[3]\n",
"\n",
"ulx, uly, lrx, lry"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2. Pixel calculation"
]
},
{
"cell_type": "code",
"execution_count": 55,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# geographic_geo_pixel_size_x\n",
"yres = -1.0000052 # km\n",
"xres = 1.0000013\n",
"\n",
"# geographic_geo_column_offset\n",
"xoffset = 0\n",
"yoffset = 3649.9802\n",
"\n",
"# geographic_geo_number_columns\n",
"ncol = 700\n",
"nrow = 765\n",
"\n",
"ulx = xoffset * math.copysign(1, xres)\n",
"uly = yoffset * math.copysign(1, yres)\n",
"uly = yoffset * yres\n",
"lrx = ulx + ncol * xres\n",
"lry = uly + nrow * yres"
]
},
{
"cell_type": "code",
"execution_count": 56,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"(0.0, -3649.9991798970395, 700.0009100000001, -4415.003157897039)"
]
},
"execution_count": 56,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ulx, uly, lrx, lry"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# geographic_geo_pixel_size_x\n",
"yres = -1.0000052 * 0.5 # km\n",
"xres = 1.0000013 * 0.5\n",
"\n",
"# geographic_geo_column_offset\n",
"xoffset = 0\n",
"yoffset = 3649.9802*2\n",
"\n",
"# geographic_geo_number_columns\n",
"ncol = 700*2\n",
"nrow = 765*2\n",
"\n",
"ulx = xoffset * xres\n",
"uly = yoffset * yres\n",
"lrx = ulx + ncol * xres\n",
"lry = uly + nrow * yres"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"(0.0, -3649.9991798970395, 700.0009100000001, -4415.003157897039)"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ulx, uly, lrx, lry"
]
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python [default]",
"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.4.5"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment