Skip to content

Instantly share code, notes, and snippets.

@AndrewAnnex
Created January 6, 2023 03:59
Show Gist options
  • Save AndrewAnnex/6b1595f17a892d074902cd33ff833a2d to your computer and use it in GitHub Desktop.
Save AndrewAnnex/6b1595f17a892d074902cd33ff833a2d to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "6d35759e-63ce-4908-a75c-30c6be82c249",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'3.4.1'"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pyproj\n",
"pyproj.__version__"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "3111aafc-471e-42c8-8611-49487a998f08",
"metadata": {},
"outputs": [],
"source": [
"from pyproj import Transformer, CRS"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "4e8f0785-92a1-4bb9-85dc-26a38b0943ee",
"metadata": {},
"outputs": [],
"source": [
"extent_cen0_xy = (-180.0, -90.0, 180.0, 90.0)\n",
"extent_cen0_yx = ( -90.0, -180.0, 90.0, 180.0)\n",
"extent_cen180_xy = ( 0.0, -90.0, 360.0, 90.0)\n",
"extent_cen180_yx = ( -90.0, 0.0, 90.0, 360.0)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "9864fa81-5606-49d9-848c-d761a7864ec0",
"metadata": {},
"outputs": [],
"source": [
"mars1 = CRS('IAU:49900')\n",
"mars2 = CRS('IAU:49915')\n",
"mars3 = CRS('IAU:49916')"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "6871ab3f-e19a-423b-b5a5-f4220c390ac8",
"metadata": {},
"outputs": [],
"source": [
"t1 = Transformer.from_crs(mars1.geodetic_crs, mars1, always_xy=True, allow_ballpark=False)\n",
"t2 = Transformer.from_crs(mars2.geodetic_crs, mars2, always_xy=True, allow_ballpark=False)\n",
"t3 = Transformer.from_crs(mars3.geodetic_crs, mars3, always_xy=True, allow_ballpark=False)"
]
},
{
"cell_type": "markdown",
"id": "186d7884-1c9b-4777-8dbb-7413a9bc4744",
"metadata": {},
"source": [
"# mars 1"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "68f7bd52-153e-453d-b906-5f2db2c3edef",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'GEOGCRS[\"Mars (2015) - Sphere / Ocentric\",DATUM[\"Mars (2015) - Sphere\",ELLIPSOID[\"Mars (2015) - Sphere\",3396190,0,LENGTHUNIT[\"metre\",1]],ANCHOR[\"Viking 1 lander: 47.95137 W\"]],PRIMEM[\"Reference Meridian\",0,ANGLEUNIT[\"degree\",0.0174532925199433]],CS[ellipsoidal,2],AXIS[\"geodetic latitude (Lat)\",north,ORDER[1],ANGLEUNIT[\"degree\",0.0174532925199433]],AXIS[\"geodetic longitude (Lon)\",east,ORDER[2],ANGLEUNIT[\"degree\",0.0174532925199433]],ID[\"IAU\",49900,2015],REMARK[\"Use semi-major radius as sphere for interoperability. Source of IAU Coordinate systems: doi://10.1007/s10569-017-9805-5\"]]'"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mars1.to_wkt()"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "64feb5fb-d41a-45fa-af3e-3a704b6524f7",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'GEOGCRS[\"Mars (2015) - Sphere / Ocentric\",DATUM[\"Mars (2015) - Sphere\",ELLIPSOID[\"Mars (2015) - Sphere\",3396190,0,LENGTHUNIT[\"metre\",1]],ANCHOR[\"Viking 1 lander: 47.95137 W\"]],PRIMEM[\"Reference Meridian\",0,ANGLEUNIT[\"degree\",0.0174532925199433]],CS[ellipsoidal,2],AXIS[\"geodetic latitude (Lat)\",north,ORDER[1],ANGLEUNIT[\"degree\",0.0174532925199433]],AXIS[\"geodetic longitude (Lon)\",east,ORDER[2],ANGLEUNIT[\"degree\",0.0174532925199433]],ID[\"IAU\",49900,2015],REMARK[\"Use semi-major radius as sphere for interoperability. Source of IAU Coordinate systems: doi://10.1007/s10569-017-9805-5\"]]'"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mars1.geodetic_crs.to_wkt()"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "85b78891-3ff8-4dab-ab19-32a97fd3163e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(True, (-180.0, -90.0, 180.0, 90.0))"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"t1.transform_bounds(*extent_cen0_xy) == extent_cen0_xy,extent_cen0_xy # expected "
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "137012ab-c2fb-4736-8abe-6e25c31a40fd",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(True, (0.0, -90.0, 360.0, 90.0))"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"t1.transform_bounds(*extent_cen180_xy) == extent_cen180_xy, extent_cen180_xy # not expected actually. I would expect this to be off given clon=0"
]
},
{
"cell_type": "markdown",
"id": "604d40c1-0e5c-4ffc-ba0a-b6c85533ff97",
"metadata": {},
"source": [
"# mars 2"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "990d9e54-98b4-4be5-af82-2c0ca84d7a10",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'PROJCRS[\"Mars (2015) - Sphere / Ocentric / Equirectangular, clon = 180\",BASEGEOGCRS[\"Mars (2015) - Sphere / Ocentric\",DATUM[\"Mars (2015) - Sphere\",ELLIPSOID[\"Mars (2015) - Sphere\",3396190,0,LENGTHUNIT[\"metre\",1]],ANCHOR[\"Viking 1 lander: 47.95137 W\"]],PRIMEM[\"Reference Meridian\",0,ANGLEUNIT[\"degree\",0.0174532925199433]],ID[\"IAU\",49900,2015]],CONVERSION[\"Equirectangular, clon = 180\",METHOD[\"Equidistant Cylindrical\",ID[\"EPSG\",1028]],PARAMETER[\"Latitude of 1st standard parallel\",0,ANGLEUNIT[\"degree\",0.0174532925199433],ID[\"EPSG\",8823]],PARAMETER[\"Longitude of natural origin\",180,ANGLEUNIT[\"degree\",0.0174532925199433],ID[\"EPSG\",8802]],PARAMETER[\"False easting\",0,LENGTHUNIT[\"metre\",1],ID[\"EPSG\",8806]],PARAMETER[\"False northing\",0,LENGTHUNIT[\"metre\",1],ID[\"EPSG\",8807]]],CS[Cartesian,2],AXIS[\"(E)\",east,ORDER[1],LENGTHUNIT[\"metre\",1]],AXIS[\"(N)\",north,ORDER[2],LENGTHUNIT[\"metre\",1]],ID[\"IAU\",49915,2015]]'"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mars2.to_wkt()"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "9b3bf69c-5de2-4c7a-9d9c-9f464dc4006f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'GEOGCRS[\"Mars (2015) - Sphere / Ocentric\",DATUM[\"Mars (2015) - Sphere\",ELLIPSOID[\"Mars (2015) - Sphere\",3396190,0,LENGTHUNIT[\"metre\",1]],ANCHOR[\"Viking 1 lander: 47.95137 W\"]],PRIMEM[\"Reference Meridian\",0,ANGLEUNIT[\"degree\",0.0174532925199433]],CS[ellipsoidal,2],AXIS[\"geodetic latitude (Lat)\",north,ORDER[1],ANGLEUNIT[\"degree\",0.0174532925199433]],AXIS[\"geodetic longitude (Lon)\",east,ORDER[2],ANGLEUNIT[\"degree\",0.0174532925199433]],ID[\"IAU\",49900,2015],REMARK[\"Use semi-major radius as sphere for interoperability. Source of IAU Coordinate systems: doi://10.1007/s10569-017-9805-5\"]]'"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mars2.geodetic_crs.to_wkt()"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "7ae6d391-0a9c-4a85-a1be-13b7a9201c20",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(-10669445.554195119, -5334722.7770975595, 9699495.9583592, 5334722.7770975595)"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"t2.transform_bounds(*extent_cen0_xy) # expected as geodetic_crs has no knowledge of clon"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "a3b36422-00a1-445c-a04d-25f880b6826b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(-10669445.554195119, -5334722.7770975595, 9699495.9583592, 5334722.7770975595)"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"t2.transform_bounds(*extent_cen180_xy) # expected"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "ae7ed1e0-bbc5-4613-be4e-8dc0ad9f6abd",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(-5334722.7770975595,\n",
" -4849747.979179599,\n",
" 5334722.7770975595,\n",
" 4849747.979179599)"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"t2.transform_bounds(*extent_cen0_yx) # expected garbage results from wrong axis ordering"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "baead2c2-4ece-4867-a21b-75bdcd24e637",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(-10669445.554195119, 0.0, 10184470.756277159, 4849747.979179599)"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"t2.transform_bounds(*extent_cen180_yx) # expected garbage results from wrong axis ordering"
]
},
{
"cell_type": "markdown",
"id": "3d7dedab-e03c-4339-82b9-52d1fab4331f",
"metadata": {},
"source": [
"# mars 3"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "d4bbed4e-1951-4335-9b99-04d466355471",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'PROJCRS[\"Mars (2015) / Ographic / Equirectangular, clon = 180\",BASEGEOGCRS[\"Mars (2015) / Ographic\",DATUM[\"Mars (2015)\",ELLIPSOID[\"Mars (2015)\",3396190,169.894447223612,LENGTHUNIT[\"metre\",1]],ANCHOR[\"Viking 1 lander: 47.95137 W\"]],PRIMEM[\"Reference Meridian\",0,ANGLEUNIT[\"degree\",0.0174532925199433]],ID[\"IAU\",49901,2015]],CONVERSION[\"Equirectangular, clon = 180\",METHOD[\"Equidistant Cylindrical\",ID[\"EPSG\",1028]],PARAMETER[\"Latitude of 1st standard parallel\",0,ANGLEUNIT[\"degree\",0.0174532925199433],ID[\"EPSG\",8823]],PARAMETER[\"Longitude of natural origin\",180,ANGLEUNIT[\"degree\",0.0174532925199433],ID[\"EPSG\",8802]],PARAMETER[\"False easting\",0,LENGTHUNIT[\"metre\",1],ID[\"EPSG\",8806]],PARAMETER[\"False northing\",0,LENGTHUNIT[\"metre\",1],ID[\"EPSG\",8807]]],CS[Cartesian,2],AXIS[\"westing (W)\",west,ORDER[1],LENGTHUNIT[\"metre\",1]],AXIS[\"(N)\",north,ORDER[2],LENGTHUNIT[\"metre\",1]],ID[\"IAU\",49916,2015]]'"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mars3.to_wkt()"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "6f0c4325-ea47-435a-b133-07236adf5b5b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'GEOGCRS[\"Mars (2015) / Ographic\",DATUM[\"Mars (2015)\",ELLIPSOID[\"Mars (2015)\",3396190,169.894447223612,LENGTHUNIT[\"metre\",1]],ANCHOR[\"Viking 1 lander: 47.95137 W\"]],PRIMEM[\"Reference Meridian\",0,ANGLEUNIT[\"degree\",0.0174532925199433]],CS[ellipsoidal,2],AXIS[\"geodetic latitude (Lat)\",north,ORDER[1],ANGLEUNIT[\"degree\",0.0174532925199433]],AXIS[\"geodetic longitude (Lon)\",west,ORDER[2],ANGLEUNIT[\"degree\",0.0174532925199433]],ID[\"IAU\",49901,2015],REMARK[\"Source of IAU Coordinate systems: doi://10.1007/s10569-017-9805-5\"]]'"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mars3.geodetic_crs.to_wkt()"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "c316738a-e844-4f5f-aac4-d9bd8386f325",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(-5334722.7770975595,\n",
" -4849747.979179599,\n",
" 5334722.7770975595,\n",
" 4849747.979179599)"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"t3.transform_bounds(*extent_cen0_xy) # expected as wrong extent provided to clon=180"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "9e87472c-ffc3-4f3d-b035-4cb8c03a0472",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(-10184470.756277159, 0.0, 10669445.554195119, 4849747.979179599)"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"t3.transform_bounds(*extent_cen180_xy) # wrong has a 0 for miny "
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "f6af5ee6-b439-4c97-a972-029141052485",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(-9699495.9583592, -5334722.7770975595, 10669445.554195119, 5334722.7770975595)"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"t3.transform_bounds(*extent_cen0_yx) # looks more right? "
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "12b61a85-0218-4dfa-bd2b-2948bdecbd18",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(-9699495.9583592, -5334722.7770975595, 10669445.554195119, 5334722.7770975595)"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"t3.transform_bounds(*extent_cen180_yx) # looks more right? "
]
},
{
"cell_type": "markdown",
"id": "450558f5-853f-4ab5-bbaa-36bf44843e05",
"metadata": {},
"source": [
"## the 3rd set here is troubling, it implies that the axis order xy isn't respected "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8fb73385-2750-4fea-a0d1-5435b2cec4ce",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda env:m2020] *",
"language": "python",
"name": "conda-env-m2020-py"
},
"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.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment