powershell - Build or use astrometry.net natively on Windows 11 - Stack Overflow

I would like to use the astrometry software suite on windows, specifically the executable files, not th

I would like to use the astrometry software suite on windows, specifically the executable files, not the web interface.

However, there are no recent and maintained binaries for Windows I could find.

One documented solution is to use the Windows Subsystem for Linux. However, this requires nevertheless to perform an OS switch (change of shell), which means I can't directly use it inside a Windows-based workflow.

What can I do ?

What I tried : build astrometry on Windows

see .html#build

It fails at the very core step of building astrometry itself. Astrometry is based on a make build system, and their build process is built for/on Linux. It includes a step of (re) building parts of the Gnu Scientific Library (GSL; shipped with astrometry code). This GSL build relies on a several thousand lines of code in bash script (~15 kLOC). But thats not the only part where it fails.

It is possible to build most of Astrometry dependancies by hand via VS Studio + cmake + some effort. Best way I found was to use vcpkg (Microsoft) which has a repository of recipes for lots of lirbaries.

In the end, make invokations fail anyway ... for example:

Makefile:204: update target 'config.h' due to: target does not exist
Creating temporary batch file C:\Users\readacted\AppData\Local\Temp\make556540-c.bat
Batch file contents:
        @echo off
        ./configure --enable-shared=no --prefix=`pwd`/stage
./configure --enable-shared=no --prefix=`pwd`/stage
CreateProcess(C:\Users\readacted\AppData\Local\Temp\make556540-c.bat,C:\Users\readacted\AppData\Local\Temp\make556540-c.bat,...)
Putting child 0396cc68 (config.h) PID 60299728 on the chain.
Live child 0396cc68 (config.h) PID 60299728
'.' n’est pas reconnu en tant que commande interne
ou externe, un programme exécutable ou un fichier de commandes.
CreateProcess(C:\Users\redacted\AppData\Local\Temp\make356496-2.bat,C:\Users\redacted\AppData\Local\Temp\make356496-2.bat,...)
'uname' n’est pas reconnu en tant que commande interne
ou externe, un programme exécutable ou un fichier de commandes.

I even tried:

  • to force make to use powershell as the default shell, but it explodes when touch, uname, rm and other Linux commands are called ...
  • to fix a few lines here and there in the make's spaghetti of scripts/configuration files, but It seems insufficient.

Here is an attempt of a powershell script to "do all the astrometry build process". It could be better, maybe.

The script creates .bat level commands for touch and uname, because make creates and invokes .bat files, even if we pass a powershell. But to no avail.

# Force start a Visual Studio shell ?
# powershell -noe -c "&{Import-Module 'C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\Microsoft.VisualStudio.DevShell.dll'; Enter-VsDevShell 7ea560d7}"
# $env:PATH="Q:\build_astrometry\cmake\bin;Q:\build_astrometry\cmake-3.31.6-windows-x86_64\bin;"+$env:PATH

function BuildAstrometry {
    param (
        [bool]$force_download,
        [string]$TARGET_INSTALL_DIR,
        [string]$pws_tweaks_file
    )
    Write-Host ("Build ASTROMETRY - {0} {1} {2}" -f $force_download, $TARGET_INSTALL_DIR, $CFITSIO_INSTALL_DIR)
    $root = "astrometry"
    if ($force_download) {
        $url = "/releases/download/0.97/astrometry-0.97.tar.gz"
        $outfile = "{0}.tar.gz" -f $root
        Push-Location -Path  $env:TEMP
        Write-Host "Download source from "$url" to "$outfile
        Invoke-WebRequest $url -OutFile $outfile
        tar xvzf $outfile
        Pop-Location
    }
    else {
        Write-Host "Do not download source (force_download="$force_download")"
    }
    $BUILD_DIR = "$env:TEMP\$root-0.97"
    If (!(test-path -PathType container $BUILD_DIR)) {
        New-Item -ItemType Directory -Path $BUILD_DIR
    }
    Push-Location -Path $BUILD_DIR
    Write-Host "Build ASTROMETRY -> start make"
    $env:INSTALL_DIR = $TARGET_INSTALL_DIR
    $python_script = "$env:VIRTUAL_ENV\Scripts\python3.exe" # symlink supposed to done earlier
    # Trick make to use powershell
    # /
    # get powershell path dynamically
    # 
    # $powershellexe=Join-Path -Path "$($PSHOME)" -ChildPath "powershell.exe"
    # the follwoing is supposed to be faster ?
    $powershellexe = [Diagnostics.Process]::GetCurrentProcess().Path
    Write-Host $powershellexe
    # transform to linux style path
    # $powershellexe = $powershellexe -replace "\\", "/" -replace ":", ""
    # ESCAPE: 
    # $powershellexe=$powershellexe -replace ":", "\:"
    Write-Host "Build ASTROMETRY -> make"
    Write-Host "Tweaks file here $pws_tweaks_file"
    $vcpkg_bin="C:\vcpkg\installed\x64-windows\bin"
    $vcpkg_inc="C:\vcpkg\installed\x64-windows\include"
    # $importPSMod ="-Noexit Import-Module $pws_tweaks_file"
    $GSL_conf="SYSTEM_GSL=yes GSL_INC=-I$vcpkg_inc\gsl GSL_LIB=-L$vcpkg_bin -lgsl"
    $CFITS_conf="CFITS_INC=-I$vcpkg_inc\cfitsio CFITS_LIB=-L$vcpkg_bin -lcfitsio"
    $WCS_conf="WCSLIB_INC=-I$vcpkg_inc WCSLIB_LIB=-L$vcpkg_bin -lwcslib"
    $CAIRO_conf="CAIRO_INC=-I$vcpkg_inc\cairo CAIRO_LIB=-L$vcpkg_bin -lcairo-2"
    # OVERLOADED SHELL with special import file see below
    make SHELL="$powershellexe -Noexit Import-Module $pws_tweaks_file" IFS=. $GSL_conf $CFITS_conf $WCS_conf $CAIRO_conf PYTHON_SCRIPT=$python_script -d
    # Write-Host "Build ASTROMETRY -> make py"
    make SHELL="$powershellexe -Noexit Import-Module $pws_tweaks_file" IFS=. py -d
    # Write-Host "Build ASTROMETRY -> make extra"
    make SHELL="$powershellexe -Noexit Import-Module $pws_tweaks_file" IFS=. extra -d
    # Write-Host "Build ASTROMETRY -> make extra"
    make SHELL="$powershellexe -Noexit Import-Module $pws_tweaks_file" IFS=. install -d
    # Pop-Location
    Write-Host "Build ASTROMETRY -> FINISHED"
}

Write-Host "Load script"

function set_python {
    $venv_dir = "$env:TEMP\venv-astrometry\"
    If (!(test-path -PathType Container $venv_dir)) {
        Write-Host "Create python 3.12 venv here: $venv_dir"
        py -3.12 -m venv $venv_dir
    }
    Write-Host "Activate venv"
    Push-Location -Path $venv_dir
    Scripts\activate.ps1
    Pop-Location

    # pip install setuptools wheel pip
    # # pip install numpy pyfits
    python.exe -m pip install --upgrade pip
    pip install astropy[recommended] --upgrade # substitude to pyfits
    New-Item -Path "$env:VIRTUAL_ENV\Scripts\python3.exe" -ItemType SymbolicLink -Value "$env:VIRTUAL_ENV\Scripts\python.exe"
}

