| 1 | """ |
| 2 | Code to obtain WCS headers for FITS files using astrometry.net |
| 3 | |
| 4 | Astrometry.net has oodles of configurable parameters. Some of |
| 5 | them can be passed in via the solverParameters argument to getWCSFieldsFor, |
| 6 | a dictionary with keys including: |
| 7 | |
| 8 | indices |
| 9 | (default: ``index-*.fits``, meaning all indices in your default index dir) |
| 10 | The file names from anet's index directory you want to have used. |
| 11 | glob patterns are expanded, but no recursion takes place. |
| 12 | |
| 13 | This could be something like:: |
| 14 | |
| 15 | ["index-4211.fits", "index-4210.fits", "index-4209.fits"] |
| 16 | |
| 17 | for largeish images or:: |
| 18 | |
| 19 | ["index-4203-*.fits", "index-4202-*.fits"] |
| 20 | |
| 21 | for small ones. You can also give absolute path names for custom |
| 22 | indices that live, e.g., in your resource directory. |
| 23 | |
| 24 | total_timelimit |
| 25 | (defaults to 600) -- number of seconds after which the anet run |
| 26 | should cancel itself. |
| 27 | |
| 28 | tweak |
| 29 | (defaults to True) -- try to obtain a polynomic correction to the |
| 30 | entire image after obtaining a solution? This can go wrong in |
| 31 | particular for exposures with many objects, so you might want to |
| 32 | set it to off for such cases. |
| 33 | |
| 34 | fields |
| 35 | (default to 1) -- FITS extension to work on |
| 36 | |
| 37 | endob |
| 38 | (defaults to not given) -- last object to be processed. You don't want to |
| 39 | raise this too high. The library will only pass on 10 objects at a |
| 40 | time anyway, but going too high here will waste lots of time on images |
| 41 | that are probably not going to resolve anyway. |
| 42 | |
| 43 | lower_pix |
| 44 | (defaults to not given) -- smallest permissible pixel size in arcsecs. If |
| 45 | at all possible, constrain this for much better results. |
| 46 | |
| 47 | upper_pix |
| 48 | (defaults to not given) -- largest permissible pixel size in arcsecs. |
| 49 | See lower_pix. |
| 50 | |
| 51 | plots |
| 52 | (defaults to False) -- generate all kinds of pretty plots? |
| 53 | |
| 54 | downsample |
| 55 | (defaults to not given) -- factor to downsample the image before |
| 56 | trying to solve. This may be necessary when not using source-extractor, |
| 57 | and it should be something like 2, 3, or 4. |
| 58 | """ |
| 59 | |
| 60 | #c Copyright 2008-2025, the GAVO project <[email protected]> |
| 61 | #c |
| 62 | #c This program is free software, covered by the GNU GPL. See the |
| 63 | #c COPYING file in the source distribution. |
| 64 | |
| 65 | |
| 66 | import globscip-python python python-stdlib 3.11 glob/__init__: |
| 67 | import gzipscip-python python python-stdlib 3.11 gzip/__init__: |
| 68 | import osscip-python python python-stdlib 3.11 os/__init__: |
| 69 | import shutilscip-python python python-stdlib 3.11 shutil/__init__: |
| 70 | import subprocessscip-python python python-stdlib 3.11 subprocess/__init__: |
| 71 | |
| 72 | from gavoscip-python python gavodachs 2.13 gavo/__init__: import basescip-python python gavodachs 2.13 `gavo.base`/__init__: |
| 73 | from gavoscip-python python gavodachs 2.13 gavo/__init__: import utilsscip-python python gavodachs 2.13 `gavo.utils`/__init__: |
| 74 | from gavo.utilsscip-python python gavodachs 2.13 `gavo.utils`/__init__: import fitstoolsscip-python python gavodachs 2.13 `gavo.utils.fitstools`/__init__: |
| 75 | from gavo.utilsscip-python python gavodachs 2.13 `gavo.utils`/__init__: import pyfits |
| 76 | |
| 77 | __docformat__scip-python python gavodachs 2.13 `gavo.helpers.anet`/__docformat__. = "restructuredtext en" |
| 78 | |
| 79 | anetIndexPathscip-python python gavodachs 2.13 `gavo.helpers.anet`/anetIndexPath. = "/usr/local/astrometry/data" |
| 80 | |
| 81 | |
| 82 | PARAM_DEFAULTSscip-python python gavodachs 2.13 `gavo.helpers.anet`/PARAM_DEFAULTS. = { |
| 83 | "total_timelimit": 600, |
| 84 | "fields": "1", |
| 85 | "endob": None, |
| 86 | "lower_pix": None, |
| 87 | "upper_pix": None, |
| 88 | "tweak": True, |
| 89 | "pix_units": "app", |
| 90 | "plots": False, |
| 91 | "downsample": None, |
| 92 | } |
| 93 | |
| 94 | |
| 95 | class Errorscip-python python gavodachs 2.13 `gavo.helpers.anet`/Error#(basescip-python python gavodachs 2.13 `gavo.base`/__init__:.Errorscip-python python gavodachs 2.13 `gavo.base.structure`/Structure#): |
| 96 | pass |
| 97 | |
| 98 | class NotSolvedscip-python python gavodachs 2.13 `gavo.helpers.anet`/NotSolved#(Errorscip-python python gavodachs 2.13 `gavo.helpers.anet`/Error#): |
| 99 | pass |
| 100 | |
| 101 | class ObjectNotFoundscip-python python gavodachs 2.13 `gavo.helpers.anet`/ObjectNotFound#(Errorscip-python python gavodachs 2.13 `gavo.helpers.anet`/Error#): |
| 102 | pass |
| 103 | |
| 104 | class ShellCommandFailedscip-python python gavodachs 2.13 `gavo.helpers.anet`/ShellCommandFailed#(Errorscip-python python gavodachs 2.13 `gavo.helpers.anet`/Error#): |
| 105 | def __init__scip-python python gavodachs 2.13 `gavo.helpers.anet`/ShellCommandFailed#__init__().(selfscip-python python gavodachs 2.13 `gavo.helpers.anet`/ShellCommandFailed#__init__().(self), msgscip-python python gavodachs 2.13 `gavo.helpers.anet`/ShellCommandFailed#__init__().(msg), retcodescip-python python gavodachs 2.13 `gavo.helpers.anet`/ShellCommandFailed#__init__().(retcode)): |
| 106 | Errorscip-python python gavodachs 2.13 `gavo.helpers.anet`/Error#.__init__scip-python python gavodachs 2.13 `gavo.utils.excs`/Error#__init__().(selfscip-python python gavodachs 2.13 `gavo.helpers.anet`/ShellCommandFailed#__init__().(self), msgscip-python python gavodachs 2.13 `gavo.helpers.anet`/ShellCommandFailed#__init__().(msg)) |
| 107 | selfscip-python python gavodachs 2.13 `gavo.helpers.anet`/ShellCommandFailed#__init__().(self).msgscip-python python gavodachs 2.13 `gavo.helpers.anet`/ShellCommandFailed#msg., selfscip-python python gavodachs 2.13 `gavo.helpers.anet`/ShellCommandFailed#__init__().(self).retcodescip-python python gavodachs 2.13 `gavo.helpers.anet`/ShellCommandFailed#retcode. = msgscip-python python gavodachs 2.13 `gavo.helpers.anet`/ShellCommandFailed#__init__().(msg), retcodescip-python python gavodachs 2.13 `gavo.helpers.anet`/ShellCommandFailed#__init__().(retcode) |
| 108 | |
| 109 | def __str__scip-python python gavodachs 2.13 `gavo.helpers.anet`/ShellCommandFailed#__str__().(selfscip-python python gavodachs 2.13 `gavo.helpers.anet`/ShellCommandFailed#__str__().(self)): |
| 110 | return "External program failure (%s). Program output: %s"%( |
| 111 | selfscip-python python gavodachs 2.13 `gavo.helpers.anet`/ShellCommandFailed#__str__().(self).retcodescip-python python gavodachs 2.13 `gavo.helpers.anet`/ShellCommandFailed#retcode., selfscip-python python gavodachs 2.13 `gavo.helpers.anet`/ShellCommandFailed#__str__().(self).msgscip-python python gavodachs 2.13 `gavo.helpers.anet`/ShellCommandFailed#msg.) |
| 112 | |
| 113 | |
| 114 | def _feedFilescip-python python gavodachs 2.13 `gavo.helpers.anet`/_feedFile().(origDirscip-python python gavodachs 2.13 `gavo.helpers.anet`/_feedFile().(origDir), fNamescip-python python gavodachs 2.13 `gavo.helpers.anet`/_feedFile().(fName)): |
| 115 | """links fName to "in.fits" in the sandbox. |
| 116 | |
| 117 | If fName ends with .gz, the function assumes it's a gzipped file and |
| 118 | unzips it to in.fits instead. |
| 119 | """ |
| 120 | srcName = osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..joinscip-python python python-stdlib 3.11 ntpath/join().(origDirscip-python python gavodachs 2.13 `gavo.helpers.anet`/_feedFile().(origDir), fNamescip-python python gavodachs 2.13 `gavo.helpers.anet`/_feedFile().(fName)) |
| 121 | destName = "img.fits" |
| 122 | if fNamescip-python python gavodachs 2.13 `gavo.helpers.anet`/_feedFile().(fName).endswith(".gz"): |
| 123 | with openscip-python python python-stdlib 3.11 builtins/open().(destName, "wb") as destF: |
| 124 | utilsscip-python python gavodachs 2.13 `gavo.utils`/__init__:.catscip-python python gavodachs 2.13 `gavo.utils.ostricks`/cat().(gzipscip-python python python-stdlib 3.11 gzip/__init__:.openscip-python python python-stdlib 3.11 gzip/open().(srcName), destF) |
| 125 | else: |
| 126 | osscip-python python python-stdlib 3.11 os/__init__:.symlinkscip-python python python-stdlib 3.11 os/symlink().(srcName, destName) |
| 127 | |
| 128 | |
| 129 | def _runShellCommandscip-python python gavodachs 2.13 `gavo.helpers.anet`/_runShellCommand().(cmdscip-python python gavodachs 2.13 `gavo.helpers.anet`/_runShellCommand().(cmd), argsscip-python python gavodachs 2.13 `gavo.helpers.anet`/_runShellCommand().(args)): |
| 130 | with openscip-python python python-stdlib 3.11 builtins/open().("lastCommand.log", "a") as logF: |
| 131 | logF.writescip-python python python-stdlib 3.11 io/TextIOBase#write().("\n\n================\nNow running: %s\n\n"% |
| 132 | " ".joinscip-python python python-stdlib 3.11 builtins/str#join().([cmdscip-python python gavodachs 2.13 `gavo.helpers.anet`/_runShellCommand().(cmd)]+argsscip-python python gavodachs 2.13 `gavo.helpers.anet`/_runShellCommand().(args))) |
| 133 | logF.flushscip-python python python-stdlib 3.11 io/IOBase#flush().() |
| 134 | proc = subprocessscip-python python python-stdlib 3.11 subprocess/__init__:.Popenscip-python python python-stdlib 3.11 subprocess/Popen#([cmdscip-python python gavodachs 2.13 `gavo.helpers.anet`/_runShellCommand().(cmd)]+argsscip-python python gavodachs 2.13 `gavo.helpers.anet`/_runShellCommand().(args), stdout=logF, |
| 135 | stderr=subprocessscip-python python python-stdlib 3.11 subprocess/__init__:.STDOUTscip-python python python-stdlib 3.11 subprocess/STDOUT.STDOUT.) |
| 136 | proc.communicatescip-python python python-stdlib 3.11 subprocess/Popen#communicate().() |
| 137 | |
| 138 | if proc.returncodescip-python python python-stdlib 3.11 subprocess/Popen#returncode.==-2: |
| 139 | raise KeyboardInterruptscip-python python python-stdlib 3.11 builtins/KeyboardInterrupt#("Child was siginted") |
| 140 | elif proc.returncodescip-python python python-stdlib 3.11 subprocess/Popen#returncode.: |
| 141 | raise ShellCommandFailedscip-python python gavodachs 2.13 `gavo.helpers.anet`/ShellCommandFailed#(openscip-python python python-stdlib 3.11 builtins/open().("lastCommand.log").readscip-python python python-stdlib 3.11 io/TextIOBase#read().(), proc.returncodescip-python python python-stdlib 3.11 subprocess/Popen#returncode.) |
| 142 | |
| 143 | |
| 144 | def _copyCurrentTreescip-python python gavodachs 2.13 `gavo.helpers.anet`/_copyCurrentTree().(copyToscip-python python gavodachs 2.13 `gavo.helpers.anet`/_copyCurrentTree().(copyTo)): |
| 145 | if copyToscip-python python gavodachs 2.13 `gavo.helpers.anet`/_copyCurrentTree().(copyTo) is not None: |
| 146 | try: |
| 147 | shutilscip-python python python-stdlib 3.11 shutil/__init__:.rmtreescip-python python python-stdlib 3.11 shutil/rmtree.rmtree.(copyToscip-python python gavodachs 2.13 `gavo.helpers.anet`/_copyCurrentTree().(copyTo)) |
| 148 | except osscip-python python python-stdlib 3.11 os/__init__:.errorscip-python python python-stdlib 3.11 os/error.: |
| 149 | pass |
| 150 | shutilscip-python python python-stdlib 3.11 shutil/__init__:.copytreescip-python python python-stdlib 3.11 shutil/copytree().(".", copyToscip-python python gavodachs 2.13 `gavo.helpers.anet`/_copyCurrentTree().(copyTo)) |
| 151 | |
| 152 | |
| 153 | # Minimal configuration for source-extractor for anet use. |
| 154 | # Do not override values in here in your sourceExtractorConfig-s. |
| 155 | _ANET_SX_STUBscip-python python gavodachs 2.13 `gavo.helpers.anet`/_ANET_SX_STUB. = """# source-extractor control file for astrometry.net |
| 156 | CATALOG_TYPE FITS_1.0 |
| 157 | # The output file name |
| 158 | CATALOG_NAME img.axy |
| 159 | # The name of the file containing _ANET_SX_PARAM |
| 160 | PARAMETERS_NAME anet.param |
| 161 | FILTER_NAME anet.filter |
| 162 | """ |
| 163 | |
| 164 | # export column spec for source-extractor; referenced in _ANET_SX_STUB |
| 165 | _ANET_SX_PARAMscip-python python gavodachs 2.13 `gavo.helpers.anet`/_ANET_SX_PARAM. = """X_IMAGE |
| 166 | Y_IMAGE |
| 167 | MAG_ISO |
| 168 | FLUX_AUTO |
| 169 | ELONGATION |
| 170 | """ |
| 171 | |
| 172 | # Blatantly stolen from anet... |
| 173 | _ANET_SX_FILTERscip-python python gavodachs 2.13 `gavo.helpers.anet`/_ANET_SX_FILTER. = """CONV NORM |
| 174 | # 5x5 convolution mask of a gaussian PSF with FWHM = 2.0 pixels. |
| 175 | 0.006319 0.040599 0.075183 0.040599 0.006319 |
| 176 | 0.040599 0.260856 0.483068 0.260856 0.040599 |
| 177 | 0.075183 0.483068 0.894573 0.483068 0.075183 |
| 178 | 0.040599 0.260856 0.483068 0.260856 0.040599 |
| 179 | 0.006319 0.040599 0.075183 0.040599 0.006319 |
| 180 | """ |
| 181 | |
| 182 | |
| 183 | def _createSourceExtractorFilesscip-python python gavodachs 2.13 `gavo.helpers.anet`/_createSourceExtractorFiles().(sourceExtractorControlscip-python python gavodachs 2.13 `gavo.helpers.anet`/_createSourceExtractorFiles().(sourceExtractorControl)): |
| 184 | with openscip-python python python-stdlib 3.11 builtins/open().("anet.control", "w") as f: |
| 185 | f.writescip-python python python-stdlib 3.11 io/TextIOBase#write().(_ANET_SX_STUBscip-python python gavodachs 2.13 `gavo.helpers.anet`/_ANET_SX_STUB.+sourceExtractorControlscip-python python gavodachs 2.13 `gavo.helpers.anet`/_createSourceExtractorFiles().(sourceExtractorControl)) |
| 186 | with openscip-python python python-stdlib 3.11 builtins/open().("anet.param", "w") as f: |
| 187 | f.writescip-python python python-stdlib 3.11 io/TextIOBase#write().(_ANET_SX_PARAMscip-python python gavodachs 2.13 `gavo.helpers.anet`/_ANET_SX_PARAM.) |
| 188 | with openscip-python python python-stdlib 3.11 builtins/open().("anet.filter", "w") as f: |
| 189 | f.writescip-python python python-stdlib 3.11 io/TextIOBase#write().(_ANET_SX_FILTERscip-python python gavodachs 2.13 `gavo.helpers.anet`/_ANET_SX_FILTER.) |
| 190 | |
| 191 | |
| 192 | def _extractSourcesscip-python python gavodachs 2.13 `gavo.helpers.anet`/_extractSources().(filterFuncscip-python python gavodachs 2.13 `gavo.helpers.anet`/_extractSources().(filterFunc)=None): |
| 193 | """does source extraction using source-extractor. |
| 194 | |
| 195 | If filterFunc is not None, it is called before sorting the extracted |
| 196 | objects. It must change the file named in the argument in place. |
| 197 | """ |
| 198 | _runShellCommandscip-python python gavodachs 2.13 `gavo.helpers.anet`/_runShellCommand().("source-extractor", ["-c", "anet.control", "img.fits"]) |
| 199 | if filterFuncscip-python python gavodachs 2.13 `gavo.helpers.anet`/_extractSources().(filterFunc) is not None: |
| 200 | filterFuncscip-python python gavodachs 2.13 `gavo.helpers.anet`/_extractSources().(filterFunc)("img.axy") |
| 201 | |
| 202 | |
| 203 | _PARAMETER_MAPscip-python python gavodachs 2.13 `gavo.helpers.anet`/_PARAMETER_MAP. = [ |
| 204 | ("total_timelimit", "--cpulimit"), |
| 205 | ("fields", "--fields"), |
| 206 | ("lower_pix", "--scale-low"), |
| 207 | ("upper_pix", "--scale-high"), |
| 208 | ("pix_units", "--scale-units"), |
| 209 | ("endob", "--depth"), |
| 210 | ("downsample", "--downsample"), |
| 211 | ] |
| 212 | |
| 213 | def _addArgsForscip-python python gavodachs 2.13 `gavo.helpers.anet`/_addArgsFor().(actParsscip-python python gavodachs 2.13 `gavo.helpers.anet`/_addArgsFor().(actPars), argsscip-python python gavodachs 2.13 `gavo.helpers.anet`/_addArgsFor().(args)): |
| 214 | if not actParsscip-python python gavodachs 2.13 `gavo.helpers.anet`/_addArgsFor().(actPars)["tweak"]: |
| 215 | argsscip-python python gavodachs 2.13 `gavo.helpers.anet`/_addArgsFor().(args).append("--no-tweak") |
| 216 | if not actParsscip-python python gavodachs 2.13 `gavo.helpers.anet`/_addArgsFor().(actPars)["plots"]: |
| 217 | argsscip-python python gavodachs 2.13 `gavo.helpers.anet`/_addArgsFor().(args).append("--no-plots") |
| 218 | for key, opthead in _PARAMETER_MAPscip-python python gavodachs 2.13 `gavo.helpers.anet`/_PARAMETER_MAP.: |
| 219 | if actParsscip-python python gavodachs 2.13 `gavo.helpers.anet`/_addArgsFor().(actPars)[key] is not None: |
| 220 | argsscip-python python gavodachs 2.13 `gavo.helpers.anet`/_addArgsFor().(args).extend([opthead, strscip-python python python-stdlib 3.11 builtins/str#(actParsscip-python python gavodachs 2.13 `gavo.helpers.anet`/_addArgsFor().(actPars)[key])]) |
| 221 | |
| 222 | |
| 223 | def _solveFieldscip-python python gavodachs 2.13 `gavo.helpers.anet`/_solveField().(fNamescip-python python gavodachs 2.13 `gavo.helpers.anet`/_solveField().(fName), |
| 224 | solverParametersscip-python python gavodachs 2.13 `gavo.helpers.anet`/_solveField().(solverParameters), |
| 225 | sourceExtractorControlscip-python python gavodachs 2.13 `gavo.helpers.anet`/_solveField().(sourceExtractorControl), |
| 226 | objectFilterscip-python python gavodachs 2.13 `gavo.helpers.anet`/_solveField().(objectFilter), |
| 227 | indexPathscip-python python gavodachs 2.13 `gavo.helpers.anet`/_solveField().(indexPath), |
| 228 | verbosescip-python python gavodachs 2.13 `gavo.helpers.anet`/_solveField().(verbose)): |
| 229 | """tries to solve an image anet's using solve-field. |
| 230 | |
| 231 | See _resolve for the meaning of the arguments. |
| 232 | """ |
| 233 | args = ["--continue"] |
| 234 | objectSource = "img.fits" |
| 235 | if sourceExtractorControlscip-python python gavodachs 2.13 `gavo.helpers.anet`/_solveField().(sourceExtractorControl) is not None: |
| 236 | _createSourceExtractorFilesscip-python python gavodachs 2.13 `gavo.helpers.anet`/_createSourceExtractorFiles().(sourceExtractorControlscip-python python gavodachs 2.13 `gavo.helpers.anet`/_solveField().(sourceExtractorControl)) |
| 237 | if sourceExtractorControlscip-python python gavodachs 2.13 `gavo.helpers.anet`/_solveField().(sourceExtractorControl)==None: |
| 238 | pass |
| 239 | elif sourceExtractorControlscip-python python gavodachs 2.13 `gavo.helpers.anet`/_solveField().(sourceExtractorControl)=="": |
| 240 | args.extendscip-python python python-stdlib 3.11 builtins/list#extend().(["--use-source-extractor"]) |
| 241 | else: |
| 242 | _extractSourcesscip-python python gavodachs 2.13 `gavo.helpers.anet`/_extractSources().(objectFilterscip-python python gavodachs 2.13 `gavo.helpers.anet`/_solveField().(objectFilter)) |
| 243 | width, height = fitstoolsscip-python python gavodachs 2.13 `gavo.utils.fitstools`/__init__:.getPrimarySize("img.fits") |
| 244 | args.extendscip-python python python-stdlib 3.11 builtins/list#extend().(["--x-column", "X_IMAGE", |
| 245 | "--y-column", "Y_IMAGE", |
| 246 | "--sort-column", "FLUX_AUTO", |
| 247 | "--use-source-extractor", |
| 248 | "--width", strscip-python python python-stdlib 3.11 builtins/str#(width), "--height", strscip-python python python-stdlib 3.11 builtins/str#(height)]) |
| 249 | objectSource = "img.axy" |
| 250 | args.appendscip-python python python-stdlib 3.11 builtins/list#append().("-v") |
| 251 | |
| 252 | with openscip-python python python-stdlib 3.11 builtins/open().("backend.cfg", "w") as backendCfg: |
| 253 | if "indices" in solverParametersscip-python python gavodachs 2.13 `gavo.helpers.anet`/_solveField().(solverParameters): |
| 254 | backendCfg.writescip-python python python-stdlib 3.11 io/TextIOBase#write().(f"add_path {indexPathscip-python python gavodachs 2.13 `gavo.helpers.anet`/_solveField().(indexPath)}\n") |
| 255 | for indF in solverParametersscip-python python gavodachs 2.13 `gavo.helpers.anet`/_solveField().(solverParameters)["indices"]: |
| 256 | fullPath = osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..joinscip-python python python-stdlib 3.11 ntpath/join().(indexPathscip-python python gavodachs 2.13 `gavo.helpers.anet`/_solveField().(indexPath), indF) |
| 257 | for fNamescip-python python gavodachs 2.13 `gavo.helpers.anet`/_solveField().(fName) in globscip-python python python-stdlib 3.11 glob/__init__:.globscip-python python python-stdlib 3.11 glob/glob().(fullPath): |
| 258 | backendCfg.writescip-python python python-stdlib 3.11 io/TextIOBase#write().("index %s\n"%fNamescip-python python gavodachs 2.13 `gavo.helpers.anet`/_solveField().(fName)) |
| 259 | backendCfg.writescip-python python python-stdlib 3.11 io/TextIOBase#write().("inparallel") |
| 260 | |
| 261 | else: |
| 262 | backendCfg.writescip-python python python-stdlib 3.11 io/TextIOBase#write().(f"add_path {indexPathscip-python python gavodachs 2.13 `gavo.helpers.anet`/_solveField().(indexPath)}\nautoindex\n") |
| 263 | |
| 264 | args.extendscip-python python python-stdlib 3.11 builtins/list#extend().(["--backend-config", "backend.cfg"]) |
| 265 | |
| 266 | actPars = PARAM_DEFAULTSscip-python python gavodachs 2.13 `gavo.helpers.anet`/PARAM_DEFAULTS..copyscip-python python python-stdlib 3.11 builtins/dict#copy().() |
| 267 | actPars.updatescip-python python python-stdlib 3.11 typing/MutableMapping#update().(solverParametersscip-python python gavodachs 2.13 `gavo.helpers.anet`/_solveField().(solverParameters)) |
| 268 | _addArgsForscip-python python gavodachs 2.13 `gavo.helpers.anet`/_addArgsFor().(actPars, args) |
| 269 | |
| 270 | args.appendscip-python python python-stdlib 3.11 builtins/list#append().(objectSource) |
| 271 | if verbosescip-python python gavodachs 2.13 `gavo.helpers.anet`/_solveField().(verbose): |
| 272 | printscip-python python python-stdlib 3.11 builtins/print().("Running %s %s"%("solve-field", " ".joinscip-python python python-stdlib 3.11 builtins/str#join().(args))) |
| 273 | _runShellCommandscip-python python gavodachs 2.13 `gavo.helpers.anet`/_runShellCommand().("solve-field", args) |
| 274 | |
| 275 | # staggered solving: This seemed like a good idea at some point but |
| 276 | # now probably no longer is. |
| 277 | # minInd, maxInd = int(actPars["startob"]), int(actPars["endob"]) |
| 278 | # curStart = minInd |
| 279 | # while True: |
| 280 | # if curStart+10>maxInd: |
| 281 | # break |
| 282 | # args.extend(["--depth", "%s-%s"%(curStart+1, curStart+15), "img.fits"]) |
| 283 | # _runShellCommand(solverBin, args) |
| 284 | # if os.path.exists("img.solved"): |
| 285 | # break |
| 286 | # curStart += 5 |
| 287 | # args[-3:] = [] |
| 288 | |
| 289 | |
| 290 | def _resolvescip-python python gavodachs 2.13 `gavo.helpers.anet`/_resolve().(fNamescip-python python gavodachs 2.13 `gavo.helpers.anet`/_resolve().(fName), |
| 291 | solverParametersscip-python python gavodachs 2.13 `gavo.helpers.anet`/_resolve().(solverParameters), |
| 292 | sourceExtractorControlscip-python python gavodachs 2.13 `gavo.helpers.anet`/_resolve().(sourceExtractorControl), |
| 293 | objectFilterscip-python python gavodachs 2.13 `gavo.helpers.anet`/_resolve().(objectFilter), |
| 294 | copyToscip-python python gavodachs 2.13 `gavo.helpers.anet`/_resolve().(copyTo), |
| 295 | indexPathscip-python python gavodachs 2.13 `gavo.helpers.anet`/_resolve().(indexPath), |
| 296 | verbosescip-python python gavodachs 2.13 `gavo.helpers.anet`/_resolve().(verbose)): |
| 297 | """runs the astrometric calibration pipeline. |
| 298 | |
| 299 | solverParameters is a dictionary; most keys in it are simply turned |
| 300 | into command line options of solve-field. |
| 301 | |
| 302 | This function litters the working directory with all kinds of files and does |
| 303 | not clean up, so you'd better run it in a sandbox. |
| 304 | |
| 305 | It raises a NotSolved exception if no solution could be found; otherwise |
| 306 | you should find the solution in img.wcs. |
| 307 | """ |
| 308 | if "_preparationFunction" in solverParametersscip-python python gavodachs 2.13 `gavo.helpers.anet`/_resolve().(solverParameters): |
| 309 | solverParametersscip-python python gavodachs 2.13 `gavo.helpers.anet`/_resolve().(solverParameters)["_preparationFunction"]() |
| 310 | try: |
| 311 | _solveFieldscip-python python gavodachs 2.13 `gavo.helpers.anet`/_solveField().(fNamescip-python python gavodachs 2.13 `gavo.helpers.anet`/_resolve().(fName), |
| 312 | solverParametersscip-python python gavodachs 2.13 `gavo.helpers.anet`/_resolve().(solverParameters), |
| 313 | sourceExtractorControlscip-python python gavodachs 2.13 `gavo.helpers.anet`/_resolve().(sourceExtractorControl), |
| 314 | objectFilterscip-python python gavodachs 2.13 `gavo.helpers.anet`/_resolve().(objectFilter), |
| 315 | indexPathscip-python python gavodachs 2.13 `gavo.helpers.anet`/_resolve().(indexPath), |
| 316 | verbosescip-python python gavodachs 2.13 `gavo.helpers.anet`/_resolve().(verbose)) |
| 317 | except Exceptionscip-python python python-stdlib 3.11 builtins/Exception#: |
| 318 | _copyCurrentTreescip-python python gavodachs 2.13 `gavo.helpers.anet`/_copyCurrentTree().(copyToscip-python python gavodachs 2.13 `gavo.helpers.anet`/_resolve().(copyTo)) |
| 319 | raise |
| 320 | _copyCurrentTreescip-python python gavodachs 2.13 `gavo.helpers.anet`/_copyCurrentTree().(copyToscip-python python gavodachs 2.13 `gavo.helpers.anet`/_resolve().(copyTo)) |
| 321 | if osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..existsscip-python python python-stdlib 3.11 ntpath/join().("img.solved"): |
| 322 | return |
| 323 | raise NotSolvedscip-python python gavodachs 2.13 `gavo.helpers.anet`/NotSolved#(fNamescip-python python gavodachs 2.13 `gavo.helpers.anet`/_resolve().(fName)) |
| 324 | |
| 325 | |
| 326 | def getWCSFieldsForscip-python python gavodachs 2.13 `gavo.helpers.anet`/getWCSFieldsFor().(fNamescip-python python gavodachs 2.13 `gavo.helpers.anet`/getWCSFieldsFor().(fName), |
| 327 | solverParametersscip-python python gavodachs 2.13 `gavo.helpers.anet`/getWCSFieldsFor().(solverParameters), |
| 328 | sourceExtractorControlscip-python python gavodachs 2.13 `gavo.helpers.anet`/getWCSFieldsFor().(sourceExtractorControl), |
| 329 | objectFilterscip-python python gavodachs 2.13 `gavo.helpers.anet`/getWCSFieldsFor().(objectFilter), |
| 330 | copyToscip-python python gavodachs 2.13 `gavo.helpers.anet`/getWCSFieldsFor().(copyTo), |
| 331 | indexPathscip-python python gavodachs 2.13 `gavo.helpers.anet`/getWCSFieldsFor().(indexPath), |
| 332 | verbosescip-python python gavodachs 2.13 `gavo.helpers.anet`/getWCSFieldsFor().(verbose)): |
| 333 | """returns a pyfits cardlist for the WCS fields on fName. |
| 334 | |
| 335 | solverParameters is a dictionary mapping solver keys to their values, |
| 336 | sourceExtractorControl is a script for source-extractor, |
| 337 | and its presence means that |
| 338 | source-extractor should be used for source extraction rather than what anet |
| 339 | has built in. objectFilter is a function that is called with the |
| 340 | name of the FITS with the extracted sources. It can remove or add |
| 341 | sources to that file before astrometry.net tries to match. |
| 342 | |
| 343 | To see what solverParameters are available, check the module docstring. |
| 344 | """ |
| 345 | try: |
| 346 | with utilsscip-python python gavodachs 2.13 `gavo.utils`/__init__:.sandbox() as origDir: |
| 347 | _feedFilescip-python python gavodachs 2.13 `gavo.helpers.anet`/_feedFile().(origDir, fNamescip-python python gavodachs 2.13 `gavo.helpers.anet`/getWCSFieldsFor().(fName)) |
| 348 | _resolvescip-python python gavodachs 2.13 `gavo.helpers.anet`/_resolve().(fNamescip-python python gavodachs 2.13 `gavo.helpers.anet`/getWCSFieldsFor().(fName), |
| 349 | solverParametersscip-python python gavodachs 2.13 `gavo.helpers.anet`/_resolve().(solverParameters)=solverParametersscip-python python gavodachs 2.13 `gavo.helpers.anet`/getWCSFieldsFor().(solverParameters), |
| 350 | sourceExtractorControlscip-python python gavodachs 2.13 `gavo.helpers.anet`/_resolve().(sourceExtractorControl)=sourceExtractorControlscip-python python gavodachs 2.13 `gavo.helpers.anet`/getWCSFieldsFor().(sourceExtractorControl), |
| 351 | objectFilterscip-python python gavodachs 2.13 `gavo.helpers.anet`/_resolve().(objectFilter)=objectFilterscip-python python gavodachs 2.13 `gavo.helpers.anet`/getWCSFieldsFor().(objectFilter), |
| 352 | copyToscip-python python gavodachs 2.13 `gavo.helpers.anet`/_resolve().(copyTo)=copyToscip-python python gavodachs 2.13 `gavo.helpers.anet`/getWCSFieldsFor().(copyTo), |
| 353 | indexPathscip-python python gavodachs 2.13 `gavo.helpers.anet`/_resolve().(indexPath)=indexPathscip-python python gavodachs 2.13 `gavo.helpers.anet`/getWCSFieldsFor().(indexPath), |
| 354 | verbosescip-python python gavodachs 2.13 `gavo.helpers.anet`/_resolve().(verbose)=verbosescip-python python gavodachs 2.13 `gavo.helpers.anet`/getWCSFieldsFor().(verbose)) |
| 355 | return pyfits.getheader("img.wcs").cards |
| 356 | except NotSolvedscip-python python gavodachs 2.13 `gavo.helpers.anet`/NotSolved#: |
| 357 | return None |