# You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # """Utility routines for using the parameter module; as with the other ciao_contrib.*_wrapper modules it is mainly intended for internal use and so the API is not guaranteed to be stable. """ import os import ciao_contrib.logger_wrapper as lw import paramio as pio logger = lw.initialize_module_logger("param_wrapper") v5 = logger.verbose5 __all__ = ("open_param_file", ) def show_pfiles(): """Returns a string listing the directories in the PFILES environment variable. """ try: pf = os.environ["PFILES"] except KeyError: raise IOError("The PFILES environment variable is not set!")
# (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # __all__ = ["get_radec_from_pos"] from ciao_contrib.logger_wrapper import initialize_module_logger logger = initialize_module_logger("parse_pos") verb0 = logger.verbose0 def _get_radec_from_str(pos): """ Get the ra/dec values from the input string. """ from coords.format import sex2deg ps = pos.split(",") if len(ps) != 2: ps = pos.split("+") if len(ps) != 2: ps = pos.split("-") if len(ps) != 2: raise ValueError(
""" import glob import json import os import subprocess from urllib.request import urlopen from urllib.error import HTTPError, URLError from ciao_contrib import logger_wrapper as lw __all__ = ('get_installed_versions', 'get_latest_versions', 'read_latest_versions', 'check_conda_versions') lgr = lw.initialize_module_logger('_tools.versioninfo') v3 = lgr.verbose3 v4 = lgr.verbose4 def read_vfile(fname): "Reads the version string from a CIAO version file" with open(fname, 'r') as fh: cts = fh.readlines() # Just take the first line, in case there are any extra new lines # in the file, as has happened. return cts[0].strip()
""" Wrapper around asect solution files. """ import numpy as np import pycrates as pcr import ciao_contrib.logger_wrapper as lw import ciao_contrib._tools.fileio as fileio # __all__ = ("",) lgr = lw.initialize_module_logger('_tools.aspsol') v3 = lgr.verbose3 class AspectSolution(object): """Represent the aspect solution for an observation. It can consist of 1 or more aspect solution files. This class deals with sorting the files in time order. After creation, the idea is that you use the .name field for any tool that needs the aspect solution (e.g. asphist.infile or skyfov.aspect), and nbins for the number of bins to use in a call to asphist. If there are multiple files then the .name field will be a comma-separated list of files. The assumption here is that
As of CIAO 4.6 there should be no need for the PBK (parameter block) file, but support has been left in. """ import os import pycrates import stk from ciao_contrib.logger_wrapper import initialize_module_logger __all__ = ('find_ancillary_files', 'find_ancillary_files_crate', 'find_ancillary_files_header') lgr = initialize_module_logger('ancillaryfiles') v1 = lgr.verbose1 v3 = lgr.verbose3 v4 = lgr.verbose4 __typemap = { 'asol': 'ASOLFILE', 'bpix': 'BPIXFILE', 'dtf': 'DTFFILE', 'flt': 'FLTFILE', 'mask': 'MASKFILE', 'mtl': 'MTLFILE', 'pbk': 'PBKFILE', # 'thresh': 'THRFILE', # 'gain': 'GAINFILE', # 'cti': 'CTIFILE',
__all__ = ( "run", "punlearn", "dmcopy", "update_column_range", "dmmerge", "dmimgcalc2", "dmimgcalc", "dmimgcalc_add", "dmkeypar", "dmhedit_key", "dmhedit_file", "get_lookup_table", "fix_bunit" # TODO: skyfov ) lgr = lw.initialize_module_logger('_tools.run') v2 = lgr.verbose2 v3 = lgr.verbose3 def run(tname, targs): """Run the tool (tname) with arguments (targs). Raises an IOError on failure. Logs the command and arguments at the DEBUG level. """ v2(">> Running {}".format(tname)) v2(">> args: {}".format(targs)) args = [tname] args.extend(targs) rval = sbp.call(args)
interface. Is it worth it? """ import os import ciao_contrib.ancillaryfiles as ancillary import ciao_contrib.logger_wrapper as lw # Can not rely on too many modules in ciao_contrib._tools as do # not want circular dependencies import ciao_contrib._tools.fileio as fileio import ciao_contrib._tools.utils as utils # __all__ = ("",) lgr = lw.initialize_module_logger('_tools.obsinfo') v2 = lgr.verbose2 v3 = lgr.verbose3 def _remove_dmfilter(fname): """Return fname stripped of any DM filter, so '/foo/bar/baz.fits' and '/foo/bar/baz.fits[sky=region(../src.reg)]' both return '/foo/bar/baz.fits'. For now only look at DM filter syntax (so anything "[...") but could also look for CFITSIO syntax ("+<block num>" and "...(copy-name)"), but only do this if find users actually use this (as unlikely used for the use cases of this module, although being used more). """
""" Routines that deal with the Chandra field-of-view (FOV) files created by the skyfov tool (and are also provided as part of the Chandra standard-data product distribution). """ import os import numpy as np import pycrates from ciao_contrib.logger_wrapper import initialize_module_logger logger = initialize_module_logger("ciao_contrib.region.fov") v1 = logger.verbose1 v3 = logger.verbose3 v4 = logger.verbose4 v5 = logger.verbose5 __all__ = ( "FOVRegion", "AxisRange", ) # not very robust def _is_int(ival): "Are we near enough an integer for display purposes?"
import socket import time from html.parser import HTMLParser from urllib.request import urlopen from urllib.error import URLError import pycrates from ciao_contrib import logger_wrapper as lw __all__ = ("check_caldb_version", "get_caldb_dir", "get_caldb_releases", "get_caldb_installed", "get_caldb_installed_version", "get_caldb_installed_date") lgr = lw.initialize_module_logger('caldb') v3 = lgr.verbose3 release_notes_url = "https://cxc.cfa.harvard.edu/caldb/downloads/releasenotes.html" def todate(txt): """Convert text to time. This is intended to convert a time string, as reported by the CALDB web pages, to a time object. Parameters ---------- txt : str or None The time string.
import pycrates from ciao_contrib.logger_wrapper import initialize_module_logger from ciao_contrib import smooth as sm __all__ = ( "make_table_crate", "make_image_crate", "add_colvals", "write_columns", "write_arrays", "scale_image_crate", "smooth_image_crate", "SimpleCoordTransform", "read_ds9_contours", ) logger = initialize_module_logger("crates_utils") v3 = logger.verbose3 # time.strftime format to create FITS (like) time format _fits_time_fmt = "%Y-%m-%dT%H:%M:%S" def add_colvals(cr, colname, colvals, unit=None, desc=None): """Add a new column to the crate. Create a new column in the crate with the given name and data values. The unit and desc fields are used to set the column unit and description if given. Parameters
import subprocess as sbp import paramio import stk import ciao_contrib.logger_wrapper as lw import ciao_contrib.runtool as rt import coords.format __all__ = ("ObsId", "make_obsid_from_headers", "print_version", "split_outroot", "to_number", "equal_elements", "getUniqueSynset", "thresh_is_set", "parse_range", "parse_xygrid", "parse_refpos", "sky_to_arcsec", "process_tmpdir") lgr = lw.initialize_module_logger('_tools.utils') v1 = lgr.verbose1 v3 = lgr.verbose3 v4 = lgr.verbose4 # This is a manually-curated list. It is (as of 2015) not expected # to grow. # _multi_obi_obsids = [ 82, 108, 279, 380, 400, 433, 800, 861, 897, 906, 943, 1411, 1431, 1456, 1561, 1578, 2010, 2042, 2077, 2365, 2783, 3057, 3182, 3764, 4175, 60879, 60880, 62249, 62264, 62796 ] def list_multi_obi_obsids():
# """ Header routines, currently limited to merging keywords. The idea is to move this from being text-based to being created with methods, and having output to text for tools that need it. """ import math import ciao_contrib.logger_wrapper as lw __all__ = ("HeaderMerge", ) lgr = lw.initialize_module_logger('_tools.merging') v2 = lgr.verbose2 v3 = lgr.verbose3 v4 = lgr.verbose4 class BaseMergeRule: """How should a list of keyword values be combined? This skips the "warn" part of the header rules. Parameters ---------- key : str The name of the keyword. default : str or None
import sys import ssl import time from io import BytesIO from subprocess import check_output import urllib.error import urllib.request import http.client from html.parser import HTMLParser import ciao_contrib.logger_wrapper as lw logger = lw.initialize_module_logger("downloadutils") v0 = logger.verbose0 v1 = logger.verbose1 v2 = logger.verbose1 v3 = logger.verbose3 v4 = logger.verbose4 __all__ = ('retrieve_url', 'find_downloadable_files', 'find_all_downloadable_files', 'ProgressBar', 'download_progress') def manual_download(url): """Try curl then wget to query the URL. Parameters
For cases when the CADC resolver is not available it falls back to using the Sesame interface from CDS: http://vizier.u-strasbg.fr/vizier/doc/sesame.htx """ from urllib.parse import quote_plus from urllib.request import urlopen from urllib.error import HTTPError, URLError import xml.etree.ElementTree as ET import ciao_contrib.logger_wrapper as lw __all__ = ("identify_name", ) logger = lw.initialize_module_logger("cda.resolver") v4 = logger.verbose4 v5 = logger.verbose5 def strtofloat(val): """Convert a string into a float. The difference to just calling float(val) is that the error is more user-friendly. Parameters ---------- val : str The number to convert
"outfile_clobber_checks", "rename_file_extension", "remove_path", "check_valid_file", "validate_outdir", "get_file_from_header", "get_minmax_times", # may want to move the following elsewhere "get_subspace", "fov_limits", "get_sky_range", "find_output_grid", "get_tangent_point") lgr = lw.initialize_module_logger('_tools.fileio') v1 = lgr.verbose1 v2 = lgr.verbose2 v3 = lgr.verbose3 v4 = lgr.verbose4 def get_infile_type(infile): """Returns 'Table' or 'Image' depending on what Crates thinks the type of infile is.""" cr = pycrates.read_file(infile) return pycrates.get_crate_type(cr) def get_filter(infile): """returns the DM filter used with an input file or stack"""
The API is not guaranteed to remain stable, so use at your own risk. """ import os import sys import time from collections import namedtuple import numpy as np import cxcdm as dm from ciao_contrib.logger_wrapper import initialize_module_logger logger = initialize_module_logger("cxcdm_wrapper") v1 = logger.verbose3 v3 = logger.verbose3 v5 = logger.verbose5 Record = namedtuple("Record", "name value unit comment") Column = namedtuple("Column", "name pos type dims unit comment range") __all__ = ["open_block_from_file", "close_block", "get_block_info", "get_block_info_from_file", "get_info_from_file", "get_keyword", "get_block_name", "convert_block_number", "get_obsfiles", "open_column", ]
import os.path import ssl import urllib.parse import urllib.request from operator import itemgetter import ciao_contrib.logger_wrapper as lw from ciao_contrib import downloadutils __init__ = ("download_chandra_obsids", ) BASE_URL = 'https://cxc.cfa.harvard.edu/cdaftp/' LOGGER = lw.initialize_module_logger("cda.data") V1 = LOGGER.verbose1 V3 = LOGGER.verbose3 __MIRROR_ENVIRON = "CDA_MIRROR_SITE" def get_mirror_location(useropt): """Returns the mirror location, if set, otherwise None. If useropt is not empty or None then this is returned, otherwise the value of the CDA_MIRROR_SITE environment variable is returned (if set), otherwise returns None. Only minor syntactic checks are made (no attempt is made to connect to the server).
# """ Processing band information (i.e. energy range and representative energy for instrument maps). """ import os import pycrates import stk import ciao_contrib.logger_wrapper as lw __all__ = ("validate_bands", ) lgr = lw.initialize_module_logger('_tools.bands') v1 = lgr.verbose1 v3 = lgr.verbose3 def validate_energy_value(enval): "Error out if enval is outside the nominal energy range of Chandra." if 0.1 <= enval <= 10.0: return raise ValueError( "Energy of {} keV is outside Chandra's nominal range of 0.1 to 10 keV." .format(enval))
""" import numpy as np from xml.etree import ElementTree from collections import OrderedDict import coords.format as coords import coords.utils as cutils from ciao_contrib.downloadutils import retrieve_url import ciao_contrib.logger_wrapper as lw logger = lw.initialize_module_logger("cda.search") v3 = logger.verbose3 v4 = logger.verbose4 v5 = logger.verbose5 __all__ = ( "search_chandra_archive", "get_chandra_obs", ) def _mkl(label): return '{http://www.ivoa.net/xml/VOTable/v1.1}' + label
# # KJG: 2016-09013 no changes needed for P3 """ Routines related specifically to converting to/from Chandra coordinates """ __all__ = ["cel_to_chandra", "sky_to_chandra"] from pixlib import Pixlib myPixlib = None import ciao_contrib.logger_wrapper as lw logger = lw.initialize_module_logger("coords.chandra") v0 = logger.verbose0 def _setup_sim(keyword_list): """ Get the kewywords related to the SIM location """ # # Get SIM if all keys are present -- should be unless merged then # all bets are off anyways. # if all([x in keyword_list for x in ["SIM_X", "SIM_Y", "SIM_Z"]]): sim = [ keyword_list["SIM_X"], keyword_list["SIM_Y"], keyword_list["SIM_Z"]