Data containers
Generating mock data¶
fakeit_for_multiple_parameters(obsconfs, model, parameters, rng_key=0, apply_stat=True, sparsify_matrix=False)
¶
Simulate multiple spectra from a spectral model and a batch of parameters.
Handles batched parameter arrays efficiently via jax.vmap and optionally
applies Poisson noise.
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]
|
One or more observation configurations. |
required |
model
|
SpectralModel
|
The spectral model to evaluate. |
required |
parameters
|
Mapping[K, V]
|
Dict mapping dotted-path parameter names to arrays whose shape encodes the batch dimensions. |
required |
rng_key
|
int
|
Random number generator seed for Poisson sampling. |
0
|
apply_stat
|
bool
|
Whether to apply Poisson noise to the folded spectra. |
True
|
sparsify_matrix
|
bool
|
Whether to use sparse transfer matrices. |
False
|
Returns:
| Type | Description |
|---|---|
|
A single array (one obs) or a list of arrays (multiple obs), each with |
|
|
shape |
Source code in src/jaxspec/data/util.py
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 | |
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
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 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 | |
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
grouping
instance-attribute
¶
The grouping matrix, trimmed to the same channel range as the transfer matrix
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).
redistribution
instance-attribute
¶
The redistribution matrix (RMF), trimmed to the same energy range as the transfer matrix
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
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 | |
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
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 | |
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
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | |
to_jax_matrix(scoo, *, sparse)
¶
Convert a sparse.COO matrix (as stored on :class:ObsConfiguration)
to a JAX-typed dense array or a JAX BCOO sparse array.
Source code in src/jaxspec/data/obsconf.py
13 14 15 16 17 18 | |
Instrument
¶
Bases: Dataset
Class to store the data of an instrument
Source code in src/jaxspec/data/instrument.py
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 | |
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
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
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. |
required | |
yscale
|
The scale of the y-axis. |
required | |
where
|
The position of the steps. |
required | |
**kwargs
|
|
required |
Source code in src/jaxspec/data/instrument.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
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. |
required | |
yscale
|
The scale of the y-axis. |
required | |
cmap
|
The colormap to use. |
required | |
vmin
|
The minimum value for the colormap. |
required | |
vmax
|
The maximum value for the colormap. |
required | |
add_labels
|
Whether to add labels to the plot. |
required | |
**kwargs
|
|
required |
Source code in src/jaxspec/data/instrument.py
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 | |
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 | |
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 |
required | |
metadata
|
Additional metadata to add to the observation |
required |
Source code in src/jaxspec/data/observation.py
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 | |
plot_counts(**kwargs)
¶
Plot the counts
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
|
required |
Source code in src/jaxspec/data/observation.py
181 182 183 184 185 186 187 188 189 | |
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
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 | |
OGIP data parsers¶
DataARF
¶
Class to handle ARF data defined with OGIP standards.
References
Source code in src/jaxspec/data/ogip.py
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 | |
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
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |
DataPHA
¶
Class to handle PHA data defined with OGIP standards.
References
Source code in src/jaxspec/data/ogip.py
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 | |
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
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 | |
DataRMF
¶
Class to handle RMF data defined with OGIP standards.
References
Source code in src/jaxspec/data/ogip.py
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 297 298 299 300 301 302 | |
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
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 297 298 299 300 301 302 | |