Last active
September 3, 2024 21:01
-
-
Save Kelvinrr/990329c9b14e50b3040c4a478abd6828 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"id": "b1c81d0a-e297-46a4-849c-f533ae4247cc", | |
"metadata": {}, | |
"source": [ | |
"# 1. Import Libraries" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"id": "e176e3fc-b096-43d2-ac9a-8bd4e016ff5c", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import plio \n", | |
"from plio.io.io_gdal import GeoDataset\n", | |
"\n", | |
"import struct\n", | |
"import numpy as np" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "6940a457-c675-4863-a976-70d7a7f29234", | |
"metadata": {}, | |
"source": [ | |
"# 2. Open image and get locations" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"id": "207959c9-c63b-408a-8bec-58332e9c6278", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"/Users/krodriguez/miniforge3/envs/plio/lib/python3.12/site-packages/osgeo/gdal.py:312: FutureWarning: Neither gdal.UseExceptions() nor gdal.DontUseExceptions() has been explicitly called. In GDAL 4.0, exceptions will be enabled by default.\n", | |
" warnings.warn(\n" | |
] | |
} | |
], | |
"source": [ | |
"arr = GeoDataset(\"M1162613292LE.lev1.cub\").read_array()\n", | |
"ISISREALNULL = struct.unpack(\">f\", bytes.fromhex(\"FF7FFFFB\"))[0]\n", | |
"null_locs = np.argwhere(arr==ISISREALNULL) + 1 # ISIS uses 1-based indexing" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "3b792b39-e857-4ab4-8455-d0cd5374a4a3", | |
"metadata": {}, | |
"source": [ | |
"# 3. Print and write out data" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"id": "93662f65-63e2-4ead-a66f-a673ae5e5db2", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"number of nulls: 1671168\n", | |
"truncated locations: \n", | |
"[[ 1 1]\n", | |
" [ 1 2]\n", | |
" [ 1 3]\n", | |
" ...\n", | |
" [52224 2530]\n", | |
" [52224 2531]\n", | |
" [52224 2532]]\n", | |
"Saving to: test.txt\n" | |
] | |
} | |
], | |
"source": [ | |
"# save as a simple line delimited file\n", | |
"filename = \"test.txt\"\n", | |
"print(f\"Saving to: {filename}\")\n", | |
"np.savetxt(filename, null_locs.astype(int), fmt='%d')\n", | |
"\n", | |
"print(\"number of nulls: \", len(null_locs))\n", | |
"print(\"truncated locations: \")\n", | |
"print(null_locs)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "ca6d3b0f-49a2-42e4-a9c3-3c91bf8c2d1b", | |
"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.12.5" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment