diff --git a/.gitignore b/.gitignore index 147841a..ff207a0 100644 --- a/.gitignore +++ b/.gitignore @@ -10,11 +10,11 @@ response_tools.egg-info/ build/ # data directories -response-information/attenuation-data/ -response-information/detector-response-data/ -response-information/effective-area-data/ -response-information/quantum-efficiency-data/ -response-information/atmospheric-data/ +response_tools/response-information/attenuation-data/ +response_tools/response-information/detector-response-data/ +response_tools/response-information/effective-area-data/ +response_tools/response-information/quantum-efficiency-data/ +response_tools/response-information/atmospheric-data/ # environment .env/ diff --git a/response-information/atmospheric-data/README.md b/response-information/atmospheric-data/README.md deleted file mode 100644 index 9775858..0000000 --- a/response-information/atmospheric-data/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Detector quantum efficiency data files - -Only really here so this folder is tracked by `git`. diff --git a/response-information/attenuation-data/README.md b/response-information/attenuation-data/README.md deleted file mode 100644 index 309fbba..0000000 --- a/response-information/attenuation-data/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Attenuator data files - -Only really here so this folder is tracked by `git`. diff --git a/response-information/detector-response-data/README.md b/response-information/detector-response-data/README.md deleted file mode 100644 index 3b663b9..0000000 --- a/response-information/detector-response-data/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Detector response data files - -Only really here so this folder is tracked by `git`. diff --git a/response-information/effective-area-data/README.md b/response-information/effective-area-data/README.md deleted file mode 100644 index 43d64b8..0000000 --- a/response-information/effective-area-data/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# Effective area data files - -Only really here so this folder is tracked by `git`. - -## Content -- `nagoya_hxt_onaxis_measurement_v1.txt` is the effective area data for the position 4 optic. -- `nagoya_sxt_onaxis_measurement_v1.txt` is the data for the position 1 optic, and includes OBFs and collimators. diff --git a/response-information/quantum-efficiency-data/README.md b/response-information/quantum-efficiency-data/README.md deleted file mode 100644 index 9775858..0000000 --- a/response-information/quantum-efficiency-data/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Detector quantum efficiency data files - -Only really here so this folder is tracked by `git`. diff --git a/response_tools/__init__.py b/response_tools/__init__.py index fea117f..b7e7b69 100644 --- a/response_tools/__init__.py +++ b/response_tools/__init__.py @@ -10,6 +10,9 @@ The information stored in a YAML file that includes information from the flight. +`~response_tools.responseFilePath` + The response data file location. + `~response_tools.__version__` The current version of the code as stated in the setup script. @@ -27,8 +30,12 @@ ... """ +import os +import pathlib + from .version import __version__ from response_tools.io.load_yaml import load_response_context # for global context info contextResponseInfo = load_response_context() +responseFilePath = os.path.join(pathlib.Path(__file__).parent, "response-information") diff --git a/response_tools/attenuation.py b/response_tools/attenuation.py index 076f259..bcf79d4 100644 --- a/response_tools/attenuation.py +++ b/response_tools/attenuation.py @@ -13,10 +13,11 @@ import pandas import scipy +import response_tools from response_tools.util import BaseOutput, native_resolution -ATT_PATH = os.path.join(pathlib.Path(__file__).parent, "..", "response-information", "attenuation-data") -ATM_PATH = os.path.join(pathlib.Path(__file__).parent, "..", "response-information", "atmospheric-data") +FILE_PATH = response_tools.responseFilePath +RESPONSE_INFO_TYPE = response_tools.contextResponseInfo["files"]["attenuation"] ASSETS_PATH = os.path.join(pathlib.Path(__file__).parent, "..", "assets", "response-tools-figs", "att-figs") @dataclass @@ -57,7 +58,7 @@ def att_thermal_blanket(mid_energies, file=None): transmissions, and more. See accessible information using `.contents` on the output. """ - _f = os.path.join(ATT_PATH, "F4_Blanket_transmission_v1.dat") if file is None else file + _f = os.path.join(FILE_PATH, RESPONSE_INFO_TYPE["att_thermal_blanket"]) if file is None else file att = scipy.io.readsav(_f) att_es, att_values = att["energy_kev"] << u.keV, att["f4_transmission"] << u.dimensionless_unscaled mid_energies = native_resolution(native_x=att_es, input_x=mid_energies) @@ -105,7 +106,7 @@ def att_uniform_al_cdte(mid_energies, position=None, file=None): """ if (position is None) or (position not in [2,4]): logging.warning(f"The {sys._getframe().f_code.co_name} `position` must be 2 or 4.") - _f = os.path.join(ATT_PATH, f"unif_att_p{position}_theoretical_v1.csv") if file is None else file + _f = os.path.join(FILE_PATH, RESPONSE_INFO_TYPE[f"att_telescope-{position}_uniform_al_cdte"]) if file is None else file att = pandas.read_csv(_f) att_es, att_values = att["energy[keV]"] << u.keV, att["transmission"] << u.dimensionless_unscaled mid_energies = native_resolution(native_x=att_es, input_x=mid_energies) @@ -151,7 +152,7 @@ def att_pixelated(mid_energies, use_model=False, file=None): transmissions, and more. See accessible information using `.contents` on the output. """ - _f = os.path.join(ATT_PATH, "20240607_fosxi4_transmission_v1.csv") if file is None else file + _f = os.path.join(FILE_PATH, RESPONSE_INFO_TYPE["att_pixelated"]) if file is None else file att = pandas.read_csv(_f) att_es, att_values_measured, att_values_modelled = att["energy"] << u.keV, att["measured_transmission"] << u.dimensionless_unscaled, att["modeled_transmission"] << u.dimensionless_unscaled @@ -197,7 +198,7 @@ def att_al_mylar(mid_energies, file=None): transmissions, and more. See accessible information using `.contents` on the output. """ - _f = os.path.join(ATT_PATH, "thin_mylar_p3_p5_theoretical_v1.csv") if file is None else file + _f = os.path.join(FILE_PATH, RESPONSE_INFO_TYPE["att_al_mylar"]) if file is None else file att = pandas.read_csv(_f) att_es, att_values = att["energy[keV]"] << u.keV, att["transmission"] << u.dimensionless_unscaled mid_energies = native_resolution(native_x=att_es, input_x=mid_energies) @@ -224,7 +225,7 @@ def _att_old_prefilter(mid_energies, position=None, file=None): if (position is None) or (position not in [0,1]): logging.warning(f"The {sys._getframe().f_code.co_name} `position` must be 0 or 1.") logging.warning(f"Caution: This might not be the function you are looking for ({sys._getframe().f_code.co_name}), please see `att_cmos_obfilter`.") - _f = os.path.join(ATT_PATH, "CMOST_Prefilter_transmission.dat") if file is None else file + _f = os.path.join(FILE_PATH, RESPONSE_INFO_TYPE["att_early_cmos_prefilter"]) if file is None else file att = scipy.io.readsav(_f) att_es, att_values = att["cmos_prefilter_transmission"]["energy_kev"][0] << u.keV, att["cmos_prefilter_transmission"][f"position{position}"][0] << u.dimensionless_unscaled @@ -304,7 +305,7 @@ def att_cmos_filter(mid_energies, telescope=None, file=None): if (telescope is None) or (telescope not in [0,1]): logging.warning(f"The `telescope` input in {sys._getframe().f_code.co_name} must be 0 or 1.") return - _f = os.path.join(ATT_PATH, f"foxsi4_telescope-{telescope}_BASIC_attenuation_filter_transmittance_v1.fits") if file is None else file + _f = os.path.join(FILE_PATH, RESPONSE_INFO_TYPE[f"att_telescope-{telescope}_cmos_prefilter"]) if file is None else file with fits.open(_f) as hdul: es, t = hdul[2].data << u.keV, hdul[1].data << u.dimensionless_unscaled mid_energies = native_resolution(native_x=es, input_x=mid_energies) @@ -352,7 +353,7 @@ def att_cmos_obfilter(mid_energies, telescope=None, file=None): if (telescope is None) or (telescope not in [0,1]): logging.warning(f"The `telescope` input in {sys._getframe().f_code.co_name} must be 0 or 1.") return - _f = os.path.join(ATT_PATH, f"foxsi4_telescope-{telescope}_BASIC_optical_blocking_filter_transmittance_v1.fits") if file is None else file + _f = os.path.join(FILE_PATH, RESPONSE_INFO_TYPE[f"att_telescope-{telescope}_cmos_obfilter"]) if file is None else file with fits.open(_f) as hdul: es, t = hdul[2].data << u.keV, hdul[1].data << u.dimensionless_unscaled mid_energies = native_resolution(native_x=es, input_x=mid_energies) @@ -399,7 +400,7 @@ def att_cmos_collimator_ratio(off_axis_angle, telescope=None, file=None): if (telescope is None) or (telescope not in [0,1]): logging.warning(f"The `telescope` input in {sys._getframe().f_code.co_name} must be 0 or 1.") return - _f = os.path.join(ATT_PATH, f"foxsi4_telescope-{telescope}_BASIC_collimator_aperture_ratio_v1.fits") if file is None else file + _f = os.path.join(FILE_PATH, RESPONSE_INFO_TYPE[f"att_telescope-{telescope}_collimator_ratio"]) if file is None else file with fits.open(_f) as hdul: oa_angles, aperture_ratio = hdul[2].data << u.arcmin, hdul[1].data << u.dimensionless_unscaled off_axis_angle = native_resolution(native_x=oa_angles, input_x=off_axis_angle) @@ -472,7 +473,7 @@ def att_foxsi4_atmosphere(mid_energies, time_range=None, file=None): warnings.warn(f"{sys._getframe().f_code.co_name} `time_range` (convertable to astropy.units.seconds) should be of length 2.") return - _f = os.path.join(ATM_PATH, f"FOXSI4_atmospheric_transmission_v1.fits") if file is None else file + _f = os.path.join(FILE_PATH, RESPONSE_INFO_TYPE["att_foxsi4_atmosphere"]) if file is None else file with fits.open(_f) as hdul: native_times, native_energies, transmission = hdul[1].data["TIME"][0]<