Sunday, July 23, 2017

ISIS3 on Windows 10 WSL Ubuntu (Bash)

-------->>>> Please see NEW 2024 version here


WARNING: text below is deprecated -------

Based on a tweet by MarsLakes, I also decided to give ISIS3 on Windows 10 a try. Note this is for Windows 10 Anniversary update or higher. Anyway, here is my current cheat sheet. It works better that I thought it would. Warning: this requires a lot of downloading.

Updated July 2019, to support ISIS3 (v3.6+) in an Anaconda environment.


(1) get Linux for Windows 10
I recommend Ubuntu 18 LTS installed via the Windows 10 app store, but other WSL flavors may work also.

And if you don't have access to the App store, try to download:
https://docs.microsoft.com/en-us/windows/wsl/install-manual

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

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

(4) From Windows, start bash and let's get the GUI working ( can be one line also, listing them all).
> sudo apt-get install -y -q xclip gnome-themes-standard gtk2-engines-murrine
> sudo apt-get install -y -q dbus dbus-x11 x11-apps libgl1-mesa-glx
-- test X11
-- add this line to bottom of .bashrc (or type):
> echo export DISPLAY=:0 >> ~/.bashrc
> source ~/.bashrc
> xclock

(5) Get Anaconda
> wget https://repo.anaconda.com/archive/Anaconda3-2019.03-Linux-x86_64.sh
-- or get latest version from download page: https://www.anaconda.com/distribution/
> bash Anaconda3-2019.03-Linux-x86_64.sh
-- follow install instructions and allow installer to update your shell (~/.bashrc) when it asks.
-- once installed, restart the Ubuntu terminal from Windows start.

(6) Get ISIS3 applications
-- here you can follow the ISIS3 installation pages: https://github.com/USGS-Astrogeology/ISIS3
or these steps:
> conda create -n isis3 python=3.6
> conda activate isis3
> conda config --env --add channels conda-forge
> conda config --env --add channels usgs-astrogeology
> conda install -c usgs-astrogeology isis3
> conda activate isis3
-- execute the ISIS3 variable initialization script with default arguments.
-- this script prepares default values for: $ISISROOT, $ISIS3DATA, $ISIS3TESTDATA
> python $CONDA_PREFIX/scripts/isis3VarInit.py

(7) Get ISIS3 base data
> conda activate isis3
> cd $ISIS3DATA
-- note the "." at the end of the next line. This is the destination and it is required (or a dir. path).
> rsync -azv --delete --partial isisdist.astrogeology.usgs.gov::isis3data/data/base .
-- note the "." at the end. This is the destination location and it is required (or a dir. path).
-- try opening something
> qview $ISIS3DATA/base/dems/MSGR_DEM_USG_EQ_I_V02_prep.cub
-- done for the minimal install. You may need lots more SPICE data for a particular mission, read more about that towards the end for the install page: https://github.com/USGS-Astrogeology/ISIS3
-- So the next time you launch an Ubuntu terminal, just type "conda activate isis3" to run ISIS3 apps.

(8) to run a test CTX image in ISIS3
-- first get some additional MRO files
> cd $ISIS3DATA
-- note the space and period at the end for the next line:
>
 rsync -azv --delete --partial --exclude='kernels' isisdist.astrogeology.usgs.gov::isis3data/data/mro .
-- now get a scripted example
> cd ~
> sudo apt-get install csh
> mkdir isis3_test
> cd isis3_test
> chmod +x CTX_process_all.csh
> printf "Group = Mapping\n  ProjectionName  = SimpleCylindrical\n  LongitudeDomain = 180\n  CenterLongitude = 0.0\n  CenterLatitude  = 0.0\nEnd_Group\nEnd" > simp0.map
> ./CTX_process_all.csh simp0.map  0
-- wait several minutes for ISIS3 to do its thing.
> qview P22_009816_1745_XI_05S073W.lev1eo.cub
figure 1. qview with CTX P22_009816_1745_XI_05S073W calibrated only

