Saturday, February 10, 2024

ISIS and ASP on Windows 11 (WSL, take 3)

Based on this original post for Windows 10 and with help from M. Phillips (LPL, see: alternative instructions and demos), I will update this post to get ISIS and ASP installed on Windows 11 (again using using WSL). Warning: this requires a lot of downloading. This took about two hours on my laptop and decent wifi, but I did have some issues with the data download.

First, ASP = NASA Ames Stereo Pipeline (GitHubDocs)
ISIS = USGS Integrated Software for Imagers and Spectrometers (GitHub, Docs)

(1) get Linux for Windows 11
I recommend Ubuntu 22 LTS installed via the Windows app store (or via wsl powershell command-line, "wsl --install -d Ubuntu-22.04").

And if you don't have access to the MS App store, you can try a more manual install.

(2) For Windows, install Xming and launch (it runs in the background minimized)

(3) Once running Ubuntu, update it (this just gets your Ubuntu system up to date)
> sudo apt-get update
> sudo apt-get upgrade

(4) Now and let's get X11 and GUIs working:
> sudo apt install -y xclip gnome-themes-standard gtk2-engines-murrine dbus dbus-x11 x11-apps libgl1-mesa-glx

Looks like Anaconda wants even more (I consider this optional for now):
> sudo apt-get install libgl1-mesa-glx libegl1-mesa libxrandr2 libxrandr2 libxss1 libxcursor1 libxcomposite1 libasound2 libxi6 libxtst6

-- test X11
-- add this line to bottom of .bashrc (or type):
> echo export DISPLAY=:0 >> ~/.bashrc
> source ~/.bashrc
> xeyes

(5) Get Anaconda (or miniconda should work too).
> wget https://repo.anaconda.com/archive/Anaconda3-2023.09-0-Linux-x86_64.sh
-- or get latest version from download page: https://repo.anaconda.com/archive/ 
> bash Anaconda3-2019.03-Linux-x86_64.sh
-- follow install instructions and allow installer to update your shell (~/.bashrc) when it asks (will need to type "yes").
-- once installed, restart the Ubuntu terminal from Windows' powershell (typing wsl) or simply from Windows start.

(6) Get ISIS and ASP applications
-- note for ISIS only, follow the installation pages on GitHub.
or these steps:
> conda create -n asp3
> conda activate asp3

> conda config --env --add channels conda-forge
> conda config --env --add channels usgs-astrogeology
> conda config --env --add channels nasa-ames-stereo-pipeline

> conda install  -c nasa-ames-stereo-pipeline -c usgs-astrogeology -c conda-forge stereo-pipeline==3.3.0
//This can take a while. If you need a more recent version, remove the ASP version above. By locking to ASP v3.3.0, it looks like ISIS v8.0.0 will be install alongside. Also mamba is a much faster environment solve, if you install it.

-- Finally, execute the ISIS variable initialization script with default arguments. execute the ISIS variable initialization script with default arguments.
-- this script prepares default values for: $ISISROOT, $ISISDATA, $ISISTESTDATA
> python $CONDA_PREFIX/scripts/isisVarInit.py

(7) Get ISIS3 base data
> conda activate asp3
-- we will need to get the base data, has target SPICE kernels and a handful of global DEMs for orthorectification. Feel free to delete any data you wont need.
> downloadIsisData base $ISISDATA