Write-Host "Start build process"
conda deactivate # just in case ...

$ASTROMETRY_INSTALL_DIR = "$env:USERPROFILE\installs\astrometry"

function install_vcpkg {
    # TODO: check if present and if not, ensure we do it once
    Set-Location C:\
    git clone .git
    Set-Location vcpkg; .\bootstrap-vcpkg.bat
    .\vcpkg.exe integrate install
}

function build_deps {
    # got the idead from there: 
    # TODO: add vcpkg to path !
    C:\vcpkg\vcpkg install libpng
    C:\vcpkg\vcpkg install zlib
    C:\vcpkg\vcpkg install bzip2
    C:\vcpkg\vcpkg install cairo # libjpg required by astrometry is missing, but somewhat included in cairo ?
    C:\vcpkg\vcpkg install wcslib
    C:\vcpkg\vcpkg install cfitsio
    C:\vcpkg\vcpkg install gsl gsl:x64-windows
    
}
# the follwing creates a powershell module file loaded by make when it invokes the overloaded shell 
function create_ps_tweak_file_for_make {
    param (
        [string]$outfile
    )
    $pscode = @"
    function touch {
        param (
            [string]`$Path
        )

        if (Test-Path `$Path) {
            # File exists, update its timestamp
            (Get-Item `$Path).LastWriteTime = Get-Date
        } else {
            # File does not exist, create it
            New-Item -ItemType File -Path `$Path | Out-Null
        }
    }

    function uname {
        param (
            [switch]`$all,      # -a, --all
            [switch]`$kernel,   # -s, --kernel-name
            [switch]`$nodename, # -n, --nodename
            [switch]`$release,  # -r, --kernel-release
            [switch]`$version,  # -v, --kernel-version
            [switch]`$machine,  # -m, --machine
            [switch]`$processor,# -p, --processor
            [switch]`$hardware, # -i, --hardware-platform
            [switch]`$os,       # -o, --operating-system
            [switch]`$help,     # --help
            [switch]`$uname_version # --version
        )

        # Map long parameters to short ones
        if (`$args) {
            foreach (`$arg in `$args) {
                switch (`$arg) {
                    `"--all`"                { `$all = `$true }
                    `"--kernel-name`"        { `$kernel = `$true }
                    `"--nodename`"           { `$nodename = `$true }
                    `"--kernel-release`"     { `$release = `$true }
                    `"--kernel-version`"     { `$version = `$true }
                    `"--machine`"            { `$machine = `$true }
                    `"--processor`"          { `$processor = `$true }
                    `"--hardware-platform`"  { `$hardware = `$true }
                    `"--operating-system`"   { `$os = `$true }
                    `"--help`"               { `$help = `$true }
                    `"--version`"            { `$uname_version = `$true }
                    default { Write-Output `"Invalid option: `$arg`nTry '--help' for more information.`"; return }
                }
            }
        }

        # Get system information
        `$osName = (Get-CimInstance Win32_OperatingSystem).Caption
        `$osVersion = (Get-CimInstance Win32_OperatingSystem).Version
        `$architecture = (Get-CimInstance Win32_OperatingSystem).OSArchitecture
        `$hostname = `$env:COMPUTERNAME
        `$kernelVersion = (Get-CimInstance Win32_OperatingSystem).BuildNumber
        `$processorType = (Get-CimInstance Win32_Processor).Name
        `$machineType = if (`$architecture -match `"64`") {`"x86_64`"} else {`"i686`"}
        `$hardwarePlatform = (Get-CimInstance Win32_ComputerSystem).Model

        if (`$help) {
            Write-Output `"Usage: uname [OPTION]...`nPrint system information.`n`nOptions:`n  -a, --all                Show all system information`n  -s, --kernel-name       Print the kernel name`n  -n, --nodename          Print the system hostname`n  -r, --kernel-release    Print the kernel release`n  -v, --kernel-version    Print the kernel version`n  -m, --machine           Print the hardware architecture`n  -p, --processor         Print the processor type`n  -i, --hardware-platform Print the hardware platform`n  -o, --operating-system  Print the operating system`n  --version              Show uname version`n  --help                 Show this message and exit`"
            return
        }

        if (`$uname_version) {
            Write-Output `"uname (PowerShell) 1.1`nBased on Windows OS`"
            return
        }

        # Handle -a (all) first since it overrides individual options
        if (`$all) {
            Write-Output `"Windows `$hostname `$kernelVersion `$osVersion `$machineType `$processorType `$hardwarePlatform`"
            return
        }

        # Collect selected outputs
        `$output = @()
        if (`$kernel) { `$output += `"Windows`" }
        if (`$nodename) { `$output += `"`$hostname`" }
        if (`$release) { `$output += `"`$kernelVersion`" }
        if (`$version) { `$output += `"`$osVersion`" }
        if (`$machine) { `$output += `"`$machineType`" }
        if (`$processor) { `$output += `"`$processorType`" }
        if (`$hardware) { `$output += `"`$hardwarePlatform`" }
        if (`$os) { `$output += `"Windows`" }

        # Default case: If no options given, return OS name
        if (-not `$output) {
            `$output = @(`$osName)
        }

        # Print the output
        Write-Output (`$output -join `" `")
    };
"@
    # Set-Content -Path $outfile -Value $pscode
    $dosuname = @"
    @echo off
setlocal enabledelayedexpansion

:: Parse command-line arguments
set `"option=%1`"

:: Get System Information
for /f `"tokens=2 delims==`" %%I in ('wmic os get Caption /value ^| find `"=`"') do set `"osName=%%I`"
for /f `"tokens=2 delims==`" %%I in ('wmic os get Version /value ^| find `"=`"') do set `"osVersion=%%I`"
for /f `"tokens=2 delims==`" %%I in ('wmic os get BuildNumber /value ^| find `"=`"') do set `"kernelVersion=%%I`"
for /f `"tokens=2 delims==`" %%I in ('wmic computersystem get Model /value ^| find `"=`"') do set `"hardware=%%I`"
for /f `"tokens=2 delims==`" %%I in ('wmic os get OSArchitecture /value ^| find `"=`"') do set `"architecture=%%I`"
for /f `"tokens=2 delims==`" %%I in ('wmic cpu get Name /value ^| find `"=`"') do set `"processor=%%I`"

set `"hostname=%COMPUTERNAME%`"
set `"machineType=x86`"
if `"%architecture%`"==`"64-bit`" set `"machineType=x86_64`"

:: Handle uname options
if `"%option%`"==`"`" (
    echo %osName%
    exit /b
)
if `"%option%`"==`"-s`" (
    echo Windows
    exit /b
)
if `"%option%`"==`"--kernel-name`" (
    echo Windows
    exit /b
)
if `"%option%`"==`"-n`" (
    echo %hostname%
    exit /b
)
if `"%option%`"==`"--nodename`" (
    echo %hostname%
    exit /b
)
if `"%option%`"==`"-r`" (
    echo %kernelVersion%
    exit /b
)
if `"%option%`"==`"--kernel-release`" (
    echo %kernelVersion%
    exit /b
)
if `"%option%`"==`"-v`" (
    echo %osVersion%
    exit /b
)
if `"%option%`"==`"--kernel-version`" (
    echo %osVersion%
    exit /b
)
if `"%option%`"==`"-m`" (
    echo %machineType%
    exit /b
)
if `"%option%`"==`"--machine`" (
    echo %machineType%
    exit /b
)
if `"%option%`"==`"-p`" (
    echo %processor%
    exit /b
)
if `"%option%`"==`"--processor`" (
    echo %processor%
    exit /b
)
if `"%option%`"==`"-i`" (
    echo %hardware%
    exit /b
)
if `"%option%`"==`"--hardware-platform`" (
    echo %hardware%
    exit /b
)
if `"%option%`"==`"-o`" (
    echo Windows
    exit /b
)
if `"%option%`"==`"--operating-system`" (
    echo Windows
    exit /b
)
if `"%option%`"==`"-a`" (
    echo Windows %hostname% %kernelVersion% %osVersion% %machineType% %processor% %hardware%
    exit /b
)
if `"%option%`"==`"--all`" (
    echo Windows %hostname% %kernelVersion% %osVersion% %machineType% %processor% %hardware%
    exit /b
)
if `"%option%`"==`"--help`" (
    echo Usage: uname.bat [OPTION]
    echo -s, --kernel-name       Print the kernel name
    echo -n, --nodename          Print the network node hostname
    echo -r, --kernel-release    Print the kernel release
    echo -v, --kernel-version    Print the kernel version
    echo -m, --machine           Print the machine hardware name
    echo -p, --processor         Print the processor type
    echo -i, --hardware-platform Print the hardware platform
    echo -o, --operating-system  Print the operating system
    echo -a, --all               Print all system information
    exit /b
)