> sudo apt-get install gpicview
> gpicview P22_009816_1745_XI_05S073W.png
figure 2. gpicview with CTX P22_009816_1745_XI_05S073W.png all map projected

(9) Now use GDAL to create a GIS-ready image (GeoTiff) not just a PNG. 
-- note ISIS3 and gdal cannot be in the same anaconda environment just yet. Let's make another independent environment for GDAL
> conda create -n gdal
> conda activate gdal
> conda install -c conda-forge gdal=3

-- first stretch to 8bit using ISIS3 (0.5% to 99.5% linear stretch -- optional):
> conda activate isis3
stretch from=P22_009816_1745_XI_05S073W.lev2.cub to=P22_009816_1745_XI_05S073W_8bit.cub+8bit+1:254 USEPERCENTAGES=true pairs="0:1 0.5:1 99.5:254 100:254" null=0 lis=1 lrs=1 his=255 hrs=255

-- now get back to GDAL's environment. Jumping between conda environments can be scripted as shown here to bounce back and forth.
> conda activate gdal
> gdal_translate P22_009816_1745_XI_05S073W_8bit.cub P22_009816_1745_XI_05S073W_8bit.tif
> gpicview P22_009816_1745_XI_05S073W_8bit.tif



Updating to the next version of ISIS3 using the latest Anaconda methods will generally only take minutes now. You can follow ISIS3 Release Notes on Astrodiscuss to get alerted to updated versions.

But when you are ready, simply run:
> conda update isis3

And if you even need to downgrade (or specify a particular version), simply list the version number like:
> conda install isis3=3.7.1






tip: Now run ISIS commands from (really a shell script) from Powershell. I guess this means ArcMap 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 isis3 ; /home/thare/isis3_test ; ./CTX_process_all.csh simp0.map  0"


-- so the trick here is the "-i" which setups the env. for ISIS3 and "-c" runs the command in quotes.
-- Also the Windows locations for /home/thare is here (you may need to show hidden files in Windows to see it): C:\Users\<WIN_USER>\AppData\Local\lxss\home\thare\
-- 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 activate gdal
> conda install -c conda-forge jupyter basemap matplotlib xerces-c kealib
-- note putting all the packages on the same line, can help with getting all dependencies correct.

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.

5 comments:

  1. Hi Trent, thanks for this guide. I have an issue with the GUI, when I open qview using Xming no qview icon is visible. Did I miss something?

    ReplyDelete
  2. For WSL2 updates (might work for WSL1 installs too), X11 works a little different.
    from: https://github.com/microsoft/WSL/issues/4106#issuecomment-557920567

    Still install Xming https://sourceforge.net/projects/xming/ and then either:
    Insecure mode: edit the desktop shortcut and add the option -ac to the end
    OR
    Secure mode: go to the installation directory and add the WSL ip in X0.hosts


    add this line to the bottom for your ~/.bashrc
    export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0

    ReplyDelete
  3. Hello Trent,
    I'm working on a linux mint machine, I followed all the steps mentioned above, my problem is that I can't display the image, I only have the qview interface with nothing at all, I have absolutely no idea where the problem comes from.

    ReplyDelete
  4. Hello, Trent.
    Based on the c shell file you provided for CTX, I modified it a bit for using ISIS for MRO images. But there I am getting the following error -
    ./marci_all.csh: line 13: syntax error near unexpected token `('
    ./marci_all.csh: line 13: `foreach i (*.IMG)'

    You can view my code here- https://github.com/Anirbanm0101/marci_isis. In this repo, I have also attached the map template I used. Can you please point me the error?
    Thanks a lot.

    ReplyDelete
  5. When I want to transform the file,there is a error about using pds2isis.
    How can I solve this promblem?
    (isis3) ryan@HYRking:~$ pds2isis from=input.img to=out.cub
    **I/O ERROR** Unable to open [/home/ryan/anaconda3/envs/isis3/data/base/translations/pdsImage.trn].

    ReplyDelete