Data containers
Generating mock data¶
fakeit_for_multiple_parameters(obsconfs, model, parameters, rng_key=0, apply_stat=True, sparsify_matrix=False)
¶
Convenience function to simulate multiple spectra from a given model and a set of parameters. This is supposed to be somewhat optimized and can handle multiple parameters at once without blowing up the memory. The parameters should be passed as a dictionary with the parameter name as the key and the parameter values as the values, the value can be a scalar or a nd-array.
Example:¶
from jaxspec.data.util import fakeit_for_multiple_parameters
from numpy.random import default_rng
rng = default_rng(42)
size = (10, 30)
parameters = {
"tbabs_1_nh": rng.uniform(0.1, 0.4, size=size),
"powerlaw_1_alpha": rng.uniform(1, 3, size=size),
"powerlaw_1_norm": rng.exponential(10 ** (-0.5), size=size),
"blackbodyrad_1_kT": rng.uniform(0.1, 3.0, size=size),
"blackbodyrad_1_norm": rng.exponential(10 ** (-3), size=size)
}
spectra = fakeit_for_multiple_parameters(obsconf, model, parameters)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obsconfs
|
ObsConfiguration | list[ObsConfiguration]
|
The observational setup(s). |
required |
model
|
SpectralModel
|
The model to use. |
required |
parameters
|
Mapping[K, V]
|
The parameters of the model. |
required |
rng_key
|
int
|
The random number generator seed. |
0
|
apply_stat
|
bool
|
Whether to apply Poisson statistic on the folded spectra or not. |
True
|
sparsify_matrix
|
bool
|
Whether to sparsify the matrix or not. |
False
|
Source code in src/jaxspec/data/util.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
|
Data containers¶
ObsConfiguration
¶
Bases: Dataset
Class to store the data of a folding model, which is the link between the unfolded and folded spectra.
Source code in src/jaxspec/data/obsconf.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
|
area
instance-attribute
¶
The effective area of the instrument
exposure
instance-attribute
¶
The total exposure
folded_background
instance-attribute
¶
The background counts, after grouping
folded_counts
instance-attribute
¶
The observed counts, after grouping
in_energies
property
¶
The energy bounds of the unfolded bins in keV. The shape is (2, n_bins).
out_energies
property
¶
The energy bounds of the folded bins in keV. The shape is (2, n_bins).
transfer_matrix
instance-attribute
¶
The transfer matrix
from_instrument(instrument, observation, low_energy=1e-20, high_energy=1e+20)
classmethod
¶
Build the observation configuration from an Instrument
and an Observation
object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
instrument
|
Instrument
|
The instrument object. |
required |
observation
|
Observation
|
The observation object. |
required |
low_energy
|
float
|
The lower bound of the energy range to consider. |
1e-20
|
high_energy
|
float
|
The upper bound of the energy range to consider. |
1e+20
|
Source code in src/jaxspec/data/obsconf.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
|
from_pha_file(pha_path, rmf_path=None, arf_path=None, bkg_path=None, low_energy=1e-20, high_energy=1e+20)
classmethod
¶
Build the observation configuration from a PHA file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pha_path
|
The path to the PHA file. |
required | |
rmf_path
|
str | None
|
The path to the RMF file. |
None
|
arf_path
|
str | None
|
The path to the ARF file. |
None
|
bkg_path
|
str | None
|
The path to the background file. |
None
|
low_energy
|
float
|
The lower bound of the energy range to consider. |
1e-20
|
high_energy
|
float
|
The upper bound of the energy range to consider. |
1e+20
|
Source code in src/jaxspec/data/obsconf.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
|
mock_from_instrument(instrument, exposure, low_energy=1e-300, high_energy=1e+300)
classmethod
¶
Create a mock observation configuration from an instrument object. The fake observation will have zero counts.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
instrument
|
Instrument
|
The instrument object. |
required |
exposure
|
float
|
The total exposure of the mock observation. |
required |
low_energy
|
float
|
The lower bound of the energy range to consider. |
1e-300
|
high_energy
|
float
|
The upper bound of the energy range to consider. |
1e+300
|
Source code in src/jaxspec/data/obsconf.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
|
Instrument
¶
Bases: Dataset
Class to store the data of an instrument
Source code in src/jaxspec/data/instrument.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
|
area
instance-attribute
¶
The effective area of the instrument
redistribution
instance-attribute
¶
The photon redistribution probability matrix
from_ogip_file(rmf_path, arf_path=None)
classmethod
¶
Load the data from OGIP files.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rmf_path
|
str | PathLike
|
The RMF file path. |
required |
arf_path
|
str | PathLike | None
|
The ARF file path. |
None
|
Source code in src/jaxspec/data/instrument.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
|
plot_area(xscale='log', yscale='log', where='post', **kwargs)
¶
Plot the effective area
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xscale
|
The scale of the x-axis. |
'log'
|
|
yscale
|
The scale of the y-axis. |
'log'
|
|
where
|
The position of the steps. |
'post'
|
|
**kwargs
|
|
{}
|
Source code in src/jaxspec/data/instrument.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
|
plot_redistribution(xscale='log', yscale='log', cmap=None, vmin=1e-06, vmax=1.0, add_labels=True, **kwargs)
¶
Plot the redistribution probability matrix
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xscale
|
The scale of the x-axis. |
'log'
|
|
yscale
|
The scale of the y-axis. |
'log'
|
|
cmap
|
The colormap to use. |
None
|
|
vmin
|
The minimum value for the colormap. |
1e-06
|
|
vmax
|
The maximum value for the colormap. |
1.0
|
|
add_labels
|
Whether to add labels to the plot. |
True
|
|
**kwargs
|
|
{}
|
Source code in src/jaxspec/data/instrument.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
|
Observation
¶
Bases: Dataset
Class to store the data of an observation
Source code in src/jaxspec/data/observation.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
|
background
instance-attribute
¶
The background counts if provided, otherwise 0
counts
instance-attribute
¶
The observed counts
exposure
instance-attribute
¶
The total exposure
folded_background
instance-attribute
¶
The background counts, after grouping
folded_counts
instance-attribute
¶
The observed counts, after grouping
grouping
instance-attribute
¶
The grouping matrix
quality
instance-attribute
¶
The quality flag
from_pha_file(pha_path, bkg_path=None, **metadata)
classmethod
¶
Build an observation from a PHA file
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pha_path
|
Path to the PHA file |
required | |
bkg_path
|
Path to the background file |
None
|
|
metadata
|
Additional metadata to add to the observation |
{}
|
Source code in src/jaxspec/data/observation.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
|
plot_counts(**kwargs)
¶
Plot the counts
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
|
{}
|
Source code in src/jaxspec/data/observation.py
185 186 187 188 189 190 191 192 193 |
|
plot_grouping()
¶
Plot the grouping matrix and compare the grouped counts to the true counts in the original channels.
Source code in src/jaxspec/data/observation.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
|
OGIP data parsers¶
DataARF
¶
Class to handle ARF data defined with OGIP standards.
References
Source code in src/jaxspec/data/ogip.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
|
from_file(arf_file)
classmethod
¶
Load the data from an ARF file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arf_file
|
str | PathLike
|
The ARF file path. |
required |
Source code in src/jaxspec/data/ogip.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
|
DataPHA
¶
Class to handle PHA data defined with OGIP standards.
References
Source code in src/jaxspec/data/ogip.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
|
from_file(pha_file)
classmethod
¶
Load the data from a PHA file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pha_file
|
str | PathLike
|
The PHA file path. |
required |
Source code in src/jaxspec/data/ogip.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
|
DataRMF
¶
Class to handle RMF data defined with OGIP standards.
References
Source code in src/jaxspec/data/ogip.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
|
from_file(rmf_file)
classmethod
¶
Load the data from an RMF file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rmf_file
|
str | PathLike
|
The RMF file path. |
required |
Source code in src/jaxspec/data/ogip.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
|