:: If the option is unknown
echo Invalid option: %option%
echo Try '--help' for more information.
exit /b
"@
    
    $dosrm = @"
    @echo off
setlocal enabledelayedexpansion

:: Default values
set `"recursive=0`"
set `"force=0`"

:: Parse options
:parse_args
if `"%1`"==`"`" goto process
if `"%1`"==`"-r`" set `"recursive=1`"
if `"%1`"==`"--recursive`" set `"recursive=1`"
if `"%1`"==`"-f`" set `"force=1`"
if `"%1`"==`"--force`" set `"force=1`"
if not `"%1`"==`"-r`" if not `"%1`"==`"-f`" if not `"%1`"==`"--recursive`" if not `"%1`"==`"--force`" (
    set `"files=!files! %1`"
)
shift
goto parse_args

:process
if `"%files%`"==`"`" (
    echo Usage: rm.bat [OPTIONS] FILE...
    echo Options:
    echo   -r, --recursive  Remove directories and their contents recursively
    echo   -f, --force      Ignore non-existent files and errors
    exit /b 1
)

:: Remove files/directories
for %%F in (%files%) do (
    if exist `"%%F`" (
        if exist `"%%F\*`" (
            :: It's a directory
            if `"%recursive%`"==`"1`" (
                rmdir /s /q `"%%F`"
            ) else (
                echo rm: cannot remove '%%F': Is a directory
            )
        ) else (
            :: It's a file
            del /q `"%%F`"
        )
    ) else (
        if `"%force%`"==`"0`" (
            echo rm: cannot remove '%%F': No such file or directory
        )
    )
)

exit /b 0
"@
    Set-Content -Path $outfile -Value $pscode
    Set-Content -Path uname.bat -Value $dosuname
    Set-Content -Path rm.bat -Value $dosrm
}
set_python
# build_deps

$pws_tweaks_file = "$env:TMP\shell_tweaks.psm1"
create_ps_tweak_file_for_make $pws_tweaks_file

Write-Host "Call BuildAstrometry"
$env:PATH = "C:\vcpkg\installed\x64-windows\bin;C:\vcpkg\installed\x64-windows\include;" + $env:PATH
BuildAstrometry $false $ASTROMETRY_INSTALL_DIR $CFITSIO_INSTALL_DIR $pws_tweaks_file

Write-Host "Script finished"

It still show several subcommands crashing and finishes with this,even if GSL is not supposed to be built (since we provide GSL_LIB & GSL_INC) :

[...]
'gcc' n’est pas reconnu en tant que commande interne
ou externe, un programme exécutable ou un fichier de commandes.
[...]
Makefile:108: update target 'gsl-an' due to: target is .PHONY
[...]
make[1]: Leaving directory 'C:/Users/redacted/AppData/Local/Temp/astrometry-0.97/gsl-an'
Reaping losing child 02e5c1b0 PID 48579424
Cleaning up temp batch file C:\Users\redacted\AppData\Local\Temp\make572908-10.bat
make: *** [Makefile:108: gsl-an] Error 2

Tools infos:

  • vcpkg : vcpkg package management program version 2025-03-13-7699e411ea11543de6abc0c7d5fd11cfe0039ae5
  • make : GNU Make 4.4.1 Built for Windows32
  • cmkae : cmake version 3.31.6
  • Visual Studio 17 (2022) Dev (power)Shell ( and using cmake -G "Visual Studio 17 2022")
  • LLVM clang version 20.1.0 Target: x86_64-pc-windows-msvc Thread model: posix InstalledDir: C:\Program Files\LLVM\bin
  • GCC gcc.exe (x86_64-posix-seh-rev0, Built by MinGW-Builds project) 13.2.0
  • and effectively installed vcpkg ports:
brotli:x64-windows                                1.1.0#1             a generic-purpose lossless compression algorithm...
bzip2:x64-windows                                 1.0.8#6             bzip2 is a freely available, patent free, high-q...
bzip2[tool]:x64-windows                                               Builds bzip2 executable
cairo:x64-windows                                 1.18.2#1            Cairo is a 2D graphics library with support for ...
cairo[fontconfig]:x64-windows                                         Build with fontconfig
cairo[freetype]:x64-windows                                           Use the freetype font backend
cfitsio:x64-windows                               3.49#6              Library of C and Fortran subroutines for reading...
dirent:x64-windows                                1.24                Dirent is a C/C++ programming interface that all...
expat:x64-windows                                 2.6.4               XML parser library written in C
fontconfig:x64-windows                            2.15.0#2            Library for configuring and customizing font acc...
freetype:x64-windows                              2.13.3              A library to render fonts.
freetype[brotli]:x64-windows                                          Support decompression of WOFF2 streams
freetype[bzip2]:x64-windows                                           Support bzip2 compressed fonts.
freetype[png]:x64-windows                                             Support PNG compressed OpenType embedded bitmaps.
freetype[zlib]:x64-windows                                            Use zlib instead of internal library for DEFLATE
gperf:x64-windows                                 3.1#6               GNU perfect hash function generator
gsl:x64-windows                                   2.8                 The GNU Scientific Library is a numerical librar...
libpng:x64-windows                                1.6.46              libpng is a library implementing an interface fo...
pixman:x64-windows                                0.44.2              Pixman is a low-level software library for pixel...
pthread:x64-windows                               3.0.0#2             empty package, linking to other port
pthreads:x64-windows                              3.0.0#14            Meta-package that provides PThreads4W on Windows...
vcpkg-cmake-config:x64-windows                    2024-05-23
vcpkg-cmake-get-vars:x64-windows                  2024-09-22
vcpkg-cmake:x64-windows                           2024-04-23
vcpkg-tool-meson:x64-windows                      1.6.1               Meson build system
zlib:x64-windows                                  1.3.1               A compression library

I would like to use the astrometry software suite on windows, specifically the executable files, not the web interface.

However, there are no recent and maintained binaries for Windows I could find.

One documented solution is to use the Windows Subsystem for Linux. However, this requires nevertheless to perform an OS switch (change of shell), which means I can't directly use it inside a Windows-based workflow.

What can I do ?

What I tried : build astrometry on Windows

see https://astrometry/doc/build.html#build

It fails at the very core step of building astrometry itself. Astrometry is based on a make build system, and their build process is built for/on Linux. It includes a step of (re) building parts of the Gnu Scientific Library (GSL; shipped with astrometry code). This GSL build relies on a several thousand lines of code in bash script (~15 kLOC). But thats not the only part where it fails.

It is possible to build most of Astrometry dependancies by hand via VS Studio + cmake + some effort. Best way I found was to use vcpkg (Microsoft) which has a repository of recipes for lots of lirbaries.

In the end, make invokations fail anyway ... for example:

Makefile:204: update target 'config.h' due to: target does not exist
Creating temporary batch file C:\Users\readacted\AppData\Local\Temp\make556540-c.bat
Batch file contents:
        @echo off
        ./configure --enable-shared=no --prefix=`pwd`/stage
./configure --enable-shared=no --prefix=`pwd`/stage
CreateProcess(C:\Users\readacted\AppData\Local\Temp\make556540-c.bat,C:\Users\readacted\AppData\Local\Temp\make556540-c.bat,...)
Putting child 0396cc68 (config.h) PID 60299728 on the chain.
Live child 0396cc68 (config.h) PID 60299728
'.' n’est pas reconnu en tant que commande interne
ou externe, un programme exécutable ou un fichier de commandes.
CreateProcess(C:\Users\redacted\AppData\Local\Temp\make356496-2.bat,C:\Users\redacted\AppData\Local\Temp\make356496-2.bat,...)
'uname' n’est pas reconnu en tant que commande interne
ou externe, un programme exécutable ou un fichier de commandes.

I even tried:

  • to force make to use powershell as the default shell, but it explodes when touch, uname, rm and other Linux commands are called ...
  • to fix a few lines here and there in the make's spaghetti of scripts/configuration files, but It seems insufficient.

Here is an attempt of a powershell script to "do all the astrometry build process". It could be better, maybe.

The script creates .bat level commands for touch and uname, because make creates and invokes .bat files, even if we pass a powershell. But to no avail.

# Force start a Visual Studio shell ?
# powershell -noe -c "&{Import-Module 'C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\Microsoft.VisualStudio.DevShell.dll'; Enter-VsDevShell 7ea560d7}"
# $env:PATH="Q:\build_astrometry\cmake\bin;Q:\build_astrometry\cmake-3.31.6-windows-x86_64\bin;"+$env:PATH

function BuildAstrometry {
    param (
        [bool]$force_download,
        [string]$TARGET_INSTALL_DIR,
        [string]$pws_tweaks_file
    )
    Write-Host ("Build ASTROMETRY - {0} {1} {2}" -f $force_download, $TARGET_INSTALL_DIR, $CFITSIO_INSTALL_DIR)
    $root = "astrometry"
    if ($force_download) {
        $url = "https://github/dstndstn/astrometry/releases/download/0.97/astrometry-0.97.tar.gz"
        $outfile = "{0}.tar.gz" -f $root
        Push-Location -Path  $env:TEMP
        Write-Host "Download source from "$url" to "$outfile
        Invoke-WebRequest $url -OutFile $outfile
        tar xvzf $outfile
        Pop-Location
    }
    else {
        Write-Host "Do not download source (force_download="$force_download")"
    }
    $BUILD_DIR = "$env:TEMP\$root-0.97"
    If (!(test-path -PathType container $BUILD_DIR)) {
        New-Item -ItemType Directory -Path $BUILD_DIR
    }
    Push-Location -Path $BUILD_DIR
    Write-Host "Build ASTROMETRY -> start make"
    $env:INSTALL_DIR = $TARGET_INSTALL_DIR
    $python_script = "$env:VIRTUAL_ENV\Scripts\python3.exe" # symlink supposed to done earlier
    # Trick make to use powershell
    # https://www.reddit/r/vim/comments/ucgb14/using_make_on_windows_10_with_powershell_as_shell/
    # get powershell path dynamically
    # https://stackoverflow/questions/59605148/powershell-find-path-to-currently-running-host-powershell-executable
    # $powershellexe=Join-Path -Path "$($PSHOME)" -ChildPath "powershell.exe"
    # the follwoing is supposed to be faster ?
    $powershellexe = [Diagnostics.Process]::GetCurrentProcess().Path
    Write-Host $powershellexe
    # transform to linux style path
    # $powershellexe = $powershellexe -replace "\\", "/" -replace ":", ""
    # ESCAPE: 
    # $powershellexe=$powershellexe -replace ":", "\:"
    Write-Host "Build ASTROMETRY -> make"
    Write-Host "Tweaks file here $pws_tweaks_file"
    $vcpkg_bin="C:\vcpkg\installed\x64-windows\bin"
    $vcpkg_inc="C:\vcpkg\installed\x64-windows\include"
    # $importPSMod ="-Noexit Import-Module $pws_tweaks_file"
    $GSL_conf="SYSTEM_GSL=yes GSL_INC=-I$vcpkg_inc\gsl GSL_LIB=-L$vcpkg_bin -lgsl"
    $CFITS_conf="CFITS_INC=-I$vcpkg_inc\cfitsio CFITS_LIB=-L$vcpkg_bin -lcfitsio"
    $WCS_conf="WCSLIB_INC=-I$vcpkg_inc WCSLIB_LIB=-L$vcpkg_bin -lwcslib"
    $CAIRO_conf="CAIRO_INC=-I$vcpkg_inc\cairo CAIRO_LIB=-L$vcpkg_bin -lcairo-2"
    # OVERLOADED SHELL with special import file see below
    make SHELL="$powershellexe -Noexit Import-Module $pws_tweaks_file" IFS=. $GSL_conf $CFITS_conf $WCS_conf $CAIRO_conf PYTHON_SCRIPT=$python_script -d
    # Write-Host "Build ASTROMETRY -> make py"
    make SHELL="$powershellexe -Noexit Import-Module $pws_tweaks_file" IFS=. py -d
    # Write-Host "Build ASTROMETRY -> make extra"
    make SHELL="$powershellexe -Noexit Import-Module $pws_tweaks_file" IFS=. extra -d
    # Write-Host "Build ASTROMETRY -> make extra"
    make SHELL="$powershellexe -Noexit Import-Module $pws_tweaks_file" IFS=. install -d
    # Pop-Location
    Write-Host "Build ASTROMETRY -> FINISHED"
}

Write-Host "Load script"

function set_python {
    $venv_dir = "$env:TEMP\venv-astrometry\"
    If (!(test-path -PathType Container $venv_dir)) {
        Write-Host "Create python 3.12 venv here: $venv_dir"
        py -3.12 -m venv $venv_dir
    }
    Write-Host "Activate venv"
    Push-Location -Path $venv_dir
    Scripts\activate.ps1
    Pop-Location

    # pip install setuptools wheel pip
    # # pip install numpy pyfits
    python.exe -m pip install --upgrade pip
    pip install astropy[recommended] --upgrade # substitude to pyfits
    New-Item -Path "$env:VIRTUAL_ENV\Scripts\python3.exe" -ItemType SymbolicLink -Value "$env:VIRTUAL_ENV\Scripts\python.exe"
}

Write-Host "Start build process"
conda deactivate # just in case ...

$ASTROMETRY_INSTALL_DIR = "$env:USERPROFILE\installs\astrometry"

function install_vcpkg {
    # TODO: check if present and if not, ensure we do it once
    Set-Location C:\
    git clone https://github/microsoft/vcpkg.git
    Set-Location vcpkg; .\bootstrap-vcpkg.bat
    .\vcpkg.exe integrate install
}

function build_deps {
    # got the idead from there: https://solarianprogrammer/2020/01/26/getting-started-gsl-gnu-scientific-library-windows-macos-linux/#gsl_installation_windows
    # TODO: add vcpkg to path !
    C:\vcpkg\vcpkg install libpng
    C:\vcpkg\vcpkg install zlib
    C:\vcpkg\vcpkg install bzip2
    C:\vcpkg\vcpkg install cairo # libjpg required by astrometry is missing, but somewhat included in cairo ?
    C:\vcpkg\vcpkg install wcslib
    C:\vcpkg\vcpkg install cfitsio
    C:\vcpkg\vcpkg install gsl gsl:x64-windows
    
}
# the follwing creates a powershell module file loaded by make when it invokes the overloaded shell 
function create_ps_tweak_file_for_make {
    param (
        [string]$outfile
    )
    $pscode = @"
    function touch {
        param (
            [string]`$Path
        )

        if (Test-Path `$Path) {
            # File exists, update its timestamp
            (Get-Item `$Path).LastWriteTime = Get-Date
        } else {
            # File does not exist, create it
            New-Item -ItemType File -Path `$Path | Out-Null
        }
    }

    function uname {
        param (
            [switch]`$all,      # -a, --all
            [switch]`$kernel,   # -s, --kernel-name
            [switch]`$nodename, # -n, --nodename
            [switch]`$release,  # -r, --kernel-release
            [switch]`$version,  # -v, --kernel-version
            [switch]`$machine,  # -m, --machine
            [switch]`$processor,# -p, --processor
            [switch]`$hardware, # -i, --hardware-platform
            [switch]`$os,       # -o, --operating-system
            [switch]`$help,     # --help
            [switch]`$uname_version # --version
        )

        # Map long parameters to short ones
        if (`$args) {
            foreach (`$arg in `$args) {
                switch (`$arg) {
                    `"--all`"                { `$all = `$true }
                    `"--kernel-name`"        { `$kernel = `$true }
                    `"--nodename`"           { `$nodename = `$true }
                    `"--kernel-release`"     { `$release = `$true }
                    `"--kernel-version`"     { `$version = `$true }
                    `"--machine`"            { `$machine = `$true }
                    `"--processor`"          { `$processor = `$true }
                    `"--hardware-platform`"  { `$hardware = `$true }
                    `"--operating-system`"   { `$os = `$true }
                    `"--help`"               { `$help = `$true }
                    `"--version`"            { `$uname_version = `$true }
                    default { Write-Output `"Invalid option: `$arg`nTry '--help' for more information.`"; return }
                }
            }
        }

        # Get system information
        `$osName = (Get-CimInstance Win32_OperatingSystem).Caption
        `$osVersion = (Get-CimInstance Win32_OperatingSystem).Version
        `$architecture = (Get-CimInstance Win32_OperatingSystem).OSArchitecture
        `$hostname = `$env:COMPUTERNAME
        `$kernelVersion = (Get-CimInstance Win32_OperatingSystem).BuildNumber
        `$processorType = (Get-CimInstance Win32_Processor).Name
        `$machineType = if (`$architecture -match `"64`") {`"x86_64`"} else {`"i686`"}
        `$hardwarePlatform = (Get-CimInstance Win32_ComputerSystem).Model

        if (`$help) {
            Write-Output `"Usage: uname [OPTION]...`nPrint system information.`n`nOptions:`n  -a, --all                Show all system information`n  -s, --kernel-name       Print the kernel name`n  -n, --nodename          Print the system hostname`n  -r, --kernel-release    Print the kernel release`n  -v, --kernel-version    Print the kernel version`n  -m, --machine           Print the hardware architecture`n  -p, --processor         Print the processor type`n  -i, --hardware-platform Print the hardware platform`n  -o, --operating-system  Print the operating system`n  --version              Show uname version`n  --help                 Show this message and exit`"
            return
        }

        if (`$uname_version) {
            Write-Output `"uname (PowerShell) 1.1`nBased on Windows OS`"
            return
        }

        # Handle -a (all) first since it overrides individual options
        if (`$all) {
            Write-Output `"Windows `$hostname `$kernelVersion `$osVersion `$machineType `$processorType `$hardwarePlatform`"
            return
        }

        # Collect selected outputs
        `$output = @()
        if (`$kernel) { `$output += `"Windows`" }
        if (`$nodename) { `$output += `"`$hostname`" }
        if (`$release) { `$output += `"`$kernelVersion`" }
        if (`$version) { `$output += `"`$osVersion`" }
        if (`$machine) { `$output += `"`$machineType`" }
        if (`$processor) { `$output += `"`$processorType`" }
        if (`$hardware) { `$output += `"`$hardwarePlatform`" }
        if (`$os) { `$output += `"Windows`" }

        # Default case: If no options given, return OS name
        if (-not `$output) {
            `$output = @(`$osName)
        }

        # Print the output
        Write-Output (`$output -join `" `")
    };
"@
    # Set-Content -Path $outfile -Value $pscode
    $dosuname = @"
    @echo off
setlocal enabledelayedexpansion

:: Parse command-line arguments
set `"option=%1`"

:: Get System Information
for /f `"tokens=2 delims==`" %%I in ('wmic os get Caption /value ^| find `"=`"') do set `"osName=%%I`"
for /f `"tokens=2 delims==`" %%I in ('wmic os get Version /value ^| find `"=`"') do set `"osVersion=%%I`"
for /f `"tokens=2 delims==`" %%I in ('wmic os get BuildNumber /value ^| find `"=`"') do set `"kernelVersion=%%I`"
for /f `"tokens=2 delims==`" %%I in ('wmic computersystem get Model /value ^| find `"=`"') do set `"hardware=%%I`"
for /f `"tokens=2 delims==`" %%I in ('wmic os get OSArchitecture /value ^| find `"=`"') do set `"architecture=%%I`"
for /f `"tokens=2 delims==`" %%I in ('wmic cpu get Name /value ^| find `"=`"') do set `"processor=%%I`"

set `"hostname=%COMPUTERNAME%`"
set `"machineType=x86`"
if `"%architecture%`"==`"64-bit`" set `"machineType=x86_64`"

:: Handle uname options
if `"%option%`"==`"`" (
    echo %osName%
    exit /b
)
if `"%option%`"==`"-s`" (
    echo Windows
    exit /b
)
if `"%option%`"==`"--kernel-name`" (
    echo Windows
    exit /b
)
if `"%option%`"==`"-n`" (
    echo %hostname%
    exit /b
)
if `"%option%`"==`"--nodename`" (
    echo %hostname%
    exit /b
)
if `"%option%`"==`"-r`" (
    echo %kernelVersion%
    exit /b
)
if `"%option%`"==`"--kernel-release`" (
    echo %kernelVersion%
    exit /b
)
if `"%option%`"==`"-v`" (
    echo %osVersion%
    exit /b
)
if `"%option%`"==`"--kernel-version`" (
    echo %osVersion%
    exit /b
)
if `"%option%`"==`"-m`" (
    echo %machineType%
    exit /b
)
if `"%option%`"==`"--machine`" (
    echo %machineType%
    exit /b
)
if `"%option%`"==`"-p`" (
    echo %processor%
    exit /b
)
if `"%option%`"==`"--processor`" (
    echo %processor%
    exit /b
)
if `"%option%`"==`"-i`" (
    echo %hardware%
    exit /b
)
if `"%option%`"==`"--hardware-platform`" (
    echo %hardware%
    exit /b
)
if `"%option%`"==`"-o`" (
    echo Windows
    exit /b
)
if `"%option%`"==`"--operating-system`" (
    echo Windows
    exit /b
)
if `"%option%`"==`"-a`" (
    echo Windows %hostname% %kernelVersion% %osVersion% %machineType% %processor% %hardware%
    exit /b
)
if `"%option%`"==`"--all`" (
    echo Windows %hostname% %kernelVersion% %osVersion% %machineType% %processor% %hardware%
    exit /b
)
if `"%option%`"==`"--help`" (
    echo Usage: uname.bat [OPTION]
    echo -s, --kernel-name       Print the kernel name
    echo -n, --nodename          Print the network node hostname
    echo -r, --kernel-release    Print the kernel release
    echo -v, --kernel-version    Print the kernel version
    echo -m, --machine           Print the machine hardware name
    echo -p, --processor         Print the processor type
    echo -i, --hardware-platform Print the hardware platform
    echo -o, --operating-system  Print the operating system
    echo -a, --all               Print all system information
    exit /b
)

