utils¶
utils
¶
Author: Corentin Ravoux
Description : Utilities including coordinate conversion and various interfaces with other codes.
gaussian_fitter_2d
¶
gaussian_fitter_2d(inpdata=None)
Bases: object
Fit a rotated 2D Gaussian (plus background) to a 2D array.
Attributes:
| Name | Type | Description |
|---|---|---|
inpdata |
ndarray
|
The 2D data being fitted. |
Store the 2D data to fit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inpdata
|
ndarray
|
The 2D data array. |
None
|
Source code in lelantos/utils.py
721 722 723 724 725 726 727 | |
moments2D
¶
moments2D()
Returns the (amplitude, xcenter, ycenter, xsigma, ysigma, rot, bkg, e) estimated from moments in the 2d input array Data
Source code in lelantos/utils.py
729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 | |
Gaussian2D
¶
Gaussian2D(amplitude, xcenter, ycenter, xsigma, ysigma, rot, bkg)
Returns a 2D Gaussian function with input parameters. rotation input rot should be in degress
Source code in lelantos/utils.py
779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 | |
FitGauss2D
¶
FitGauss2D(ip=None)
Fits 2D gaussian to Data with optional Initial conditions ip=(amplitude, xcenter, ycenter, xsigma, ysigma, rot, bkg) Example:
X,Y=np.indices((40,40),dtype=np.float) Data=np.exp(-(((X-25)/5)2 +((Y-15)/10)2)/2) + 1 FitGauss2D(Data) (array([ 1.00000000e+00, 2.50000000e+01, 1.50000000e+01, 5.00000000e+00, 1.00000000e+01, 2.09859373e-07, 1]), 2)
Source code in lelantos/utils.py
800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 | |
Logger
¶
Logger(name='Python_Report', log_level='info')
Bases: object
Thin wrapper around :mod:logging for console or file reports.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Report file name (file mode). |
log_level |
str
|
|
Store the logger name and level (call a setup_* method next).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Report file path. Defaults to |
'Python_Report'
|
log_level
|
str
|
Logging level. Defaults to |
'info'
|
Source code in lelantos/utils.py
873 874 875 876 877 878 879 880 881 | |
setup_logging
¶
setup_logging()
Taken from https://nbodykit.readthedocs.io/ Turn on logging, with the specified level. Parameters
log_level : 'info', 'debug', 'warning' the logging level to set; logging below this level is ignored
Source code in lelantos/utils.py
883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 | |
setup_report_logging
¶
setup_report_logging()
Configure :mod:logging to write to the report file name.
Source code in lelantos/utils.py
925 926 927 928 929 930 931 932 933 934 935 936 937 | |
add
staticmethod
¶
add(line, level='info')
Emit a log line at the given level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
line
|
str
|
Message to log. |
required |
level
|
str
|
|
'info'
|
Source code in lelantos/utils.py
939 940 941 942 943 944 945 946 947 948 949 950 951 952 | |
add_array_statistics
staticmethod
¶
add_array_statistics(arr, char)
Log the min/max/mean/std of an array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
ndarray | None
|
Array to summarise (no-op if None). |
required |
char
|
str
|
Label used in the log messages. |
required |
Source code in lelantos/utils.py
954 955 956 957 958 959 960 961 962 963 964 965 966 | |
close
staticmethod
¶
close()
Flush and shut down the logging system.
Source code in lelantos/utils.py
968 969 970 971 | |
ForkingPickler4
¶
ForkingPickler4(*args)
Bases: ForkingPickler
ForkingPickler forced to protocol 4 (for >4 GiB multiprocessing payloads).
Force pickle protocol 4 then delegate to the base pickler.
Source code in lelantos/utils.py
1018 1019 1020 1021 1022 1023 1024 | |
dumps
classmethod
¶
dumps(obj, protocol=4)
Pickle obj with protocol 4.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Object to serialise. |
required | |
protocol
|
int
|
Pickle protocol. Defaults to 4. |
4
|
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
The pickled payload. |
Source code in lelantos/utils.py
1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 | |
Pickle4Reducer
¶
Bases: AbstractReducer
Multiprocessing reducer using protocol-4 pickling.
Assign to a context reducer (ctx.reducer = Pickle4Reducer()) to allow
multiprocessing payloads larger than 4 GiB.
mpc_per_pixel
¶
mpc_per_pixel(size, shape)
Physical size of one pixel along each axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
array - like
|
Box physical size per axis (Mpc.h^-1). |
required |
shape
|
array - like
|
Box pixel count per axis. |
required |
Returns:
| Type | Description |
|---|---|
|
numpy.ndarray: |
Source code in lelantos/utils.py
41 42 43 44 45 46 47 48 49 50 51 | |
pixel_per_mpc
¶
pixel_per_mpc(size, shape)
Number of pixels per Mpc.h^-1 along each axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
array - like
|
Box physical size per axis (Mpc.h^-1). |
required |
shape
|
array - like
|
Box pixel count per axis. |
required |
Returns:
| Type | Description |
|---|---|
|
numpy.ndarray: |
Source code in lelantos/utils.py
54 55 56 57 58 59 60 61 62 63 64 | |
get_map_shape
¶
get_map_shape(size, mpc_per_pixel)
Pixel shape implied by a physical size and pixel scale.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
array - like
|
Box physical size per axis (Mpc.h^-1). |
required |
mpc_per_pixel
|
array - like
|
Mpc.h^-1 per pixel per axis. |
required |
Returns:
| Type | Description |
|---|---|
|
numpy.ndarray: |
Source code in lelantos/utils.py
67 68 69 70 71 72 73 74 75 76 77 | |
get_map_size
¶
get_map_size(shape, mpc_per_pixel)
Physical size implied by a pixel shape and pixel scale.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
array - like
|
Box pixel count per axis. |
required |
mpc_per_pixel
|
array - like
|
Mpc.h^-1 per pixel per axis. |
required |
Returns:
| Type | Description |
|---|---|
|
numpy.ndarray: |
Source code in lelantos/utils.py
80 81 82 83 84 85 86 87 88 89 90 | |
get_cosmo_function
¶
get_cosmo_function(Omega_m, Omega_k=0.0)
Build comoving-distance functions and their inverses (via picca).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Omega_m
|
float
|
Matter density parameter. |
required |
Omega_k
|
float
|
Curvature density parameter. Defaults to 0.0. |
0.0
|
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
|
|
|
and |
||
|
the two |
Source code in lelantos/utils.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
return_suplementary_parameters
¶
return_suplementary_parameters(mode, property=None, zmin=None, zmax=None)
Return the extra parameters needed by a coordinate transform.
For the "middle" transform this is the mid-redshift of the box, taken
either from a property object or from an explicit (zmin, zmax) window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
str
|
Coordinate transform mode (e.g. |
required |
property
|
optional
|
Object exposing |
None
|
zmin
|
float
|
Minimum redshift (if |
None
|
zmax
|
float
|
Maximum redshift (if |
None
|
Returns:
| Type | Description |
|---|---|
|
list | None: |
Source code in lelantos/utils.py
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 | |
convert_cartesian_to_sky
¶
convert_cartesian_to_sky(X, Y, Z, method, inv_rcomov=None, inv_distang=None, distang=None, suplementary_parameters=None)
Convert cartesian coordinates to sky coordinates (Mpc.h-1 to radians).
Dispatches to the full_angle / full / middle implementation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X, Y, Z
|
array - like
|
Cartesian comoving coordinates (Mpc.h^-1). |
required |
method
|
str
|
Transform mode ( |
required |
inv_rcomov
|
callable
|
Comoving distance -> redshift. |
None
|
inv_distang
|
callable
|
Angular-diameter distance -> redshift. |
None
|
distang
|
callable
|
Redshift -> angular-diameter distance. |
None
|
suplementary_parameters
|
list
|
Extra params (e.g. middle z). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
|
Source code in lelantos/utils.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 174 175 176 177 | |
convert_sky_to_cartesian
¶
convert_sky_to_cartesian(RA, DEC, z, method, rcomov=None, distang=None, suplementary_parameters=None)
Convert sky coordinates to cartesian coordinates (radians to Mpc.h-1).
Dispatches to the full_angle / full / middle implementation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
RA, DEC
|
array - like
|
Sky angles (radians). |
required |
z
|
array - like
|
Redshift. |
required |
method
|
str
|
Transform mode ( |
required |
rcomov
|
callable
|
Redshift -> comoving distance. |
None
|
distang
|
callable
|
Redshift -> angular-diameter distance. |
None
|
suplementary_parameters
|
list
|
Extra params (e.g. middle z). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
|
Source code in lelantos/utils.py
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 | |
convert_cartesian_to_sky_full_angle
¶
convert_cartesian_to_sky_full_angle(X, Y, Z, inv_rcomov)
Cartesian -> sky using the exact spherical angles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X, Y, Z
|
array - like
|
Cartesian comoving coordinates (Mpc.h^-1). |
required |
inv_rcomov
|
callable
|
Comoving distance -> redshift. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
|
Source code in lelantos/utils.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
convert_sky_to_cartesian_full_angle
¶
convert_sky_to_cartesian_full_angle(RA, DEC, z, rcomov)
Sky -> cartesian using the exact spherical angles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
RA, DEC
|
array - like
|
Sky angles (radians). |
required |
z
|
array - like
|
Redshift. |
required |
rcomov
|
callable
|
Redshift -> comoving distance. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
|
Source code in lelantos/utils.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | |
convert_cartesian_to_sky_full
¶
convert_cartesian_to_sky_full(X, Y, Z, inv_rcomov)
Cartesian -> sky using the small-angle (X/Z, Y/Z) approximation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X, Y, Z
|
array - like
|
Cartesian comoving coordinates (Mpc.h^-1). |
required |
inv_rcomov
|
callable
|
Comoving distance -> redshift. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
|
Source code in lelantos/utils.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
convert_sky_to_cartesian_full
¶
convert_sky_to_cartesian_full(RA, DEC, z, rcomov)
Sky -> cartesian using the small-angle approximation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
RA, DEC
|
array - like
|
Sky angles (radians). |
required |
z
|
array - like
|
Redshift. |
required |
rcomov
|
callable
|
Redshift -> comoving distance. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
|
Source code in lelantos/utils.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | |
convert_cartesian_to_sky_middle
¶
convert_cartesian_to_sky_middle(X, Y, Z, inv_rcomov, distang, middle_z)
Cartesian -> sky using a tangent plane at the box mid-redshift.
Transverse coordinates are divided by the angular-diameter distance at the
fixed middle_z; the radial coordinate maps directly to redshift.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X, Y, Z
|
array - like
|
Cartesian comoving coordinates (Mpc.h^-1). |
required |
inv_rcomov
|
callable
|
Comoving distance -> redshift. |
required |
distang
|
callable
|
Redshift -> angular-diameter distance. |
required |
middle_z
|
float
|
Reference (box centre) redshift. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
|
Source code in lelantos/utils.py
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | |
convert_sky_to_cartesian_middle
¶
convert_sky_to_cartesian_middle(RA, DEC, z, rcomov, distang, middle_z)
Sky -> cartesian using a tangent plane at the box mid-redshift.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
RA, DEC
|
array - like
|
Sky angles (radians). |
required |
z
|
array - like
|
Redshift. |
required |
rcomov
|
callable
|
Redshift -> comoving distance. |
required |
distang
|
callable
|
Redshift -> angular-diameter distance. |
required |
middle_z
|
float
|
Reference (box centre) redshift. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
|
Source code in lelantos/utils.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 | |
convert_z_cartesian_to_sky_middle
¶
convert_z_cartesian_to_sky_middle(Z, inv_rcomov)
Map the radial cartesian coordinate to redshift (middle transform).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Z
|
array - like
|
Radial comoving coordinate (Mpc.h^-1). |
required |
inv_rcomov
|
callable
|
Comoving distance -> redshift. |
required |
Returns:
| Type | Description |
|---|---|
|
array-like: Redshift. |
Source code in lelantos/utils.py
315 316 317 318 319 320 321 322 323 324 325 326 | |
convert_z_sky_to_cartesian_middle
¶
convert_z_sky_to_cartesian_middle(z, rcomov)
Map redshift to the radial cartesian coordinate (middle transform).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z
|
array - like
|
Redshift. |
required |
rcomov
|
callable
|
Redshift -> comoving distance. |
required |
Returns:
| Type | Description |
|---|---|
|
array-like: Radial comoving coordinate (Mpc.h^-1). |
Source code in lelantos/utils.py
329 330 331 332 333 334 335 336 337 338 339 340 | |
get_direction_indexes
¶
get_direction_indexes(direction, rotate)
Map a slicing direction name to axis indexes and labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
direction
|
str
|
One of |
required |
rotate
|
bool
|
Swap the in-plane x/y indexes if True. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
|
|
|
two in-plane axis indexes, the slice-normal axis index and a label dict. |
Source code in lelantos/utils.py
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 | |
saclay_mock_box_cosmo_parameters
¶
saclay_mock_box_cosmo_parameters(box_shape, size_cell)
Return the SaclayMocks fiducial cosmology and box radial bounds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
box_shape
|
tuple[int]
|
Box pixel shape |
required |
size_cell
|
float
|
Cell size (Mpc.h^-1). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
|
|
|
distance and redshift, distance/redshift interpolators, radial box |
||
|
bounds and the reduced Hubble constant. |
Source code in lelantos/utils.py
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 | |
saclay_mock_center_of_the_box
¶
saclay_mock_center_of_the_box(box_bound)
Return the (RA, Dec) centre of a SaclayMocks box footprint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
box_bound
|
sequence
|
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
|
Source code in lelantos/utils.py
425 426 427 428 429 430 431 432 433 434 435 436 | |
saclay_mock_coord_dm_map
¶
saclay_mock_coord_dm_map(X, Y, Z, Rmin, size_cell, box_shape, interpolation_method)
Convert cartesian coordinates to SaclayMocks dark-matter box indexes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X, Y, Z
|
array - like
|
Cartesian coordinates (Mpc.h^-1). |
required |
Rmin
|
float
|
Radial lower bound of the box (Mpc.h^-1). |
required |
size_cell
|
float
|
Cell size (Mpc.h^-1). |
required |
box_shape
|
tuple[int]
|
Box pixel shape. |
required |
interpolation_method
|
str
|
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
|
Source code in lelantos/utils.py
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 | |
saclay_mock_read_box
¶
saclay_mock_read_box(box_dir, n_x, name_box)
Read one SaclayMocks box FITS slab from disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
box_dir
|
str
|
Directory holding the box FITS files. |
required |
n_x
|
int
|
Slab index. |
required |
name_box
|
str
|
Box field name (e.g. |
required |
Returns:
| Type | Description |
|---|---|
|
numpy.ndarray: The slab data array. |
Source code in lelantos/utils.py
467 468 469 470 471 472 473 474 475 476 477 478 479 480 | |
saclay_mock_get_box
¶
saclay_mock_get_box(box_dir, box_shape, name_box='box')
Assemble a full SaclayMocks box from its per-slab FITS files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
box_dir
|
str
|
Directory holding the box FITS files. |
required |
box_shape
|
tuple[int]
|
Full box pixel shape. |
required |
name_box
|
str
|
Box field name. Defaults to |
'box'
|
Returns:
| Type | Description |
|---|---|
|
numpy.ndarray: The assembled 3D box. |
Source code in lelantos/utils.py
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 | |
saclay_mock_sky_to_cartesian
¶
saclay_mock_sky_to_cartesian(ra, dec, R, ra0, dec0)
XYZ of a point P (ra,dec,R) in a frame with observer at O, Z along OP, X along ra0, Y along dec0 angles in radians tested that ra,dec, R = box.ComputeRaDecR(R0,ra0,dec0,X,Y,Z) x,y,z = box.ComputeXYZ(ra[0],dec[0],R,ra0,dec0) print x-X,y-Y,z-R0-Z prints ~1E-13 for random inputs
Source code in lelantos/utils.py
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 | |
cut_sky_catalog
¶
cut_sky_catalog(ra, dec, z, ramin=None, ramax=None, decmin=None, decmax=None, zmin=None, zmax=None)
Boolean mask selecting objects inside a sky/redshift footprint.
RA/Dec bounds are given in degrees and compared against ra/dec in
radians; unset bounds impose no constraint on that edge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ra, dec
|
array - like
|
Object sky angles (radians). |
required |
z
|
array - like
|
Object redshift. |
required |
ramin, ramax, decmin, decmax
|
float
|
Angular bounds (degrees). |
required |
zmin, zmax
|
float
|
Redshift bounds. |
required |
Returns:
| Type | Description |
|---|---|
|
numpy.ndarray: Boolean mask of the selected objects. |
Source code in lelantos/utils.py
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 | |
init_shared_array
¶
init_shared_array(shape, full_value=np.inf)
Allocate a flat multiprocessing shared array filled with a constant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
tuple[int]
|
Logical array shape (flattened for sharing). |
required |
full_value
|
float
|
Fill value. Defaults to |
inf
|
Returns:
| Type | Description |
|---|---|
|
multiprocessing.Array: Shared double array of |
Source code in lelantos/utils.py
563 564 565 566 567 568 569 570 571 572 573 574 575 576 | |
mp_array_to_numpyarray
¶
mp_array_to_numpyarray(mp_arr)
View a multiprocessing shared array as a numpy array (no copy).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mp_arr
|
Array
|
Shared array. |
required |
Returns:
| Type | Description |
|---|---|
|
numpy.ndarray: A numpy view onto the shared buffer. |
Source code in lelantos/utils.py
579 580 581 582 583 584 585 586 587 588 | |
bin_ndarray
¶
bin_ndarray(ndarray, new_shape, operation='mean')
From : https://stackoverflow.com/questions/8090229/resize-with-averaging-or-rebin-a-numpy-2d-array/29042041 Bins an ndarray in all axes based on the target shape, by summing or averaging. Number of output dimensions must match number of input dimensions. Example
m = np.arange(0,100,1).reshape((10,10)) n = bin_ndarray(m, new_shape=(5,5), operation='sum') print(n) [[ 22 30 38 46 54][102 110 118 126 134] [182 190 198 206 214][262 270 278 286 294] [342 350 358 366 374]]
Source code in lelantos/utils.py
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 | |
interpolate_map
¶
interpolate_map(interpolation_method, map_array, coord)
Sample a 3D map at 3D-gridded coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interpolation_method
|
str
|
|
required |
map_array
|
ndarray
|
The 3D map to sample. |
required |
coord
|
ndarray
|
Coordinate grid of shape |
required |
Returns:
| Type | Description |
|---|---|
|
numpy.ndarray: Sampled values of shape |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in lelantos/utils.py
635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 | |
interpolate_and_fill_map
¶
interpolate_and_fill_map(interpolation_method, map_array, coord)
Sample a 3D map at a flat list of 3D coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interpolation_method
|
str
|
|
required |
map_array
|
ndarray
|
The 3D map to sample. |
required |
coord
|
ndarray
|
Coordinates of shape |
required |
Returns:
| Type | Description |
|---|---|
|
numpy.ndarray: Sampled values of length |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in lelantos/utils.py
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 | |
gaussian_smoothing
¶
gaussian_smoothing(mapdata, sigma)
Gaussian-smooth an array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapdata
|
ndarray
|
Input array. |
required |
sigma
|
float | sequence
|
Gaussian kernel standard deviation. |
required |
Returns:
| Type | Description |
|---|---|
|
numpy.ndarray: The smoothed array. |
Source code in lelantos/utils.py
700 701 702 703 704 705 706 707 708 709 710 711 | |
create_log
¶
create_log(log_level='info')
Create and configure a stream :class:Logger.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
log_level
|
str
|
|
'info'
|
Returns:
| Name | Type | Description |
|---|---|---|
Logger |
A logger writing to the console. |
Source code in lelantos/utils.py
833 834 835 836 837 838 839 840 841 842 843 844 | |
create_report_log
¶
create_report_log(name='Python_Report', log_level='info')
Create and configure a file (report) :class:Logger.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Report file path. Defaults to |
'Python_Report'
|
log_level
|
str
|
|
'info'
|
Returns:
| Name | Type | Description |
|---|---|---|
Logger |
A logger writing to |
Source code in lelantos/utils.py
847 848 849 850 851 852 853 854 855 856 857 858 859 | |
latex_float
¶
latex_float(float_input, decimals_input='{0:.2g}')
example use: import matplotlib.pyplot as plt plt.figure(),plt.clf() plt.plot(np.array([1,2.]),'ko-',label="$P_0="+latex_float(7.63e-5)+'$'), plt.legend()
Source code in lelantos/utils.py
974 975 976 977 978 979 980 981 982 983 984 985 986 987 | |
return_key
¶
return_key(dictionary, string, default_value)
Return dictionary[string] if present, else a default.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dictionary
|
dict
|
Source mapping. |
required |
string
|
Key to look up. |
required | |
default_value
|
Value returned when the key is absent. |
required |
Returns:
| Type | Description |
|---|---|
|
The value at |
Source code in lelantos/utils.py
990 991 992 993 994 995 996 997 998 999 1000 1001 | |
dump
¶
dump(obj, file, protocol=4)
Pickle obj to file using protocol 4.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Object to serialise. |
required | |
file
|
Writable binary file object. |
required | |
protocol
|
int
|
Pickle protocol. Defaults to 4. |
4
|
Source code in lelantos/utils.py
1040 1041 1042 1043 1044 1045 1046 1047 1048 | |
patch_mp_connection_bpo_17560
¶
patch_mp_connection_bpo_17560(log=None)
Apply PR-10305 / bpo-17560 connection send/receive max size update
See the original issue at https://bugs.python.org/issue17560 and https://github.com/python/cpython/pull/10305 for the pull request.
This only supports Python versions 3.3 - 3.7, this function does nothing for Python versions outside of that range.
Source code in lelantos/utils.py
1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 | |
hist_profile
¶
hist_profile(x, y, bins, range_x, range_y, outlier_insensitive=False)
Binned mean (or median) profile of y versus x with errors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array - like
|
Values binned along the x-axis. |
required |
y
|
array - like
|
Values averaged within each x-bin. |
required |
bins
|
int
|
Number of x-bins. |
required |
range_x
|
sequence
|
|
required |
range_y
|
sequence
|
|
required |
outlier_insensitive
|
bool
|
Use median and a percentile-based spread instead of mean and standard deviation. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
|
Source code in lelantos/utils.py
1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 | |
plot_histo
¶
plot_histo(value, value_name, name, dotted=False, **kwargs)
Draw a histogram of value on the current axes.
Binning, colour, normalisation, etc. are read from kwargs keys prefixed
by value_name (see the plot_args config dicts).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
array - like
|
Values to histogram. |
required |
value_name
|
str
|
Prefix used to look up styling in |
required |
name
|
str
|
Base output name (suffixed for norm/cumulative). |
required |
dotted
|
bool
|
Draw a dashed outline-only histogram. |
False
|
**kwargs
|
Styling options ( |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
|
|
|
histogram outputs. |
Source code in lelantos/utils.py
1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 | |
save_histo
¶
save_histo(pwd, value, value_name, name, comparison=None, comparison_legend=None, **kwargs)
Plot and save a histogram (with optional comparison series) as a PDF.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pwd
|
str
|
Output directory. |
required |
value
|
array - like
|
Values to histogram. |
required |
value_name
|
str
|
Quantity name (styling prefix + axis label). |
required |
name
|
str
|
Base output name. |
required |
comparison
|
list[array - like]
|
Extra series to overplot. |
None
|
comparison_legend
|
list[str]
|
Legend labels. |
None
|
**kwargs
|
Styling options. |
{}
|
Source code in lelantos/utils.py
1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 | |
plot_mean_redshift_dependence
¶
plot_mean_redshift_dependence(value, redshift, value_name, name, **kwargs)
Plot the binned mean of value versus redshift (or wavelength).
The x-axis can be converted to observed or rest-frame Lyman-alpha
wavelength via the {value_name}_lambda_obs / _lambda_rest kwargs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
array - like
|
Quantity to average. |
required |
redshift
|
array - like
|
Redshift of each value. |
required |
value_name
|
str
|
Styling/label prefix. |
required |
name
|
str
|
Base output name. |
required |
**kwargs
|
Binning/labelling options. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
The (possibly suffixed) output name. |
Source code in lelantos/utils.py
1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 | |
save_mean_redshift_dependence
¶
save_mean_redshift_dependence(pwd, value, redshift, value_name, name, comparison=None, comparison_redshift=None, comparison_legend=None, **kwargs)
Plot and save the mean-vs-redshift dependence (with comparisons) as PDF.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pwd
|
str
|
Output directory. |
required |
value
|
array - like
|
Quantity to average. |
required |
redshift
|
array - like
|
Redshift of each value. |
required |
value_name
|
str
|
Styling/label prefix. |
required |
name
|
str
|
Base output name. |
required |
comparison
|
list[array - like]
|
Extra series to overplot. |
None
|
comparison_redshift
|
list[array - like]
|
Redshifts of the comparison series. |
None
|
comparison_legend
|
list[str]
|
Legend labels. |
None
|
**kwargs
|
Binning/labelling options. |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If both observed- and rest-frame wavelength are requested. |
Source code in lelantos/utils.py
1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 | |
plot_redshift_dependence
¶
plot_redshift_dependence(value, redshift, value_name, name, **kwargs)
Scatter value versus redshift over a redshift window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
array - like
|
Quantity to plot. |
required |
redshift
|
array - like
|
Redshift of each value. |
required |
value_name
|
str
|
Styling/label prefix. |
required |
name
|
str
|
Base output name. |
required |
**kwargs
|
|
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
The output name. |
Source code in lelantos/utils.py
1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 | |
save_redshift_dependence
¶
save_redshift_dependence(pwd, value, redshift, value_name, name, comparison=None, comparison_redshift=None, comparison_legend=None, **kwargs)
Plot and save the value-vs-redshift scatter (with comparisons) as PDF.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pwd
|
str
|
Output directory. |
required |
value
|
array - like
|
Quantity to plot. |
required |
redshift
|
array - like
|
Redshift of each value. |
required |
value_name
|
str
|
Styling/label prefix. |
required |
name
|
str
|
Base output name. |
required |
comparison
|
list[array - like]
|
Extra series to overplot. |
None
|
comparison_redshift
|
list[array - like]
|
Redshifts of the comparison series. |
None
|
comparison_legend
|
list[str]
|
Legend labels. |
None
|
**kwargs
|
Plot options. |
{}
|
Source code in lelantos/utils.py
1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 | |
plot_ra_dec
¶
plot_ra_dec(ra, dec, name, **kwargs)
Scatter objects in the RA/Dec plane, optionally outlining RA sub-cuts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ra, dec
|
array - like
|
Object sky angles. |
required |
name
|
str
|
Base output name. |
required |
**kwargs
|
|
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
The output name. |
Source code in lelantos/utils.py
1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 | |
save_ra_dec
¶
save_ra_dec(pwd, ra, dec, name, comparison_ra=None, comparison_dec=None, comparison_legend=None, **kwargs)
Plot and save the RA/Dec diagram (with optional comparison) as a PDF.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pwd
|
str
|
Output directory. |
required |
ra, dec
|
array - like
|
Object sky angles. |
required |
name
|
str
|
Base output name. |
required |
comparison_ra
|
list[array - like]
|
Comparison RA series. |
None
|
comparison_dec
|
list[array - like]
|
Comparison Dec series. |
None
|
comparison_legend
|
list[str]
|
Legend labels. |
None
|
**kwargs
|
Axis-limit / label / styling options. |
{}
|
Source code in lelantos/utils.py
1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 | |