├── __init__.py ├── cdsclient ├── __init__.py ├── __pycache__ │ └── find_sdss9.cpython-38.pyc ├── LICENSE.txt ├── find_notavailable.py ├── find_gsc1.2.py ├── find_gsc1.3.py ├── find_const.py ├── find_gsc2.3.py ├── find_pmm2.py ├── find_gsc.py ├── find_cmc14.py ├── find_gsc1_2.py ├── find_gsc1_3.py ├── find_apm.py ├── find_ucac3.py ├── find_2psc3.py ├── find_ppmx.py ├── find_2mass.py ├── find_ppmxl.py ├── find_denis3.py ├── find_glimpse.py ├── find_nomad1.py ├── find_gsc2_3.py ├── find_kic.py ├── find_spm4.py ├── find_ucac4.py ├── find_sdss8.py ├── find_usnob1.py └── find_sdss9.py ├── pyproject.toml └── README.md /__init__.py: -------------------------------------------------------------------------------- 1 | """ VizieR query """ 2 | 3 | __version__ = "1.1.9" 4 | 5 | import cdsclient 6 | -------------------------------------------------------------------------------- /cdsclient/__init__.py: -------------------------------------------------------------------------------- 1 | """ VizieR query """ 2 | 3 | __version__ = "1.1.8" 4 | 5 | import cdsclient 6 | -------------------------------------------------------------------------------- /cdsclient/__pycache__/find_sdss9.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cds-astro/cds.cdsclient/HEAD/cdsclient/__pycache__/find_sdss9.cpython-38.pyc -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | name="cdsclient" 3 | authors = [ 4 | { name="Gilles Landais (CDS)"}, 5 | ] 6 | description = "CDS VizieR client (query large table)" 7 | readme = "README.md" 8 | keywords = ["astronomy"] 9 | requires-python = ">=3.6" 10 | dependencies = ["astropy>=3.2", 11 | "numpy>=1.17.2" 12 | ] 13 | classifiers=[ 14 | "Programming Language :: Python :: 3.6", 15 | "License :: OSI Approved :: BSD License", 16 | "Operating System :: OS Independent", 17 | "Intended Audience :: Science/Research", 18 | "Topic :: Scientific/Engineering :: Astronomy", 19 | ] 20 | dynamic = ["version"] 21 | 22 | [project.urls] 23 | repository = "https://github.com/cds-astro/cds.cdsclient" 24 | 25 | [build-system] 26 | requires = ["hatchling"] 27 | build-backend = "hatchling.build" 28 | 29 | [tool.hatch.version] 30 | path = "__init__.py" 31 | -------------------------------------------------------------------------------- /cdsclient/LICENSE.txt: -------------------------------------------------------------------------------- 1 | License: BSD License 2.0 2 | 3 | Copyright (c) , 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the nor the 14 | names of its contributors may be used to endorse or promote products 15 | derived from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## CDS Python package to query large catalogues 2 | 3 | **Note**: API import changed in the last version - see example below 4 | 5 | **License** : BSD License 6 | 7 | **Installation** : 8 | ``` 9 | git clone https://github.com/cds-astro/cds.cdsclient.git 10 | cd cds.cdsclient 11 | pip install . 12 | ``` 13 | 14 | **vizquery.py** : the vizquery package 15 | query all VizieR catalogues using ASU parameters 16 | metadata retrieving: get columns/table information 17 | and list large tables 18 | 19 | **Examples** : 20 | * list big catalogues : vizquery.py -l 21 | * get columns information for 2mass (=II/246) : vizquery.py -source=II/246 -i 22 | * query GAIA (I/337/gaia) arroud M1 (10arcsec) : vizquery.py -source=I/337/gaia -c=M1 -c.rs=10 23 | * get hipparcos (HIP=A) in votable : vizquery.py -source=I/239/hip_main -mime=votable -out.max=50 "HIP=1" 24 | 25 | 26 | **Using dedicated script: find_...py** 27 | * query 2mass arround M1: find_2mass.py M1 28 | * query sdss12 arround '217.488910+36.086880': find_sdss-dr12.py "217.488910+36.086880" 29 | * query gaia by offset (**allows to get the whole table by parts**) : find_gaia_edr3.py --offset 0..1000 30 | * query 2mass with jamg constraint: find_2mass.py --jmag="<11" 31 | You can also query with constraints see --help 32 | * query sdss using identifier: find_sdss-dr12.py --objID=1237662225689281592 --mime=tsv 33 | 34 | **API Example**: 35 | 36 | ``` 37 | import cdsclient.find_sdss9 as sdss 38 | process = sdss.QueryCatVizieR() 39 | process.position = "217.091350+35.985222" 40 | process.radius = 120 41 | process.query_cat(limit=10) 42 | data = process.get() 43 | print (data) 44 | ``` 45 | 46 | -------------------------------------------------------------------------------- /cdsclient/find_notavailable.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """G.Landais (CDS) 24-mar-2018 3 | Query urat1_neighbourhood 4 | 5 | find_notavailable.py [-h] [-a] [-r radius] [-m max] [constraints] [--format=tsv|votable|ascii] [position] 6 | 7 | -a: display all columns 8 | -r: radius in arcsec 9 | -m: max number of lines in output 10 | -h: this help 11 | --format: output (--format=tsv|votable|ascii) 12 | --sort : sort by distance (available with position only) 13 | --add : column name in output 14 | --file : query with a list 15 | 16 | position : ra dec position or target name 17 | example: find_notavailable.py M1 18 | 19 | Other constraints: 20 | --sort : ... 21 | --add= : ... 22 | --file= : ... 23 | 24 | 25 | Example: 26 | 27 | Licensed under a BSD license - see LICENSE.txt for details 28 | 29 | """ 30 | 31 | import os, sys 32 | import getopt 33 | try: 34 | sys.path.append(os.path.split(os.path.abspath(sys.argv[0]))[0]) 35 | import vizquery 36 | except: 37 | sys.stderr.write("(error) needs vizquery.py in PYTHONPATH\n") 38 | sys.exit(1) 39 | 40 | if int(sys.version[0])<3: 41 | from urllib2 import quote 42 | else: 43 | from urllib.parse import quote 44 | 45 | NO_FORMAT = "noformat" 46 | 47 | class QueryCat(): 48 | def __init__(self): 49 | self.position = None 50 | self.radius = vizquery.DEFAULT_RADIUS 51 | self.format = None 52 | 53 | def query_cat(self, constraints=None, all = False, limit=vizquery.DEFAULT_LIMIT): 54 | """init constraints parameters 55 | :param constraints: list of constraints ((name,value), ...) 56 | :param all: display all columns(efault False) 57 | :param limit: max number of records 58 | """ 59 | pass 60 | 61 | def get(self): 62 | """get astropy table""" 63 | pass 64 | 65 | def print_stdout(self): 66 | """print the result on stdout""" 67 | pass 68 | 69 | 70 | class QueryCatVizieR(QueryCat): 71 | def __init__(self): 72 | QueryCat.__init__(self) 73 | self.__client = vizquery.CDSClient(default_format=vizquery.FORMAT_ASCII) 74 | self.limit = vizquery.DEFAULT_LIMIT 75 | 76 | def query_cat(self, constraints=None, all=False, limit=vizquery.DEFAULT_LIMIT, columns=None, filename=None): 77 | params = [] 78 | 79 | if self.position: 80 | params.append("-c={0}".format(quote(self.position))) 81 | 82 | if self.radius: 83 | params.append("-c.rs={0:f}".format(self.radius)) 84 | 85 | if all is True: 86 | params.append("-out.all=1") 87 | 88 | if limit is not None: 89 | params.append("-out.max={0:d}".format(limit)) 90 | else: 91 | params.append("-out.max={0:d}".format(self.limit)) 92 | 93 | if columns is not None: 94 | for column in columns: params.append("-out={0}".format(column)) 95 | 96 | file_col = None 97 | if constraints is not None: 98 | for constraint in constraints: 99 | if constraint[1] == "" or constraint[1] == "-": 100 | file_col = constraint[0] 101 | params.append("{0}={1}".format(constraint[0], constraint[1].replace("+","%2B"))) 102 | 103 | if filename is not None: 104 | #params.append("-out.form=hori") 105 | #params.append("-out.add=_1") 106 | 107 | if file_col is not None: 108 | params.append("-sort={0}".format(file_col)) 109 | else: 110 | params.append("-out.add=_r") 111 | params.append("-sort=_r") 112 | 113 | self.__client.query("urat1_neighbourhood", params=params, filename=filename) 114 | 115 | if self.format is not None: 116 | self.__client.format = self.format 117 | 118 | def get(self): 119 | return self.__client.get() 120 | 121 | def print_stdout(self): 122 | return self.__client.print_stdout() 123 | 124 | 125 | 126 | if __name__ == "__main__": 127 | 128 | __radius = vizquery.DEFAULT_RADIUS 129 | __position = None 130 | __limit = None 131 | __mime = vizquery.FORMAT_ASCII 132 | __noformat = False 133 | __ipix = None 134 | __all = False 135 | __sort = False 136 | __add = None 137 | __filename = None 138 | __constraints = [] 139 | 140 | 141 | __options = ('help','format=','sort','add=','file=') 142 | try : 143 | __opts, __args = getopt.getopt(sys.argv[1:], 'har:m:f:', __options) 144 | except: 145 | help("__main__") 146 | sys.exit(1) 147 | 148 | for __o, __a in __opts: 149 | if __o in ("-h", "--help"): 150 | help("__main__") 151 | sys.exit(1) 152 | 153 | elif __o == "-r": 154 | try: 155 | __radius = float(__a) 156 | except: 157 | sys.stderr.write("(error) wrong radius format\n") 158 | 159 | elif __o == "-m": 160 | try: 161 | __limit = int(__a) 162 | except: 163 | sys.stderr.write("(error) wrong limit/max format\n") 164 | 165 | elif __o == "-a": 166 | __all = True 167 | 168 | elif __o == "--format": 169 | __mime = __a 170 | 171 | elif __o == "--no-format": 172 | __noformat = True 173 | 174 | elif __o == "--ipix": 175 | __ipix = __a 176 | 177 | elif __o == "--count": 178 | __count = True 179 | 180 | elif __o == "--sort": 181 | __sort = True 182 | __constraints.append(("-out.add", "_r")) 183 | __constraints.append(("-sort", "_r")) 184 | 185 | elif __o == "--add": 186 | if __add is None: __add = [] 187 | __add.append(__a) 188 | 189 | if __o in ("-f", "--file"): 190 | __filename = __a 191 | 192 | else: 193 | for opt in __options[2:]: 194 | value = opt[:len(opt)-1] 195 | if __o[2:] == value: 196 | __constraints.append((value, __a)) 197 | break 198 | 199 | for __arg in __args: 200 | if __position is None: 201 | __position = __arg 202 | else: 203 | __position += " "+ __arg 204 | 205 | if __noformat is True or __ipix is not None: 206 | if __sort is True : 207 | raise Exception("--sort function is not compatible with --ipix/--no-format") 208 | if __filename is not None: 209 | raise Exception("--file option is not compatible with --ipix/--no-format") 210 | 211 | __querycat = QueryCatClient() 212 | if __ipix is not None: 213 | __querycat.set_healpix(__ipix) 214 | __querycat.noformat=__noformat 215 | 216 | else: 217 | __querycat = QueryCatVizieR() 218 | 219 | 220 | __querycat.position = __position 221 | __querycat.radius = __radius 222 | 223 | if __mime in (vizquery.FORMAT_TSV, vizquery.FORMAT_VOTABLE, vizquery.FORMAT_ASCII): 224 | __querycat.format = __mime 225 | else: 226 | raise Exception("format not yet available") 227 | 228 | __querycat.query_cat(constraints=__constraints, all=__all, limit=__limit, columns=__add, filename=__filename) 229 | __querycat.print_stdout() 230 | 231 | -------------------------------------------------------------------------------- /cdsclient/find_gsc1.2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """G.Landais (CDS) 24-mar-2018 3 | Query I/254/out 4 | 5 | find_gsc1.2.py [-h] [-a] [-r radius] [-m max] [constraints] [--format=tsv|votable|ascii] [position] 6 | 7 | -a: display all columns 8 | -r: radius in arcsec 9 | -m: max number of lines in output 10 | -h: this help 11 | --format: output (--format=tsv|votable|ascii) 12 | --sort : sort by distance (available with position only) 13 | --add : column name in output 14 | --file : query with a list 15 | 16 | position : ra dec position or target name 17 | example: find_gsc1.2.py M1 18 | 19 | Other constraints: 20 | --sort : ... 21 | --add= : ... 22 | --file= : ... 23 | --GSC= : ... 24 | --RAJ2000= : ... 25 | --DEJ2000= : ... 26 | --Pmag= : ... 27 | 28 | 29 | Example: --GSC=">10" 30 | 31 | Licensed under a BSD license - see LICENSE.txt for details 32 | 33 | """ 34 | 35 | import os, sys 36 | import getopt 37 | import vizquery 38 | 39 | if int(sys.version[0])<3: 40 | from urllib2 import quote 41 | else: 42 | from urllib.parse import quote 43 | 44 | NO_FORMAT = "noformat" 45 | DEBUG = False 46 | 47 | class QueryCat(): 48 | def __init__(self): 49 | self.position = None 50 | self.radius = vizquery.DEFAULT_RADIUS 51 | self.format = None 52 | 53 | def query_cat(self, constraints=None, all = False, limit=vizquery.DEFAULT_LIMIT): 54 | """init constraints parameters 55 | :param constraints: list of constraints ((name,value), ...) 56 | :param all: display all columns(efault False) 57 | :param limit: max number of records 58 | """ 59 | pass 60 | 61 | def get(self): 62 | """get astropy table""" 63 | pass 64 | 65 | def print_stdout(self): 66 | """print the result on stdout""" 67 | pass 68 | 69 | 70 | class QueryCatVizieR(QueryCat): 71 | def __init__(self): 72 | QueryCat.__init__(self) 73 | self.__client = vizquery.CDSClient(default_format=vizquery.FORMAT_ASCII) 74 | self.limit = vizquery.DEFAULT_LIMIT 75 | 76 | def query_cat(self, constraints=None, all=False, limit=vizquery.DEFAULT_LIMIT, columns=None, filename=None): 77 | params = [] 78 | 79 | if self.position: 80 | params.append("-c={0}".format(quote(self.position))) 81 | 82 | if self.radius: 83 | params.append("-c.rs={0:f}".format(self.radius)) 84 | 85 | if all is True: 86 | params.append("-out.all=1") 87 | 88 | if limit is not None: 89 | params.append("-out.max={0:d}".format(limit)) 90 | else: 91 | params.append("-out.max={0:d}".format(self.limit)) 92 | 93 | if columns is not None: 94 | for column in columns: params.append("-out={0}".format(column)) 95 | 96 | file_col = None 97 | if constraints is not None: 98 | for constraint in constraints: 99 | if constraint[1] == "" or constraint[1] == "-": 100 | file_col = constraint[0] 101 | params.append("{0}={1}".format(constraint[0], constraint[1].replace("+","%2B"))) 102 | 103 | if filename is not None: 104 | #params.append("-out.form=hori") 105 | #params.append("-out.add=_1") 106 | 107 | if file_col is not None: 108 | params.append("-sort={0}".format(file_col)) 109 | else: 110 | params.append("-out.add=_r") 111 | params.append("-sort=_r") 112 | 113 | self.__client.query("I/254/out", params=params, filename=filename) 114 | 115 | if self.format is not None: 116 | self.__client.format = self.format 117 | 118 | def get(self): 119 | return self.__client.get() 120 | 121 | def print_stdout(self): 122 | return self.__client.print_stdout() 123 | 124 | 125 | 126 | 127 | if __name__ == "__main__": 128 | 129 | __radius = vizquery.DEFAULT_RADIUS 130 | __position = None 131 | __limit = None 132 | __mime = vizquery.FORMAT_ASCII 133 | __noformat = False 134 | __ipix = None 135 | __all = False 136 | __sort = False 137 | __add = None 138 | __filename = None 139 | __constraints = [] 140 | __offset = None 141 | 142 | __options = ('help','format=','sort','add=','file=','GSC=','RAJ2000=','DEJ2000=','Pmag=') 143 | try : 144 | __opts, __args = getopt.getopt(sys.argv[1:], 'hvar:m:f:', __options) 145 | except: 146 | help("__main__") 147 | sys.exit(1) 148 | 149 | for __o, __a in __opts: 150 | if __o == '-v': 151 | DEBUG = True 152 | continue 153 | 154 | if __o in ("-h", "--help"): 155 | help("__main__") 156 | sys.exit(1) 157 | 158 | elif __o == "-r": 159 | try: 160 | __radius = float(__a) 161 | except: 162 | sys.stderr.write("(error) wrong radius format\n") 163 | 164 | elif __o == "-m": 165 | try: 166 | __limit = int(__a) 167 | except: 168 | raise Exception("(error) wrong limit/max format") 169 | 170 | elif __o == "-a": 171 | __all = True 172 | 173 | elif __o == "--format": 174 | __mime = __a 175 | 176 | elif __o == "--no-format": 177 | __noformat = True 178 | 179 | elif __o == "--ipix": 180 | __ipix = __a 181 | 182 | elif __o == "--count": 183 | __count = True 184 | 185 | elif __o == "--sort": 186 | __sort = True 187 | __constraints.append(("-out.add", "_r")) 188 | __constraints.append(("-sort", "_r")) 189 | 190 | elif __o == "--add": 191 | if __add is None: __add = [] 192 | __add.append(__a) 193 | 194 | elif __o == "--offset": 195 | __offset = __a 196 | continue 197 | 198 | if __o in ("-f", "--file"): 199 | __filename = __a 200 | 201 | else: 202 | for opt in __options[2:]: 203 | value = opt[:len(opt)-1] 204 | if __o[2:] == value: 205 | __constraints.append((value, __a)) 206 | break 207 | 208 | for __arg in __args: 209 | if __position is None: 210 | __position = __arg 211 | else: 212 | __position += " "+ __arg 213 | 214 | if __noformat is True or __ipix is not None or __offset is not None: 215 | if __sort is True : 216 | raise Exception("--sort function is not compatible with --ipix/--no-format") 217 | if __filename is not None: 218 | raise Exception("--file option is not compatible with --ipix/--no-format") 219 | 220 | if len(__constraints)>0: 221 | raise Exception("Constraints "+str(__constraints)+" is not available in this mode (--ipix/--offset/--no-format)") 222 | 223 | __querycat = QueryCatClient() 224 | if __ipix is not None: 225 | __querycat.set_healpix(__ipix) 226 | __querycat.noformat=__noformat 227 | 228 | if __offset : 229 | s = __offset.split("..") 230 | if len(s) != 2: raise Exception("error offset syntax: min..max") 231 | try: 232 | __querycat.set_offset(int(s[0]), int(s[1])) 233 | except: 234 | raise Exception("error offset syntax: begin..nb_records") 235 | 236 | if __mime is None or __mime == vizquery.FORMAT_ASCII: 237 | __mime = vizquery.FORMAT_TSV 238 | 239 | else: 240 | __querycat = QueryCatVizieR() 241 | 242 | __querycat.position = __position 243 | __querycat.radius = __radius 244 | 245 | if __mime in (vizquery.FORMAT_TSV, vizquery.FORMAT_VOTABLE, vizquery.FORMAT_ASCII): 246 | __querycat.format = __mime 247 | else: 248 | raise Exception("format not yet available") 249 | 250 | __querycat.query_cat(constraints=__constraints, all=__all, limit=__limit, columns=__add, filename=__filename) 251 | __querycat.print_stdout() 252 | 253 | -------------------------------------------------------------------------------- /cdsclient/find_gsc1.3.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """G.Landais (CDS) 24-mar-2018 3 | Query I/255/out 4 | 5 | find_gsc1.3.py [-h] [-a] [-r radius] [-m max] [constraints] [--format=tsv|votable|ascii] [position] 6 | 7 | -a: display all columns 8 | -r: radius in arcsec 9 | -m: max number of lines in output 10 | -h: this help 11 | --format: output (--format=tsv|votable|ascii) 12 | --sort : sort by distance (available with position only) 13 | --add : column name in output 14 | --file : query with a list 15 | 16 | position : ra dec position or target name 17 | example: find_gsc1.3.py M1 18 | 19 | Other constraints: 20 | --sort : ... 21 | --add= : ... 22 | --file= : ... 23 | --GSC= : ... 24 | --RAJ2000= : ... 25 | --DEJ2000= : ... 26 | --Pmag= : ... 27 | 28 | 29 | Example: --GSC=">10" 30 | 31 | Licensed under a BSD license - see LICENSE.txt for details 32 | 33 | """ 34 | 35 | import os, sys 36 | import getopt 37 | import vizquery 38 | 39 | if int(sys.version[0])<3: 40 | from urllib2 import quote 41 | else: 42 | from urllib.parse import quote 43 | 44 | NO_FORMAT = "noformat" 45 | DEBUG = False 46 | 47 | class QueryCat(): 48 | def __init__(self): 49 | self.position = None 50 | self.radius = vizquery.DEFAULT_RADIUS 51 | self.format = None 52 | 53 | def query_cat(self, constraints=None, all = False, limit=vizquery.DEFAULT_LIMIT): 54 | """init constraints parameters 55 | :param constraints: list of constraints ((name,value), ...) 56 | :param all: display all columns(efault False) 57 | :param limit: max number of records 58 | """ 59 | pass 60 | 61 | def get(self): 62 | """get astropy table""" 63 | pass 64 | 65 | def print_stdout(self): 66 | """print the result on stdout""" 67 | pass 68 | 69 | 70 | class QueryCatVizieR(QueryCat): 71 | def __init__(self): 72 | QueryCat.__init__(self) 73 | self.__client = vizquery.CDSClient(default_format=vizquery.FORMAT_ASCII) 74 | self.limit = vizquery.DEFAULT_LIMIT 75 | 76 | def query_cat(self, constraints=None, all=False, limit=vizquery.DEFAULT_LIMIT, columns=None, filename=None): 77 | params = [] 78 | 79 | if self.position: 80 | params.append("-c={0}".format(quote(self.position))) 81 | 82 | if self.radius: 83 | params.append("-c.rs={0:f}".format(self.radius)) 84 | 85 | if all is True: 86 | params.append("-out.all=1") 87 | 88 | if limit is not None: 89 | params.append("-out.max={0:d}".format(limit)) 90 | else: 91 | params.append("-out.max={0:d}".format(self.limit)) 92 | 93 | if columns is not None: 94 | for column in columns: params.append("-out={0}".format(column)) 95 | 96 | file_col = None 97 | if constraints is not None: 98 | for constraint in constraints: 99 | if constraint[1] == "" or constraint[1] == "-": 100 | file_col = constraint[0] 101 | params.append("{0}={1}".format(constraint[0], constraint[1].replace("+","%2B"))) 102 | 103 | if filename is not None: 104 | #params.append("-out.form=hori") 105 | #params.append("-out.add=_1") 106 | 107 | if file_col is not None: 108 | params.append("-sort={0}".format(file_col)) 109 | else: 110 | params.append("-out.add=_r") 111 | params.append("-sort=_r") 112 | 113 | self.__client.query("I/255/out", params=params, filename=filename) 114 | 115 | if self.format is not None: 116 | self.__client.format = self.format 117 | 118 | def get(self): 119 | return self.__client.get() 120 | 121 | def print_stdout(self): 122 | return self.__client.print_stdout() 123 | 124 | 125 | 126 | 127 | if __name__ == "__main__": 128 | 129 | __radius = vizquery.DEFAULT_RADIUS 130 | __position = None 131 | __limit = None 132 | __mime = vizquery.FORMAT_ASCII 133 | __noformat = False 134 | __ipix = None 135 | __all = False 136 | __sort = False 137 | __add = None 138 | __filename = None 139 | __constraints = [] 140 | __offset = None 141 | 142 | __options = ('help','format=','sort','add=','file=','GSC=','RAJ2000=','DEJ2000=','Pmag=') 143 | try : 144 | __opts, __args = getopt.getopt(sys.argv[1:], 'hvar:m:f:', __options) 145 | except: 146 | help("__main__") 147 | sys.exit(1) 148 | 149 | for __o, __a in __opts: 150 | if __o == '-v': 151 | DEBUG = True 152 | continue 153 | 154 | if __o in ("-h", "--help"): 155 | help("__main__") 156 | sys.exit(1) 157 | 158 | elif __o == "-r": 159 | try: 160 | __radius = float(__a) 161 | except: 162 | sys.stderr.write("(error) wrong radius format\n") 163 | 164 | elif __o == "-m": 165 | try: 166 | __limit = int(__a) 167 | except: 168 | raise Exception("(error) wrong limit/max format") 169 | 170 | elif __o == "-a": 171 | __all = True 172 | 173 | elif __o == "--format": 174 | __mime = __a 175 | 176 | elif __o == "--no-format": 177 | __noformat = True 178 | 179 | elif __o == "--ipix": 180 | __ipix = __a 181 | 182 | elif __o == "--count": 183 | __count = True 184 | 185 | elif __o == "--sort": 186 | __sort = True 187 | __constraints.append(("-out.add", "_r")) 188 | __constraints.append(("-sort", "_r")) 189 | 190 | elif __o == "--add": 191 | if __add is None: __add = [] 192 | __add.append(__a) 193 | 194 | elif __o == "--offset": 195 | __offset = __a 196 | continue 197 | 198 | if __o in ("-f", "--file"): 199 | __filename = __a 200 | 201 | else: 202 | for opt in __options[2:]: 203 | value = opt[:len(opt)-1] 204 | if __o[2:] == value: 205 | __constraints.append((value, __a)) 206 | break 207 | 208 | for __arg in __args: 209 | if __position is None: 210 | __position = __arg 211 | else: 212 | __position += " "+ __arg 213 | 214 | if __noformat is True or __ipix is not None or __offset is not None: 215 | if __sort is True : 216 | raise Exception("--sort function is not compatible with --ipix/--no-format") 217 | if __filename is not None: 218 | raise Exception("--file option is not compatible with --ipix/--no-format") 219 | 220 | if len(__constraints)>0: 221 | raise Exception("Constraints "+str(__constraints)+" is not available in this mode (--ipix/--offset/--no-format)") 222 | 223 | __querycat = QueryCatClient() 224 | if __ipix is not None: 225 | __querycat.set_healpix(__ipix) 226 | __querycat.noformat=__noformat 227 | 228 | if __offset : 229 | s = __offset.split("..") 230 | if len(s) != 2: raise Exception("error offset syntax: min..max") 231 | try: 232 | __querycat.set_offset(int(s[0]), int(s[1])) 233 | except: 234 | raise Exception("error offset syntax: begin..nb_records") 235 | 236 | if __mime is None or __mime == vizquery.FORMAT_ASCII: 237 | __mime = vizquery.FORMAT_TSV 238 | 239 | else: 240 | __querycat = QueryCatVizieR() 241 | 242 | __querycat.position = __position 243 | __querycat.radius = __radius 244 | 245 | if __mime in (vizquery.FORMAT_TSV, vizquery.FORMAT_VOTABLE, vizquery.FORMAT_ASCII): 246 | __querycat.format = __mime 247 | else: 248 | raise Exception("format not yet available") 249 | 250 | __querycat.query_cat(constraints=__constraints, all=__all, limit=__limit, columns=__add, filename=__filename) 251 | __querycat.print_stdout() 252 | 253 | -------------------------------------------------------------------------------- /cdsclient/find_const.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """G.Landais (CDS) 24-mar-2018 3 | Query VI/42/out 4 | 5 | find_const.py [-h] [-a] [-r radius] [-m max] [constraints] [--format=tsv|votable|ascii] [position] 6 | 7 | -a: display all columns 8 | -r: radius in arcsec 9 | -m: max number of lines in output 10 | -h: this help 11 | --format: output (--format=tsv|votable|ascii) 12 | --sort : sort by distance (available with position only) 13 | --add : column name in output 14 | --file : query with a list 15 | 16 | position : ra dec position or target name 17 | example: find_const.py M1 18 | 19 | Other constraints: 20 | --sort : ... 21 | --add= : ... 22 | --file= : ... 23 | 24 | 25 | Example: 26 | 27 | Licensed under a BSD license - see LICENSE.txt for details 28 | 29 | """ 30 | 31 | import os, sys 32 | import getopt 33 | try: 34 | sys.path.append(os.path.split(os.path.abspath(sys.argv[0]))[0]) 35 | import vizquery 36 | except: 37 | sys.stderr.write("(error) needs vizquery.py in PYTHONPATH\n") 38 | sys.exit(1) 39 | 40 | if int(sys.version[0])<3: 41 | from urllib2 import quote 42 | else: 43 | from urllib.parse import quote 44 | 45 | NO_FORMAT = "noformat" 46 | DEBUG = False 47 | 48 | class QueryCat(): 49 | def __init__(self): 50 | self.position = None 51 | self.radius = vizquery.DEFAULT_RADIUS 52 | self.format = None 53 | 54 | def query_cat(self, constraints=None, all = False, limit=vizquery.DEFAULT_LIMIT): 55 | """init constraints parameters 56 | :param constraints: list of constraints ((name,value), ...) 57 | :param all: display all columns(efault False) 58 | :param limit: max number of records 59 | """ 60 | pass 61 | 62 | def get(self): 63 | """get astropy table""" 64 | pass 65 | 66 | def print_stdout(self): 67 | """print the result on stdout""" 68 | pass 69 | 70 | 71 | class QueryCatVizieR(QueryCat): 72 | def __init__(self): 73 | QueryCat.__init__(self) 74 | self.__client = vizquery.CDSClient(default_format=vizquery.FORMAT_ASCII) 75 | self.limit = vizquery.DEFAULT_LIMIT 76 | 77 | def query_cat(self, constraints=None, all=False, limit=vizquery.DEFAULT_LIMIT, columns=None, filename=None): 78 | params = [] 79 | 80 | if self.position: 81 | params.append("-c={0}".format(quote(self.position))) 82 | 83 | if self.radius: 84 | params.append("-c.rs={0:f}".format(self.radius)) 85 | 86 | if all is True: 87 | params.append("-out.all=1") 88 | 89 | if limit is not None: 90 | params.append("-out.max={0:d}".format(limit)) 91 | else: 92 | params.append("-out.max={0:d}".format(self.limit)) 93 | 94 | if columns is not None: 95 | for column in columns: params.append("-out={0}".format(column)) 96 | 97 | file_col = None 98 | if constraints is not None: 99 | for constraint in constraints: 100 | if constraint[1] == "" or constraint[1] == "-": 101 | file_col = constraint[0] 102 | params.append("{0}={1}".format(constraint[0], constraint[1].replace("+","%2B"))) 103 | 104 | if filename is not None: 105 | #params.append("-out.form=hori") 106 | #params.append("-out.add=_1") 107 | 108 | if file_col is not None: 109 | params.append("-sort={0}".format(file_col)) 110 | else: 111 | params.append("-out.add=_r") 112 | params.append("-sort=_r") 113 | 114 | self.__client.query("VI/42/out", params=params, filename=filename) 115 | 116 | if self.format is not None: 117 | self.__client.format = self.format 118 | 119 | def get(self): 120 | return self.__client.get() 121 | 122 | def print_stdout(self): 123 | return self.__client.print_stdout() 124 | 125 | 126 | 127 | 128 | if __name__ == "__main__": 129 | 130 | __radius = vizquery.DEFAULT_RADIUS 131 | __position = None 132 | __limit = None 133 | __mime = vizquery.FORMAT_ASCII 134 | __noformat = False 135 | __ipix = None 136 | __all = False 137 | __sort = False 138 | __add = None 139 | __filename = None 140 | __constraints = [] 141 | __offset = None 142 | 143 | __options = ('help','format=','sort','add=','file=') 144 | try : 145 | __opts, __args = getopt.getopt(sys.argv[1:], 'hvar:m:f:', __options) 146 | except: 147 | help("__main__") 148 | sys.exit(1) 149 | 150 | for __o, __a in __opts: 151 | if __o == '-v': 152 | DEBUG = True 153 | continue 154 | 155 | if __o in ("-h", "--help"): 156 | help("__main__") 157 | sys.exit(1) 158 | 159 | elif __o == "-r": 160 | try: 161 | __radius = float(__a) 162 | except: 163 | sys.stderr.write("(error) wrong radius format\n") 164 | 165 | elif __o == "-m": 166 | try: 167 | __limit = int(__a) 168 | except: 169 | raise Exception("(error) wrong limit/max format") 170 | 171 | elif __o == "-a": 172 | __all = True 173 | 174 | elif __o == "--format": 175 | __mime = __a 176 | 177 | elif __o == "--no-format": 178 | __noformat = True 179 | 180 | elif __o == "--ipix": 181 | __ipix = __a 182 | 183 | elif __o == "--count": 184 | __count = True 185 | 186 | elif __o == "--sort": 187 | __sort = True 188 | __constraints.append(("-out.add", "_r")) 189 | __constraints.append(("-sort", "_r")) 190 | 191 | elif __o == "--add": 192 | if __add is None: __add = [] 193 | __add.append(__a) 194 | 195 | elif __o == "--offset": 196 | __offset = __a 197 | continue 198 | 199 | if __o in ("-f", "--file"): 200 | __filename = __a 201 | 202 | else: 203 | for opt in __options[2:]: 204 | value = opt[:len(opt)-1] 205 | if __o[2:] == value: 206 | __constraints.append((value, __a)) 207 | break 208 | 209 | for __arg in __args: 210 | if __position is None: 211 | __position = __arg 212 | else: 213 | __position += " "+ __arg 214 | 215 | if __noformat is True or __ipix is not None or __offset is not None: 216 | if __sort is True : 217 | raise Exception("--sort function is not compatible with --ipix/--no-format") 218 | if __filename is not None: 219 | raise Exception("--file option is not compatible with --ipix/--no-format") 220 | 221 | if len(__constraints)>0: 222 | raise Exception("Constraints "+str(__constraints)+" is not available in this mode (--ipix/--offset/--no-format)") 223 | 224 | __querycat = QueryCatClient() 225 | if __ipix is not None: 226 | __querycat.set_healpix(__ipix) 227 | __querycat.noformat=__noformat 228 | 229 | if __offset : 230 | s = __offset.split("..") 231 | if len(s) != 2: raise Exception("error offset syntax: min..max") 232 | try: 233 | __querycat.set_offset(int(s[0]), int(s[1])) 234 | except: 235 | raise Exception("error offset syntax: begin..nb_records") 236 | 237 | if __mime is None or __mime == vizquery.FORMAT_ASCII: 238 | __mime = vizquery.FORMAT_TSV 239 | 240 | else: 241 | __querycat = QueryCatVizieR() 242 | 243 | __querycat.position = __position 244 | __querycat.radius = __radius 245 | 246 | if __mime in (vizquery.FORMAT_TSV, vizquery.FORMAT_VOTABLE, vizquery.FORMAT_ASCII): 247 | __querycat.format = __mime 248 | else: 249 | raise Exception("format not yet available") 250 | 251 | __querycat.query_cat(constraints=__constraints, all=__all, limit=__limit, columns=__add, filename=__filename) 252 | __querycat.print_stdout() 253 | 254 | -------------------------------------------------------------------------------- /cdsclient/find_gsc2.3.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """G.Landais (CDS) 24-mar-2018 3 | Query I/305/out 4 | 5 | find_gsc2.3.py [-h] [-a] [-r radius] [-m max] [constraints] [--format=tsv|votable|ascii] [position] 6 | 7 | -a: display all columns 8 | -r: radius in arcsec 9 | -m: max number of lines in output 10 | -h: this help 11 | --format: output (--format=tsv|votable|ascii) 12 | --sort : sort by distance (available with position only) 13 | --add : column name in output 14 | --file : query with a list 15 | 16 | position : ra dec position or target name 17 | example: find_gsc2.3.py M1 18 | 19 | Other constraints: 20 | --sort : ... 21 | --add= : ... 22 | --file= : ... 23 | --GSC2.3= : ... 24 | --RAJ2000= : ... 25 | --DEJ2000= : ... 26 | --Fmag= : ... 27 | --jmag= : ... 28 | --Vmag= : ... 29 | --Nmag= : ... 30 | 31 | 32 | Example: --GSC2.3=">10" 33 | 34 | Licensed under a BSD license - see LICENSE.txt for details 35 | 36 | """ 37 | 38 | import os, sys 39 | import getopt 40 | import vizquery 41 | 42 | if int(sys.version[0])<3: 43 | from urllib2 import quote 44 | else: 45 | from urllib.parse import quote 46 | 47 | NO_FORMAT = "noformat" 48 | DEBUG = False 49 | 50 | class QueryCat(): 51 | def __init__(self): 52 | self.position = None 53 | self.radius = vizquery.DEFAULT_RADIUS 54 | self.format = None 55 | 56 | def query_cat(self, constraints=None, all = False, limit=vizquery.DEFAULT_LIMIT): 57 | """init constraints parameters 58 | :param constraints: list of constraints ((name,value), ...) 59 | :param all: display all columns(efault False) 60 | :param limit: max number of records 61 | """ 62 | pass 63 | 64 | def get(self): 65 | """get astropy table""" 66 | pass 67 | 68 | def print_stdout(self): 69 | """print the result on stdout""" 70 | pass 71 | 72 | 73 | class QueryCatVizieR(QueryCat): 74 | def __init__(self): 75 | QueryCat.__init__(self) 76 | self.__client = vizquery.CDSClient(default_format=vizquery.FORMAT_ASCII) 77 | self.limit = vizquery.DEFAULT_LIMIT 78 | 79 | def query_cat(self, constraints=None, all=False, limit=vizquery.DEFAULT_LIMIT, columns=None, filename=None): 80 | params = [] 81 | 82 | if self.position: 83 | params.append("-c={0}".format(quote(self.position))) 84 | 85 | if self.radius: 86 | params.append("-c.rs={0:f}".format(self.radius)) 87 | 88 | if all is True: 89 | params.append("-out.all=1") 90 | 91 | if limit is not None: 92 | params.append("-out.max={0:d}".format(limit)) 93 | else: 94 | params.append("-out.max={0:d}".format(self.limit)) 95 | 96 | if columns is not None: 97 | for column in columns: params.append("-out={0}".format(column)) 98 | 99 | file_col = None 100 | if constraints is not None: 101 | for constraint in constraints: 102 | if constraint[1] == "" or constraint[1] == "-": 103 | file_col = constraint[0] 104 | params.append("{0}={1}".format(constraint[0], constraint[1].replace("+","%2B"))) 105 | 106 | if filename is not None: 107 | #params.append("-out.form=hori") 108 | #params.append("-out.add=_1") 109 | 110 | if file_col is not None: 111 | params.append("-sort={0}".format(file_col)) 112 | else: 113 | params.append("-out.add=_r") 114 | params.append("-sort=_r") 115 | 116 | self.__client.query("I/305/out", params=params, filename=filename) 117 | 118 | if self.format is not None: 119 | self.__client.format = self.format 120 | 121 | def get(self): 122 | return self.__client.get() 123 | 124 | def print_stdout(self): 125 | return self.__client.print_stdout() 126 | 127 | 128 | 129 | 130 | if __name__ == "__main__": 131 | 132 | __radius = vizquery.DEFAULT_RADIUS 133 | __position = None 134 | __limit = None 135 | __mime = vizquery.FORMAT_ASCII 136 | __noformat = False 137 | __ipix = None 138 | __all = False 139 | __sort = False 140 | __add = None 141 | __filename = None 142 | __constraints = [] 143 | __offset = None 144 | 145 | __options = ('help','format=','sort','add=','file=','GSC2.3=','RAJ2000=','DEJ2000=','Fmag=','jmag=','Vmag=','Nmag=') 146 | try : 147 | __opts, __args = getopt.getopt(sys.argv[1:], 'hvar:m:f:', __options) 148 | except: 149 | help("__main__") 150 | sys.exit(1) 151 | 152 | for __o, __a in __opts: 153 | if __o == '-v': 154 | DEBUG = True 155 | continue 156 | 157 | if __o in ("-h", "--help"): 158 | help("__main__") 159 | sys.exit(1) 160 | 161 | elif __o == "-r": 162 | try: 163 | __radius = float(__a) 164 | except: 165 | sys.stderr.write("(error) wrong radius format\n") 166 | 167 | elif __o == "-m": 168 | try: 169 | __limit = int(__a) 170 | except: 171 | raise Exception("(error) wrong limit/max format") 172 | 173 | elif __o == "-a": 174 | __all = True 175 | 176 | elif __o == "--format": 177 | __mime = __a 178 | 179 | elif __o == "--no-format": 180 | __noformat = True 181 | 182 | elif __o == "--ipix": 183 | __ipix = __a 184 | 185 | elif __o == "--count": 186 | __count = True 187 | 188 | elif __o == "--sort": 189 | __sort = True 190 | __constraints.append(("-out.add", "_r")) 191 | __constraints.append(("-sort", "_r")) 192 | 193 | elif __o == "--add": 194 | if __add is None: __add = [] 195 | __add.append(__a) 196 | 197 | elif __o == "--offset": 198 | __offset = __a 199 | continue 200 | 201 | if __o in ("-f", "--file"): 202 | __filename = __a 203 | 204 | else: 205 | for opt in __options[2:]: 206 | value = opt[:len(opt)-1] 207 | if __o[2:] == value: 208 | __constraints.append((value, __a)) 209 | break 210 | 211 | for __arg in __args: 212 | if __position is None: 213 | __position = __arg 214 | else: 215 | __position += " "+ __arg 216 | 217 | if __noformat is True or __ipix is not None or __offset is not None: 218 | if __sort is True : 219 | raise Exception("--sort function is not compatible with --ipix/--no-format") 220 | if __filename is not None: 221 | raise Exception("--file option is not compatible with --ipix/--no-format") 222 | 223 | if len(__constraints)>0: 224 | raise Exception("Constraints "+str(__constraints)+" is not available in this mode (--ipix/--offset/--no-format)") 225 | 226 | __querycat = QueryCatClient() 227 | if __ipix is not None: 228 | __querycat.set_healpix(__ipix) 229 | __querycat.noformat=__noformat 230 | 231 | if __offset : 232 | s = __offset.split("..") 233 | if len(s) != 2: raise Exception("error offset syntax: min..max") 234 | try: 235 | __querycat.set_offset(int(s[0]), int(s[1])) 236 | except: 237 | raise Exception("error offset syntax: begin..nb_records") 238 | 239 | if __mime is None or __mime == vizquery.FORMAT_ASCII: 240 | __mime = vizquery.FORMAT_TSV 241 | 242 | else: 243 | __querycat = QueryCatVizieR() 244 | 245 | __querycat.position = __position 246 | __querycat.radius = __radius 247 | 248 | if __mime in (vizquery.FORMAT_TSV, vizquery.FORMAT_VOTABLE, vizquery.FORMAT_ASCII): 249 | __querycat.format = __mime 250 | else: 251 | raise Exception("format not yet available") 252 | 253 | __querycat.query_cat(constraints=__constraints, all=__all, limit=__limit, columns=__add, filename=__filename) 254 | __querycat.print_stdout() 255 | 256 | -------------------------------------------------------------------------------- /cdsclient/find_pmm2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """G.Landais (CDS) 24-mar-2018 3 | Query I/252/out 4 | 5 | find_pmm2.py [-h] [-a] [-r radius] [-m max] [constraints] [--format=tsv|votable|ascii] [position] 6 | 7 | -a: display all columns 8 | -r: radius in arcsec 9 | -m: max number of lines in output 10 | -h: this help 11 | --format: output (--format=tsv|votable|ascii) 12 | --noheader: remove header (not available for all options) 13 | --sort : sort by distance (available with position only) 14 | --add : column name in output 15 | --file : query with a list 16 | 17 | position : ra dec position or target name 18 | example: find_pmm2.py M1 19 | 20 | Other constraints: 21 | --sort : ... 22 | --add= : ... 23 | --file= : ... 24 | --noheader : ... 25 | --USNO-A2.0= : ... 26 | --RAJ2000= : ... 27 | --DEJ2000= : ... 28 | 29 | 30 | Example: --USNO-A2.0=">10" 31 | 32 | Licensed under a BSD license - see LICENSE.txt for details 33 | 34 | """ 35 | 36 | import os, sys 37 | import getopt 38 | import cdsclient.vizquery as vizquery 39 | #import vizquery 40 | 41 | if int(sys.version[0])<3: 42 | from urllib2 import quote 43 | else: 44 | from urllib.parse import quote 45 | 46 | NO_FORMAT = "noformat" 47 | DEBUG = False 48 | 49 | class QueryCat(): 50 | def __init__(self): 51 | self.position = None 52 | self.radius = vizquery.DEFAULT_RADIUS 53 | self.format = None 54 | 55 | def query_cat(self, constraints=None, all = False, limit=vizquery.DEFAULT_LIMIT): 56 | """init constraints parameters 57 | :param constraints: list of constraints ((name,value), ...) 58 | :param all: display all columns(efault False) 59 | :param limit: max number of records 60 | """ 61 | pass 62 | 63 | def get(self): 64 | """get astropy table""" 65 | pass 66 | 67 | def print_stdout(self): 68 | """print the result on stdout""" 69 | pass 70 | 71 | 72 | class QueryCatVizieR(QueryCat): 73 | def __init__(self): 74 | QueryCat.__init__(self) 75 | self.__client = vizquery.CDSClient(default_format=vizquery.FORMAT_ASCII) 76 | self.limit = vizquery.DEFAULT_LIMIT 77 | 78 | def query_cat(self, constraints=None, all=False, limit=vizquery.DEFAULT_LIMIT, columns=None, filename=None): 79 | params = [] 80 | 81 | if self.position: 82 | params.append("-c={0}".format(quote(self.position))) 83 | 84 | if self.radius: 85 | params.append("-c.rs={0:f}".format(self.radius)) 86 | 87 | if all is True: 88 | params.append("-out.all=1") 89 | 90 | if limit is not None: 91 | params.append("-out.max={0:d}".format(limit)) 92 | else: 93 | params.append("-out.max={0:d}".format(self.limit)) 94 | 95 | if columns is not None: 96 | for column in columns: params.append("-out={0}".format(column)) 97 | 98 | file_col = None 99 | if constraints is not None: 100 | for constraint in constraints: 101 | if constraint[1] == "" or constraint[1] == "-": 102 | file_col = constraint[0] 103 | params.append("{0}={1}".format(constraint[0], constraint[1].replace("+","%2B"))) 104 | 105 | if filename is not None: 106 | #params.append("-out.form=hori") 107 | #params.append("-out.add=_1") 108 | 109 | if file_col is not None: 110 | params.append("-sort={0}".format(file_col)) 111 | else: 112 | params.append("-out.add=_r") 113 | params.append("-sort=_r") 114 | 115 | self.__client.query("I/252/out", params=params, filename=filename) 116 | 117 | if self.format is not None: 118 | self.__client.format = self.format 119 | 120 | def get(self): 121 | return self.__client.get() 122 | 123 | def print_stdout(self): 124 | return self.__client.print_stdout() 125 | 126 | 127 | 128 | 129 | if __name__ == "__main__": 130 | 131 | __radius = vizquery.DEFAULT_RADIUS 132 | __position = None 133 | __limit = None 134 | __mime = vizquery.FORMAT_ASCII 135 | __noformat = False 136 | __noheader = False 137 | __ipix = None 138 | __all = False 139 | __sort = False 140 | __add = None 141 | __filename = None 142 | __constraints = [] 143 | __offset = None 144 | 145 | __options = ('help','format=','sort','add=','file=','noheader','USNO-A2.0=','RAJ2000=','DEJ2000=') 146 | try : 147 | __opts, __args = getopt.getopt(sys.argv[1:], 'hvar:m:f:', __options) 148 | except: 149 | help("__main__") 150 | sys.exit(1) 151 | 152 | for __o, __a in __opts: 153 | if __o == '-v': 154 | DEBUG = True 155 | continue 156 | 157 | if __o in ("-h", "--help"): 158 | help("__main__") 159 | sys.exit(1) 160 | 161 | elif __o == "-r": 162 | try: 163 | __radius = float(__a) 164 | except: 165 | sys.stderr.write("(error) wrong radius format\n") 166 | 167 | elif __o == "-m": 168 | try: 169 | __limit = int(__a) 170 | except: 171 | raise Exception("(error) wrong limit/max format") 172 | 173 | elif __o == "-a": 174 | __all = True 175 | 176 | elif __o == "--format": 177 | __mime = __a 178 | 179 | elif __o == "--no-format": 180 | __noformat = True 181 | 182 | elif __o == "--noheader": 183 | __noheader = True 184 | 185 | elif __o == "--ipix": 186 | __ipix = __a 187 | 188 | elif __o == "--count": 189 | __count = True 190 | 191 | elif __o == "--sort": 192 | __sort = True 193 | __constraints.append(("-out.add", "_r")) 194 | __constraints.append(("-sort", "_r")) 195 | 196 | elif __o == "--add": 197 | if __add is None: __add = [] 198 | __add.append(__a) 199 | 200 | elif __o == "--offset": 201 | __offset = __a 202 | continue 203 | 204 | if __o in ("-f", "--file"): 205 | __filename = __a 206 | 207 | else: 208 | for opt in __options[2:]: 209 | value = opt[:len(opt)-1] 210 | if __o[2:] == value: 211 | __constraints.append((value, __a)) 212 | break 213 | 214 | for __arg in __args: 215 | if __position is None: 216 | __position = __arg 217 | else: 218 | __position += " "+ __arg 219 | 220 | if __noformat is True or __ipix is not None or __offset is not None or __noheader: 221 | if __sort is True : 222 | raise Exception("--sort function is not compatible with --ipix/--no-format") 223 | if __filename is not None: 224 | raise Exception("--file option is not compatible with --ipix/--no-format") 225 | 226 | if len(__constraints)>0: 227 | raise Exception("Constraints "+str(__constraints)+" is not available in this mode (--ipix/--offset/--no-format)") 228 | 229 | __querycat = QueryCatClient() 230 | if __ipix is not None: 231 | __querycat.set_healpix(__ipix) 232 | __querycat.noformat=__noformat 233 | __querycat.noheader=__noheader 234 | 235 | if __offset : 236 | s = __offset.split("..") 237 | if len(s) != 2: raise Exception("error offset syntax: min..max") 238 | try: 239 | __querycat.set_offset(int(s[0]), int(s[1])) 240 | except: 241 | raise Exception("error offset syntax: begin..nb_records") 242 | 243 | if __mime is None or __mime == vizquery.FORMAT_ASCII: 244 | __mime = vizquery.FORMAT_TSV 245 | 246 | else: 247 | __querycat = QueryCatVizieR() 248 | 249 | __querycat.position = __position 250 | __querycat.radius = __radius 251 | 252 | if __mime in (vizquery.FORMAT_TSV, vizquery.FORMAT_VOTABLE, vizquery.FORMAT_ASCII): 253 | __querycat.format = __mime 254 | else: 255 | raise Exception("format not yet available") 256 | 257 | __querycat.query_cat(constraints=__constraints, all=__all, limit=__limit, columns=__add, filename=__filename) 258 | __querycat.print_stdout() 259 | 260 | -------------------------------------------------------------------------------- /cdsclient/find_gsc.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """G.Landais (CDS) 24-mar-2018 3 | Query I/220/out 4 | 5 | find_gsc.py [-h] [-a] [-r radius] [-m max] [constraints] [--format=tsv|votable|ascii] [position] 6 | 7 | -a: display all columns 8 | -r: radius in arcsec 9 | -m: max number of lines in output 10 | -h: this help 11 | --format: output (--format=tsv|votable|ascii) 12 | --noheader: remove header (not available for all options) 13 | --sort : sort by distance (available with position only) 14 | --add : column name in output 15 | --file : query with a list 16 | 17 | position : ra dec position or target name 18 | example: find_gsc.py M1 19 | 20 | Other constraints: 21 | --sort : ... 22 | --add= : ... 23 | --file= : ... 24 | --noheader : ... 25 | --GSC= : ... 26 | --RAJ2000= : ... 27 | --DEJ2000= : ... 28 | --Pmag= : ... 29 | 30 | 31 | Example: --GSC=">10" 32 | 33 | Licensed under a BSD license - see LICENSE.txt for details 34 | 35 | """ 36 | 37 | import os, sys 38 | import getopt 39 | import cdsclient.vizquery as vizquery 40 | #import vizquery 41 | 42 | if int(sys.version[0])<3: 43 | from urllib2 import quote 44 | else: 45 | from urllib.parse import quote 46 | 47 | NO_FORMAT = "noformat" 48 | DEBUG = False 49 | 50 | class QueryCat(): 51 | def __init__(self): 52 | self.position = None 53 | self.radius = vizquery.DEFAULT_RADIUS 54 | self.format = None 55 | 56 | def query_cat(self, constraints=None, all = False, limit=vizquery.DEFAULT_LIMIT): 57 | """init constraints parameters 58 | :param constraints: list of constraints ((name,value), ...) 59 | :param all: display all columns(efault False) 60 | :param limit: max number of records 61 | """ 62 | pass 63 | 64 | def get(self): 65 | """get astropy table""" 66 | pass 67 | 68 | def print_stdout(self): 69 | """print the result on stdout""" 70 | pass 71 | 72 | 73 | class QueryCatVizieR(QueryCat): 74 | def __init__(self): 75 | QueryCat.__init__(self) 76 | self.__client = vizquery.CDSClient(default_format=vizquery.FORMAT_ASCII) 77 | self.limit = vizquery.DEFAULT_LIMIT 78 | 79 | def query_cat(self, constraints=None, all=False, limit=vizquery.DEFAULT_LIMIT, columns=None, filename=None): 80 | params = [] 81 | 82 | if self.position: 83 | params.append("-c={0}".format(quote(self.position))) 84 | 85 | if self.radius: 86 | params.append("-c.rs={0:f}".format(self.radius)) 87 | 88 | if all is True: 89 | params.append("-out.all=1") 90 | 91 | if limit is not None: 92 | params.append("-out.max={0:d}".format(limit)) 93 | else: 94 | params.append("-out.max={0:d}".format(self.limit)) 95 | 96 | if columns is not None: 97 | for column in columns: params.append("-out={0}".format(column)) 98 | 99 | file_col = None 100 | if constraints is not None: 101 | for constraint in constraints: 102 | if constraint[1] == "" or constraint[1] == "-": 103 | file_col = constraint[0] 104 | params.append("{0}={1}".format(constraint[0], constraint[1].replace("+","%2B"))) 105 | 106 | if filename is not None: 107 | #params.append("-out.form=hori") 108 | #params.append("-out.add=_1") 109 | 110 | if file_col is not None: 111 | params.append("-sort={0}".format(file_col)) 112 | else: 113 | params.append("-out.add=_r") 114 | params.append("-sort=_r") 115 | 116 | self.__client.query("I/220/out", params=params, filename=filename) 117 | 118 | if self.format is not None: 119 | self.__client.format = self.format 120 | 121 | def get(self): 122 | return self.__client.get() 123 | 124 | def print_stdout(self): 125 | return self.__client.print_stdout() 126 | 127 | 128 | 129 | 130 | if __name__ == "__main__": 131 | 132 | __radius = vizquery.DEFAULT_RADIUS 133 | __position = None 134 | __limit = None 135 | __mime = vizquery.FORMAT_ASCII 136 | __noformat = False 137 | __noheader = False 138 | __ipix = None 139 | __all = False 140 | __sort = False 141 | __add = None 142 | __filename = None 143 | __constraints = [] 144 | __offset = None 145 | 146 | __options = ('help','format=','sort','add=','file=','noheader','GSC=','RAJ2000=','DEJ2000=','Pmag=') 147 | try : 148 | __opts, __args = getopt.getopt(sys.argv[1:], 'hvar:m:f:', __options) 149 | except: 150 | help("__main__") 151 | sys.exit(1) 152 | 153 | for __o, __a in __opts: 154 | if __o == '-v': 155 | DEBUG = True 156 | continue 157 | 158 | if __o in ("-h", "--help"): 159 | help("__main__") 160 | sys.exit(1) 161 | 162 | elif __o == "-r": 163 | try: 164 | __radius = float(__a) 165 | except: 166 | sys.stderr.write("(error) wrong radius format\n") 167 | 168 | elif __o == "-m": 169 | try: 170 | __limit = int(__a) 171 | except: 172 | raise Exception("(error) wrong limit/max format") 173 | 174 | elif __o == "-a": 175 | __all = True 176 | 177 | elif __o == "--format": 178 | __mime = __a 179 | 180 | elif __o == "--no-format": 181 | __noformat = True 182 | 183 | elif __o == "--noheader": 184 | __noheader = True 185 | 186 | elif __o == "--ipix": 187 | __ipix = __a 188 | 189 | elif __o == "--count": 190 | __count = True 191 | 192 | elif __o == "--sort": 193 | __sort = True 194 | __constraints.append(("-out.add", "_r")) 195 | __constraints.append(("-sort", "_r")) 196 | 197 | elif __o == "--add": 198 | if __add is None: __add = [] 199 | __add.append(__a) 200 | 201 | elif __o == "--offset": 202 | __offset = __a 203 | continue 204 | 205 | if __o in ("-f", "--file"): 206 | __filename = __a 207 | 208 | else: 209 | for opt in __options[2:]: 210 | value = opt[:len(opt)-1] 211 | if __o[2:] == value: 212 | __constraints.append((value, __a)) 213 | break 214 | 215 | for __arg in __args: 216 | if __position is None: 217 | __position = __arg 218 | else: 219 | __position += " "+ __arg 220 | 221 | if __noformat is True or __ipix is not None or __offset is not None or __noheader: 222 | if __sort is True : 223 | raise Exception("--sort function is not compatible with --ipix/--no-format") 224 | if __filename is not None: 225 | raise Exception("--file option is not compatible with --ipix/--no-format") 226 | 227 | if len(__constraints)>0: 228 | raise Exception("Constraints "+str(__constraints)+" is not available in this mode (--ipix/--offset/--no-format)") 229 | 230 | __querycat = QueryCatClient() 231 | if __ipix is not None: 232 | __querycat.set_healpix(__ipix) 233 | __querycat.noformat=__noformat 234 | __querycat.noheader=__noheader 235 | 236 | if __offset : 237 | s = __offset.split("..") 238 | if len(s) != 2: raise Exception("error offset syntax: min..max") 239 | try: 240 | __querycat.set_offset(int(s[0]), int(s[1])) 241 | except: 242 | raise Exception("error offset syntax: begin..nb_records") 243 | 244 | if __mime is None or __mime == vizquery.FORMAT_ASCII: 245 | __mime = vizquery.FORMAT_TSV 246 | 247 | else: 248 | __querycat = QueryCatVizieR() 249 | 250 | __querycat.position = __position 251 | __querycat.radius = __radius 252 | 253 | if __mime in (vizquery.FORMAT_TSV, vizquery.FORMAT_VOTABLE, vizquery.FORMAT_ASCII): 254 | __querycat.format = __mime 255 | else: 256 | raise Exception("format not yet available") 257 | 258 | __querycat.query_cat(constraints=__constraints, all=__all, limit=__limit, columns=__add, filename=__filename) 259 | __querycat.print_stdout() 260 | 261 | -------------------------------------------------------------------------------- /cdsclient/find_cmc14.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """G.Landais (CDS) 24-mar-2018 3 | Query I/304/out 4 | 5 | find_cmc14.py [-h] [-a] [-r radius] [-m max] [constraints] [--format=tsv|votable|ascii] [position] 6 | 7 | -a: display all columns 8 | -r: radius in arcsec 9 | -m: max number of lines in output 10 | -h: this help 11 | --format: output (--format=tsv|votable|ascii) 12 | --noheader: remove header (not available for all options) 13 | --sort : sort by distance (available with position only) 14 | --add : column name in output 15 | --file : query with a list 16 | 17 | position : ra dec position or target name 18 | example: find_cmc14.py M1 19 | 20 | Other constraints: 21 | --sort : ... 22 | --add= : ... 23 | --file= : ... 24 | --noheader : ... 25 | --CMC14= : ... 26 | --Jmag= : ... 27 | --Hmag= : ... 28 | --Ksmag= : ... 29 | 30 | 31 | Example: --CMC14=">10" 32 | 33 | Licensed under a BSD license - see LICENSE.txt for details 34 | 35 | """ 36 | 37 | import os, sys 38 | import getopt 39 | import cdsclient.vizquery as vizquery 40 | #import vizquery 41 | 42 | if int(sys.version[0])<3: 43 | from urllib2 import quote 44 | else: 45 | from urllib.parse import quote 46 | 47 | NO_FORMAT = "noformat" 48 | DEBUG = False 49 | 50 | class QueryCat(): 51 | def __init__(self): 52 | self.position = None 53 | self.radius = vizquery.DEFAULT_RADIUS 54 | self.format = None 55 | 56 | def query_cat(self, constraints=None, all = False, limit=vizquery.DEFAULT_LIMIT): 57 | """init constraints parameters 58 | :param constraints: list of constraints ((name,value), ...) 59 | :param all: display all columns(efault False) 60 | :param limit: max number of records 61 | """ 62 | pass 63 | 64 | def get(self): 65 | """get astropy table""" 66 | pass 67 | 68 | def print_stdout(self): 69 | """print the result on stdout""" 70 | pass 71 | 72 | 73 | class QueryCatVizieR(QueryCat): 74 | def __init__(self): 75 | QueryCat.__init__(self) 76 | self.__client = vizquery.CDSClient(default_format=vizquery.FORMAT_ASCII) 77 | self.limit = vizquery.DEFAULT_LIMIT 78 | 79 | def query_cat(self, constraints=None, all=False, limit=vizquery.DEFAULT_LIMIT, columns=None, filename=None): 80 | params = [] 81 | 82 | if self.position: 83 | params.append("-c={0}".format(quote(self.position))) 84 | 85 | if self.radius: 86 | params.append("-c.rs={0:f}".format(self.radius)) 87 | 88 | if all is True: 89 | params.append("-out.all=1") 90 | 91 | if limit is not None: 92 | params.append("-out.max={0:d}".format(limit)) 93 | else: 94 | params.append("-out.max={0:d}".format(self.limit)) 95 | 96 | if columns is not None: 97 | for column in columns: params.append("-out={0}".format(column)) 98 | 99 | file_col = None 100 | if constraints is not None: 101 | for constraint in constraints: 102 | if constraint[1] == "" or constraint[1] == "-": 103 | file_col = constraint[0] 104 | params.append("{0}={1}".format(constraint[0], constraint[1].replace("+","%2B"))) 105 | 106 | if filename is not None: 107 | #params.append("-out.form=hori") 108 | #params.append("-out.add=_1") 109 | 110 | if file_col is not None: 111 | params.append("-sort={0}".format(file_col)) 112 | else: 113 | params.append("-out.add=_r") 114 | params.append("-sort=_r") 115 | 116 | self.__client.query("I/304/out", params=params, filename=filename) 117 | 118 | if self.format is not None: 119 | self.__client.format = self.format 120 | 121 | def get(self): 122 | return self.__client.get() 123 | 124 | def print_stdout(self): 125 | return self.__client.print_stdout() 126 | 127 | 128 | 129 | 130 | if __name__ == "__main__": 131 | 132 | __radius = vizquery.DEFAULT_RADIUS 133 | __position = None 134 | __limit = None 135 | __mime = vizquery.FORMAT_ASCII 136 | __noformat = False 137 | __noheader = False 138 | __ipix = None 139 | __all = False 140 | __sort = False 141 | __add = None 142 | __filename = None 143 | __constraints = [] 144 | __offset = None 145 | 146 | __options = ('help','format=','sort','add=','file=','noheader','CMC14=','Jmag=','Hmag=','Ksmag=') 147 | try : 148 | __opts, __args = getopt.getopt(sys.argv[1:], 'hvar:m:f:', __options) 149 | except: 150 | help("__main__") 151 | sys.exit(1) 152 | 153 | for __o, __a in __opts: 154 | if __o == '-v': 155 | DEBUG = True 156 | continue 157 | 158 | if __o in ("-h", "--help"): 159 | help("__main__") 160 | sys.exit(1) 161 | 162 | elif __o == "-r": 163 | try: 164 | __radius = float(__a) 165 | except: 166 | sys.stderr.write("(error) wrong radius format\n") 167 | 168 | elif __o == "-m": 169 | try: 170 | __limit = int(__a) 171 | except: 172 | raise Exception("(error) wrong limit/max format") 173 | 174 | elif __o == "-a": 175 | __all = True 176 | 177 | elif __o == "--format": 178 | __mime = __a 179 | 180 | elif __o == "--no-format": 181 | __noformat = True 182 | 183 | elif __o == "--noheader": 184 | __noheader = True 185 | 186 | elif __o == "--ipix": 187 | __ipix = __a 188 | 189 | elif __o == "--count": 190 | __count = True 191 | 192 | elif __o == "--sort": 193 | __sort = True 194 | __constraints.append(("-out.add", "_r")) 195 | __constraints.append(("-sort", "_r")) 196 | 197 | elif __o == "--add": 198 | if __add is None: __add = [] 199 | __add.append(__a) 200 | 201 | elif __o == "--offset": 202 | __offset = __a 203 | continue 204 | 205 | if __o in ("-f", "--file"): 206 | __filename = __a 207 | 208 | else: 209 | for opt in __options[2:]: 210 | value = opt[:len(opt)-1] 211 | if __o[2:] == value: 212 | __constraints.append((value, __a)) 213 | break 214 | 215 | for __arg in __args: 216 | if __position is None: 217 | __position = __arg 218 | else: 219 | __position += " "+ __arg 220 | 221 | if __noformat is True or __ipix is not None or __offset is not None or __noheader: 222 | if __sort is True : 223 | raise Exception("--sort function is not compatible with --ipix/--no-format") 224 | if __filename is not None: 225 | raise Exception("--file option is not compatible with --ipix/--no-format") 226 | 227 | if len(__constraints)>0: 228 | raise Exception("Constraints "+str(__constraints)+" is not available in this mode (--ipix/--offset/--no-format)") 229 | 230 | __querycat = QueryCatClient() 231 | if __ipix is not None: 232 | __querycat.set_healpix(__ipix) 233 | __querycat.noformat=__noformat 234 | __querycat.noheader=__noheader 235 | 236 | if __offset : 237 | s = __offset.split("..") 238 | if len(s) != 2: raise Exception("error offset syntax: min..max") 239 | try: 240 | __querycat.set_offset(int(s[0]), int(s[1])) 241 | except: 242 | raise Exception("error offset syntax: begin..nb_records") 243 | 244 | if __mime is None or __mime == vizquery.FORMAT_ASCII: 245 | __mime = vizquery.FORMAT_TSV 246 | 247 | else: 248 | __querycat = QueryCatVizieR() 249 | 250 | __querycat.position = __position 251 | __querycat.radius = __radius 252 | 253 | if __mime in (vizquery.FORMAT_TSV, vizquery.FORMAT_VOTABLE, vizquery.FORMAT_ASCII): 254 | __querycat.format = __mime 255 | else: 256 | raise Exception("format not yet available") 257 | 258 | __querycat.query_cat(constraints=__constraints, all=__all, limit=__limit, columns=__add, filename=__filename) 259 | __querycat.print_stdout() 260 | 261 | -------------------------------------------------------------------------------- /cdsclient/find_gsc1_2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """G.Landais (CDS) 24-mar-2018 3 | Query I/254/out 4 | 5 | find_gsc1_2.py [-h] [-a] [-r radius] [-m max] [constraints] [--format=tsv|votable|ascii] [position] 6 | 7 | -a: display all columns 8 | -r: radius in arcsec 9 | -m: max number of lines in output 10 | -h: this help 11 | --format: output (--format=tsv|votable|ascii) 12 | --noheader: remove header (not available for all options) 13 | --sort : sort by distance (available with position only) 14 | --add : column name in output 15 | --file : query with a list 16 | 17 | position : ra dec position or target name 18 | example: find_gsc1_2.py M1 19 | 20 | Other constraints: 21 | --sort : ... 22 | --add= : ... 23 | --file= : ... 24 | --noheader : ... 25 | --GSC= : ... 26 | --RAJ2000= : ... 27 | --DEJ2000= : ... 28 | --Pmag= : ... 29 | 30 | 31 | Example: --GSC=">10" 32 | 33 | Licensed under a BSD license - see LICENSE.txt for details 34 | 35 | """ 36 | 37 | import os, sys 38 | import getopt 39 | import cdsclient.vizquery as vizquery 40 | #import vizquery 41 | 42 | if int(sys.version[0])<3: 43 | from urllib2 import quote 44 | else: 45 | from urllib.parse import quote 46 | 47 | NO_FORMAT = "noformat" 48 | DEBUG = False 49 | 50 | class QueryCat(): 51 | def __init__(self): 52 | self.position = None 53 | self.radius = vizquery.DEFAULT_RADIUS 54 | self.format = None 55 | 56 | def query_cat(self, constraints=None, all = False, limit=vizquery.DEFAULT_LIMIT): 57 | """init constraints parameters 58 | :param constraints: list of constraints ((name,value), ...) 59 | :param all: display all columns(efault False) 60 | :param limit: max number of records 61 | """ 62 | pass 63 | 64 | def get(self): 65 | """get astropy table""" 66 | pass 67 | 68 | def print_stdout(self): 69 | """print the result on stdout""" 70 | pass 71 | 72 | 73 | class QueryCatVizieR(QueryCat): 74 | def __init__(self): 75 | QueryCat.__init__(self) 76 | self.__client = vizquery.CDSClient(default_format=vizquery.FORMAT_ASCII) 77 | self.limit = vizquery.DEFAULT_LIMIT 78 | 79 | def query_cat(self, constraints=None, all=False, limit=vizquery.DEFAULT_LIMIT, columns=None, filename=None): 80 | params = [] 81 | 82 | if self.position: 83 | params.append("-c={0}".format(quote(self.position))) 84 | 85 | if self.radius: 86 | params.append("-c.rs={0:f}".format(self.radius)) 87 | 88 | if all is True: 89 | params.append("-out.all=1") 90 | 91 | if limit is not None: 92 | params.append("-out.max={0:d}".format(limit)) 93 | else: 94 | params.append("-out.max={0:d}".format(self.limit)) 95 | 96 | if columns is not None: 97 | for column in columns: params.append("-out={0}".format(column)) 98 | 99 | file_col = None 100 | if constraints is not None: 101 | for constraint in constraints: 102 | if constraint[1] == "" or constraint[1] == "-": 103 | file_col = constraint[0] 104 | params.append("{0}={1}".format(constraint[0], constraint[1].replace("+","%2B"))) 105 | 106 | if filename is not None: 107 | #params.append("-out.form=hori") 108 | #params.append("-out.add=_1") 109 | 110 | if file_col is not None: 111 | params.append("-sort={0}".format(file_col)) 112 | else: 113 | params.append("-out.add=_r") 114 | params.append("-sort=_r") 115 | 116 | self.__client.query("I/254/out", params=params, filename=filename) 117 | 118 | if self.format is not None: 119 | self.__client.format = self.format 120 | 121 | def get(self): 122 | return self.__client.get() 123 | 124 | def print_stdout(self): 125 | return self.__client.print_stdout() 126 | 127 | 128 | 129 | 130 | if __name__ == "__main__": 131 | 132 | __radius = vizquery.DEFAULT_RADIUS 133 | __position = None 134 | __limit = None 135 | __mime = vizquery.FORMAT_ASCII 136 | __noformat = False 137 | __noheader = False 138 | __ipix = None 139 | __all = False 140 | __sort = False 141 | __add = None 142 | __filename = None 143 | __constraints = [] 144 | __offset = None 145 | 146 | __options = ('help','format=','sort','add=','file=','noheader','GSC=','RAJ2000=','DEJ2000=','Pmag=') 147 | try : 148 | __opts, __args = getopt.getopt(sys.argv[1:], 'hvar:m:f:', __options) 149 | except: 150 | help("__main__") 151 | sys.exit(1) 152 | 153 | for __o, __a in __opts: 154 | if __o == '-v': 155 | DEBUG = True 156 | continue 157 | 158 | if __o in ("-h", "--help"): 159 | help("__main__") 160 | sys.exit(1) 161 | 162 | elif __o == "-r": 163 | try: 164 | __radius = float(__a) 165 | except: 166 | sys.stderr.write("(error) wrong radius format\n") 167 | 168 | elif __o == "-m": 169 | try: 170 | __limit = int(__a) 171 | except: 172 | raise Exception("(error) wrong limit/max format") 173 | 174 | elif __o == "-a": 175 | __all = True 176 | 177 | elif __o == "--format": 178 | __mime = __a 179 | 180 | elif __o == "--no-format": 181 | __noformat = True 182 | 183 | elif __o == "--noheader": 184 | __noheader = True 185 | 186 | elif __o == "--ipix": 187 | __ipix = __a 188 | 189 | elif __o == "--count": 190 | __count = True 191 | 192 | elif __o == "--sort": 193 | __sort = True 194 | __constraints.append(("-out.add", "_r")) 195 | __constraints.append(("-sort", "_r")) 196 | 197 | elif __o == "--add": 198 | if __add is None: __add = [] 199 | __add.append(__a) 200 | 201 | elif __o == "--offset": 202 | __offset = __a 203 | continue 204 | 205 | if __o in ("-f", "--file"): 206 | __filename = __a 207 | 208 | else: 209 | for opt in __options[2:]: 210 | value = opt[:len(opt)-1] 211 | if __o[2:] == value: 212 | __constraints.append((value, __a)) 213 | break 214 | 215 | for __arg in __args: 216 | if __position is None: 217 | __position = __arg 218 | else: 219 | __position += " "+ __arg 220 | 221 | if __noformat is True or __ipix is not None or __offset is not None or __noheader: 222 | if __sort is True : 223 | raise Exception("--sort function is not compatible with --ipix/--no-format") 224 | if __filename is not None: 225 | raise Exception("--file option is not compatible with --ipix/--no-format") 226 | 227 | if len(__constraints)>0: 228 | raise Exception("Constraints "+str(__constraints)+" is not available in this mode (--ipix/--offset/--no-format)") 229 | 230 | __querycat = QueryCatClient() 231 | if __ipix is not None: 232 | __querycat.set_healpix(__ipix) 233 | __querycat.noformat=__noformat 234 | __querycat.noheader=__noheader 235 | 236 | if __offset : 237 | s = __offset.split("..") 238 | if len(s) != 2: raise Exception("error offset syntax: min..max") 239 | try: 240 | __querycat.set_offset(int(s[0]), int(s[1])) 241 | except: 242 | raise Exception("error offset syntax: begin..nb_records") 243 | 244 | if __mime is None or __mime == vizquery.FORMAT_ASCII: 245 | __mime = vizquery.FORMAT_TSV 246 | 247 | else: 248 | __querycat = QueryCatVizieR() 249 | 250 | __querycat.position = __position 251 | __querycat.radius = __radius 252 | 253 | if __mime in (vizquery.FORMAT_TSV, vizquery.FORMAT_VOTABLE, vizquery.FORMAT_ASCII): 254 | __querycat.format = __mime 255 | else: 256 | raise Exception("format not yet available") 257 | 258 | __querycat.query_cat(constraints=__constraints, all=__all, limit=__limit, columns=__add, filename=__filename) 259 | __querycat.print_stdout() 260 | 261 | -------------------------------------------------------------------------------- /cdsclient/find_gsc1_3.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """G.Landais (CDS) 24-mar-2018 3 | Query I/255/out 4 | 5 | find_gsc1_3.py [-h] [-a] [-r radius] [-m max] [constraints] [--format=tsv|votable|ascii] [position] 6 | 7 | -a: display all columns 8 | -r: radius in arcsec 9 | -m: max number of lines in output 10 | -h: this help 11 | --format: output (--format=tsv|votable|ascii) 12 | --noheader: remove header (not available for all options) 13 | --sort : sort by distance (available with position only) 14 | --add : column name in output 15 | --file : query with a list 16 | 17 | position : ra dec position or target name 18 | example: find_gsc1_3.py M1 19 | 20 | Other constraints: 21 | --sort : ... 22 | --add= : ... 23 | --file= : ... 24 | --noheader : ... 25 | --GSC= : ... 26 | --RAJ2000= : ... 27 | --DEJ2000= : ... 28 | --Pmag= : ... 29 | 30 | 31 | Example: --GSC=">10" 32 | 33 | Licensed under a BSD license - see LICENSE.txt for details 34 | 35 | """ 36 | 37 | import os, sys 38 | import getopt 39 | import cdsclient.vizquery as vizquery 40 | #import vizquery 41 | 42 | if int(sys.version[0])<3: 43 | from urllib2 import quote 44 | else: 45 | from urllib.parse import quote 46 | 47 | NO_FORMAT = "noformat" 48 | DEBUG = False 49 | 50 | class QueryCat(): 51 | def __init__(self): 52 | self.position = None 53 | self.radius = vizquery.DEFAULT_RADIUS 54 | self.format = None 55 | 56 | def query_cat(self, constraints=None, all = False, limit=vizquery.DEFAULT_LIMIT): 57 | """init constraints parameters 58 | :param constraints: list of constraints ((name,value), ...) 59 | :param all: display all columns(efault False) 60 | :param limit: max number of records 61 | """ 62 | pass 63 | 64 | def get(self): 65 | """get astropy table""" 66 | pass 67 | 68 | def print_stdout(self): 69 | """print the result on stdout""" 70 | pass 71 | 72 | 73 | class QueryCatVizieR(QueryCat): 74 | def __init__(self): 75 | QueryCat.__init__(self) 76 | self.__client = vizquery.CDSClient(default_format=vizquery.FORMAT_ASCII) 77 | self.limit = vizquery.DEFAULT_LIMIT 78 | 79 | def query_cat(self, constraints=None, all=False, limit=vizquery.DEFAULT_LIMIT, columns=None, filename=None): 80 | params = [] 81 | 82 | if self.position: 83 | params.append("-c={0}".format(quote(self.position))) 84 | 85 | if self.radius: 86 | params.append("-c.rs={0:f}".format(self.radius)) 87 | 88 | if all is True: 89 | params.append("-out.all=1") 90 | 91 | if limit is not None: 92 | params.append("-out.max={0:d}".format(limit)) 93 | else: 94 | params.append("-out.max={0:d}".format(self.limit)) 95 | 96 | if columns is not None: 97 | for column in columns: params.append("-out={0}".format(column)) 98 | 99 | file_col = None 100 | if constraints is not None: 101 | for constraint in constraints: 102 | if constraint[1] == "" or constraint[1] == "-": 103 | file_col = constraint[0] 104 | params.append("{0}={1}".format(constraint[0], constraint[1].replace("+","%2B"))) 105 | 106 | if filename is not None: 107 | #params.append("-out.form=hori") 108 | #params.append("-out.add=_1") 109 | 110 | if file_col is not None: 111 | params.append("-sort={0}".format(file_col)) 112 | else: 113 | params.append("-out.add=_r") 114 | params.append("-sort=_r") 115 | 116 | self.__client.query("I/255/out", params=params, filename=filename) 117 | 118 | if self.format is not None: 119 | self.__client.format = self.format 120 | 121 | def get(self): 122 | return self.__client.get() 123 | 124 | def print_stdout(self): 125 | return self.__client.print_stdout() 126 | 127 | 128 | 129 | 130 | if __name__ == "__main__": 131 | 132 | __radius = vizquery.DEFAULT_RADIUS 133 | __position = None 134 | __limit = None 135 | __mime = vizquery.FORMAT_ASCII 136 | __noformat = False 137 | __noheader = False 138 | __ipix = None 139 | __all = False 140 | __sort = False 141 | __add = None 142 | __filename = None 143 | __constraints = [] 144 | __offset = None 145 | 146 | __options = ('help','format=','sort','add=','file=','noheader','GSC=','RAJ2000=','DEJ2000=','Pmag=') 147 | try : 148 | __opts, __args = getopt.getopt(sys.argv[1:], 'hvar:m:f:', __options) 149 | except: 150 | help("__main__") 151 | sys.exit(1) 152 | 153 | for __o, __a in __opts: 154 | if __o == '-v': 155 | DEBUG = True 156 | continue 157 | 158 | if __o in ("-h", "--help"): 159 | help("__main__") 160 | sys.exit(1) 161 | 162 | elif __o == "-r": 163 | try: 164 | __radius = float(__a) 165 | except: 166 | sys.stderr.write("(error) wrong radius format\n") 167 | 168 | elif __o == "-m": 169 | try: 170 | __limit = int(__a) 171 | except: 172 | raise Exception("(error) wrong limit/max format") 173 | 174 | elif __o == "-a": 175 | __all = True 176 | 177 | elif __o == "--format": 178 | __mime = __a 179 | 180 | elif __o == "--no-format": 181 | __noformat = True 182 | 183 | elif __o == "--noheader": 184 | __noheader = True 185 | 186 | elif __o == "--ipix": 187 | __ipix = __a 188 | 189 | elif __o == "--count": 190 | __count = True 191 | 192 | elif __o == "--sort": 193 | __sort = True 194 | __constraints.append(("-out.add", "_r")) 195 | __constraints.append(("-sort", "_r")) 196 | 197 | elif __o == "--add": 198 | if __add is None: __add = [] 199 | __add.append(__a) 200 | 201 | elif __o == "--offset": 202 | __offset = __a 203 | continue 204 | 205 | if __o in ("-f", "--file"): 206 | __filename = __a 207 | 208 | else: 209 | for opt in __options[2:]: 210 | value = opt[:len(opt)-1] 211 | if __o[2:] == value: 212 | __constraints.append((value, __a)) 213 | break 214 | 215 | for __arg in __args: 216 | if __position is None: 217 | __position = __arg 218 | else: 219 | __position += " "+ __arg 220 | 221 | if __noformat is True or __ipix is not None or __offset is not None or __noheader: 222 | if __sort is True : 223 | raise Exception("--sort function is not compatible with --ipix/--no-format") 224 | if __filename is not None: 225 | raise Exception("--file option is not compatible with --ipix/--no-format") 226 | 227 | if len(__constraints)>0: 228 | raise Exception("Constraints "+str(__constraints)+" is not available in this mode (--ipix/--offset/--no-format)") 229 | 230 | __querycat = QueryCatClient() 231 | if __ipix is not None: 232 | __querycat.set_healpix(__ipix) 233 | __querycat.noformat=__noformat 234 | __querycat.noheader=__noheader 235 | 236 | if __offset : 237 | s = __offset.split("..") 238 | if len(s) != 2: raise Exception("error offset syntax: min..max") 239 | try: 240 | __querycat.set_offset(int(s[0]), int(s[1])) 241 | except: 242 | raise Exception("error offset syntax: begin..nb_records") 243 | 244 | if __mime is None or __mime == vizquery.FORMAT_ASCII: 245 | __mime = vizquery.FORMAT_TSV 246 | 247 | else: 248 | __querycat = QueryCatVizieR() 249 | 250 | __querycat.position = __position 251 | __querycat.radius = __radius 252 | 253 | if __mime in (vizquery.FORMAT_TSV, vizquery.FORMAT_VOTABLE, vizquery.FORMAT_ASCII): 254 | __querycat.format = __mime 255 | else: 256 | raise Exception("format not yet available") 257 | 258 | __querycat.query_cat(constraints=__constraints, all=__all, limit=__limit, columns=__add, filename=__filename) 259 | __querycat.print_stdout() 260 | 261 | -------------------------------------------------------------------------------- /cdsclient/find_apm.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """G.Landais (CDS) 24-mar-2018 3 | Query I/267/out 4 | 5 | find_apm.py [-h] [-a] [-r radius] [-m max] [constraints] [--format=tsv|votable|ascii] [position] 6 | 7 | -a: display all columns 8 | -r: radius in arcsec 9 | -m: max number of lines in output 10 | -h: this help 11 | --format: output (--format=tsv|votable|ascii) 12 | --noheader: remove header (not available for all options) 13 | --sort : sort by distance (available with position only) 14 | --add : column name in output 15 | --file : query with a list 16 | 17 | position : ra dec position or target name 18 | example: find_apm.py M1 19 | 20 | Other constraints: 21 | --sort : ... 22 | --add= : ... 23 | --file= : ... 24 | --noheader : ... 25 | --APM-ID= : ... 26 | --RAJ2000= : ... 27 | --DEJ2000= : ... 28 | --rmag= : ... 29 | --bmag= : ... 30 | 31 | 32 | Example: --APM-ID=">10" 33 | 34 | Licensed under a BSD license - see LICENSE.txt for details 35 | 36 | """ 37 | 38 | import os, sys 39 | import getopt 40 | import cdsclient.vizquery as vizquery 41 | #import vizquery 42 | 43 | if int(sys.version[0])<3: 44 | from urllib2 import quote 45 | else: 46 | from urllib.parse import quote 47 | 48 | NO_FORMAT = "noformat" 49 | DEBUG = False 50 | 51 | class QueryCat(): 52 | def __init__(self): 53 | self.position = None 54 | self.radius = vizquery.DEFAULT_RADIUS 55 | self.format = None 56 | 57 | def query_cat(self, constraints=None, all = False, limit=vizquery.DEFAULT_LIMIT): 58 | """init constraints parameters 59 | :param constraints: list of constraints ((name,value), ...) 60 | :param all: display all columns(efault False) 61 | :param limit: max number of records 62 | """ 63 | pass 64 | 65 | def get(self): 66 | """get astropy table""" 67 | pass 68 | 69 | def print_stdout(self): 70 | """print the result on stdout""" 71 | pass 72 | 73 | 74 | class QueryCatVizieR(QueryCat): 75 | def __init__(self): 76 | QueryCat.__init__(self) 77 | self.__client = vizquery.CDSClient(default_format=vizquery.FORMAT_ASCII) 78 | self.limit = vizquery.DEFAULT_LIMIT 79 | 80 | def query_cat(self, constraints=None, all=False, limit=vizquery.DEFAULT_LIMIT, columns=None, filename=None): 81 | params = [] 82 | 83 | if self.position: 84 | params.append("-c={0}".format(quote(self.position))) 85 | 86 | if self.radius: 87 | params.append("-c.rs={0:f}".format(self.radius)) 88 | 89 | if all is True: 90 | params.append("-out.all=1") 91 | 92 | if limit is not None: 93 | params.append("-out.max={0:d}".format(limit)) 94 | else: 95 | params.append("-out.max={0:d}".format(self.limit)) 96 | 97 | if columns is not None: 98 | for column in columns: params.append("-out={0}".format(column)) 99 | 100 | file_col = None 101 | if constraints is not None: 102 | for constraint in constraints: 103 | if constraint[1] == "" or constraint[1] == "-": 104 | file_col = constraint[0] 105 | params.append("{0}={1}".format(constraint[0], constraint[1].replace("+","%2B"))) 106 | 107 | if filename is not None: 108 | #params.append("-out.form=hori") 109 | #params.append("-out.add=_1") 110 | 111 | if file_col is not None: 112 | params.append("-sort={0}".format(file_col)) 113 | else: 114 | params.append("-out.add=_r") 115 | params.append("-sort=_r") 116 | 117 | self.__client.query("I/267/out", params=params, filename=filename) 118 | 119 | if self.format is not None: 120 | self.__client.format = self.format 121 | 122 | def get(self): 123 | return self.__client.get() 124 | 125 | def print_stdout(self): 126 | return self.__client.print_stdout() 127 | 128 | 129 | 130 | 131 | if __name__ == "__main__": 132 | 133 | __radius = vizquery.DEFAULT_RADIUS 134 | __position = None 135 | __limit = None 136 | __mime = vizquery.FORMAT_ASCII 137 | __noformat = False 138 | __noheader = False 139 | __ipix = None 140 | __all = False 141 | __sort = False 142 | __add = None 143 | __filename = None 144 | __constraints = [] 145 | __offset = None 146 | 147 | __options = ('help','format=','sort','add=','file=','noheader','APM-ID=','RAJ2000=','DEJ2000=','rmag=','bmag=') 148 | try : 149 | __opts, __args = getopt.getopt(sys.argv[1:], 'hvar:m:f:', __options) 150 | except: 151 | help("__main__") 152 | sys.exit(1) 153 | 154 | for __o, __a in __opts: 155 | if __o == '-v': 156 | DEBUG = True 157 | continue 158 | 159 | if __o in ("-h", "--help"): 160 | help("__main__") 161 | sys.exit(1) 162 | 163 | elif __o == "-r": 164 | try: 165 | __radius = float(__a) 166 | except: 167 | sys.stderr.write("(error) wrong radius format\n") 168 | 169 | elif __o == "-m": 170 | try: 171 | __limit = int(__a) 172 | except: 173 | raise Exception("(error) wrong limit/max format") 174 | 175 | elif __o == "-a": 176 | __all = True 177 | 178 | elif __o == "--format": 179 | __mime = __a 180 | 181 | elif __o == "--no-format": 182 | __noformat = True 183 | 184 | elif __o == "--noheader": 185 | __noheader = True 186 | 187 | elif __o == "--ipix": 188 | __ipix = __a 189 | 190 | elif __o == "--count": 191 | __count = True 192 | 193 | elif __o == "--sort": 194 | __sort = True 195 | __constraints.append(("-out.add", "_r")) 196 | __constraints.append(("-sort", "_r")) 197 | 198 | elif __o == "--add": 199 | if __add is None: __add = [] 200 | __add.append(__a) 201 | 202 | elif __o == "--offset": 203 | __offset = __a 204 | continue 205 | 206 | if __o in ("-f", "--file"): 207 | __filename = __a 208 | 209 | else: 210 | for opt in __options[2:]: 211 | value = opt[:len(opt)-1] 212 | if __o[2:] == value: 213 | __constraints.append((value, __a)) 214 | break 215 | 216 | for __arg in __args: 217 | if __position is None: 218 | __position = __arg 219 | else: 220 | __position += " "+ __arg 221 | 222 | if __noformat is True or __ipix is not None or __offset is not None or __noheader: 223 | if __sort is True : 224 | raise Exception("--sort function is not compatible with --ipix/--no-format") 225 | if __filename is not None: 226 | raise Exception("--file option is not compatible with --ipix/--no-format") 227 | 228 | if len(__constraints)>0: 229 | raise Exception("Constraints "+str(__constraints)+" is not available in this mode (--ipix/--offset/--no-format)") 230 | 231 | __querycat = QueryCatClient() 232 | if __ipix is not None: 233 | __querycat.set_healpix(__ipix) 234 | __querycat.noformat=__noformat 235 | __querycat.noheader=__noheader 236 | 237 | if __offset : 238 | s = __offset.split("..") 239 | if len(s) != 2: raise Exception("error offset syntax: min..max") 240 | try: 241 | __querycat.set_offset(int(s[0]), int(s[1])) 242 | except: 243 | raise Exception("error offset syntax: begin..nb_records") 244 | 245 | if __mime is None or __mime == vizquery.FORMAT_ASCII: 246 | __mime = vizquery.FORMAT_TSV 247 | 248 | else: 249 | __querycat = QueryCatVizieR() 250 | 251 | __querycat.position = __position 252 | __querycat.radius = __radius 253 | 254 | if __mime in (vizquery.FORMAT_TSV, vizquery.FORMAT_VOTABLE, vizquery.FORMAT_ASCII): 255 | __querycat.format = __mime 256 | else: 257 | raise Exception("format not yet available") 258 | 259 | __querycat.query_cat(constraints=__constraints, all=__all, limit=__limit, columns=__add, filename=__filename) 260 | __querycat.print_stdout() 261 | 262 | -------------------------------------------------------------------------------- /cdsclient/find_ucac3.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """G.Landais (CDS) 24-mar-2018 3 | Query I/315/out 4 | 5 | find_ucac3.py [-h] [-a] [-r radius] [-m max] [constraints] [--format=tsv|votable|ascii] [position] 6 | 7 | -a: display all columns 8 | -r: radius in arcsec 9 | -m: max number of lines in output 10 | -h: this help 11 | --format: output (--format=tsv|votable|ascii) 12 | --noheader: remove header (not available for all options) 13 | --sort : sort by distance (available with position only) 14 | --add : column name in output 15 | --file : query with a list 16 | 17 | position : ra dec position or target name 18 | example: find_ucac3.py M1 19 | 20 | Other constraints: 21 | --sort : ... 22 | --add= : ... 23 | --file= : ... 24 | --noheader : ... 25 | --3UC= : ... 26 | --RAJ2000= : ... 27 | --DEJ2000= : ... 28 | --Jmag= : ... 29 | --Kmag= : ... 30 | 31 | 32 | Example: --3UC=">10" 33 | 34 | Licensed under a BSD license - see LICENSE.txt for details 35 | 36 | """ 37 | 38 | import os, sys 39 | import getopt 40 | import cdsclient.vizquery as vizquery 41 | #import vizquery 42 | 43 | if int(sys.version[0])<3: 44 | from urllib2 import quote 45 | else: 46 | from urllib.parse import quote 47 | 48 | NO_FORMAT = "noformat" 49 | DEBUG = False 50 | 51 | class QueryCat(): 52 | def __init__(self): 53 | self.position = None 54 | self.radius = vizquery.DEFAULT_RADIUS 55 | self.format = None 56 | 57 | def query_cat(self, constraints=None, all = False, limit=vizquery.DEFAULT_LIMIT): 58 | """init constraints parameters 59 | :param constraints: list of constraints ((name,value), ...) 60 | :param all: display all columns(efault False) 61 | :param limit: max number of records 62 | """ 63 | pass 64 | 65 | def get(self): 66 | """get astropy table""" 67 | pass 68 | 69 | def print_stdout(self): 70 | """print the result on stdout""" 71 | pass 72 | 73 | 74 | class QueryCatVizieR(QueryCat): 75 | def __init__(self): 76 | QueryCat.__init__(self) 77 | self.__client = vizquery.CDSClient(default_format=vizquery.FORMAT_ASCII) 78 | self.limit = vizquery.DEFAULT_LIMIT 79 | 80 | def query_cat(self, constraints=None, all=False, limit=vizquery.DEFAULT_LIMIT, columns=None, filename=None): 81 | params = [] 82 | 83 | if self.position: 84 | params.append("-c={0}".format(quote(self.position))) 85 | 86 | if self.radius: 87 | params.append("-c.rs={0:f}".format(self.radius)) 88 | 89 | if all is True: 90 | params.append("-out.all=1") 91 | 92 | if limit is not None: 93 | params.append("-out.max={0:d}".format(limit)) 94 | else: 95 | params.append("-out.max={0:d}".format(self.limit)) 96 | 97 | if columns is not None: 98 | for column in columns: params.append("-out={0}".format(column)) 99 | 100 | file_col = None 101 | if constraints is not None: 102 | for constraint in constraints: 103 | if constraint[1] == "" or constraint[1] == "-": 104 | file_col = constraint[0] 105 | params.append("{0}={1}".format(constraint[0], constraint[1].replace("+","%2B"))) 106 | 107 | if filename is not None: 108 | #params.append("-out.form=hori") 109 | #params.append("-out.add=_1") 110 | 111 | if file_col is not None: 112 | params.append("-sort={0}".format(file_col)) 113 | else: 114 | params.append("-out.add=_r") 115 | params.append("-sort=_r") 116 | 117 | self.__client.query("I/315/out", params=params, filename=filename) 118 | 119 | if self.format is not None: 120 | self.__client.format = self.format 121 | 122 | def get(self): 123 | return self.__client.get() 124 | 125 | def print_stdout(self): 126 | return self.__client.print_stdout() 127 | 128 | 129 | 130 | 131 | if __name__ == "__main__": 132 | 133 | __radius = vizquery.DEFAULT_RADIUS 134 | __position = None 135 | __limit = None 136 | __mime = vizquery.FORMAT_ASCII 137 | __noformat = False 138 | __noheader = False 139 | __ipix = None 140 | __all = False 141 | __sort = False 142 | __add = None 143 | __filename = None 144 | __constraints = [] 145 | __offset = None 146 | 147 | __options = ('help','format=','sort','add=','file=','noheader','3UC=','RAJ2000=','DEJ2000=','Jmag=','Kmag=') 148 | try : 149 | __opts, __args = getopt.getopt(sys.argv[1:], 'hvar:m:f:', __options) 150 | except: 151 | help("__main__") 152 | sys.exit(1) 153 | 154 | for __o, __a in __opts: 155 | if __o == '-v': 156 | DEBUG = True 157 | continue 158 | 159 | if __o in ("-h", "--help"): 160 | help("__main__") 161 | sys.exit(1) 162 | 163 | elif __o == "-r": 164 | try: 165 | __radius = float(__a) 166 | except: 167 | sys.stderr.write("(error) wrong radius format\n") 168 | 169 | elif __o == "-m": 170 | try: 171 | __limit = int(__a) 172 | except: 173 | raise Exception("(error) wrong limit/max format") 174 | 175 | elif __o == "-a": 176 | __all = True 177 | 178 | elif __o == "--format": 179 | __mime = __a 180 | 181 | elif __o == "--no-format": 182 | __noformat = True 183 | 184 | elif __o == "--noheader": 185 | __noheader = True 186 | 187 | elif __o == "--ipix": 188 | __ipix = __a 189 | 190 | elif __o == "--count": 191 | __count = True 192 | 193 | elif __o == "--sort": 194 | __sort = True 195 | __constraints.append(("-out.add", "_r")) 196 | __constraints.append(("-sort", "_r")) 197 | 198 | elif __o == "--add": 199 | if __add is None: __add = [] 200 | __add.append(__a) 201 | 202 | elif __o == "--offset": 203 | __offset = __a 204 | continue 205 | 206 | if __o in ("-f", "--file"): 207 | __filename = __a 208 | 209 | else: 210 | for opt in __options[2:]: 211 | value = opt[:len(opt)-1] 212 | if __o[2:] == value: 213 | __constraints.append((value, __a)) 214 | break 215 | 216 | for __arg in __args: 217 | if __position is None: 218 | __position = __arg 219 | else: 220 | __position += " "+ __arg 221 | 222 | if __noformat is True or __ipix is not None or __offset is not None or __noheader: 223 | if __sort is True : 224 | raise Exception("--sort function is not compatible with --ipix/--no-format") 225 | if __filename is not None: 226 | raise Exception("--file option is not compatible with --ipix/--no-format") 227 | 228 | if len(__constraints)>0: 229 | raise Exception("Constraints "+str(__constraints)+" is not available in this mode (--ipix/--offset/--no-format)") 230 | 231 | __querycat = QueryCatClient() 232 | if __ipix is not None: 233 | __querycat.set_healpix(__ipix) 234 | __querycat.noformat=__noformat 235 | __querycat.noheader=__noheader 236 | 237 | if __offset : 238 | s = __offset.split("..") 239 | if len(s) != 2: raise Exception("error offset syntax: min..max") 240 | try: 241 | __querycat.set_offset(int(s[0]), int(s[1])) 242 | except: 243 | raise Exception("error offset syntax: begin..nb_records") 244 | 245 | if __mime is None or __mime == vizquery.FORMAT_ASCII: 246 | __mime = vizquery.FORMAT_TSV 247 | 248 | else: 249 | __querycat = QueryCatVizieR() 250 | 251 | __querycat.position = __position 252 | __querycat.radius = __radius 253 | 254 | if __mime in (vizquery.FORMAT_TSV, vizquery.FORMAT_VOTABLE, vizquery.FORMAT_ASCII): 255 | __querycat.format = __mime 256 | else: 257 | raise Exception("format not yet available") 258 | 259 | __querycat.query_cat(constraints=__constraints, all=__all, limit=__limit, columns=__add, filename=__filename) 260 | __querycat.print_stdout() 261 | 262 | -------------------------------------------------------------------------------- /cdsclient/find_2psc3.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """G.Landais (CDS) 24-mar-2018 3 | Query II/241/out 4 | 5 | find_2psc3.py [-h] [-a] [-r radius] [-m max] [constraints] [--format=tsv|votable|ascii] [position] 6 | 7 | -a: display all columns 8 | -r: radius in arcsec 9 | -m: max number of lines in output 10 | -h: this help 11 | --format: output (--format=tsv|votable|ascii) 12 | --noheader: remove header (not available for all options) 13 | --sort : sort by distance (available with position only) 14 | --add : column name in output 15 | --file : query with a list 16 | 17 | position : ra dec position or target name 18 | example: find_2psc3.py M1 19 | 20 | Other constraints: 21 | --sort : ... 22 | --add= : ... 23 | --file= : ... 24 | --noheader : ... 25 | --RAJ2000= : ... 26 | --DEJ2000= : ... 27 | --Jmag= : ... 28 | --Hmag= : ... 29 | --Kmag= : ... 30 | 31 | 32 | Example: --RAJ2000=">10" 33 | 34 | Licensed under a BSD license - see LICENSE.txt for details 35 | 36 | """ 37 | 38 | import os, sys 39 | import getopt 40 | import cdsclient.vizquery as vizquery 41 | #import vizquery 42 | 43 | if int(sys.version[0])<3: 44 | from urllib2 import quote 45 | else: 46 | from urllib.parse import quote 47 | 48 | NO_FORMAT = "noformat" 49 | DEBUG = False 50 | 51 | class QueryCat(): 52 | def __init__(self): 53 | self.position = None 54 | self.radius = vizquery.DEFAULT_RADIUS 55 | self.format = None 56 | 57 | def query_cat(self, constraints=None, all = False, limit=vizquery.DEFAULT_LIMIT): 58 | """init constraints parameters 59 | :param constraints: list of constraints ((name,value), ...) 60 | :param all: display all columns(efault False) 61 | :param limit: max number of records 62 | """ 63 | pass 64 | 65 | def get(self): 66 | """get astropy table""" 67 | pass 68 | 69 | def print_stdout(self): 70 | """print the result on stdout""" 71 | pass 72 | 73 | 74 | class QueryCatVizieR(QueryCat): 75 | def __init__(self): 76 | QueryCat.__init__(self) 77 | self.__client = vizquery.CDSClient(default_format=vizquery.FORMAT_ASCII) 78 | self.limit = vizquery.DEFAULT_LIMIT 79 | 80 | def query_cat(self, constraints=None, all=False, limit=vizquery.DEFAULT_LIMIT, columns=None, filename=None): 81 | params = [] 82 | 83 | if self.position: 84 | params.append("-c={0}".format(quote(self.position))) 85 | 86 | if self.radius: 87 | params.append("-c.rs={0:f}".format(self.radius)) 88 | 89 | if all is True: 90 | params.append("-out.all=1") 91 | 92 | if limit is not None: 93 | params.append("-out.max={0:d}".format(limit)) 94 | else: 95 | params.append("-out.max={0:d}".format(self.limit)) 96 | 97 | if columns is not None: 98 | for column in columns: params.append("-out={0}".format(column)) 99 | 100 | file_col = None 101 | if constraints is not None: 102 | for constraint in constraints: 103 | if constraint[1] == "" or constraint[1] == "-": 104 | file_col = constraint[0] 105 | params.append("{0}={1}".format(constraint[0], constraint[1].replace("+","%2B"))) 106 | 107 | if filename is not None: 108 | #params.append("-out.form=hori") 109 | #params.append("-out.add=_1") 110 | 111 | if file_col is not None: 112 | params.append("-sort={0}".format(file_col)) 113 | else: 114 | params.append("-out.add=_r") 115 | params.append("-sort=_r") 116 | 117 | self.__client.query("II/241/out", params=params, filename=filename) 118 | 119 | if self.format is not None: 120 | self.__client.format = self.format 121 | 122 | def get(self): 123 | return self.__client.get() 124 | 125 | def print_stdout(self): 126 | return self.__client.print_stdout() 127 | 128 | 129 | 130 | 131 | if __name__ == "__main__": 132 | 133 | __radius = vizquery.DEFAULT_RADIUS 134 | __position = None 135 | __limit = None 136 | __mime = vizquery.FORMAT_ASCII 137 | __noformat = False 138 | __noheader = False 139 | __ipix = None 140 | __all = False 141 | __sort = False 142 | __add = None 143 | __filename = None 144 | __constraints = [] 145 | __offset = None 146 | 147 | __options = ('help','format=','sort','add=','file=','noheader','RAJ2000=','DEJ2000=','Jmag=','Hmag=','Kmag=') 148 | try : 149 | __opts, __args = getopt.getopt(sys.argv[1:], 'hvar:m:f:', __options) 150 | except: 151 | help("__main__") 152 | sys.exit(1) 153 | 154 | for __o, __a in __opts: 155 | if __o == '-v': 156 | DEBUG = True 157 | continue 158 | 159 | if __o in ("-h", "--help"): 160 | help("__main__") 161 | sys.exit(1) 162 | 163 | elif __o == "-r": 164 | try: 165 | __radius = float(__a) 166 | except: 167 | sys.stderr.write("(error) wrong radius format\n") 168 | 169 | elif __o == "-m": 170 | try: 171 | __limit = int(__a) 172 | except: 173 | raise Exception("(error) wrong limit/max format") 174 | 175 | elif __o == "-a": 176 | __all = True 177 | 178 | elif __o == "--format": 179 | __mime = __a 180 | 181 | elif __o == "--no-format": 182 | __noformat = True 183 | 184 | elif __o == "--noheader": 185 | __noheader = True 186 | 187 | elif __o == "--ipix": 188 | __ipix = __a 189 | 190 | elif __o == "--count": 191 | __count = True 192 | 193 | elif __o == "--sort": 194 | __sort = True 195 | __constraints.append(("-out.add", "_r")) 196 | __constraints.append(("-sort", "_r")) 197 | 198 | elif __o == "--add": 199 | if __add is None: __add = [] 200 | __add.append(__a) 201 | 202 | elif __o == "--offset": 203 | __offset = __a 204 | continue 205 | 206 | if __o in ("-f", "--file"): 207 | __filename = __a 208 | 209 | else: 210 | for opt in __options[2:]: 211 | value = opt[:len(opt)-1] 212 | if __o[2:] == value: 213 | __constraints.append((value, __a)) 214 | break 215 | 216 | for __arg in __args: 217 | if __position is None: 218 | __position = __arg 219 | else: 220 | __position += " "+ __arg 221 | 222 | if __noformat is True or __ipix is not None or __offset is not None or __noheader: 223 | if __sort is True : 224 | raise Exception("--sort function is not compatible with --ipix/--no-format") 225 | if __filename is not None: 226 | raise Exception("--file option is not compatible with --ipix/--no-format") 227 | 228 | if len(__constraints)>0: 229 | raise Exception("Constraints "+str(__constraints)+" is not available in this mode (--ipix/--offset/--no-format)") 230 | 231 | __querycat = QueryCatClient() 232 | if __ipix is not None: 233 | __querycat.set_healpix(__ipix) 234 | __querycat.noformat=__noformat 235 | __querycat.noheader=__noheader 236 | 237 | if __offset : 238 | s = __offset.split("..") 239 | if len(s) != 2: raise Exception("error offset syntax: min..max") 240 | try: 241 | __querycat.set_offset(int(s[0]), int(s[1])) 242 | except: 243 | raise Exception("error offset syntax: begin..nb_records") 244 | 245 | if __mime is None or __mime == vizquery.FORMAT_ASCII: 246 | __mime = vizquery.FORMAT_TSV 247 | 248 | else: 249 | __querycat = QueryCatVizieR() 250 | 251 | __querycat.position = __position 252 | __querycat.radius = __radius 253 | 254 | if __mime in (vizquery.FORMAT_TSV, vizquery.FORMAT_VOTABLE, vizquery.FORMAT_ASCII): 255 | __querycat.format = __mime 256 | else: 257 | raise Exception("format not yet available") 258 | 259 | __querycat.query_cat(constraints=__constraints, all=__all, limit=__limit, columns=__add, filename=__filename) 260 | __querycat.print_stdout() 261 | 262 | -------------------------------------------------------------------------------- /cdsclient/find_ppmx.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """G.Landais (CDS) 24-mar-2018 3 | Query I/312/sample 4 | 5 | find_ppmx.py [-h] [-a] [-r radius] [-m max] [constraints] [--format=tsv|votable|ascii] [position] 6 | 7 | -a: display all columns 8 | -r: radius in arcsec 9 | -m: max number of lines in output 10 | -h: this help 11 | --format: output (--format=tsv|votable|ascii) 12 | --noheader: remove header (not available for all options) 13 | --sort : sort by distance (available with position only) 14 | --add : column name in output 15 | --file : query with a list 16 | 17 | position : ra dec position or target name 18 | example: find_ppmx.py M1 19 | 20 | Other constraints: 21 | --sort : ... 22 | --add= : ... 23 | --file= : ... 24 | --noheader : ... 25 | --PPMX= : ... 26 | --RAJ2000= : ... 27 | --DEJ2000= : ... 28 | --Jmag= : ... 29 | --Hmag= : ... 30 | --Kmag= : ... 31 | 32 | 33 | Example: --PPMX=">10" 34 | 35 | Licensed under a BSD license - see LICENSE.txt for details 36 | 37 | """ 38 | 39 | import os, sys 40 | import getopt 41 | import cdsclient.vizquery as vizquery 42 | #import vizquery 43 | 44 | if int(sys.version[0])<3: 45 | from urllib2 import quote 46 | else: 47 | from urllib.parse import quote 48 | 49 | NO_FORMAT = "noformat" 50 | DEBUG = False 51 | 52 | class QueryCat(): 53 | def __init__(self): 54 | self.position = None 55 | self.radius = vizquery.DEFAULT_RADIUS 56 | self.format = None 57 | 58 | def query_cat(self, constraints=None, all = False, limit=vizquery.DEFAULT_LIMIT): 59 | """init constraints parameters 60 | :param constraints: list of constraints ((name,value), ...) 61 | :param all: display all columns(efault False) 62 | :param limit: max number of records 63 | """ 64 | pass 65 | 66 | def get(self): 67 | """get astropy table""" 68 | pass 69 | 70 | def print_stdout(self): 71 | """print the result on stdout""" 72 | pass 73 | 74 | 75 | class QueryCatVizieR(QueryCat): 76 | def __init__(self): 77 | QueryCat.__init__(self) 78 | self.__client = vizquery.CDSClient(default_format=vizquery.FORMAT_ASCII) 79 | self.limit = vizquery.DEFAULT_LIMIT 80 | 81 | def query_cat(self, constraints=None, all=False, limit=vizquery.DEFAULT_LIMIT, columns=None, filename=None): 82 | params = [] 83 | 84 | if self.position: 85 | params.append("-c={0}".format(quote(self.position))) 86 | 87 | if self.radius: 88 | params.append("-c.rs={0:f}".format(self.radius)) 89 | 90 | if all is True: 91 | params.append("-out.all=1") 92 | 93 | if limit is not None: 94 | params.append("-out.max={0:d}".format(limit)) 95 | else: 96 | params.append("-out.max={0:d}".format(self.limit)) 97 | 98 | if columns is not None: 99 | for column in columns: params.append("-out={0}".format(column)) 100 | 101 | file_col = None 102 | if constraints is not None: 103 | for constraint in constraints: 104 | if constraint[1] == "" or constraint[1] == "-": 105 | file_col = constraint[0] 106 | params.append("{0}={1}".format(constraint[0], constraint[1].replace("+","%2B"))) 107 | 108 | if filename is not None: 109 | #params.append("-out.form=hori") 110 | #params.append("-out.add=_1") 111 | 112 | if file_col is not None: 113 | params.append("-sort={0}".format(file_col)) 114 | else: 115 | params.append("-out.add=_r") 116 | params.append("-sort=_r") 117 | 118 | self.__client.query("I/312/sample", params=params, filename=filename) 119 | 120 | if self.format is not None: 121 | self.__client.format = self.format 122 | 123 | def get(self): 124 | return self.__client.get() 125 | 126 | def print_stdout(self): 127 | return self.__client.print_stdout() 128 | 129 | 130 | 131 | 132 | if __name__ == "__main__": 133 | 134 | __radius = vizquery.DEFAULT_RADIUS 135 | __position = None 136 | __limit = None 137 | __mime = vizquery.FORMAT_ASCII 138 | __noformat = False 139 | __noheader = False 140 | __ipix = None 141 | __all = False 142 | __sort = False 143 | __add = None 144 | __filename = None 145 | __constraints = [] 146 | __offset = None 147 | 148 | __options = ('help','format=','sort','add=','file=','noheader','PPMX=','RAJ2000=','DEJ2000=','Jmag=','Hmag=','Kmag=') 149 | try : 150 | __opts, __args = getopt.getopt(sys.argv[1:], 'hvar:m:f:', __options) 151 | except: 152 | help("__main__") 153 | sys.exit(1) 154 | 155 | for __o, __a in __opts: 156 | if __o == '-v': 157 | DEBUG = True 158 | continue 159 | 160 | if __o in ("-h", "--help"): 161 | help("__main__") 162 | sys.exit(1) 163 | 164 | elif __o == "-r": 165 | try: 166 | __radius = float(__a) 167 | except: 168 | sys.stderr.write("(error) wrong radius format\n") 169 | 170 | elif __o == "-m": 171 | try: 172 | __limit = int(__a) 173 | except: 174 | raise Exception("(error) wrong limit/max format") 175 | 176 | elif __o == "-a": 177 | __all = True 178 | 179 | elif __o == "--format": 180 | __mime = __a 181 | 182 | elif __o == "--no-format": 183 | __noformat = True 184 | 185 | elif __o == "--noheader": 186 | __noheader = True 187 | 188 | elif __o == "--ipix": 189 | __ipix = __a 190 | 191 | elif __o == "--count": 192 | __count = True 193 | 194 | elif __o == "--sort": 195 | __sort = True 196 | __constraints.append(("-out.add", "_r")) 197 | __constraints.append(("-sort", "_r")) 198 | 199 | elif __o == "--add": 200 | if __add is None: __add = [] 201 | __add.append(__a) 202 | 203 | elif __o == "--offset": 204 | __offset = __a 205 | continue 206 | 207 | if __o in ("-f", "--file"): 208 | __filename = __a 209 | 210 | else: 211 | for opt in __options[2:]: 212 | value = opt[:len(opt)-1] 213 | if __o[2:] == value: 214 | __constraints.append((value, __a)) 215 | break 216 | 217 | for __arg in __args: 218 | if __position is None: 219 | __position = __arg 220 | else: 221 | __position += " "+ __arg 222 | 223 | if __noformat is True or __ipix is not None or __offset is not None or __noheader: 224 | if __sort is True : 225 | raise Exception("--sort function is not compatible with --ipix/--no-format") 226 | if __filename is not None: 227 | raise Exception("--file option is not compatible with --ipix/--no-format") 228 | 229 | if len(__constraints)>0: 230 | raise Exception("Constraints "+str(__constraints)+" is not available in this mode (--ipix/--offset/--no-format)") 231 | 232 | __querycat = QueryCatClient() 233 | if __ipix is not None: 234 | __querycat.set_healpix(__ipix) 235 | __querycat.noformat=__noformat 236 | __querycat.noheader=__noheader 237 | 238 | if __offset : 239 | s = __offset.split("..") 240 | if len(s) != 2: raise Exception("error offset syntax: min..max") 241 | try: 242 | __querycat.set_offset(int(s[0]), int(s[1])) 243 | except: 244 | raise Exception("error offset syntax: begin..nb_records") 245 | 246 | if __mime is None or __mime == vizquery.FORMAT_ASCII: 247 | __mime = vizquery.FORMAT_TSV 248 | 249 | else: 250 | __querycat = QueryCatVizieR() 251 | 252 | __querycat.position = __position 253 | __querycat.radius = __radius 254 | 255 | if __mime in (vizquery.FORMAT_TSV, vizquery.FORMAT_VOTABLE, vizquery.FORMAT_ASCII): 256 | __querycat.format = __mime 257 | else: 258 | raise Exception("format not yet available") 259 | 260 | __querycat.query_cat(constraints=__constraints, all=__all, limit=__limit, columns=__add, filename=__filename) 261 | __querycat.print_stdout() 262 | 263 | -------------------------------------------------------------------------------- /cdsclient/find_2mass.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """G.Landais (CDS) 24-mar-2018 3 | Query II/246/out 4 | 5 | find_2mass.py [-h] [-a] [-r radius] [-m max] [constraints] [--format=tsv|votable|ascii] [position] 6 | 7 | -a: display all columns 8 | -r: radius in arcsec 9 | -m: max number of lines in output 10 | -h: this help 11 | --format: output (--format=tsv|votable|ascii) 12 | --noheader: remove header (not available for all options) 13 | --sort : sort by distance (available with position only) 14 | --add : column name in output 15 | --file : query with a list 16 | 17 | position : ra dec position or target name 18 | example: find_2mass.py M1 19 | 20 | Other constraints: 21 | --sort : ... 22 | --add= : ... 23 | --file= : ... 24 | --noheader : ... 25 | --RAJ2000= : ... 26 | --DEJ2000= : ... 27 | --2MASS= : ... 28 | --Jmag= : ... 29 | --Hmag= : ... 30 | --Kmag= : ... 31 | 32 | 33 | Example: --RAJ2000=">10" 34 | 35 | Licensed under a BSD license - see LICENSE.txt for details 36 | 37 | """ 38 | 39 | import os, sys 40 | import getopt 41 | import cdsclient.vizquery as vizquery 42 | #import vizquery 43 | 44 | if int(sys.version[0])<3: 45 | from urllib2 import quote 46 | else: 47 | from urllib.parse import quote 48 | 49 | NO_FORMAT = "noformat" 50 | DEBUG = False 51 | 52 | class QueryCat(): 53 | def __init__(self): 54 | self.position = None 55 | self.radius = vizquery.DEFAULT_RADIUS 56 | self.format = None 57 | 58 | def query_cat(self, constraints=None, all = False, limit=vizquery.DEFAULT_LIMIT): 59 | """init constraints parameters 60 | :param constraints: list of constraints ((name,value), ...) 61 | :param all: display all columns(efault False) 62 | :param limit: max number of records 63 | """ 64 | pass 65 | 66 | def get(self): 67 | """get astropy table""" 68 | pass 69 | 70 | def print_stdout(self): 71 | """print the result on stdout""" 72 | pass 73 | 74 | 75 | class QueryCatVizieR(QueryCat): 76 | def __init__(self): 77 | QueryCat.__init__(self) 78 | self.__client = vizquery.CDSClient(default_format=vizquery.FORMAT_ASCII) 79 | self.limit = vizquery.DEFAULT_LIMIT 80 | 81 | def query_cat(self, constraints=None, all=False, limit=vizquery.DEFAULT_LIMIT, columns=None, filename=None): 82 | params = [] 83 | 84 | if self.position: 85 | params.append("-c={0}".format(quote(self.position))) 86 | 87 | if self.radius: 88 | params.append("-c.rs={0:f}".format(self.radius)) 89 | 90 | if all is True: 91 | params.append("-out.all=1") 92 | 93 | if limit is not None: 94 | params.append("-out.max={0:d}".format(limit)) 95 | else: 96 | params.append("-out.max={0:d}".format(self.limit)) 97 | 98 | if columns is not None: 99 | for column in columns: params.append("-out={0}".format(column)) 100 | 101 | file_col = None 102 | if constraints is not None: 103 | for constraint in constraints: 104 | if constraint[1] == "" or constraint[1] == "-": 105 | file_col = constraint[0] 106 | params.append("{0}={1}".format(constraint[0], constraint[1].replace("+","%2B"))) 107 | 108 | if filename is not None: 109 | #params.append("-out.form=hori") 110 | #params.append("-out.add=_1") 111 | 112 | if file_col is not None: 113 | params.append("-sort={0}".format(file_col)) 114 | else: 115 | params.append("-out.add=_r") 116 | params.append("-sort=_r") 117 | 118 | self.__client.query("II/246/out", params=params, filename=filename) 119 | 120 | if self.format is not None: 121 | self.__client.format = self.format 122 | 123 | def get(self): 124 | return self.__client.get() 125 | 126 | def print_stdout(self): 127 | return self.__client.print_stdout() 128 | 129 | 130 | 131 | 132 | if __name__ == "__main__": 133 | 134 | __radius = vizquery.DEFAULT_RADIUS 135 | __position = None 136 | __limit = None 137 | __mime = vizquery.FORMAT_ASCII 138 | __noformat = False 139 | __noheader = False 140 | __ipix = None 141 | __all = False 142 | __sort = False 143 | __add = None 144 | __filename = None 145 | __constraints = [] 146 | __offset = None 147 | 148 | __options = ('help','format=','sort','add=','file=','noheader','RAJ2000=','DEJ2000=','2MASS=','Jmag=','Hmag=','Kmag=') 149 | try : 150 | __opts, __args = getopt.getopt(sys.argv[1:], 'hvar:m:f:', __options) 151 | except: 152 | help("__main__") 153 | sys.exit(1) 154 | 155 | for __o, __a in __opts: 156 | if __o == '-v': 157 | DEBUG = True 158 | continue 159 | 160 | if __o in ("-h", "--help"): 161 | help("__main__") 162 | sys.exit(1) 163 | 164 | elif __o == "-r": 165 | try: 166 | __radius = float(__a) 167 | except: 168 | sys.stderr.write("(error) wrong radius format\n") 169 | 170 | elif __o == "-m": 171 | try: 172 | __limit = int(__a) 173 | except: 174 | raise Exception("(error) wrong limit/max format") 175 | 176 | elif __o == "-a": 177 | __all = True 178 | 179 | elif __o == "--format": 180 | __mime = __a 181 | 182 | elif __o == "--no-format": 183 | __noformat = True 184 | 185 | elif __o == "--noheader": 186 | __noheader = True 187 | 188 | elif __o == "--ipix": 189 | __ipix = __a 190 | 191 | elif __o == "--count": 192 | __count = True 193 | 194 | elif __o == "--sort": 195 | __sort = True 196 | __constraints.append(("-out.add", "_r")) 197 | __constraints.append(("-sort", "_r")) 198 | 199 | elif __o == "--add": 200 | if __add is None: __add = [] 201 | __add.append(__a) 202 | 203 | elif __o == "--offset": 204 | __offset = __a 205 | continue 206 | 207 | if __o in ("-f", "--file"): 208 | __filename = __a 209 | 210 | else: 211 | for opt in __options[2:]: 212 | value = opt[:len(opt)-1] 213 | if __o[2:] == value: 214 | __constraints.append((value, __a)) 215 | break 216 | 217 | for __arg in __args: 218 | if __position is None: 219 | __position = __arg 220 | else: 221 | __position += " "+ __arg 222 | 223 | if __noformat is True or __ipix is not None or __offset is not None or __noheader: 224 | if __sort is True : 225 | raise Exception("--sort function is not compatible with --ipix/--no-format") 226 | if __filename is not None: 227 | raise Exception("--file option is not compatible with --ipix/--no-format") 228 | 229 | if len(__constraints)>0: 230 | raise Exception("Constraints "+str(__constraints)+" is not available in this mode (--ipix/--offset/--no-format)") 231 | 232 | __querycat = QueryCatClient() 233 | if __ipix is not None: 234 | __querycat.set_healpix(__ipix) 235 | __querycat.noformat=__noformat 236 | __querycat.noheader=__noheader 237 | 238 | if __offset : 239 | s = __offset.split("..") 240 | if len(s) != 2: raise Exception("error offset syntax: min..max") 241 | try: 242 | __querycat.set_offset(int(s[0]), int(s[1])) 243 | except: 244 | raise Exception("error offset syntax: begin..nb_records") 245 | 246 | if __mime is None or __mime == vizquery.FORMAT_ASCII: 247 | __mime = vizquery.FORMAT_TSV 248 | 249 | else: 250 | __querycat = QueryCatVizieR() 251 | 252 | __querycat.position = __position 253 | __querycat.radius = __radius 254 | 255 | if __mime in (vizquery.FORMAT_TSV, vizquery.FORMAT_VOTABLE, vizquery.FORMAT_ASCII): 256 | __querycat.format = __mime 257 | else: 258 | raise Exception("format not yet available") 259 | 260 | __querycat.query_cat(constraints=__constraints, all=__all, limit=__limit, columns=__add, filename=__filename) 261 | __querycat.print_stdout() 262 | 263 | -------------------------------------------------------------------------------- /cdsclient/find_ppmxl.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """G.Landais (CDS) 24-mar-2018 3 | Query I/317/sample 4 | 5 | find_ppmxl.py [-h] [-a] [-r radius] [-m max] [constraints] [--format=tsv|votable|ascii] [position] 6 | 7 | -a: display all columns 8 | -r: radius in arcsec 9 | -m: max number of lines in output 10 | -h: this help 11 | --format: output (--format=tsv|votable|ascii) 12 | --noheader: remove header (not available for all options) 13 | --sort : sort by distance (available with position only) 14 | --add : column name in output 15 | --file : query with a list 16 | 17 | position : ra dec position or target name 18 | example: find_ppmxl.py M1 19 | 20 | Other constraints: 21 | --sort : ... 22 | --add= : ... 23 | --file= : ... 24 | --noheader : ... 25 | --PPMXL= : ... 26 | --RAJ2000= : ... 27 | --DEJ2000= : ... 28 | --Jmag= : ... 29 | --Hmag= : ... 30 | --Kmag= : ... 31 | 32 | 33 | Example: --PPMXL=">10" 34 | 35 | Licensed under a BSD license - see LICENSE.txt for details 36 | 37 | """ 38 | 39 | import os, sys 40 | import getopt 41 | import cdsclient.vizquery as vizquery 42 | #import vizquery 43 | 44 | if int(sys.version[0])<3: 45 | from urllib2 import quote 46 | else: 47 | from urllib.parse import quote 48 | 49 | NO_FORMAT = "noformat" 50 | DEBUG = False 51 | 52 | class QueryCat(): 53 | def __init__(self): 54 | self.position = None 55 | self.radius = vizquery.DEFAULT_RADIUS 56 | self.format = None 57 | 58 | def query_cat(self, constraints=None, all = False, limit=vizquery.DEFAULT_LIMIT): 59 | """init constraints parameters 60 | :param constraints: list of constraints ((name,value), ...) 61 | :param all: display all columns(efault False) 62 | :param limit: max number of records 63 | """ 64 | pass 65 | 66 | def get(self): 67 | """get astropy table""" 68 | pass 69 | 70 | def print_stdout(self): 71 | """print the result on stdout""" 72 | pass 73 | 74 | 75 | class QueryCatVizieR(QueryCat): 76 | def __init__(self): 77 | QueryCat.__init__(self) 78 | self.__client = vizquery.CDSClient(default_format=vizquery.FORMAT_ASCII) 79 | self.limit = vizquery.DEFAULT_LIMIT 80 | 81 | def query_cat(self, constraints=None, all=False, limit=vizquery.DEFAULT_LIMIT, columns=None, filename=None): 82 | params = [] 83 | 84 | if self.position: 85 | params.append("-c={0}".format(quote(self.position))) 86 | 87 | if self.radius: 88 | params.append("-c.rs={0:f}".format(self.radius)) 89 | 90 | if all is True: 91 | params.append("-out.all=1") 92 | 93 | if limit is not None: 94 | params.append("-out.max={0:d}".format(limit)) 95 | else: 96 | params.append("-out.max={0:d}".format(self.limit)) 97 | 98 | if columns is not None: 99 | for column in columns: params.append("-out={0}".format(column)) 100 | 101 | file_col = None 102 | if constraints is not None: 103 | for constraint in constraints: 104 | if constraint[1] == "" or constraint[1] == "-": 105 | file_col = constraint[0] 106 | params.append("{0}={1}".format(constraint[0], constraint[1].replace("+","%2B"))) 107 | 108 | if filename is not None: 109 | #params.append("-out.form=hori") 110 | #params.append("-out.add=_1") 111 | 112 | if file_col is not None: 113 | params.append("-sort={0}".format(file_col)) 114 | else: 115 | params.append("-out.add=_r") 116 | params.append("-sort=_r") 117 | 118 | self.__client.query("I/317/sample", params=params, filename=filename) 119 | 120 | if self.format is not None: 121 | self.__client.format = self.format 122 | 123 | def get(self): 124 | return self.__client.get() 125 | 126 | def print_stdout(self): 127 | return self.__client.print_stdout() 128 | 129 | 130 | 131 | 132 | if __name__ == "__main__": 133 | 134 | __radius = vizquery.DEFAULT_RADIUS 135 | __position = None 136 | __limit = None 137 | __mime = vizquery.FORMAT_ASCII 138 | __noformat = False 139 | __noheader = False 140 | __ipix = None 141 | __all = False 142 | __sort = False 143 | __add = None 144 | __filename = None 145 | __constraints = [] 146 | __offset = None 147 | 148 | __options = ('help','format=','sort','add=','file=','noheader','PPMXL=','RAJ2000=','DEJ2000=','Jmag=','Hmag=','Kmag=') 149 | try : 150 | __opts, __args = getopt.getopt(sys.argv[1:], 'hvar:m:f:', __options) 151 | except: 152 | help("__main__") 153 | sys.exit(1) 154 | 155 | for __o, __a in __opts: 156 | if __o == '-v': 157 | DEBUG = True 158 | continue 159 | 160 | if __o in ("-h", "--help"): 161 | help("__main__") 162 | sys.exit(1) 163 | 164 | elif __o == "-r": 165 | try: 166 | __radius = float(__a) 167 | except: 168 | sys.stderr.write("(error) wrong radius format\n") 169 | 170 | elif __o == "-m": 171 | try: 172 | __limit = int(__a) 173 | except: 174 | raise Exception("(error) wrong limit/max format") 175 | 176 | elif __o == "-a": 177 | __all = True 178 | 179 | elif __o == "--format": 180 | __mime = __a 181 | 182 | elif __o == "--no-format": 183 | __noformat = True 184 | 185 | elif __o == "--noheader": 186 | __noheader = True 187 | 188 | elif __o == "--ipix": 189 | __ipix = __a 190 | 191 | elif __o == "--count": 192 | __count = True 193 | 194 | elif __o == "--sort": 195 | __sort = True 196 | __constraints.append(("-out.add", "_r")) 197 | __constraints.append(("-sort", "_r")) 198 | 199 | elif __o == "--add": 200 | if __add is None: __add = [] 201 | __add.append(__a) 202 | 203 | elif __o == "--offset": 204 | __offset = __a 205 | continue 206 | 207 | if __o in ("-f", "--file"): 208 | __filename = __a 209 | 210 | else: 211 | for opt in __options[2:]: 212 | value = opt[:len(opt)-1] 213 | if __o[2:] == value: 214 | __constraints.append((value, __a)) 215 | break 216 | 217 | for __arg in __args: 218 | if __position is None: 219 | __position = __arg 220 | else: 221 | __position += " "+ __arg 222 | 223 | if __noformat is True or __ipix is not None or __offset is not None or __noheader: 224 | if __sort is True : 225 | raise Exception("--sort function is not compatible with --ipix/--no-format") 226 | if __filename is not None: 227 | raise Exception("--file option is not compatible with --ipix/--no-format") 228 | 229 | if len(__constraints)>0: 230 | raise Exception("Constraints "+str(__constraints)+" is not available in this mode (--ipix/--offset/--no-format)") 231 | 232 | __querycat = QueryCatClient() 233 | if __ipix is not None: 234 | __querycat.set_healpix(__ipix) 235 | __querycat.noformat=__noformat 236 | __querycat.noheader=__noheader 237 | 238 | if __offset : 239 | s = __offset.split("..") 240 | if len(s) != 2: raise Exception("error offset syntax: min..max") 241 | try: 242 | __querycat.set_offset(int(s[0]), int(s[1])) 243 | except: 244 | raise Exception("error offset syntax: begin..nb_records") 245 | 246 | if __mime is None or __mime == vizquery.FORMAT_ASCII: 247 | __mime = vizquery.FORMAT_TSV 248 | 249 | else: 250 | __querycat = QueryCatVizieR() 251 | 252 | __querycat.position = __position 253 | __querycat.radius = __radius 254 | 255 | if __mime in (vizquery.FORMAT_TSV, vizquery.FORMAT_VOTABLE, vizquery.FORMAT_ASCII): 256 | __querycat.format = __mime 257 | else: 258 | raise Exception("format not yet available") 259 | 260 | __querycat.query_cat(constraints=__constraints, all=__all, limit=__limit, columns=__add, filename=__filename) 261 | __querycat.print_stdout() 262 | 263 | -------------------------------------------------------------------------------- /cdsclient/find_denis3.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """G.Landais (CDS) 24-mar-2018 3 | Query B/denis/denis 4 | 5 | find_denis3.py [-h] [-a] [-r radius] [-m max] [constraints] [--format=tsv|votable|ascii] [position] 6 | 7 | -a: display all columns 8 | -r: radius in arcsec 9 | -m: max number of lines in output 10 | -h: this help 11 | --format: output (--format=tsv|votable|ascii) 12 | --noheader: remove header (not available for all options) 13 | --sort : sort by distance (available with position only) 14 | --add : column name in output 15 | --file : query with a list 16 | 17 | position : ra dec position or target name 18 | example: find_denis3.py M1 19 | 20 | Other constraints: 21 | --sort : ... 22 | --add= : ... 23 | --file= : ... 24 | --noheader : ... 25 | --RAJ2000= : ... 26 | --DEJ2000= : ... 27 | --Imag= : ... 28 | --Jmag= : ... 29 | --Kmag= : ... 30 | --DENIS= : ... 31 | 32 | 33 | Example: --RAJ2000=">10" 34 | 35 | Licensed under a BSD license - see LICENSE.txt for details 36 | 37 | """ 38 | 39 | import os, sys 40 | import getopt 41 | import cdsclient.vizquery as vizquery 42 | #import vizquery 43 | 44 | if int(sys.version[0])<3: 45 | from urllib2 import quote 46 | else: 47 | from urllib.parse import quote 48 | 49 | NO_FORMAT = "noformat" 50 | DEBUG = False 51 | 52 | class QueryCat(): 53 | def __init__(self): 54 | self.position = None 55 | self.radius = vizquery.DEFAULT_RADIUS 56 | self.format = None 57 | 58 | def query_cat(self, constraints=None, all = False, limit=vizquery.DEFAULT_LIMIT): 59 | """init constraints parameters 60 | :param constraints: list of constraints ((name,value), ...) 61 | :param all: display all columns(efault False) 62 | :param limit: max number of records 63 | """ 64 | pass 65 | 66 | def get(self): 67 | """get astropy table""" 68 | pass 69 | 70 | def print_stdout(self): 71 | """print the result on stdout""" 72 | pass 73 | 74 | 75 | class QueryCatVizieR(QueryCat): 76 | def __init__(self): 77 | QueryCat.__init__(self) 78 | self.__client = vizquery.CDSClient(default_format=vizquery.FORMAT_ASCII) 79 | self.limit = vizquery.DEFAULT_LIMIT 80 | 81 | def query_cat(self, constraints=None, all=False, limit=vizquery.DEFAULT_LIMIT, columns=None, filename=None): 82 | params = [] 83 | 84 | if self.position: 85 | params.append("-c={0}".format(quote(self.position))) 86 | 87 | if self.radius: 88 | params.append("-c.rs={0:f}".format(self.radius)) 89 | 90 | if all is True: 91 | params.append("-out.all=1") 92 | 93 | if limit is not None: 94 | params.append("-out.max={0:d}".format(limit)) 95 | else: 96 | params.append("-out.max={0:d}".format(self.limit)) 97 | 98 | if columns is not None: 99 | for column in columns: params.append("-out={0}".format(column)) 100 | 101 | file_col = None 102 | if constraints is not None: 103 | for constraint in constraints: 104 | if constraint[1] == "" or constraint[1] == "-": 105 | file_col = constraint[0] 106 | params.append("{0}={1}".format(constraint[0], constraint[1].replace("+","%2B"))) 107 | 108 | if filename is not None: 109 | #params.append("-out.form=hori") 110 | #params.append("-out.add=_1") 111 | 112 | if file_col is not None: 113 | params.append("-sort={0}".format(file_col)) 114 | else: 115 | params.append("-out.add=_r") 116 | params.append("-sort=_r") 117 | 118 | self.__client.query("B/denis/denis", params=params, filename=filename) 119 | 120 | if self.format is not None: 121 | self.__client.format = self.format 122 | 123 | def get(self): 124 | return self.__client.get() 125 | 126 | def print_stdout(self): 127 | return self.__client.print_stdout() 128 | 129 | 130 | 131 | 132 | if __name__ == "__main__": 133 | 134 | __radius = vizquery.DEFAULT_RADIUS 135 | __position = None 136 | __limit = None 137 | __mime = vizquery.FORMAT_ASCII 138 | __noformat = False 139 | __noheader = False 140 | __ipix = None 141 | __all = False 142 | __sort = False 143 | __add = None 144 | __filename = None 145 | __constraints = [] 146 | __offset = None 147 | 148 | __options = ('help','format=','sort','add=','file=','noheader','RAJ2000=','DEJ2000=','Imag=','Jmag=','Kmag=','DENIS=') 149 | try : 150 | __opts, __args = getopt.getopt(sys.argv[1:], 'hvar:m:f:', __options) 151 | except: 152 | help("__main__") 153 | sys.exit(1) 154 | 155 | for __o, __a in __opts: 156 | if __o == '-v': 157 | DEBUG = True 158 | continue 159 | 160 | if __o in ("-h", "--help"): 161 | help("__main__") 162 | sys.exit(1) 163 | 164 | elif __o == "-r": 165 | try: 166 | __radius = float(__a) 167 | except: 168 | sys.stderr.write("(error) wrong radius format\n") 169 | 170 | elif __o == "-m": 171 | try: 172 | __limit = int(__a) 173 | except: 174 | raise Exception("(error) wrong limit/max format") 175 | 176 | elif __o == "-a": 177 | __all = True 178 | 179 | elif __o == "--format": 180 | __mime = __a 181 | 182 | elif __o == "--no-format": 183 | __noformat = True 184 | 185 | elif __o == "--noheader": 186 | __noheader = True 187 | 188 | elif __o == "--ipix": 189 | __ipix = __a 190 | 191 | elif __o == "--count": 192 | __count = True 193 | 194 | elif __o == "--sort": 195 | __sort = True 196 | __constraints.append(("-out.add", "_r")) 197 | __constraints.append(("-sort", "_r")) 198 | 199 | elif __o == "--add": 200 | if __add is None: __add = [] 201 | __add.append(__a) 202 | 203 | elif __o == "--offset": 204 | __offset = __a 205 | continue 206 | 207 | if __o in ("-f", "--file"): 208 | __filename = __a 209 | 210 | else: 211 | for opt in __options[2:]: 212 | value = opt[:len(opt)-1] 213 | if __o[2:] == value: 214 | __constraints.append((value, __a)) 215 | break 216 | 217 | for __arg in __args: 218 | if __position is None: 219 | __position = __arg 220 | else: 221 | __position += " "+ __arg 222 | 223 | if __noformat is True or __ipix is not None or __offset is not None or __noheader: 224 | if __sort is True : 225 | raise Exception("--sort function is not compatible with --ipix/--no-format") 226 | if __filename is not None: 227 | raise Exception("--file option is not compatible with --ipix/--no-format") 228 | 229 | if len(__constraints)>0: 230 | raise Exception("Constraints "+str(__constraints)+" is not available in this mode (--ipix/--offset/--no-format)") 231 | 232 | __querycat = QueryCatClient() 233 | if __ipix is not None: 234 | __querycat.set_healpix(__ipix) 235 | __querycat.noformat=__noformat 236 | __querycat.noheader=__noheader 237 | 238 | if __offset : 239 | s = __offset.split("..") 240 | if len(s) != 2: raise Exception("error offset syntax: min..max") 241 | try: 242 | __querycat.set_offset(int(s[0]), int(s[1])) 243 | except: 244 | raise Exception("error offset syntax: begin..nb_records") 245 | 246 | if __mime is None or __mime == vizquery.FORMAT_ASCII: 247 | __mime = vizquery.FORMAT_TSV 248 | 249 | else: 250 | __querycat = QueryCatVizieR() 251 | 252 | __querycat.position = __position 253 | __querycat.radius = __radius 254 | 255 | if __mime in (vizquery.FORMAT_TSV, vizquery.FORMAT_VOTABLE, vizquery.FORMAT_ASCII): 256 | __querycat.format = __mime 257 | else: 258 | raise Exception("format not yet available") 259 | 260 | __querycat.query_cat(constraints=__constraints, all=__all, limit=__limit, columns=__add, filename=__filename) 261 | __querycat.print_stdout() 262 | 263 | -------------------------------------------------------------------------------- /cdsclient/find_glimpse.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """G.Landais (CDS) 24-mar-2018 3 | Query II/293/glimpse 4 | 5 | find_glimpse.py [-h] [-a] [-r radius] [-m max] [constraints] [--format=tsv|votable|ascii] [position] 6 | 7 | -a: display all columns 8 | -r: radius in arcsec 9 | -m: max number of lines in output 10 | -h: this help 11 | --format: output (--format=tsv|votable|ascii) 12 | --noheader: remove header (not available for all options) 13 | --sort : sort by distance (available with position only) 14 | --add : column name in output 15 | --file : query with a list 16 | 17 | position : ra dec position or target name 18 | example: find_glimpse.py M1 19 | 20 | Other constraints: 21 | --sort : ... 22 | --add= : ... 23 | --file= : ... 24 | --noheader : ... 25 | --GLIMPSE= : ... 26 | --RAJ2000= : ... 27 | --DEJ2000= : ... 28 | --Jmag= : ... 29 | --Hmag= : ... 30 | --Kmag= : ... 31 | 32 | 33 | Example: --GLIMPSE=">10" 34 | 35 | Licensed under a BSD license - see LICENSE.txt for details 36 | 37 | """ 38 | 39 | import os, sys 40 | import getopt 41 | import cdsclient.vizquery as vizquery 42 | #import vizquery 43 | 44 | if int(sys.version[0])<3: 45 | from urllib2 import quote 46 | else: 47 | from urllib.parse import quote 48 | 49 | NO_FORMAT = "noformat" 50 | DEBUG = False 51 | 52 | class QueryCat(): 53 | def __init__(self): 54 | self.position = None 55 | self.radius = vizquery.DEFAULT_RADIUS 56 | self.format = None 57 | 58 | def query_cat(self, constraints=None, all = False, limit=vizquery.DEFAULT_LIMIT): 59 | """init constraints parameters 60 | :param constraints: list of constraints ((name,value), ...) 61 | :param all: display all columns(efault False) 62 | :param limit: max number of records 63 | """ 64 | pass 65 | 66 | def get(self): 67 | """get astropy table""" 68 | pass 69 | 70 | def print_stdout(self): 71 | """print the result on stdout""" 72 | pass 73 | 74 | 75 | class QueryCatVizieR(QueryCat): 76 | def __init__(self): 77 | QueryCat.__init__(self) 78 | self.__client = vizquery.CDSClient(default_format=vizquery.FORMAT_ASCII) 79 | self.limit = vizquery.DEFAULT_LIMIT 80 | 81 | def query_cat(self, constraints=None, all=False, limit=vizquery.DEFAULT_LIMIT, columns=None, filename=None): 82 | params = [] 83 | 84 | if self.position: 85 | params.append("-c={0}".format(quote(self.position))) 86 | 87 | if self.radius: 88 | params.append("-c.rs={0:f}".format(self.radius)) 89 | 90 | if all is True: 91 | params.append("-out.all=1") 92 | 93 | if limit is not None: 94 | params.append("-out.max={0:d}".format(limit)) 95 | else: 96 | params.append("-out.max={0:d}".format(self.limit)) 97 | 98 | if columns is not None: 99 | for column in columns: params.append("-out={0}".format(column)) 100 | 101 | file_col = None 102 | if constraints is not None: 103 | for constraint in constraints: 104 | if constraint[1] == "" or constraint[1] == "-": 105 | file_col = constraint[0] 106 | params.append("{0}={1}".format(constraint[0], constraint[1].replace("+","%2B"))) 107 | 108 | if filename is not None: 109 | #params.append("-out.form=hori") 110 | #params.append("-out.add=_1") 111 | 112 | if file_col is not None: 113 | params.append("-sort={0}".format(file_col)) 114 | else: 115 | params.append("-out.add=_r") 116 | params.append("-sort=_r") 117 | 118 | self.__client.query("II/293/glimpse", params=params, filename=filename) 119 | 120 | if self.format is not None: 121 | self.__client.format = self.format 122 | 123 | def get(self): 124 | return self.__client.get() 125 | 126 | def print_stdout(self): 127 | return self.__client.print_stdout() 128 | 129 | 130 | 131 | 132 | if __name__ == "__main__": 133 | 134 | __radius = vizquery.DEFAULT_RADIUS 135 | __position = None 136 | __limit = None 137 | __mime = vizquery.FORMAT_ASCII 138 | __noformat = False 139 | __noheader = False 140 | __ipix = None 141 | __all = False 142 | __sort = False 143 | __add = None 144 | __filename = None 145 | __constraints = [] 146 | __offset = None 147 | 148 | __options = ('help','format=','sort','add=','file=','noheader','GLIMPSE=','RAJ2000=','DEJ2000=','Jmag=','Hmag=','Kmag=') 149 | try : 150 | __opts, __args = getopt.getopt(sys.argv[1:], 'hvar:m:f:', __options) 151 | except: 152 | help("__main__") 153 | sys.exit(1) 154 | 155 | for __o, __a in __opts: 156 | if __o == '-v': 157 | DEBUG = True 158 | continue 159 | 160 | if __o in ("-h", "--help"): 161 | help("__main__") 162 | sys.exit(1) 163 | 164 | elif __o == "-r": 165 | try: 166 | __radius = float(__a) 167 | except: 168 | sys.stderr.write("(error) wrong radius format\n") 169 | 170 | elif __o == "-m": 171 | try: 172 | __limit = int(__a) 173 | except: 174 | raise Exception("(error) wrong limit/max format") 175 | 176 | elif __o == "-a": 177 | __all = True 178 | 179 | elif __o == "--format": 180 | __mime = __a 181 | 182 | elif __o == "--no-format": 183 | __noformat = True 184 | 185 | elif __o == "--noheader": 186 | __noheader = True 187 | 188 | elif __o == "--ipix": 189 | __ipix = __a 190 | 191 | elif __o == "--count": 192 | __count = True 193 | 194 | elif __o == "--sort": 195 | __sort = True 196 | __constraints.append(("-out.add", "_r")) 197 | __constraints.append(("-sort", "_r")) 198 | 199 | elif __o == "--add": 200 | if __add is None: __add = [] 201 | __add.append(__a) 202 | 203 | elif __o == "--offset": 204 | __offset = __a 205 | continue 206 | 207 | if __o in ("-f", "--file"): 208 | __filename = __a 209 | 210 | else: 211 | for opt in __options[2:]: 212 | value = opt[:len(opt)-1] 213 | if __o[2:] == value: 214 | __constraints.append((value, __a)) 215 | break 216 | 217 | for __arg in __args: 218 | if __position is None: 219 | __position = __arg 220 | else: 221 | __position += " "+ __arg 222 | 223 | if __noformat is True or __ipix is not None or __offset is not None or __noheader: 224 | if __sort is True : 225 | raise Exception("--sort function is not compatible with --ipix/--no-format") 226 | if __filename is not None: 227 | raise Exception("--file option is not compatible with --ipix/--no-format") 228 | 229 | if len(__constraints)>0: 230 | raise Exception("Constraints "+str(__constraints)+" is not available in this mode (--ipix/--offset/--no-format)") 231 | 232 | __querycat = QueryCatClient() 233 | if __ipix is not None: 234 | __querycat.set_healpix(__ipix) 235 | __querycat.noformat=__noformat 236 | __querycat.noheader=__noheader 237 | 238 | if __offset : 239 | s = __offset.split("..") 240 | if len(s) != 2: raise Exception("error offset syntax: min..max") 241 | try: 242 | __querycat.set_offset(int(s[0]), int(s[1])) 243 | except: 244 | raise Exception("error offset syntax: begin..nb_records") 245 | 246 | if __mime is None or __mime == vizquery.FORMAT_ASCII: 247 | __mime = vizquery.FORMAT_TSV 248 | 249 | else: 250 | __querycat = QueryCatVizieR() 251 | 252 | __querycat.position = __position 253 | __querycat.radius = __radius 254 | 255 | if __mime in (vizquery.FORMAT_TSV, vizquery.FORMAT_VOTABLE, vizquery.FORMAT_ASCII): 256 | __querycat.format = __mime 257 | else: 258 | raise Exception("format not yet available") 259 | 260 | __querycat.query_cat(constraints=__constraints, all=__all, limit=__limit, columns=__add, filename=__filename) 261 | __querycat.print_stdout() 262 | 263 | -------------------------------------------------------------------------------- /cdsclient/find_nomad1.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """G.Landais (CDS) 24-mar-2018 3 | Query I/297/out 4 | 5 | find_nomad1.py [-h] [-a] [-r radius] [-m max] [constraints] [--format=tsv|votable|ascii] [position] 6 | 7 | -a: display all columns 8 | -r: radius in arcsec 9 | -m: max number of lines in output 10 | -h: this help 11 | --format: output (--format=tsv|votable|ascii) 12 | --noheader: remove header (not available for all options) 13 | --sort : sort by distance (available with position only) 14 | --add : column name in output 15 | --file : query with a list 16 | 17 | position : ra dec position or target name 18 | example: find_nomad1.py M1 19 | 20 | Other constraints: 21 | --sort : ... 22 | --add= : ... 23 | --file= : ... 24 | --noheader : ... 25 | --NOMAD1= : ... 26 | --USNO-B1= : ... 27 | --UCAC2= : ... 28 | --Tycho-2= : ... 29 | --RAJ2000= : ... 30 | --DEJ2000= : ... 31 | 32 | 33 | Example: --NOMAD1=">10" 34 | 35 | Licensed under a BSD license - see LICENSE.txt for details 36 | 37 | """ 38 | 39 | import os, sys 40 | import getopt 41 | import cdsclient.vizquery as vizquery 42 | #import vizquery 43 | 44 | if int(sys.version[0])<3: 45 | from urllib2 import quote 46 | else: 47 | from urllib.parse import quote 48 | 49 | NO_FORMAT = "noformat" 50 | DEBUG = False 51 | 52 | class QueryCat(): 53 | def __init__(self): 54 | self.position = None 55 | self.radius = vizquery.DEFAULT_RADIUS 56 | self.format = None 57 | 58 | def query_cat(self, constraints=None, all = False, limit=vizquery.DEFAULT_LIMIT): 59 | """init constraints parameters 60 | :param constraints: list of constraints ((name,value), ...) 61 | :param all: display all columns(efault False) 62 | :param limit: max number of records 63 | """ 64 | pass 65 | 66 | def get(self): 67 | """get astropy table""" 68 | pass 69 | 70 | def print_stdout(self): 71 | """print the result on stdout""" 72 | pass 73 | 74 | 75 | class QueryCatVizieR(QueryCat): 76 | def __init__(self): 77 | QueryCat.__init__(self) 78 | self.__client = vizquery.CDSClient(default_format=vizquery.FORMAT_ASCII) 79 | self.limit = vizquery.DEFAULT_LIMIT 80 | 81 | def query_cat(self, constraints=None, all=False, limit=vizquery.DEFAULT_LIMIT, columns=None, filename=None): 82 | params = [] 83 | 84 | if self.position: 85 | params.append("-c={0}".format(quote(self.position))) 86 | 87 | if self.radius: 88 | params.append("-c.rs={0:f}".format(self.radius)) 89 | 90 | if all is True: 91 | params.append("-out.all=1") 92 | 93 | if limit is not None: 94 | params.append("-out.max={0:d}".format(limit)) 95 | else: 96 | params.append("-out.max={0:d}".format(self.limit)) 97 | 98 | if columns is not None: 99 | for column in columns: params.append("-out={0}".format(column)) 100 | 101 | file_col = None 102 | if constraints is not None: 103 | for constraint in constraints: 104 | if constraint[1] == "" or constraint[1] == "-": 105 | file_col = constraint[0] 106 | params.append("{0}={1}".format(constraint[0], constraint[1].replace("+","%2B"))) 107 | 108 | if filename is not None: 109 | #params.append("-out.form=hori") 110 | #params.append("-out.add=_1") 111 | 112 | if file_col is not None: 113 | params.append("-sort={0}".format(file_col)) 114 | else: 115 | params.append("-out.add=_r") 116 | params.append("-sort=_r") 117 | 118 | self.__client.query("I/297/out", params=params, filename=filename) 119 | 120 | if self.format is not None: 121 | self.__client.format = self.format 122 | 123 | def get(self): 124 | return self.__client.get() 125 | 126 | def print_stdout(self): 127 | return self.__client.print_stdout() 128 | 129 | 130 | 131 | 132 | if __name__ == "__main__": 133 | 134 | __radius = vizquery.DEFAULT_RADIUS 135 | __position = None 136 | __limit = None 137 | __mime = vizquery.FORMAT_ASCII 138 | __noformat = False 139 | __noheader = False 140 | __ipix = None 141 | __all = False 142 | __sort = False 143 | __add = None 144 | __filename = None 145 | __constraints = [] 146 | __offset = None 147 | 148 | __options = ('help','format=','sort','add=','file=','noheader','NOMAD1=','USNO-B1=','UCAC2=','Tycho-2=','RAJ2000=','DEJ2000=') 149 | try : 150 | __opts, __args = getopt.getopt(sys.argv[1:], 'hvar:m:f:', __options) 151 | except: 152 | help("__main__") 153 | sys.exit(1) 154 | 155 | for __o, __a in __opts: 156 | if __o == '-v': 157 | DEBUG = True 158 | continue 159 | 160 | if __o in ("-h", "--help"): 161 | help("__main__") 162 | sys.exit(1) 163 | 164 | elif __o == "-r": 165 | try: 166 | __radius = float(__a) 167 | except: 168 | sys.stderr.write("(error) wrong radius format\n") 169 | 170 | elif __o == "-m": 171 | try: 172 | __limit = int(__a) 173 | except: 174 | raise Exception("(error) wrong limit/max format") 175 | 176 | elif __o == "-a": 177 | __all = True 178 | 179 | elif __o == "--format": 180 | __mime = __a 181 | 182 | elif __o == "--no-format": 183 | __noformat = True 184 | 185 | elif __o == "--noheader": 186 | __noheader = True 187 | 188 | elif __o == "--ipix": 189 | __ipix = __a 190 | 191 | elif __o == "--count": 192 | __count = True 193 | 194 | elif __o == "--sort": 195 | __sort = True 196 | __constraints.append(("-out.add", "_r")) 197 | __constraints.append(("-sort", "_r")) 198 | 199 | elif __o == "--add": 200 | if __add is None: __add = [] 201 | __add.append(__a) 202 | 203 | elif __o == "--offset": 204 | __offset = __a 205 | continue 206 | 207 | if __o in ("-f", "--file"): 208 | __filename = __a 209 | 210 | else: 211 | for opt in __options[2:]: 212 | value = opt[:len(opt)-1] 213 | if __o[2:] == value: 214 | __constraints.append((value, __a)) 215 | break 216 | 217 | for __arg in __args: 218 | if __position is None: 219 | __position = __arg 220 | else: 221 | __position += " "+ __arg 222 | 223 | if __noformat is True or __ipix is not None or __offset is not None or __noheader: 224 | if __sort is True : 225 | raise Exception("--sort function is not compatible with --ipix/--no-format") 226 | if __filename is not None: 227 | raise Exception("--file option is not compatible with --ipix/--no-format") 228 | 229 | if len(__constraints)>0: 230 | raise Exception("Constraints "+str(__constraints)+" is not available in this mode (--ipix/--offset/--no-format)") 231 | 232 | __querycat = QueryCatClient() 233 | if __ipix is not None: 234 | __querycat.set_healpix(__ipix) 235 | __querycat.noformat=__noformat 236 | __querycat.noheader=__noheader 237 | 238 | if __offset : 239 | s = __offset.split("..") 240 | if len(s) != 2: raise Exception("error offset syntax: min..max") 241 | try: 242 | __querycat.set_offset(int(s[0]), int(s[1])) 243 | except: 244 | raise Exception("error offset syntax: begin..nb_records") 245 | 246 | if __mime is None or __mime == vizquery.FORMAT_ASCII: 247 | __mime = vizquery.FORMAT_TSV 248 | 249 | else: 250 | __querycat = QueryCatVizieR() 251 | 252 | __querycat.position = __position 253 | __querycat.radius = __radius 254 | 255 | if __mime in (vizquery.FORMAT_TSV, vizquery.FORMAT_VOTABLE, vizquery.FORMAT_ASCII): 256 | __querycat.format = __mime 257 | else: 258 | raise Exception("format not yet available") 259 | 260 | __querycat.query_cat(constraints=__constraints, all=__all, limit=__limit, columns=__add, filename=__filename) 261 | __querycat.print_stdout() 262 | 263 | -------------------------------------------------------------------------------- /cdsclient/find_gsc2_3.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """G.Landais (CDS) 24-mar-2018 3 | Query I/305/out 4 | 5 | find_gsc2_3.py [-h] [-a] [-r radius] [-m max] [constraints] [--format=tsv|votable|ascii] [position] 6 | 7 | -a: display all columns 8 | -r: radius in arcsec 9 | -m: max number of lines in output 10 | -h: this help 11 | --format: output (--format=tsv|votable|ascii) 12 | --noheader: remove header (not available for all options) 13 | --sort : sort by distance (available with position only) 14 | --add : column name in output 15 | --file : query with a list 16 | 17 | position : ra dec position or target name 18 | example: find_gsc2_3.py M1 19 | 20 | Other constraints: 21 | --sort : ... 22 | --add= : ... 23 | --file= : ... 24 | --noheader : ... 25 | --GSC2.3= : ... 26 | --RAJ2000= : ... 27 | --DEJ2000= : ... 28 | --Fmag= : ... 29 | --jmag= : ... 30 | --Vmag= : ... 31 | --Nmag= : ... 32 | 33 | 34 | Example: --GSC2.3=">10" 35 | 36 | Licensed under a BSD license - see LICENSE.txt for details 37 | 38 | """ 39 | 40 | import os, sys 41 | import getopt 42 | import cdsclient.vizquery as vizquery 43 | #import vizquery 44 | 45 | if int(sys.version[0])<3: 46 | from urllib2 import quote 47 | else: 48 | from urllib.parse import quote 49 | 50 | NO_FORMAT = "noformat" 51 | DEBUG = False 52 | 53 | class QueryCat(): 54 | def __init__(self): 55 | self.position = None 56 | self.radius = vizquery.DEFAULT_RADIUS 57 | self.format = None 58 | 59 | def query_cat(self, constraints=None, all = False, limit=vizquery.DEFAULT_LIMIT): 60 | """init constraints parameters 61 | :param constraints: list of constraints ((name,value), ...) 62 | :param all: display all columns(efault False) 63 | :param limit: max number of records 64 | """ 65 | pass 66 | 67 | def get(self): 68 | """get astropy table""" 69 | pass 70 | 71 | def print_stdout(self): 72 | """print the result on stdout""" 73 | pass 74 | 75 | 76 | class QueryCatVizieR(QueryCat): 77 | def __init__(self): 78 | QueryCat.__init__(self) 79 | self.__client = vizquery.CDSClient(default_format=vizquery.FORMAT_ASCII) 80 | self.limit = vizquery.DEFAULT_LIMIT 81 | 82 | def query_cat(self, constraints=None, all=False, limit=vizquery.DEFAULT_LIMIT, columns=None, filename=None): 83 | params = [] 84 | 85 | if self.position: 86 | params.append("-c={0}".format(quote(self.position))) 87 | 88 | if self.radius: 89 | params.append("-c.rs={0:f}".format(self.radius)) 90 | 91 | if all is True: 92 | params.append("-out.all=1") 93 | 94 | if limit is not None: 95 | params.append("-out.max={0:d}".format(limit)) 96 | else: 97 | params.append("-out.max={0:d}".format(self.limit)) 98 | 99 | if columns is not None: 100 | for column in columns: params.append("-out={0}".format(column)) 101 | 102 | file_col = None 103 | if constraints is not None: 104 | for constraint in constraints: 105 | if constraint[1] == "" or constraint[1] == "-": 106 | file_col = constraint[0] 107 | params.append("{0}={1}".format(constraint[0], constraint[1].replace("+","%2B"))) 108 | 109 | if filename is not None: 110 | #params.append("-out.form=hori") 111 | #params.append("-out.add=_1") 112 | 113 | if file_col is not None: 114 | params.append("-sort={0}".format(file_col)) 115 | else: 116 | params.append("-out.add=_r") 117 | params.append("-sort=_r") 118 | 119 | self.__client.query("I/305/out", params=params, filename=filename) 120 | 121 | if self.format is not None: 122 | self.__client.format = self.format 123 | 124 | def get(self): 125 | return self.__client.get() 126 | 127 | def print_stdout(self): 128 | return self.__client.print_stdout() 129 | 130 | 131 | 132 | 133 | if __name__ == "__main__": 134 | 135 | __radius = vizquery.DEFAULT_RADIUS 136 | __position = None 137 | __limit = None 138 | __mime = vizquery.FORMAT_ASCII 139 | __noformat = False 140 | __noheader = False 141 | __ipix = None 142 | __all = False 143 | __sort = False 144 | __add = None 145 | __filename = None 146 | __constraints = [] 147 | __offset = None 148 | 149 | __options = ('help','format=','sort','add=','file=','noheader','GSC2.3=','RAJ2000=','DEJ2000=','Fmag=','jmag=','Vmag=','Nmag=') 150 | try : 151 | __opts, __args = getopt.getopt(sys.argv[1:], 'hvar:m:f:', __options) 152 | except: 153 | help("__main__") 154 | sys.exit(1) 155 | 156 | for __o, __a in __opts: 157 | if __o == '-v': 158 | DEBUG = True 159 | continue 160 | 161 | if __o in ("-h", "--help"): 162 | help("__main__") 163 | sys.exit(1) 164 | 165 | elif __o == "-r": 166 | try: 167 | __radius = float(__a) 168 | except: 169 | sys.stderr.write("(error) wrong radius format\n") 170 | 171 | elif __o == "-m": 172 | try: 173 | __limit = int(__a) 174 | except: 175 | raise Exception("(error) wrong limit/max format") 176 | 177 | elif __o == "-a": 178 | __all = True 179 | 180 | elif __o == "--format": 181 | __mime = __a 182 | 183 | elif __o == "--no-format": 184 | __noformat = True 185 | 186 | elif __o == "--noheader": 187 | __noheader = True 188 | 189 | elif __o == "--ipix": 190 | __ipix = __a 191 | 192 | elif __o == "--count": 193 | __count = True 194 | 195 | elif __o == "--sort": 196 | __sort = True 197 | __constraints.append(("-out.add", "_r")) 198 | __constraints.append(("-sort", "_r")) 199 | 200 | elif __o == "--add": 201 | if __add is None: __add = [] 202 | __add.append(__a) 203 | 204 | elif __o == "--offset": 205 | __offset = __a 206 | continue 207 | 208 | if __o in ("-f", "--file"): 209 | __filename = __a 210 | 211 | else: 212 | for opt in __options[2:]: 213 | value = opt[:len(opt)-1] 214 | if __o[2:] == value: 215 | __constraints.append((value, __a)) 216 | break 217 | 218 | for __arg in __args: 219 | if __position is None: 220 | __position = __arg 221 | else: 222 | __position += " "+ __arg 223 | 224 | if __noformat is True or __ipix is not None or __offset is not None or __noheader: 225 | if __sort is True : 226 | raise Exception("--sort function is not compatible with --ipix/--no-format") 227 | if __filename is not None: 228 | raise Exception("--file option is not compatible with --ipix/--no-format") 229 | 230 | if len(__constraints)>0: 231 | raise Exception("Constraints "+str(__constraints)+" is not available in this mode (--ipix/--offset/--no-format)") 232 | 233 | __querycat = QueryCatClient() 234 | if __ipix is not None: 235 | __querycat.set_healpix(__ipix) 236 | __querycat.noformat=__noformat 237 | __querycat.noheader=__noheader 238 | 239 | if __offset : 240 | s = __offset.split("..") 241 | if len(s) != 2: raise Exception("error offset syntax: min..max") 242 | try: 243 | __querycat.set_offset(int(s[0]), int(s[1])) 244 | except: 245 | raise Exception("error offset syntax: begin..nb_records") 246 | 247 | if __mime is None or __mime == vizquery.FORMAT_ASCII: 248 | __mime = vizquery.FORMAT_TSV 249 | 250 | else: 251 | __querycat = QueryCatVizieR() 252 | 253 | __querycat.position = __position 254 | __querycat.radius = __radius 255 | 256 | if __mime in (vizquery.FORMAT_TSV, vizquery.FORMAT_VOTABLE, vizquery.FORMAT_ASCII): 257 | __querycat.format = __mime 258 | else: 259 | raise Exception("format not yet available") 260 | 261 | __querycat.query_cat(constraints=__constraints, all=__all, limit=__limit, columns=__add, filename=__filename) 262 | __querycat.print_stdout() 263 | 264 | -------------------------------------------------------------------------------- /cdsclient/find_kic.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """G.Landais (CDS) 24-mar-2018 3 | Query V/133/kic 4 | 5 | find_kic.py [-h] [-a] [-r radius] [-m max] [constraints] [--format=tsv|votable|ascii] [position] 6 | 7 | -a: display all columns 8 | -r: radius in arcsec 9 | -m: max number of lines in output 10 | -h: this help 11 | --format: output (--format=tsv|votable|ascii) 12 | --noheader: remove header (not available for all options) 13 | --sort : sort by distance (available with position only) 14 | --add : column name in output 15 | --file : query with a list 16 | 17 | position : ra dec position or target name 18 | example: find_kic.py M1 19 | 20 | Other constraints: 21 | --sort : ... 22 | --add= : ... 23 | --file= : ... 24 | --noheader : ... 25 | --KIC= : ... 26 | --RAJ2000= : ... 27 | --DEJ2000= : ... 28 | --umag= : ... 29 | --gmag= : ... 30 | --rmag= : ... 31 | --imag= : ... 32 | --zmag= : ... 33 | 34 | 35 | Example: --KIC=">10" 36 | 37 | Licensed under a BSD license - see LICENSE.txt for details 38 | 39 | """ 40 | 41 | import os, sys 42 | import getopt 43 | import cdsclient.vizquery as vizquery 44 | #import vizquery 45 | 46 | if int(sys.version[0])<3: 47 | from urllib2 import quote 48 | else: 49 | from urllib.parse import quote 50 | 51 | NO_FORMAT = "noformat" 52 | DEBUG = False 53 | 54 | class QueryCat(): 55 | def __init__(self): 56 | self.position = None 57 | self.radius = vizquery.DEFAULT_RADIUS 58 | self.format = None 59 | 60 | def query_cat(self, constraints=None, all = False, limit=vizquery.DEFAULT_LIMIT): 61 | """init constraints parameters 62 | :param constraints: list of constraints ((name,value), ...) 63 | :param all: display all columns(efault False) 64 | :param limit: max number of records 65 | """ 66 | pass 67 | 68 | def get(self): 69 | """get astropy table""" 70 | pass 71 | 72 | def print_stdout(self): 73 | """print the result on stdout""" 74 | pass 75 | 76 | 77 | class QueryCatVizieR(QueryCat): 78 | def __init__(self): 79 | QueryCat.__init__(self) 80 | self.__client = vizquery.CDSClient(default_format=vizquery.FORMAT_ASCII) 81 | self.limit = vizquery.DEFAULT_LIMIT 82 | 83 | def query_cat(self, constraints=None, all=False, limit=vizquery.DEFAULT_LIMIT, columns=None, filename=None): 84 | params = [] 85 | 86 | if self.position: 87 | params.append("-c={0}".format(quote(self.position))) 88 | 89 | if self.radius: 90 | params.append("-c.rs={0:f}".format(self.radius)) 91 | 92 | if all is True: 93 | params.append("-out.all=1") 94 | 95 | if limit is not None: 96 | params.append("-out.max={0:d}".format(limit)) 97 | else: 98 | params.append("-out.max={0:d}".format(self.limit)) 99 | 100 | if columns is not None: 101 | for column in columns: params.append("-out={0}".format(column)) 102 | 103 | file_col = None 104 | if constraints is not None: 105 | for constraint in constraints: 106 | if constraint[1] == "" or constraint[1] == "-": 107 | file_col = constraint[0] 108 | params.append("{0}={1}".format(constraint[0], constraint[1].replace("+","%2B"))) 109 | 110 | if filename is not None: 111 | #params.append("-out.form=hori") 112 | #params.append("-out.add=_1") 113 | 114 | if file_col is not None: 115 | params.append("-sort={0}".format(file_col)) 116 | else: 117 | params.append("-out.add=_r") 118 | params.append("-sort=_r") 119 | 120 | self.__client.query("V/133/kic", params=params, filename=filename) 121 | 122 | if self.format is not None: 123 | self.__client.format = self.format 124 | 125 | def get(self): 126 | return self.__client.get() 127 | 128 | def print_stdout(self): 129 | return self.__client.print_stdout() 130 | 131 | 132 | 133 | 134 | if __name__ == "__main__": 135 | 136 | __radius = vizquery.DEFAULT_RADIUS 137 | __position = None 138 | __limit = None 139 | __mime = vizquery.FORMAT_ASCII 140 | __noformat = False 141 | __noheader = False 142 | __ipix = None 143 | __all = False 144 | __sort = False 145 | __add = None 146 | __filename = None 147 | __constraints = [] 148 | __offset = None 149 | 150 | __options = ('help','format=','sort','add=','file=','noheader','KIC=','RAJ2000=','DEJ2000=','umag=','gmag=','rmag=','imag=','zmag=') 151 | try : 152 | __opts, __args = getopt.getopt(sys.argv[1:], 'hvar:m:f:', __options) 153 | except: 154 | help("__main__") 155 | sys.exit(1) 156 | 157 | for __o, __a in __opts: 158 | if __o == '-v': 159 | DEBUG = True 160 | continue 161 | 162 | if __o in ("-h", "--help"): 163 | help("__main__") 164 | sys.exit(1) 165 | 166 | elif __o == "-r": 167 | try: 168 | __radius = float(__a) 169 | except: 170 | sys.stderr.write("(error) wrong radius format\n") 171 | 172 | elif __o == "-m": 173 | try: 174 | __limit = int(__a) 175 | except: 176 | raise Exception("(error) wrong limit/max format") 177 | 178 | elif __o == "-a": 179 | __all = True 180 | 181 | elif __o == "--format": 182 | __mime = __a 183 | 184 | elif __o == "--no-format": 185 | __noformat = True 186 | 187 | elif __o == "--noheader": 188 | __noheader = True 189 | 190 | elif __o == "--ipix": 191 | __ipix = __a 192 | 193 | elif __o == "--count": 194 | __count = True 195 | 196 | elif __o == "--sort": 197 | __sort = True 198 | __constraints.append(("-out.add", "_r")) 199 | __constraints.append(("-sort", "_r")) 200 | 201 | elif __o == "--add": 202 | if __add is None: __add = [] 203 | __add.append(__a) 204 | 205 | elif __o == "--offset": 206 | __offset = __a 207 | continue 208 | 209 | if __o in ("-f", "--file"): 210 | __filename = __a 211 | 212 | else: 213 | for opt in __options[2:]: 214 | value = opt[:len(opt)-1] 215 | if __o[2:] == value: 216 | __constraints.append((value, __a)) 217 | break 218 | 219 | for __arg in __args: 220 | if __position is None: 221 | __position = __arg 222 | else: 223 | __position += " "+ __arg 224 | 225 | if __noformat is True or __ipix is not None or __offset is not None or __noheader: 226 | if __sort is True : 227 | raise Exception("--sort function is not compatible with --ipix/--no-format") 228 | if __filename is not None: 229 | raise Exception("--file option is not compatible with --ipix/--no-format") 230 | 231 | if len(__constraints)>0: 232 | raise Exception("Constraints "+str(__constraints)+" is not available in this mode (--ipix/--offset/--no-format)") 233 | 234 | __querycat = QueryCatClient() 235 | if __ipix is not None: 236 | __querycat.set_healpix(__ipix) 237 | __querycat.noformat=__noformat 238 | __querycat.noheader=__noheader 239 | 240 | if __offset : 241 | s = __offset.split("..") 242 | if len(s) != 2: raise Exception("error offset syntax: min..max") 243 | try: 244 | __querycat.set_offset(int(s[0]), int(s[1])) 245 | except: 246 | raise Exception("error offset syntax: begin..nb_records") 247 | 248 | if __mime is None or __mime == vizquery.FORMAT_ASCII: 249 | __mime = vizquery.FORMAT_TSV 250 | 251 | else: 252 | __querycat = QueryCatVizieR() 253 | 254 | __querycat.position = __position 255 | __querycat.radius = __radius 256 | 257 | if __mime in (vizquery.FORMAT_TSV, vizquery.FORMAT_VOTABLE, vizquery.FORMAT_ASCII): 258 | __querycat.format = __mime 259 | else: 260 | raise Exception("format not yet available") 261 | 262 | __querycat.query_cat(constraints=__constraints, all=__all, limit=__limit, columns=__add, filename=__filename) 263 | __querycat.print_stdout() 264 | 265 | -------------------------------------------------------------------------------- /cdsclient/find_spm4.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """G.Landais (CDS) 24-mar-2018 3 | Query I/320/spm4 4 | 5 | find_spm4.py [-h] [-a] [-r radius] [-m max] [constraints] [--format=tsv|votable|ascii] [position] 6 | 7 | -a: display all columns 8 | -r: radius in arcsec 9 | -m: max number of lines in output 10 | -h: this help 11 | --format: output (--format=tsv|votable|ascii) 12 | --noheader: remove header (not available for all options) 13 | --sort : sort by distance (available with position only) 14 | --add : column name in output 15 | --file : query with a list 16 | 17 | position : ra dec position or target name 18 | example: find_spm4.py M1 19 | 20 | Other constraints: 21 | --sort : ... 22 | --add= : ... 23 | --file= : ... 24 | --noheader : ... 25 | --SPMID= : ... 26 | --RAJ2000= : ... 27 | --DEJ2000= : ... 28 | --Bmag= : ... 29 | --Vmag= : ... 30 | --Jmag= : ... 31 | --Hmag= : ... 32 | --Kmag= : ... 33 | 34 | 35 | Example: --SPMID=">10" 36 | 37 | Licensed under a BSD license - see LICENSE.txt for details 38 | 39 | """ 40 | 41 | import os, sys 42 | import getopt 43 | import cdsclient.vizquery as vizquery 44 | #import vizquery 45 | 46 | if int(sys.version[0])<3: 47 | from urllib2 import quote 48 | else: 49 | from urllib.parse import quote 50 | 51 | NO_FORMAT = "noformat" 52 | DEBUG = False 53 | 54 | class QueryCat(): 55 | def __init__(self): 56 | self.position = None 57 | self.radius = vizquery.DEFAULT_RADIUS 58 | self.format = None 59 | 60 | def query_cat(self, constraints=None, all = False, limit=vizquery.DEFAULT_LIMIT): 61 | """init constraints parameters 62 | :param constraints: list of constraints ((name,value), ...) 63 | :param all: display all columns(efault False) 64 | :param limit: max number of records 65 | """ 66 | pass 67 | 68 | def get(self): 69 | """get astropy table""" 70 | pass 71 | 72 | def print_stdout(self): 73 | """print the result on stdout""" 74 | pass 75 | 76 | 77 | class QueryCatVizieR(QueryCat): 78 | def __init__(self): 79 | QueryCat.__init__(self) 80 | self.__client = vizquery.CDSClient(default_format=vizquery.FORMAT_ASCII) 81 | self.limit = vizquery.DEFAULT_LIMIT 82 | 83 | def query_cat(self, constraints=None, all=False, limit=vizquery.DEFAULT_LIMIT, columns=None, filename=None): 84 | params = [] 85 | 86 | if self.position: 87 | params.append("-c={0}".format(quote(self.position))) 88 | 89 | if self.radius: 90 | params.append("-c.rs={0:f}".format(self.radius)) 91 | 92 | if all is True: 93 | params.append("-out.all=1") 94 | 95 | if limit is not None: 96 | params.append("-out.max={0:d}".format(limit)) 97 | else: 98 | params.append("-out.max={0:d}".format(self.limit)) 99 | 100 | if columns is not None: 101 | for column in columns: params.append("-out={0}".format(column)) 102 | 103 | file_col = None 104 | if constraints is not None: 105 | for constraint in constraints: 106 | if constraint[1] == "" or constraint[1] == "-": 107 | file_col = constraint[0] 108 | params.append("{0}={1}".format(constraint[0], constraint[1].replace("+","%2B"))) 109 | 110 | if filename is not None: 111 | #params.append("-out.form=hori") 112 | #params.append("-out.add=_1") 113 | 114 | if file_col is not None: 115 | params.append("-sort={0}".format(file_col)) 116 | else: 117 | params.append("-out.add=_r") 118 | params.append("-sort=_r") 119 | 120 | self.__client.query("I/320/spm4", params=params, filename=filename) 121 | 122 | if self.format is not None: 123 | self.__client.format = self.format 124 | 125 | def get(self): 126 | return self.__client.get() 127 | 128 | def print_stdout(self): 129 | return self.__client.print_stdout() 130 | 131 | 132 | 133 | 134 | if __name__ == "__main__": 135 | 136 | __radius = vizquery.DEFAULT_RADIUS 137 | __position = None 138 | __limit = None 139 | __mime = vizquery.FORMAT_ASCII 140 | __noformat = False 141 | __noheader = False 142 | __ipix = None 143 | __all = False 144 | __sort = False 145 | __add = None 146 | __filename = None 147 | __constraints = [] 148 | __offset = None 149 | 150 | __options = ('help','format=','sort','add=','file=','noheader','SPMID=','RAJ2000=','DEJ2000=','Bmag=','Vmag=','Jmag=','Hmag=','Kmag=') 151 | try : 152 | __opts, __args = getopt.getopt(sys.argv[1:], 'hvar:m:f:', __options) 153 | except: 154 | help("__main__") 155 | sys.exit(1) 156 | 157 | for __o, __a in __opts: 158 | if __o == '-v': 159 | DEBUG = True 160 | continue 161 | 162 | if __o in ("-h", "--help"): 163 | help("__main__") 164 | sys.exit(1) 165 | 166 | elif __o == "-r": 167 | try: 168 | __radius = float(__a) 169 | except: 170 | sys.stderr.write("(error) wrong radius format\n") 171 | 172 | elif __o == "-m": 173 | try: 174 | __limit = int(__a) 175 | except: 176 | raise Exception("(error) wrong limit/max format") 177 | 178 | elif __o == "-a": 179 | __all = True 180 | 181 | elif __o == "--format": 182 | __mime = __a 183 | 184 | elif __o == "--no-format": 185 | __noformat = True 186 | 187 | elif __o == "--noheader": 188 | __noheader = True 189 | 190 | elif __o == "--ipix": 191 | __ipix = __a 192 | 193 | elif __o == "--count": 194 | __count = True 195 | 196 | elif __o == "--sort": 197 | __sort = True 198 | __constraints.append(("-out.add", "_r")) 199 | __constraints.append(("-sort", "_r")) 200 | 201 | elif __o == "--add": 202 | if __add is None: __add = [] 203 | __add.append(__a) 204 | 205 | elif __o == "--offset": 206 | __offset = __a 207 | continue 208 | 209 | if __o in ("-f", "--file"): 210 | __filename = __a 211 | 212 | else: 213 | for opt in __options[2:]: 214 | value = opt[:len(opt)-1] 215 | if __o[2:] == value: 216 | __constraints.append((value, __a)) 217 | break 218 | 219 | for __arg in __args: 220 | if __position is None: 221 | __position = __arg 222 | else: 223 | __position += " "+ __arg 224 | 225 | if __noformat is True or __ipix is not None or __offset is not None or __noheader: 226 | if __sort is True : 227 | raise Exception("--sort function is not compatible with --ipix/--no-format") 228 | if __filename is not None: 229 | raise Exception("--file option is not compatible with --ipix/--no-format") 230 | 231 | if len(__constraints)>0: 232 | raise Exception("Constraints "+str(__constraints)+" is not available in this mode (--ipix/--offset/--no-format)") 233 | 234 | __querycat = QueryCatClient() 235 | if __ipix is not None: 236 | __querycat.set_healpix(__ipix) 237 | __querycat.noformat=__noformat 238 | __querycat.noheader=__noheader 239 | 240 | if __offset : 241 | s = __offset.split("..") 242 | if len(s) != 2: raise Exception("error offset syntax: min..max") 243 | try: 244 | __querycat.set_offset(int(s[0]), int(s[1])) 245 | except: 246 | raise Exception("error offset syntax: begin..nb_records") 247 | 248 | if __mime is None or __mime == vizquery.FORMAT_ASCII: 249 | __mime = vizquery.FORMAT_TSV 250 | 251 | else: 252 | __querycat = QueryCatVizieR() 253 | 254 | __querycat.position = __position 255 | __querycat.radius = __radius 256 | 257 | if __mime in (vizquery.FORMAT_TSV, vizquery.FORMAT_VOTABLE, vizquery.FORMAT_ASCII): 258 | __querycat.format = __mime 259 | else: 260 | raise Exception("format not yet available") 261 | 262 | __querycat.query_cat(constraints=__constraints, all=__all, limit=__limit, columns=__add, filename=__filename) 263 | __querycat.print_stdout() 264 | 265 | -------------------------------------------------------------------------------- /cdsclient/find_ucac4.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """G.Landais (CDS) 24-mar-2018 3 | Query I/322A/out 4 | 5 | find_ucac4.py [-h] [-a] [-r radius] [-m max] [constraints] [--format=tsv|votable|ascii] [position] 6 | 7 | -a: display all columns 8 | -r: radius in arcsec 9 | -m: max number of lines in output 10 | -h: this help 11 | --format: output (--format=tsv|votable|ascii) 12 | --noheader: remove header (not available for all options) 13 | --sort : sort by distance (available with position only) 14 | --add : column name in output 15 | --file : query with a list 16 | 17 | position : ra dec position or target name 18 | example: find_ucac4.py M1 19 | 20 | Other constraints: 21 | --sort : ... 22 | --add= : ... 23 | --file= : ... 24 | --noheader : ... 25 | --UCAC4= : ... 26 | --RAJ2000= : ... 27 | --DEJ2000= : ... 28 | --Jmag= : ... 29 | --Hmag= : ... 30 | --Kmag= : ... 31 | --Bmag= : ... 32 | --Vmag= : ... 33 | 34 | 35 | Example: --UCAC4=">10" 36 | 37 | Licensed under a BSD license - see LICENSE.txt for details 38 | 39 | """ 40 | 41 | import os, sys 42 | import getopt 43 | import cdsclient.vizquery as vizquery 44 | #import vizquery 45 | 46 | if int(sys.version[0])<3: 47 | from urllib2 import quote 48 | else: 49 | from urllib.parse import quote 50 | 51 | NO_FORMAT = "noformat" 52 | DEBUG = False 53 | 54 | class QueryCat(): 55 | def __init__(self): 56 | self.position = None 57 | self.radius = vizquery.DEFAULT_RADIUS 58 | self.format = None 59 | 60 | def query_cat(self, constraints=None, all = False, limit=vizquery.DEFAULT_LIMIT): 61 | """init constraints parameters 62 | :param constraints: list of constraints ((name,value), ...) 63 | :param all: display all columns(efault False) 64 | :param limit: max number of records 65 | """ 66 | pass 67 | 68 | def get(self): 69 | """get astropy table""" 70 | pass 71 | 72 | def print_stdout(self): 73 | """print the result on stdout""" 74 | pass 75 | 76 | 77 | class QueryCatVizieR(QueryCat): 78 | def __init__(self): 79 | QueryCat.__init__(self) 80 | self.__client = vizquery.CDSClient(default_format=vizquery.FORMAT_ASCII) 81 | self.limit = vizquery.DEFAULT_LIMIT 82 | 83 | def query_cat(self, constraints=None, all=False, limit=vizquery.DEFAULT_LIMIT, columns=None, filename=None): 84 | params = [] 85 | 86 | if self.position: 87 | params.append("-c={0}".format(quote(self.position))) 88 | 89 | if self.radius: 90 | params.append("-c.rs={0:f}".format(self.radius)) 91 | 92 | if all is True: 93 | params.append("-out.all=1") 94 | 95 | if limit is not None: 96 | params.append("-out.max={0:d}".format(limit)) 97 | else: 98 | params.append("-out.max={0:d}".format(self.limit)) 99 | 100 | if columns is not None: 101 | for column in columns: params.append("-out={0}".format(column)) 102 | 103 | file_col = None 104 | if constraints is not None: 105 | for constraint in constraints: 106 | if constraint[1] == "" or constraint[1] == "-": 107 | file_col = constraint[0] 108 | params.append("{0}={1}".format(constraint[0], constraint[1].replace("+","%2B"))) 109 | 110 | if filename is not None: 111 | #params.append("-out.form=hori") 112 | #params.append("-out.add=_1") 113 | 114 | if file_col is not None: 115 | params.append("-sort={0}".format(file_col)) 116 | else: 117 | params.append("-out.add=_r") 118 | params.append("-sort=_r") 119 | 120 | self.__client.query("I/322A/out", params=params, filename=filename) 121 | 122 | if self.format is not None: 123 | self.__client.format = self.format 124 | 125 | def get(self): 126 | return self.__client.get() 127 | 128 | def print_stdout(self): 129 | return self.__client.print_stdout() 130 | 131 | 132 | 133 | 134 | if __name__ == "__main__": 135 | 136 | __radius = vizquery.DEFAULT_RADIUS 137 | __position = None 138 | __limit = None 139 | __mime = vizquery.FORMAT_ASCII 140 | __noformat = False 141 | __noheader = False 142 | __ipix = None 143 | __all = False 144 | __sort = False 145 | __add = None 146 | __filename = None 147 | __constraints = [] 148 | __offset = None 149 | 150 | __options = ('help','format=','sort','add=','file=','noheader','UCAC4=','RAJ2000=','DEJ2000=','Jmag=','Hmag=','Kmag=','Bmag=','Vmag=') 151 | try : 152 | __opts, __args = getopt.getopt(sys.argv[1:], 'hvar:m:f:', __options) 153 | except: 154 | help("__main__") 155 | sys.exit(1) 156 | 157 | for __o, __a in __opts: 158 | if __o == '-v': 159 | DEBUG = True 160 | continue 161 | 162 | if __o in ("-h", "--help"): 163 | help("__main__") 164 | sys.exit(1) 165 | 166 | elif __o == "-r": 167 | try: 168 | __radius = float(__a) 169 | except: 170 | sys.stderr.write("(error) wrong radius format\n") 171 | 172 | elif __o == "-m": 173 | try: 174 | __limit = int(__a) 175 | except: 176 | raise Exception("(error) wrong limit/max format") 177 | 178 | elif __o == "-a": 179 | __all = True 180 | 181 | elif __o == "--format": 182 | __mime = __a 183 | 184 | elif __o == "--no-format": 185 | __noformat = True 186 | 187 | elif __o == "--noheader": 188 | __noheader = True 189 | 190 | elif __o == "--ipix": 191 | __ipix = __a 192 | 193 | elif __o == "--count": 194 | __count = True 195 | 196 | elif __o == "--sort": 197 | __sort = True 198 | __constraints.append(("-out.add", "_r")) 199 | __constraints.append(("-sort", "_r")) 200 | 201 | elif __o == "--add": 202 | if __add is None: __add = [] 203 | __add.append(__a) 204 | 205 | elif __o == "--offset": 206 | __offset = __a 207 | continue 208 | 209 | if __o in ("-f", "--file"): 210 | __filename = __a 211 | 212 | else: 213 | for opt in __options[2:]: 214 | value = opt[:len(opt)-1] 215 | if __o[2:] == value: 216 | __constraints.append((value, __a)) 217 | break 218 | 219 | for __arg in __args: 220 | if __position is None: 221 | __position = __arg 222 | else: 223 | __position += " "+ __arg 224 | 225 | if __noformat is True or __ipix is not None or __offset is not None or __noheader: 226 | if __sort is True : 227 | raise Exception("--sort function is not compatible with --ipix/--no-format") 228 | if __filename is not None: 229 | raise Exception("--file option is not compatible with --ipix/--no-format") 230 | 231 | if len(__constraints)>0: 232 | raise Exception("Constraints "+str(__constraints)+" is not available in this mode (--ipix/--offset/--no-format)") 233 | 234 | __querycat = QueryCatClient() 235 | if __ipix is not None: 236 | __querycat.set_healpix(__ipix) 237 | __querycat.noformat=__noformat 238 | __querycat.noheader=__noheader 239 | 240 | if __offset : 241 | s = __offset.split("..") 242 | if len(s) != 2: raise Exception("error offset syntax: min..max") 243 | try: 244 | __querycat.set_offset(int(s[0]), int(s[1])) 245 | except: 246 | raise Exception("error offset syntax: begin..nb_records") 247 | 248 | if __mime is None or __mime == vizquery.FORMAT_ASCII: 249 | __mime = vizquery.FORMAT_TSV 250 | 251 | else: 252 | __querycat = QueryCatVizieR() 253 | 254 | __querycat.position = __position 255 | __querycat.radius = __radius 256 | 257 | if __mime in (vizquery.FORMAT_TSV, vizquery.FORMAT_VOTABLE, vizquery.FORMAT_ASCII): 258 | __querycat.format = __mime 259 | else: 260 | raise Exception("format not yet available") 261 | 262 | __querycat.query_cat(constraints=__constraints, all=__all, limit=__limit, columns=__add, filename=__filename) 263 | __querycat.print_stdout() 264 | 265 | -------------------------------------------------------------------------------- /cdsclient/find_sdss8.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """G.Landais (CDS) 24-mar-2018 3 | Query II/306/sdss8 4 | 5 | find_sdss8.py [-h] [-a] [-r radius] [-m max] [constraints] [--format=tsv|votable|ascii] [position] 6 | 7 | -a: display all columns 8 | -r: radius in arcsec 9 | -m: max number of lines in output 10 | -h: this help 11 | --format: output (--format=tsv|votable|ascii) 12 | --noheader: remove header (not available for all options) 13 | --sort : sort by distance (available with position only) 14 | --add : column name in output 15 | --file : query with a list 16 | 17 | position : ra dec position or target name 18 | example: find_sdss8.py M1 19 | 20 | Other constraints: 21 | --sort : ... 22 | --add= : ... 23 | --file= : ... 24 | --noheader : ... 25 | --SDSS8= : ... 26 | --RA_ICRS= : ... 27 | --DE_ICRS= : ... 28 | --umag= : ... 29 | --gmag= : ... 30 | --rmag= : ... 31 | --imag= : ... 32 | --zmag= : ... 33 | 34 | 35 | Example: --SDSS8=">10" 36 | 37 | Licensed under a BSD license - see LICENSE.txt for details 38 | 39 | """ 40 | 41 | import os, sys 42 | import getopt 43 | import cdsclient.vizquery as vizquery 44 | #import vizquery 45 | 46 | if int(sys.version[0])<3: 47 | from urllib2 import quote 48 | else: 49 | from urllib.parse import quote 50 | 51 | NO_FORMAT = "noformat" 52 | DEBUG = False 53 | 54 | class QueryCat(): 55 | def __init__(self): 56 | self.position = None 57 | self.radius = vizquery.DEFAULT_RADIUS 58 | self.format = None 59 | 60 | def query_cat(self, constraints=None, all = False, limit=vizquery.DEFAULT_LIMIT): 61 | """init constraints parameters 62 | :param constraints: list of constraints ((name,value), ...) 63 | :param all: display all columns(efault False) 64 | :param limit: max number of records 65 | """ 66 | pass 67 | 68 | def get(self): 69 | """get astropy table""" 70 | pass 71 | 72 | def print_stdout(self): 73 | """print the result on stdout""" 74 | pass 75 | 76 | 77 | class QueryCatVizieR(QueryCat): 78 | def __init__(self): 79 | QueryCat.__init__(self) 80 | self.__client = vizquery.CDSClient(default_format=vizquery.FORMAT_ASCII) 81 | self.limit = vizquery.DEFAULT_LIMIT 82 | 83 | def query_cat(self, constraints=None, all=False, limit=vizquery.DEFAULT_LIMIT, columns=None, filename=None): 84 | params = [] 85 | 86 | if self.position: 87 | params.append("-c={0}".format(quote(self.position))) 88 | 89 | if self.radius: 90 | params.append("-c.rs={0:f}".format(self.radius)) 91 | 92 | if all is True: 93 | params.append("-out.all=1") 94 | 95 | if limit is not None: 96 | params.append("-out.max={0:d}".format(limit)) 97 | else: 98 | params.append("-out.max={0:d}".format(self.limit)) 99 | 100 | if columns is not None: 101 | for column in columns: params.append("-out={0}".format(column)) 102 | 103 | file_col = None 104 | if constraints is not None: 105 | for constraint in constraints: 106 | if constraint[1] == "" or constraint[1] == "-": 107 | file_col = constraint[0] 108 | params.append("{0}={1}".format(constraint[0], constraint[1].replace("+","%2B"))) 109 | 110 | if filename is not None: 111 | #params.append("-out.form=hori") 112 | #params.append("-out.add=_1") 113 | 114 | if file_col is not None: 115 | params.append("-sort={0}".format(file_col)) 116 | else: 117 | params.append("-out.add=_r") 118 | params.append("-sort=_r") 119 | 120 | self.__client.query("II/306/sdss8", params=params, filename=filename) 121 | 122 | if self.format is not None: 123 | self.__client.format = self.format 124 | 125 | def get(self): 126 | return self.__client.get() 127 | 128 | def print_stdout(self): 129 | return self.__client.print_stdout() 130 | 131 | 132 | 133 | 134 | if __name__ == "__main__": 135 | 136 | __radius = vizquery.DEFAULT_RADIUS 137 | __position = None 138 | __limit = None 139 | __mime = vizquery.FORMAT_ASCII 140 | __noformat = False 141 | __noheader = False 142 | __ipix = None 143 | __all = False 144 | __sort = False 145 | __add = None 146 | __filename = None 147 | __constraints = [] 148 | __offset = None 149 | 150 | __options = ('help','format=','sort','add=','file=','noheader','SDSS8=','RA_ICRS=','DE_ICRS=','umag=','gmag=','rmag=','imag=','zmag=') 151 | try : 152 | __opts, __args = getopt.getopt(sys.argv[1:], 'hvar:m:f:', __options) 153 | except: 154 | help("__main__") 155 | sys.exit(1) 156 | 157 | for __o, __a in __opts: 158 | if __o == '-v': 159 | DEBUG = True 160 | continue 161 | 162 | if __o in ("-h", "--help"): 163 | help("__main__") 164 | sys.exit(1) 165 | 166 | elif __o == "-r": 167 | try: 168 | __radius = float(__a) 169 | except: 170 | sys.stderr.write("(error) wrong radius format\n") 171 | 172 | elif __o == "-m": 173 | try: 174 | __limit = int(__a) 175 | except: 176 | raise Exception("(error) wrong limit/max format") 177 | 178 | elif __o == "-a": 179 | __all = True 180 | 181 | elif __o == "--format": 182 | __mime = __a 183 | 184 | elif __o == "--no-format": 185 | __noformat = True 186 | 187 | elif __o == "--noheader": 188 | __noheader = True 189 | 190 | elif __o == "--ipix": 191 | __ipix = __a 192 | 193 | elif __o == "--count": 194 | __count = True 195 | 196 | elif __o == "--sort": 197 | __sort = True 198 | __constraints.append(("-out.add", "_r")) 199 | __constraints.append(("-sort", "_r")) 200 | 201 | elif __o == "--add": 202 | if __add is None: __add = [] 203 | __add.append(__a) 204 | 205 | elif __o == "--offset": 206 | __offset = __a 207 | continue 208 | 209 | if __o in ("-f", "--file"): 210 | __filename = __a 211 | 212 | else: 213 | for opt in __options[2:]: 214 | value = opt[:len(opt)-1] 215 | if __o[2:] == value: 216 | __constraints.append((value, __a)) 217 | break 218 | 219 | for __arg in __args: 220 | if __position is None: 221 | __position = __arg 222 | else: 223 | __position += " "+ __arg 224 | 225 | if __noformat is True or __ipix is not None or __offset is not None or __noheader: 226 | if __sort is True : 227 | raise Exception("--sort function is not compatible with --ipix/--no-format") 228 | if __filename is not None: 229 | raise Exception("--file option is not compatible with --ipix/--no-format") 230 | 231 | if len(__constraints)>0: 232 | raise Exception("Constraints "+str(__constraints)+" is not available in this mode (--ipix/--offset/--no-format)") 233 | 234 | __querycat = QueryCatClient() 235 | if __ipix is not None: 236 | __querycat.set_healpix(__ipix) 237 | __querycat.noformat=__noformat 238 | __querycat.noheader=__noheader 239 | 240 | if __offset : 241 | s = __offset.split("..") 242 | if len(s) != 2: raise Exception("error offset syntax: min..max") 243 | try: 244 | __querycat.set_offset(int(s[0]), int(s[1])) 245 | except: 246 | raise Exception("error offset syntax: begin..nb_records") 247 | 248 | if __mime is None or __mime == vizquery.FORMAT_ASCII: 249 | __mime = vizquery.FORMAT_TSV 250 | 251 | else: 252 | __querycat = QueryCatVizieR() 253 | 254 | __querycat.position = __position 255 | __querycat.radius = __radius 256 | 257 | if __mime in (vizquery.FORMAT_TSV, vizquery.FORMAT_VOTABLE, vizquery.FORMAT_ASCII): 258 | __querycat.format = __mime 259 | else: 260 | raise Exception("format not yet available") 261 | 262 | __querycat.query_cat(constraints=__constraints, all=__all, limit=__limit, columns=__add, filename=__filename) 263 | __querycat.print_stdout() 264 | 265 | -------------------------------------------------------------------------------- /cdsclient/find_usnob1.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """G.Landais (CDS) 24-mar-2018 3 | Query I/284/out 4 | 5 | find_usnob1.py [-h] [-a] [-r radius] [-m max] [constraints] [--format=tsv|votable|ascii] [position] 6 | 7 | -a: display all columns 8 | -r: radius in arcsec 9 | -m: max number of lines in output 10 | -h: this help 11 | --format: output (--format=tsv|votable|ascii) 12 | --noheader: remove header (not available for all options) 13 | --sort : sort by distance (available with position only) 14 | --add : column name in output 15 | --file : query with a list 16 | 17 | position : ra dec position or target name 18 | example: find_usnob1.py M1 19 | 20 | Other constraints: 21 | --sort : ... 22 | --add= : ... 23 | --file= : ... 24 | --noheader : ... 25 | --USNO-B1.0= : ... 26 | --RAJ2000= : ... 27 | --DEJ2000= : ... 28 | --B1mag= : ... 29 | --R1mag= : ... 30 | --B2mag= : ... 31 | --R2mag= : ... 32 | --Imag= : ... 33 | 34 | 35 | Example: --USNO-B1.0=">10" 36 | 37 | Licensed under a BSD license - see LICENSE.txt for details 38 | 39 | """ 40 | 41 | import os, sys 42 | import getopt 43 | import cdsclient.vizquery as vizquery 44 | #import vizquery 45 | 46 | if int(sys.version[0])<3: 47 | from urllib2 import quote 48 | else: 49 | from urllib.parse import quote 50 | 51 | NO_FORMAT = "noformat" 52 | DEBUG = False 53 | 54 | class QueryCat(): 55 | def __init__(self): 56 | self.position = None 57 | self.radius = vizquery.DEFAULT_RADIUS 58 | self.format = None 59 | 60 | def query_cat(self, constraints=None, all = False, limit=vizquery.DEFAULT_LIMIT): 61 | """init constraints parameters 62 | :param constraints: list of constraints ((name,value), ...) 63 | :param all: display all columns(efault False) 64 | :param limit: max number of records 65 | """ 66 | pass 67 | 68 | def get(self): 69 | """get astropy table""" 70 | pass 71 | 72 | def print_stdout(self): 73 | """print the result on stdout""" 74 | pass 75 | 76 | 77 | class QueryCatVizieR(QueryCat): 78 | def __init__(self): 79 | QueryCat.__init__(self) 80 | self.__client = vizquery.CDSClient(default_format=vizquery.FORMAT_ASCII) 81 | self.limit = vizquery.DEFAULT_LIMIT 82 | 83 | def query_cat(self, constraints=None, all=False, limit=vizquery.DEFAULT_LIMIT, columns=None, filename=None): 84 | params = [] 85 | 86 | if self.position: 87 | params.append("-c={0}".format(quote(self.position))) 88 | 89 | if self.radius: 90 | params.append("-c.rs={0:f}".format(self.radius)) 91 | 92 | if all is True: 93 | params.append("-out.all=1") 94 | 95 | if limit is not None: 96 | params.append("-out.max={0:d}".format(limit)) 97 | else: 98 | params.append("-out.max={0:d}".format(self.limit)) 99 | 100 | if columns is not None: 101 | for column in columns: params.append("-out={0}".format(column)) 102 | 103 | file_col = None 104 | if constraints is not None: 105 | for constraint in constraints: 106 | if constraint[1] == "" or constraint[1] == "-": 107 | file_col = constraint[0] 108 | params.append("{0}={1}".format(constraint[0], constraint[1].replace("+","%2B"))) 109 | 110 | if filename is not None: 111 | #params.append("-out.form=hori") 112 | #params.append("-out.add=_1") 113 | 114 | if file_col is not None: 115 | params.append("-sort={0}".format(file_col)) 116 | else: 117 | params.append("-out.add=_r") 118 | params.append("-sort=_r") 119 | 120 | self.__client.query("I/284/out", params=params, filename=filename) 121 | 122 | if self.format is not None: 123 | self.__client.format = self.format 124 | 125 | def get(self): 126 | return self.__client.get() 127 | 128 | def print_stdout(self): 129 | return self.__client.print_stdout() 130 | 131 | 132 | 133 | 134 | if __name__ == "__main__": 135 | 136 | __radius = vizquery.DEFAULT_RADIUS 137 | __position = None 138 | __limit = None 139 | __mime = vizquery.FORMAT_ASCII 140 | __noformat = False 141 | __noheader = False 142 | __ipix = None 143 | __all = False 144 | __sort = False 145 | __add = None 146 | __filename = None 147 | __constraints = [] 148 | __offset = None 149 | 150 | __options = ('help','format=','sort','add=','file=','noheader','USNO-B1.0=','RAJ2000=','DEJ2000=','B1mag=','R1mag=','B2mag=','R2mag=','Imag=') 151 | try : 152 | __opts, __args = getopt.getopt(sys.argv[1:], 'hvar:m:f:', __options) 153 | except: 154 | help("__main__") 155 | sys.exit(1) 156 | 157 | for __o, __a in __opts: 158 | if __o == '-v': 159 | DEBUG = True 160 | continue 161 | 162 | if __o in ("-h", "--help"): 163 | help("__main__") 164 | sys.exit(1) 165 | 166 | elif __o == "-r": 167 | try: 168 | __radius = float(__a) 169 | except: 170 | sys.stderr.write("(error) wrong radius format\n") 171 | 172 | elif __o == "-m": 173 | try: 174 | __limit = int(__a) 175 | except: 176 | raise Exception("(error) wrong limit/max format") 177 | 178 | elif __o == "-a": 179 | __all = True 180 | 181 | elif __o == "--format": 182 | __mime = __a 183 | 184 | elif __o == "--no-format": 185 | __noformat = True 186 | 187 | elif __o == "--noheader": 188 | __noheader = True 189 | 190 | elif __o == "--ipix": 191 | __ipix = __a 192 | 193 | elif __o == "--count": 194 | __count = True 195 | 196 | elif __o == "--sort": 197 | __sort = True 198 | __constraints.append(("-out.add", "_r")) 199 | __constraints.append(("-sort", "_r")) 200 | 201 | elif __o == "--add": 202 | if __add is None: __add = [] 203 | __add.append(__a) 204 | 205 | elif __o == "--offset": 206 | __offset = __a 207 | continue 208 | 209 | if __o in ("-f", "--file"): 210 | __filename = __a 211 | 212 | else: 213 | for opt in __options[2:]: 214 | value = opt[:len(opt)-1] 215 | if __o[2:] == value: 216 | __constraints.append((value, __a)) 217 | break 218 | 219 | for __arg in __args: 220 | if __position is None: 221 | __position = __arg 222 | else: 223 | __position += " "+ __arg 224 | 225 | if __noformat is True or __ipix is not None or __offset is not None or __noheader: 226 | if __sort is True : 227 | raise Exception("--sort function is not compatible with --ipix/--no-format") 228 | if __filename is not None: 229 | raise Exception("--file option is not compatible with --ipix/--no-format") 230 | 231 | if len(__constraints)>0: 232 | raise Exception("Constraints "+str(__constraints)+" is not available in this mode (--ipix/--offset/--no-format)") 233 | 234 | __querycat = QueryCatClient() 235 | if __ipix is not None: 236 | __querycat.set_healpix(__ipix) 237 | __querycat.noformat=__noformat 238 | __querycat.noheader=__noheader 239 | 240 | if __offset : 241 | s = __offset.split("..") 242 | if len(s) != 2: raise Exception("error offset syntax: min..max") 243 | try: 244 | __querycat.set_offset(int(s[0]), int(s[1])) 245 | except: 246 | raise Exception("error offset syntax: begin..nb_records") 247 | 248 | if __mime is None or __mime == vizquery.FORMAT_ASCII: 249 | __mime = vizquery.FORMAT_TSV 250 | 251 | else: 252 | __querycat = QueryCatVizieR() 253 | 254 | __querycat.position = __position 255 | __querycat.radius = __radius 256 | 257 | if __mime in (vizquery.FORMAT_TSV, vizquery.FORMAT_VOTABLE, vizquery.FORMAT_ASCII): 258 | __querycat.format = __mime 259 | else: 260 | raise Exception("format not yet available") 261 | 262 | __querycat.query_cat(constraints=__constraints, all=__all, limit=__limit, columns=__add, filename=__filename) 263 | __querycat.print_stdout() 264 | 265 | -------------------------------------------------------------------------------- /cdsclient/find_sdss9.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """G.Landais (CDS) 24-mar-2018 3 | Query V/139/sdss9 4 | 5 | find_sdss9.py [-h] [-a] [-r radius] [-m max] [constraints] [--format=tsv|votable|ascii] [position] 6 | 7 | -a: display all columns 8 | -r: radius in arcsec 9 | -m: max number of lines in output 10 | -h: this help 11 | --format: output (--format=tsv|votable|ascii) 12 | --noheader: remove header (not available for all options) 13 | --sort : sort by distance (available with position only) 14 | --add : column name in output 15 | --file : query with a list 16 | 17 | position : ra dec position or target name 18 | example: find_sdss9.py M1 19 | 20 | Other constraints: 21 | --sort : ... 22 | --add= : ... 23 | --file= : ... 24 | --noheader : ... 25 | --SDSS9= : ... 26 | --SDSS-ID= : ... 27 | --objID= : ... 28 | --Sp-ID= : ... 29 | --RA_ICRS= : ... 30 | --DE_ICRS= : ... 31 | --umag= : ... 32 | --gmag= : ... 33 | --rmag= : ... 34 | --imag= : ... 35 | --zmag= : ... 36 | 37 | 38 | Example: --SDSS9=">10" 39 | 40 | Licensed under a BSD license - see LICENSE.txt for details 41 | 42 | """ 43 | 44 | import os, sys 45 | import getopt 46 | import cdsclient.vizquery as vizquery 47 | #import vizquery 48 | 49 | if int(sys.version[0])<3: 50 | from urllib2 import quote 51 | else: 52 | from urllib.parse import quote 53 | 54 | NO_FORMAT = "noformat" 55 | DEBUG = False 56 | 57 | class QueryCat(): 58 | def __init__(self): 59 | self.position = None 60 | self.radius = vizquery.DEFAULT_RADIUS 61 | self.format = None 62 | 63 | def query_cat(self, constraints=None, all = False, limit=vizquery.DEFAULT_LIMIT): 64 | """init constraints parameters 65 | :param constraints: list of constraints ((name,value), ...) 66 | :param all: display all columns(efault False) 67 | :param limit: max number of records 68 | """ 69 | pass 70 | 71 | def get(self): 72 | """get astropy table""" 73 | pass 74 | 75 | def print_stdout(self): 76 | """print the result on stdout""" 77 | pass 78 | 79 | 80 | class QueryCatVizieR(QueryCat): 81 | def __init__(self): 82 | QueryCat.__init__(self) 83 | self.__client = vizquery.CDSClient(default_format=vizquery.FORMAT_ASCII) 84 | self.limit = vizquery.DEFAULT_LIMIT 85 | 86 | def query_cat(self, constraints=None, all=False, limit=vizquery.DEFAULT_LIMIT, columns=None, filename=None): 87 | params = [] 88 | 89 | if self.position: 90 | params.append("-c={0}".format(quote(self.position))) 91 | 92 | if self.radius: 93 | params.append("-c.rs={0:f}".format(self.radius)) 94 | 95 | if all is True: 96 | params.append("-out.all=1") 97 | 98 | if limit is not None: 99 | params.append("-out.max={0:d}".format(limit)) 100 | else: 101 | params.append("-out.max={0:d}".format(self.limit)) 102 | 103 | if columns is not None: 104 | for column in columns: params.append("-out={0}".format(column)) 105 | 106 | file_col = None 107 | if constraints is not None: 108 | for constraint in constraints: 109 | if constraint[1] == "" or constraint[1] == "-": 110 | file_col = constraint[0] 111 | params.append("{0}={1}".format(constraint[0], constraint[1].replace("+","%2B"))) 112 | 113 | if filename is not None: 114 | #params.append("-out.form=hori") 115 | #params.append("-out.add=_1") 116 | 117 | if file_col is not None: 118 | params.append("-sort={0}".format(file_col)) 119 | else: 120 | params.append("-out.add=_r") 121 | params.append("-sort=_r") 122 | 123 | self.__client.query("V/139/sdss9", params=params, filename=filename) 124 | 125 | if self.format is not None: 126 | self.__client.format = self.format 127 | 128 | def get(self): 129 | return self.__client.get() 130 | 131 | def print_stdout(self): 132 | return self.__client.print_stdout() 133 | 134 | 135 | 136 | 137 | if __name__ == "__main__": 138 | 139 | __radius = vizquery.DEFAULT_RADIUS 140 | __position = None 141 | __limit = None 142 | __mime = vizquery.FORMAT_ASCII 143 | __noformat = False 144 | __noheader = False 145 | __ipix = None 146 | __all = False 147 | __sort = False 148 | __add = None 149 | __filename = None 150 | __constraints = [] 151 | __offset = None 152 | 153 | __options = ('help','format=','sort','add=','file=','noheader','SDSS9=','SDSS-ID=','objID=','Sp-ID=','RA_ICRS=','DE_ICRS=','umag=','gmag=','rmag=','imag=','zmag=') 154 | try : 155 | __opts, __args = getopt.getopt(sys.argv[1:], 'hvar:m:f:', __options) 156 | except: 157 | help("__main__") 158 | sys.exit(1) 159 | 160 | for __o, __a in __opts: 161 | if __o == '-v': 162 | DEBUG = True 163 | continue 164 | 165 | if __o in ("-h", "--help"): 166 | help("__main__") 167 | sys.exit(1) 168 | 169 | elif __o == "-r": 170 | try: 171 | __radius = float(__a) 172 | except: 173 | sys.stderr.write("(error) wrong radius format\n") 174 | 175 | elif __o == "-m": 176 | try: 177 | __limit = int(__a) 178 | except: 179 | raise Exception("(error) wrong limit/max format") 180 | 181 | elif __o == "-a": 182 | __all = True 183 | 184 | elif __o == "--format": 185 | __mime = __a 186 | 187 | elif __o == "--no-format": 188 | __noformat = True 189 | 190 | elif __o == "--noheader": 191 | __noheader = True 192 | 193 | elif __o == "--ipix": 194 | __ipix = __a 195 | 196 | elif __o == "--count": 197 | __count = True 198 | 199 | elif __o == "--sort": 200 | __sort = True 201 | __constraints.append(("-out.add", "_r")) 202 | __constraints.append(("-sort", "_r")) 203 | 204 | elif __o == "--add": 205 | if __add is None: __add = [] 206 | __add.append(__a) 207 | 208 | elif __o == "--offset": 209 | __offset = __a 210 | continue 211 | 212 | if __o in ("-f", "--file"): 213 | __filename = __a 214 | 215 | else: 216 | for opt in __options[2:]: 217 | value = opt[:len(opt)-1] 218 | if __o[2:] == value: 219 | __constraints.append((value, __a)) 220 | break 221 | 222 | for __arg in __args: 223 | if __position is None: 224 | __position = __arg 225 | else: 226 | __position += " "+ __arg 227 | 228 | if __noformat is True or __ipix is not None or __offset is not None or __noheader: 229 | if __sort is True : 230 | raise Exception("--sort function is not compatible with --ipix/--no-format") 231 | if __filename is not None: 232 | raise Exception("--file option is not compatible with --ipix/--no-format") 233 | 234 | if len(__constraints)>0: 235 | raise Exception("Constraints "+str(__constraints)+" is not available in this mode (--ipix/--offset/--no-format)") 236 | 237 | __querycat = QueryCatClient() 238 | if __ipix is not None: 239 | __querycat.set_healpix(__ipix) 240 | __querycat.noformat=__noformat 241 | __querycat.noheader=__noheader 242 | 243 | if __offset : 244 | s = __offset.split("..") 245 | if len(s) != 2: raise Exception("error offset syntax: min..max") 246 | try: 247 | __querycat.set_offset(int(s[0]), int(s[1])) 248 | except: 249 | raise Exception("error offset syntax: begin..nb_records") 250 | 251 | if __mime is None or __mime == vizquery.FORMAT_ASCII: 252 | __mime = vizquery.FORMAT_TSV 253 | 254 | else: 255 | __querycat = QueryCatVizieR() 256 | 257 | __querycat.position = __position 258 | __querycat.radius = __radius 259 | 260 | if __mime in (vizquery.FORMAT_TSV, vizquery.FORMAT_VOTABLE, vizquery.FORMAT_ASCII): 261 | __querycat.format = __mime 262 | else: 263 | raise Exception("format not yet available") 264 | 265 | __querycat.query_cat(constraints=__constraints, all=__all, limit=__limit, columns=__add, filename=__filename) 266 | __querycat.print_stdout() 267 | 268 | --------------------------------------------------------------------------------