:: If the option is unknown
echo Invalid option: %option%
echo Try '--help' for more information.
exit /b
"@
    
    $dosrm = @"
    @echo off
setlocal enabledelayedexpansion

:: Default values
set `"recursive=0`"
set `"force=0`"

:: Parse options
:parse_args
if `"%1`"==`"`" goto process
if `"%1`"==`"-r`" set `"recursive=1`"
if `"%1`"==`"--recursive`" set `"recursive=1`"
if `"%1`"==`"-f`" set `"force=1`"
if `"%1`"==`"--force`" set `"force=1`"
if not `"%1`"==`"-r`" if not `"%1`"==`"-f`" if not `"%1`"==`"--recursive`" if not `"%1`"==`"--force`" (
    set `"files=!files! %1`"
)
shift
goto parse_args

:process
if `"%files%`"==`"`" (
    echo Usage: rm.bat [OPTIONS] FILE...
    echo Options:
    echo   -r, --recursive  Remove directories and their contents recursively
    echo   -f, --force      Ignore non-existent files and errors
    exit /b 1
)

:: Remove files/directories
for %%F in (%files%) do (
    if exist `"%%F`" (
        if exist `"%%F\*`" (
            :: It's a directory
            if `"%recursive%`"==`"1`" (
                rmdir /s /q `"%%F`"
            ) else (
                echo rm: cannot remove '%%F': Is a directory
            )
        ) else (
            :: It's a file
            del /q `"%%F`"
        )
    ) else (
        if `"%force%`"==`"0`" (
            echo rm: cannot remove '%%F': No such file or directory
        )
    )
)

exit /b 0
"@
    Set-Content -Path $outfile -Value $pscode
    Set-Content -Path uname.bat -Value $dosuname
    Set-Content -Path rm.bat -Value $dosrm
}
set_python
# build_deps

$pws_tweaks_file = "$env:TMP\shell_tweaks.psm1"
create_ps_tweak_file_for_make $pws_tweaks_file

Write-Host "Call BuildAstrometry"
$env:PATH = "C:\vcpkg\installed\x64-windows\bin;C:\vcpkg\installed\x64-windows\include;" + $env:PATH
BuildAstrometry $false $ASTROMETRY_INSTALL_DIR $CFITSIO_INSTALL_DIR $pws_tweaks_file

Write-Host "Script finished"

It still show several subcommands crashing and finishes with this,even if GSL is not supposed to be built (since we provide GSL_LIB & GSL_INC) :

[...]
'gcc' n’est pas reconnu en tant que commande interne
ou externe, un programme exécutable ou un fichier de commandes.
[...]
Makefile:108: update target 'gsl-an' due to: target is .PHONY
[...]
make[1]: Leaving directory 'C:/Users/redacted/AppData/Local/Temp/astrometry-0.97/gsl-an'
Reaping losing child 02e5c1b0 PID 48579424
Cleaning up temp batch file C:\Users\redacted\AppData\Local\Temp\make572908-10.bat
make: *** [Makefile:108: gsl-an] Error 2

Tools infos:

  • vcpkg : vcpkg package management program version 2025-03-13-7699e411ea11543de6abc0c7d5fd11cfe0039ae5
  • make : GNU Make 4.4.1 Built for Windows32
  • cmkae : cmake version 3.31.6
  • Visual Studio 17 (2022) Dev (power)Shell ( and using cmake -G "Visual Studio 17 2022")
  • LLVM clang version 20.1.0 Target: x86_64-pc-windows-msvc Thread model: posix InstalledDir: C:\Program Files\LLVM\bin
  • GCC gcc.exe (x86_64-posix-seh-rev0, Built by MinGW-Builds project) 13.2.0
  • and effectively installed vcpkg ports:
brotli:x64-windows                                1.1.0#1             a generic-purpose lossless compression algorithm...
bzip2:x64-windows                                 1.0.8#6             bzip2 is a freely available, patent free, high-q...
bzip2[tool]:x64-windows                                               Builds bzip2 executable
cairo:x64-windows                                 1.18.2#1            Cairo is a 2D graphics library with support for ...
cairo[fontconfig]:x64-windows                                         Build with fontconfig
cairo[freetype]:x64-windows                                           Use the freetype font backend
cfitsio:x64-windows                               3.49#6              Library of C and Fortran subroutines for reading...
dirent:x64-windows                                1.24                Dirent is a C/C++ programming interface that all...
expat:x64-windows                                 2.6.4               XML parser library written in C
fontconfig:x64-windows                            2.15.0#2            Library for configuring and customizing font acc...
freetype:x64-windows                              2.13.3              A library to render fonts.
freetype[brotli]:x64-windows                                          Support decompression of WOFF2 streams
freetype[bzip2]:x64-windows                                           Support bzip2 compressed fonts.
freetype[png]:x64-windows                                             Support PNG compressed OpenType embedded bitmaps.
freetype[zlib]:x64-windows                                            Use zlib instead of internal library for DEFLATE
gperf:x64-windows                                 3.1#6               GNU perfect hash function generator
gsl:x64-windows                                   2.8                 The GNU Scientific Library is a numerical librar...
libpng:x64-windows                                1.6.46              libpng is a library implementing an interface fo...
pixman:x64-windows                                0.44.2              Pixman is a low-level software library for pixel...
pthread:x64-windows                               3.0.0#2             empty package, linking to other port
pthreads:x64-windows                              3.0.0#14            Meta-package that provides PThreads4W on Windows...
vcpkg-cmake-config:x64-windows                    2024-05-23
vcpkg-cmake-get-vars:x64-windows                  2024-09-22
vcpkg-cmake:x64-windows                           2024-04-23
vcpkg-tool-meson:x64-windows                      1.6.1               Meson build system
zlib:x64-windows                                  1.3.1               A compression library
Share Improve this question asked Mar 22 at 15:54 LoneWandererLoneWanderer 3,3513 gold badges26 silver badges46 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

The best I could come up with is this.

The strategy

  • build astrometry on WSL

  • write powershell commands to mimic astrometry via WSL single calls like this one:

PS > wsl -d Ubuntu --user foo -- solve-field --version
0.97
# except I want this syntax
PS > solve-field --version # WSL under the hood
0.97

Side note : wsl -d Ubuntu --user foo -- solve-field --version also works with Windows 11 DOS shell. The following could be adapted as a .bat file.

The recipe

  1. Install astrometry on WSL Ubuntu via the ./astrometry-0.97/doc/install_astrometry_on_linux.sh install script (it is aslo possible to do it via APT install but I can't tell which version it's using). Beware that it could require some slight modifications depending on Ubuntu version. Here is my modified one.

    Also be aware that the script downloads tons of Gibi of stars catalog.

    Since I had to make some tests, I modifed it to save and restore the catalogs instead of reinstalling them.

    #!/bin/sh
    
    WORKSPACE_DIR="/tmp"
    
    # basic linux install/build libs, python, and other support
    cd $WORKSPACE_DIR && \
    sudo apt update && \
    sudo apt install -y make build-essential python3 python3-pip \
     netpbm libnetpbm10-dev zlib1g-dev libcairo2-dev libjpeg-dev libcfitsio-dev libbz2-dev wcslib-dev \
     wget \
     python3-numpy python3-scipy python3-fitsio python3-astrometry
    # depends on ubuntu ...
    #python3 -m venv ~/astrometry-venv
    #~/astrometry-venv/bin/activate
    #pip3 install numpy scipy fitsio astrometry && \
    
    # backup stars index files
    mkdir $WORKSPACE_DIR/data
    sudo mv /usr/local/astrometry/data/* $WORKSPACE_DIR/data
    
    # astrometry
    # netpbm includes may change depending on distro ... learned it there:
    # https://github/dstndstn/astrometry/blob/main/.circleci/config.yml#L189
    # so:
    # ubuntu 22.04 ==> sudo ln -s /usr/include /usr/local/include/netpbm
    # 
    # ubuntu 24.04 ==> /usr/include/netpbm/pam.h
    
    
    # includes ubuntu 22.04
    # export NETPBM_INC="-I /usr/include/"
    # export NETPBM_LIB="-L /usr/lib/libnetpbm"
    
    # includes Ubuntu 24.04
    export NETPBM_INC="-I /usr/include/"
    export NETPBM_LIB="-L /usr/lib/x86_64-linux-gnu/"
    
    rm -rf astrometry-0.97 && \
    # rm -f astrometry-latest.tar.gz* && \ don't redownload, I already done it
    wget http://astrometry/downloads/astrometry-latest.tar.gz && \
    tar xvzf astrometry-latest.tar.gz && \
    cd astrometry-* && \
    make         && \
    make py      && \
    make extra   && \
    sudo make install && \
    #make && \ # NETPBM_INC="-I /usr/include/pnm.h" NETPBM_LIB="L /usr/lib/libnetpbm" && \
    #make py && \ #NETPBM_INC="-I /usr/include/pnm.h" NETPBM_LIB="L /usr/lib/libnetpbm" && \
    #make extra && \ # NETPBM_INC="-I /usr/include/pnm.h" NETPBM_LIB="L /usr/lib/libnetpbm" && \
    #make install && \
    
    # fix Ubuntu 24.04, some built binaries expect another bin where it is absent ...
    sudo ln -s /usr/bin/an-fitstopnm /user/local/astrometry/
    # TODO: we should update $PATH everywhere for everyone ?
    
    # restore stars index files
    sudo mv $WORKSPACE_DIR/data /usr/local/astrometry/data
    
    # download and install index files
    # rm -rf /usr/local/astrometry/data/* && \
    # wget -r -nd -np -P /usr/local/astrometry/data/ "http://data.astrometry/4100/" && \
    # These files are HUGE.....
    # wget -r -nd -np -P /usr/local/astrometry/data/ "https://portal.nersc.gov/project/cosmo/temp/dstn/index-5200/LITE/"
    
  2. Prepare Special environment variables so WSL can call a single Ubuntu command with proper PATH definitions.
    Powershell can call Linux commands via wsl.exe <some params>.
    However, several Linux PATH defining commands may not be available, so astrometry could not be natively visible.
    An explanation I found here to deal with weird errors at single wsl invokations: https://www.reddit/r/bashonubuntuonwindows/comments/l92hoh/question_modify_path_for_invoking_from_wslexe/
    Quoting:

    Edit2: Finally found the issue. 6339 to be precise. That linked to a nice blog post explaining that .bashrc doesn't get run, but a custom file with specified by $BASH_ENV. Using u/lookanerd's link, I needed to set 2 environment variables in Windows:

    Name Value
    BASH_ENV ~/.bash_env_noninteractive
    WSLENV BASH_ENV/u

    And then put my exports into ~/.bash_env_noninteractive (or whatever you want to name it).

    ./bash_env_noninteractiveis where you would force the $PATH to astrometry within Ubuntu.

$ cat ~/.bash_env_noninteractive
PATH="/usr/local/astrometry/bin:$PATH"
  1. Create on or more powershell scripts that mirror each astrometry commands like this :
function Convert-PathToWSL {
    param (
        [string]$winPath
    )
    $wslPath = wsl wslpath "`"$winPath`""
    return $wslPath.Trim()
}