Data Notes:
--Due to what I can only call an unfortunate quirk for the files on S3 cloud (doesn't support symbolic links), you will get many copies of the same DEMs (Mars, Moon, ...). It is more than 12GB of extra files. Feel free to delete all but the last version under $CONDA_PREFIX/data/base/dems
--I ran out of space on my main drive, so I edited my environment variable "ISISDATA" to point to a USB drive "/mnt/d/data/". This can be updated here "~/anaconda3/envs/asp3/etc/conda/activate.d/isis-activate.sh"
    --To get Ubuntu to see a new drive, you may need to get out and back into Ubuntu. In a powershell you can type "wsl --shutdown" and then restart with "wsl".

Done. at least for the minimal install. You may need lots more SPICE data for a particular mission, read more about that on the ISIS install page.
-- So the next time you launch an Ubuntu terminal, just type "conda activate asp3" to run ISIS and ASP routines.

(8) to run a test CTX elevation model in ASP (uses ISIS also). 
-- first get some additional MRO files
> downloadIsisData mro $ISISDATA --exclude="{ck/**,spk/**}"

from here, lets run the CTX2 demo script creating a DEM, orthoimage (DRG) and hillshade using ISIS and ASP.
wget http://pds-imaging.jpl.nasa.gov/data/mro/mars_reconnaissance_orbiter/ctx/mrox_2469/data/F21_044073_1653_XN_14S037W.IMG
wget http://pds-imaging.jpl.nasa.gov/data/mro/mars_reconnaissance_orbiter/ctx/mrox_2475/data/F22_044218_1653_XN_14S037W.IMG

## ISIS commands
mroctx2isis from=F21_044073_1653_XN_14S037W.IMG to=F21_044073_1653_XN_14S037W.lev0.cub
mroctx2isis from=F22_044218_1653_XN_14S037W.IMG to=F22_044218_1653_XN_14S037W.lev0.cub
spiceinit from=F21_044073_1653_XN_14S037W.lev0.cub web=yes
spiceinit from=F22_044218_1653_XN_14S037W.lev0.cub web=yes
ctxcal from=F21_044073_1653_XN_14S037W.lev0.cub to=F21_044073_1653_XN_14S037W.cal.cub
ctxcal from=F22_044218_1653_XN_14S037W.lev0.cub to=F22_044218_1653_XN_14S037W.cal.cub
ctxevenodd from=F21_044073_1653_XN_14S037W.cal.cub to=F21_044073_1653_XN_14S037W.lev1.cub
ctxevenodd from=F22_044218_1653_XN_14S037W.cal.cub to=F22_044218_1653_XN_14S037W.lev1.cub

## ASP commands
parallel_stereo F21_044073_1653_XN_14S037W.lev1.cub F22_044218_1653_XN_14S037W.lev1.cub --left-image-crop-win 2264 6880 2000 2000 --right-image-crop-win 2411 7695 2000 2000 stereo_only/stereo_only -s stereo.nonmap 
point2dem --tr 6.0 -r mars --sinusoidal --proj-lon 322 --proj-lat 0 stereo_only/stereo_only-PC.tif --orthoimage stereo_only/stereo_only-L.tif 
hillshade --azimuth 300 --elevation 20 stereo_only/stereo_only-DEM.tif -o stereo_only/stereo_only-hill.tif

(9) Simple viewer and GDAL Tips (GDAL tools come with ASP binaries)
 sudo apt-get install gpicview
-- install a simple image viewer. Or you can try a hidden linux gem called "tuiview" to visualize 32bit GIS files. see GDAL env. below.
> gpicview stereo_only/stereo_only-hill.tif
--my hillshade has a right edge issue (not sure why yet). But DEM and CTX DRG (orthoimage) look great.

-- stretching to 8bit for this simple viewer.
> gdal_translate -scale -ot Byte stereo_only/stereo_only-DEM.tif stereo_only/stereo_only-DEM_8bit.tif
> gpicview stereo_only/stereo_only-DEM_8bit.tif

> gdal_translate -scale -ot Byte stereo_only/stereo_only-DRG.tif stereo_only/stereo_only-DRG_8bit.tif
> gpicview stereo_only/stereo_only-DRG_8bit.tif


figure 1. gpicview(s) with test stereo-derived CTX orthorectified image (DRG) and DEM and  create in ASP. Note that more should be done to align to MOLA!

tip: Now run ISIS commands from (really a shell script) from Powershell. I guess this means ArcGIS or Socet GXP might be able to run ISIS3 commands...

From Windows, start powershell (not the (x86) version), from the horrible blue background (do yourself a favor and turn the background black), run:
> bash -i -c "conda activate asp3 ; /home/thare ; ls -l "

-- so the trick here is the "-i" which setups the environment (e.g., bash) and "-c" runs the command in quotes.
-- In Bash, your Windows files are: /mnt/c or /mnt/d, etc.
-- more tricks: https://www.howtogeek.com/262086/how-to-run-linux-commands-from-outside-the-bash-shell-on-windows-10/

reference: https://msdn.microsoft.com/en-us/commandline/wsl/faq


tip: more Python 3.x packages for Anaconda with GDAL

> conda create -n gdal3
> conda activate gdal3
> conda install -c conda-forge tuiview jupyter basemap matplotlib xerces-c kealib
-- note putting all the packages on the same line, can help with getting all dependencies correct. GDAL tools come with ASP, but adding all these additional requirements make be bad. Here they are safely in their own conda environment.

When you run from your Ubuntu side:
> jupyter notebook
you can then run your browser on the Windows-side using the link provided in Ubuntu - pretty cool.

No comments:

Post a Comment