Display & Metrics¶
Functions for visualising PSFs and measuring image quality.
display_psf¶
from psfcraft import display_psf
Plots a PSF image with log-stretch colour mapping.
fig, ax = plt.subplots()
display_psf(psf, ax=ax, title="My PSF", colorbar=True)
display_psf ¶
display_psf(hdulist_or_filename, ext=0, vmin=1e-07, vmax=0.1, scale='log', cmap=None, title=None, imagecrop=None, adjust_for_oversampling=False, normalize='None', crosshairs=False, markcentroid=False, colorbar=True, colorbar_orientation='vertical', pixelscale='PIXELSCL', ax=None, return_ax=False, interpolation=None, cube_slice=None, angular_coordinate_unit=u.arcsec) -> None
Display a PSF image stored in a FITS HDUList or file.
Renders a 2-D PSF on a linear or logarithmic colour scale with optional crosshairs, centroid marker, and colour bar. Axes are labelled in angular units (default: arcseconds).
| Parameters: |
|
|---|
| Returns: |
|
|---|
Example
psf = tel.calc_psf(fov_arcsec=2.0) display_psf(psf, scale='log', title='My PSF')
Source code in psfcraft/utils.py
902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 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 | |
display_ee¶
from psfcraft import display_ee
Plots the Encircled Energy (EE) curve as a function of radius.
display_ee(psf)
display_ee ¶
display_ee(hdulist_or_filename=None, ext: int = 0, overplot: bool = False, ax=None, mark_levels: bool = True, **kwargs: object) -> None
Plot the azimuthally averaged Encircled Energy (EE) curve for a PSF.
The EE is computed via :func:radial_profile and plotted as a function
of angular radius in arcseconds. Reference lines are optionally drawn
at EE = 50 %, 80 %, and 95 %.
| Parameters: |
|
|---|
| Raises: |
|
|---|
Example
psf = tel.calc_psf(fov_arcsec=3.0) fig, ax = plt.subplots() display_ee(psf, ax=ax, mark_levels=True)
Source code in psfcraft/utils.py
1124 1125 1126 1127 1128 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 | |
measure_ee¶
from psfcraft import measure_ee
Returns a callable f(r) that gives the EE fraction within radius r (arcsec).
ee_func = measure_ee(psf)
print(f"EE50: {ee_func(0.15):.3f}") # fraction within 0.15 arcsec
# Sweep radii
import numpy as np
radii = np.linspace(0.05, 0.5, 50)
ee_curve = [ee_func(r) for r in radii]
measure_ee ¶
measure_ee(hdulist_or_filename=None, ext=0, center=None, binsize=None, normalize='None')
measure encircled energy vs radius and return as an interpolator
Returns a function object which when called returns the Encircled Energy inside a given radius, for any arbitrary desired radius smaller than the image size.
Parameters¶
hdulist_or_filename : string Either a fits.HDUList object or a filename of a FITS file on disk ext : int Extension in that FITS file center : tuple of floats Coordinates (x,y) of PSF center. Default is image center. binsize: size of step for profile. Default is pixel size. normalize : string set to 'peak' to normalize peak intensity =1, or to 'total' to normalize total flux=1. Default is no normalization (i.e. retain whatever normalization was used in computing the PSF itself)
Returns¶
encircled_energy: function A function which will return the encircled energy interpolated to any desired radius.
Examples¶
ee = measure_ee("someimage.fits") # doctest: +SKIP print("The EE at 0.5 arcsec is ", ee(0.5)) # doctest: +SKIP
Source code in poppy/utils.py
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 778 779 780 | |
measure_centroid¶
from psfcraft.utils import measure_centroid
measure_centroid ¶
measure_centroid(HDUlist_or_filename=None, ext=0, slice=0, boxsize=20, verbose=False, units='pixels', relativeto='origin', **kwargs)
Measure the center of an image via center-of-mass
The centroid method used is the floating-box center of mass algorithm by Jeff Valenti et al., which has been adopted for JWST target acquisition measurements on orbit. See JWST technical reports JWST-STScI-001117 and JWST-STScI-001134 for details.
Parameters¶
HDUlist_or_filename : string Either a fits.HDUList object or a filename of a FITS file on disk ext : int Extension in that FITS file slice : int, optional If that extension is a 3D datacube, which slice (plane) of that datacube to use boxsize : int Half box size for centroid relativeto : string either 'origin' for relative to pixel (0,0) or 'center' for relative to image center. Default is 'origin' units : string either 'pixels' for position in pixels or 'arcsec' for arcseconds. Relative to the relativeto parameter point in either case. verbose : bool Be more verbose
Returns¶
CoM : array_like [Y, X] coordinates of center of mass.
Source code in poppy/utils.py
1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 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 | |