function Invoke-AstrometryCommand {
    param (
        [string]$command,
        [string[]]$args
    )
    $wslArgs = $args | ForEach-Object {
        if (Test-Path $_) { Convert-PathToWSL $_ } else { $_ }
    }
    $wslCommand = "/usr/local/astrometry/bin/$command " + ($wslArgs -join ' ')
    wsl -d Ubuntu --user foo -- $wslCommand
}

function solve-field {
    # TODO: better args management to isolate path and rest of solve-field args
    $newpath = wsl wslpath """$args""" # WSL directive to convert Windows path (\) to linux convention (/) and apply WSL mouting points
    # wsl -d Ubuntu --user foo -- /usr/local/astrometry/bin/solve-field $newpath
    Invoke-AstrometryCommand "solve-field" $args
}
# TODO : write all other astrometry commands from /usr/local/astrometry/bin/
  1. Find a way to put script into PATH at powershell load. Here is an attempt located at C:\astrometry\astrometry.psm1. You can add this file to your autoload powershell file, for me its here %USERPROFILE%\Documents\WindowsPowerShell\profile.ps1 and already contains some conda magic. Simply add the line: Import-Module -Force C:\astrometry\astrometry.psm1

  2. Finally unlock the full mapping:



function Convert-PathToWSL {
    param (
        [string]$winPath
    )
    # Write-Host "input Path $winPath"
    $wslPath = wsl -d Ubuntu wslpath """$winPath"""
    $wslPath = $wslPath.Trim()
    # Write-Host "Output Path $wslPath"
    return $wslPath
}

function Invoke-AstrometryCommand {
    param (
        [string]$command,
        [string[]]$cmdArgs
    )
    $wslArgs = $cmdArgs | ForEach-Object {
        if (Test-Path $_) { Convert-PathToWSL $_ } else { $_ }
    }
    $linux_cmd_args = ($wslArgs -join ' ')
    # Write-Host "Astrometry COMMAND     = $command"
    # Write-Host "Astrometry COMMAND ARGS= $linux_cmd_args"
    wsl -d Ubuntu --user bkap -- /usr/local/astrometry/bin/$command "$linux_cmd_args"
}

function solve-field {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "solve-field" "$field_args"
    Write-Host "If solve-field succeeded, you may find useful to rename the solved '.new' file with a FIT extension"
}

# function plotann {
#     param (
#         [string[]]$field_args
#     )
#     Invoke-AstrometryCommand "plotann" "$field_args"
# }

# function wcsinfo {
#     param (
#         [string[]]$field_args
#     )
#     Invoke-AstrometryCommand "wcsinfo" "$field_args"
# }


function an-fitstopnm {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "an-fitstopnm" "$field_args"
}
function degtohms {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "degtohms" "$field_args"
}
function fits-guess-scale {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "fits-guess-scale" "$field_args"
}
function hpsplit {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "hpsplit" "$field_args"
}
function listhead {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "listhead" "$field_args"
}
function pad-file {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "pad-file" "$field_args"
}
function query-starkd {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "query-starkd" "$field_args"
}
function tablist {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "tablist" "$field_args"
}
function votabletofits {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "votabletofits" "$field_args"
}
function wcs-resample {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "wcs-resample" "$field_args"
}
function an-pnmtofits {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "an-pnmtofits" "$field_args"
}
function downsample-fits {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "downsample-fits" "$field_args"
}
function fitsgetext {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "fitsgetext" "$field_args"
}
function image2pnm {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "image2pnm" "$field_args"
}
function liststruc {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "liststruc" "$field_args"
}
function plot-constellations {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "plot-constellations" "$field_args"
}
function removelines {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "removelines" "$field_args"
}
function tabmerge {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "tabmerge" "$field_args"
}
function wcs-grab {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "wcs-grab" "$field_args"
}
function wcs-to-tan {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "wcs-to-tan" "$field_args"
}
function astrometry-engine {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "astrometry-engine" "$field_args"
}
function fit-wcs {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "fit-wcs" "$field_args"
}
function get-healpix {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "get-healpix" "$field_args"
}
function image2xy {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "image2xy" "$field_args"
}
function merge-columns {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "merge-columns" "$field_args"
}
function plotann {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "plotann.py" "$field_args"
}
# function solve-field {
#     param (
#         [string[]]$field_args
#     )
#     Invoke-AstrometryCommand "solve-field" "$field_args"
# }
function tabsort {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "tabsort" "$field_args"
}
function wcs-match {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "wcs-match" "$field_args"
}
function wcs-xy2rd {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "wcs-xy2rd" "$field_args"
}
function augment-xylist {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "augment-xylist" "$field_args"
}
function fits-column-merge {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "fits-column-merge" "$field_args"
}
function get-wcs {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "get-wcs" "$field_args"
}
function imarith {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "imarith" "$field_args"
}
function modhead {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "modhead" "$field_args"
}
function plotquad {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "plotquad" "$field_args"
}
function startree {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "startree" "$field_args"
}
function text2fits {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "text2fits" "$field_args"
}
function wcs-pv2sip {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "wcs-pv2sip" "$field_args"
}
function wcsinfo {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "wcsinfo" "$field_args"
}
function build-astrometry-index {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "build-astrometry-index" "$field_args"
}
function fits-flip-endian {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "fits-flip-endian" "$field_args"
}
function hmstodeg {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "hmstodeg" "$field_args"
}
function imstat {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "imstat" "$field_args"
}
function new-wcs {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "new-wcs" "$field_args"
}
function plotxy {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "plotxy" "$field_args"
}
function subtable {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "subtable" "$field_args"
}
function uniformize {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "uniformize" "$field_args"
}
function wcs-rd2xy {
    param (
        [string[]]$field_args
    )
    Invoke-AstrometryCommand "wcs-rd2xy" "$field_args"
}

Export-ModuleMember -Function solve-field, `
                              an-fitstopnm, `
                              degtohms, `
                              fits-guess-scale, `
                              hpsplit, `
                              listhead, `
                              pad-file, `
                              query-starkd, `
                              tablist, `
                              votabletofits, `
                              wcs-resample, `
                              an-pnmtofits, `
                              downsample-fits, `
                              fitsgetext, `
                              image2pnm, `
                              liststruc, `
                              plot-constellations, `
                              removelines, `
                              tabmerge, `
                              wcs-grab, `
                              wcs-to-tan, `
                              astrometry-engine, `
                              fit-wcs, `
                              get-healpix, `
                              image2xy, `
                              merge-columns, `
                              plotann, `
                              tabsort, `
                              wcs-match, `
                              wcs-xy2rd, `
                              augment-xylist, `
                              fits-column-merge, `
                              get-wcs, `
                              imarith, `
                              modhead, `
                              plotquad, `
                              startree, `
                              text2fits, `
                              wcs-pv2sip, `
                              wcsinfo, `
                              build-astrometry-index, `
                              fits-flip-endian, `
                              hmstodeg, `
                              imstat, `
                              new-wcs, `
                              plotxy, `
                              subtable, `
                              uniformize, `
                              wcs-rd2xy
                              

That's the best I could come up. All astrometry commands can then become available on command line, **and all input windows paths would be automagically transtyped to Linux :) **

The other way would be to join astrometry dev team & create & maintain the build process for Windows. (and get rid of make)


Some caveat to keep in mind:

  • you may need to explcitily set the distro WSL should use (-d ) otherwise, it could call the default one, which could be completly different environment. In my case, it was set to a docker-related default value.
PS > wsl --list
Distributions du Sous-système Windows pour Linux :
Ubuntu-22.04 (par défaut)
docker-desktop-data # this was a default one, and wsl wslpath does not work nicely with this one ...
Ubuntu-24.04
Ubuntu
  • for wsl wslpath I had to set the default distro to Ubuntu otherwise I would get cryptic errors from WSL ...
PS > wsl --set-default docker-desktop-data
L’opération a réussi.
PS > wsl wslpath """$env:USERPROFILE""" # triple quote necessary...
<3>WSL (14 - Relay) ERROR: CreateProcessParseCommon:863: Failed to translate C:\Users\redacted\AppData\Local\Temp\astrometry-0.97
<3>WSL (14 - Relay) ERROR: CreateProcessParseCommon:909: getpwuid(0) failed 2
<3>WSL (14 - Relay) ERROR: UtilTranslatePathList:2878: Failed to translate C:\vcpkg\installed\x64-windows\bin
<3>WSL (14 - Relay) ERROR: UtilTranslatePathList:2878: Failed to translate C:\vcpkg\installed\x64-windows\include
... 
and tons of error lines


PS > wsl --set-default Ubuntu-22.04
L’opération a réussi.
PS  > wsl wslpath """$env:USERPROFILE"""
/mnt/c/Users/redacted

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744309606a4567886.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信