some code formatting
This commit is contained in:
@@ -48,20 +48,16 @@ def _upsampled_dft(data, upsampled_region_size, upsample_factor=1, axis_offsets=
|
|||||||
"""
|
"""
|
||||||
# if people pass in an integer, expand it to a list of equal-sized sections
|
# if people pass in an integer, expand it to a list of equal-sized sections
|
||||||
if not hasattr(upsampled_region_size, "__iter__"):
|
if not hasattr(upsampled_region_size, "__iter__"):
|
||||||
upsampled_region_size = [
|
upsampled_region_size = [upsampled_region_size] * data.ndim
|
||||||
upsampled_region_size,
|
|
||||||
] * data.ndim
|
|
||||||
else:
|
else:
|
||||||
if len(upsampled_region_size) != data.ndim:
|
if len(upsampled_region_size) != data.ndim:
|
||||||
raise ValueError("shape of upsampled region sizes must be equal " "to input data's number of dimensions.")
|
raise ValueError("shape of upsampled region sizes must be equal to input data's number of dimensions.")
|
||||||
|
|
||||||
if axis_offsets is None:
|
if axis_offsets is None:
|
||||||
axis_offsets = [
|
axis_offsets = [0] * data.ndim
|
||||||
0,
|
|
||||||
] * data.ndim
|
|
||||||
else:
|
else:
|
||||||
if len(axis_offsets) != data.ndim:
|
if len(axis_offsets) != data.ndim:
|
||||||
raise ValueError("number of axis offsets must be equal to input " "data's number of dimensions.")
|
raise ValueError("number of axis offsets must be equal to input data's number of dimensions.")
|
||||||
|
|
||||||
im2pi = 1j * 2 * np.pi
|
im2pi = 1j * 2 * np.pi
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -173,11 +173,7 @@ def get_product_list(target=None, proposal_id=None, instrument="foc"):
|
|||||||
|
|
||||||
observations = Observations.query_criteria(obs_id=list(results["Dataset"][b]))
|
observations = Observations.query_criteria(obs_id=list(results["Dataset"][b]))
|
||||||
products = Observations.filter_products(
|
products = Observations.filter_products(
|
||||||
Observations.get_product_list(observations),
|
Observations.get_product_list(observations), productType=["SCIENCE"], dataproduct_type=dataproduct_type, calib_level=[2], description=description
|
||||||
productType=["SCIENCE"],
|
|
||||||
dataproduct_type=dataproduct_type,
|
|
||||||
calib_level=[2],
|
|
||||||
description=description,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
products["proposal_id"] = Column(products["proposal_id"], dtype="U35")
|
products["proposal_id"] = Column(products["proposal_id"], dtype="U35")
|
||||||
|
|||||||
@@ -191,8 +191,8 @@ def bin_ndarray(ndarray, new_shape, operation="sum"):
|
|||||||
|
|
||||||
Example
|
Example
|
||||||
-------
|
-------
|
||||||
>>> m = np.arange(0,100,1).reshape((10,10))
|
>>> m = np.arange(0, 100, 1).reshape((10, 10))
|
||||||
>>> n = bin_ndarray(m, new_shape=(5,5), operation='sum')
|
>>> n = bin_ndarray(m, new_shape=(5, 5), operation="sum")
|
||||||
>>> print(n)
|
>>> print(n)
|
||||||
|
|
||||||
[[ 22 30 38 46 54]
|
[[ 22 30 38 46 54]
|
||||||
@@ -279,9 +279,7 @@ def crop_array(data_array, headers, error_array=None, data_mask=None, step=5, nu
|
|||||||
if null_val is None:
|
if null_val is None:
|
||||||
null_val = [1.00 * error.mean() for error in error_array]
|
null_val = [1.00 * error.mean() for error in error_array]
|
||||||
elif type(null_val) is float:
|
elif type(null_val) is float:
|
||||||
null_val = [
|
null_val = [null_val] * error_array.shape[0]
|
||||||
null_val,
|
|
||||||
] * error_array.shape[0]
|
|
||||||
|
|
||||||
vertex = np.zeros((data_array.shape[0], 4), dtype=int)
|
vertex = np.zeros((data_array.shape[0], 4), dtype=int)
|
||||||
for i, image in enumerate(data_array): # Get vertex of the rectangular convex hull of each image
|
for i, image in enumerate(data_array): # Get vertex of the rectangular convex hull of each image
|
||||||
@@ -348,10 +346,7 @@ def crop_array(data_array, headers, error_array=None, data_mask=None, step=5, nu
|
|||||||
headers,
|
headers,
|
||||||
vmin=convert_flux * data_array[data_array > 0.0].mean() / 5.0,
|
vmin=convert_flux * data_array[data_array > 0.0].mean() / 5.0,
|
||||||
vmax=convert_flux * data_array[data_array > 0.0].max(),
|
vmax=convert_flux * data_array[data_array > 0.0].max(),
|
||||||
rectangle=[
|
rectangle=[rectangle] * len(headers),
|
||||||
rectangle,
|
|
||||||
]
|
|
||||||
* len(headers),
|
|
||||||
savename=savename + "_crop_region",
|
savename=savename + "_crop_region",
|
||||||
plots_folder=plots_folder,
|
plots_folder=plots_folder,
|
||||||
)
|
)
|
||||||
@@ -629,12 +624,7 @@ def rebin_array(data_array, error_array, headers, pxsize=2, scale="px", operatio
|
|||||||
|
|
||||||
# Compute binning ratio
|
# Compute binning ratio
|
||||||
if scale.lower() in ["px", "pixel"]:
|
if scale.lower() in ["px", "pixel"]:
|
||||||
Dxy_arr[i] = np.array(
|
Dxy_arr[i] = np.array([pxsize] * 2)
|
||||||
[
|
|
||||||
pxsize,
|
|
||||||
]
|
|
||||||
* 2
|
|
||||||
)
|
|
||||||
scale = "px"
|
scale = "px"
|
||||||
elif scale.lower() in ["arcsec", "arcseconds"]:
|
elif scale.lower() in ["arcsec", "arcseconds"]:
|
||||||
Dxy_arr[i] = np.array(pxsize / np.abs(w.wcs.cdelt) / 3600.0)
|
Dxy_arr[i] = np.array(pxsize / np.abs(w.wcs.cdelt) / 3600.0)
|
||||||
@@ -938,12 +928,7 @@ def smooth_data(data_array, error_array, data_mask, headers, FWHM=1.5, scale="pi
|
|||||||
dist_rc = np.where(data_mask, np.sqrt((r - xx) ** 2 + (c - yy) ** 2), fmax)
|
dist_rc = np.where(data_mask, np.sqrt((r - xx) ** 2 + (c - yy) ** 2), fmax)
|
||||||
# Catch expected "OverflowWarning" as we overflow values that are not in the image
|
# Catch expected "OverflowWarning" as we overflow values that are not in the image
|
||||||
with warnings.catch_warnings(record=True) as w:
|
with warnings.catch_warnings(record=True) as w:
|
||||||
g_rc = np.array(
|
g_rc = np.array([np.exp(-0.5 * (dist_rc / stdev) ** 2) / (2.0 * np.pi * stdev**2)] * data_array.shape[0])
|
||||||
[
|
|
||||||
np.exp(-0.5 * (dist_rc / stdev) ** 2) / (2.0 * np.pi * stdev**2),
|
|
||||||
]
|
|
||||||
* data_array.shape[0]
|
|
||||||
)
|
|
||||||
# Apply weighted combination
|
# Apply weighted combination
|
||||||
smoothed[r, c] = np.where(data_mask[r, c], np.sum(data_array * weight * g_rc) / np.sum(weight * g_rc), data_array.mean(axis=0)[r, c])
|
smoothed[r, c] = np.where(data_mask[r, c], np.sum(data_array * weight * g_rc) / np.sum(weight * g_rc), data_array.mean(axis=0)[r, c])
|
||||||
error[r, c] = np.where(
|
error[r, c] = np.where(
|
||||||
@@ -1438,9 +1423,7 @@ def compute_Stokes(data_array, error_array, data_mask, headers, FWHM=None, scale
|
|||||||
all_Q_stokes = np.zeros((np.unique(rotate).size, data_array.shape[1], data_array.shape[2]))
|
all_Q_stokes = np.zeros((np.unique(rotate).size, data_array.shape[1], data_array.shape[2]))
|
||||||
all_U_stokes = np.zeros((np.unique(rotate).size, data_array.shape[1], data_array.shape[2]))
|
all_U_stokes = np.zeros((np.unique(rotate).size, data_array.shape[1], data_array.shape[2]))
|
||||||
all_Stokes_cov = np.zeros((np.unique(rotate).size, 3, 3, data_array.shape[1], data_array.shape[2]))
|
all_Stokes_cov = np.zeros((np.unique(rotate).size, 3, 3, data_array.shape[1], data_array.shape[2]))
|
||||||
all_header_stokes = [
|
all_header_stokes = [{}] * np.unique(rotate).size
|
||||||
{},
|
|
||||||
] * np.unique(rotate).size
|
|
||||||
|
|
||||||
for i, rot in enumerate(np.unique(rotate)):
|
for i, rot in enumerate(np.unique(rotate)):
|
||||||
rot_mask = rotate == rot
|
rot_mask = rotate == rot
|
||||||
|
|||||||
@@ -23,12 +23,7 @@ def main(infile, P_cut=0.99, target=None, display="pf", output_dir=None):
|
|||||||
stkI = Stokes["I_STOKES"].data
|
stkI = Stokes["I_STOKES"].data
|
||||||
QN, UN, QN_ERR, UN_ERR = np.full((4, stkI.shape[0], stkI.shape[1]), np.nan)
|
QN, UN, QN_ERR, UN_ERR = np.full((4, stkI.shape[0], stkI.shape[1]), np.nan)
|
||||||
for sflux, nflux in zip(
|
for sflux, nflux in zip(
|
||||||
[
|
[Stokes["Q_STOKES"].data, Stokes["U_STOKES"].data, np.sqrt(Stokes["IQU_COV_MATRIX"].data[1, 1]), np.sqrt(Stokes["IQU_COV_MATRIX"].data[2, 2])],
|
||||||
Stokes["Q_STOKES"].data,
|
|
||||||
Stokes["U_STOKES"].data,
|
|
||||||
np.sqrt(Stokes["IQU_COV_MATRIX"].data[1, 1]),
|
|
||||||
np.sqrt(Stokes["IQU_COV_MATRIX"].data[2, 2]),
|
|
||||||
],
|
|
||||||
[QN, UN, QN_ERR, UN_ERR],
|
[QN, UN, QN_ERR, UN_ERR],
|
||||||
):
|
):
|
||||||
nflux[stkI > 0.0] = sflux[stkI > 0.0] / stkI[stkI > 0.0]
|
nflux[stkI > 0.0] = sflux[stkI > 0.0] / stkI[stkI > 0.0]
|
||||||
@@ -49,25 +44,10 @@ def main(infile, P_cut=0.99, target=None, display="pf", output_dir=None):
|
|||||||
target = Stokes[0].header["TARGNAME"]
|
target = Stokes[0].header["TARGNAME"]
|
||||||
|
|
||||||
fig = figure(figsize=(8, 8.5), layout="constrained")
|
fig = figure(figsize=(8, 8.5), layout="constrained")
|
||||||
fig, ax = polarization_map(
|
fig, ax = polarization_map(Stokes, P_cut=P_cut, step_vec=1, scale_vec=5, display=display, fig=fig, width=0.33, linewidth=0.5)
|
||||||
Stokes,
|
|
||||||
P_cut=P_cut,
|
|
||||||
step_vec=1,
|
|
||||||
scale_vec=5,
|
|
||||||
display=display,
|
|
||||||
fig=fig,
|
|
||||||
width=0.33,
|
|
||||||
linewidth=0.5,
|
|
||||||
)
|
|
||||||
|
|
||||||
ax.plot(*Stokescenter, marker="+", color="k", lw=3)
|
ax.plot(*Stokescenter, marker="+", color="k", lw=3)
|
||||||
ax.plot(
|
ax.plot(*Stokescenter, marker="+", color="red", lw=1.5, label="Best confidence for center: {0}".format(Stokespos.to_string("hmsdms")))
|
||||||
*Stokescenter,
|
|
||||||
marker="+",
|
|
||||||
color="red",
|
|
||||||
lw=1.5,
|
|
||||||
label="Best confidence for center: {0}".format(Stokespos.to_string("hmsdms")),
|
|
||||||
)
|
|
||||||
ax.contour(Stokescentconf, [0.01], colors="k", linewidths=3)
|
ax.contour(Stokescentconf, [0.01], colors="k", linewidths=3)
|
||||||
confcentcont = ax.contour(Stokescentconf, [0.01], colors="red")
|
confcentcont = ax.contour(Stokescentconf, [0.01], colors="red")
|
||||||
# confcont = ax.contour(Stokesconf, [0.9905], colors="r")
|
# confcont = ax.contour(Stokesconf, [0.9905], colors="r")
|
||||||
@@ -82,14 +62,7 @@ def main(infile, P_cut=0.99, target=None, display="pf", output_dir=None):
|
|||||||
# handles.append(Rectangle((0, 0), 1, 1, fill=False, ls="--", ec=snr3cont.get_edgecolor()[0]))
|
# handles.append(Rectangle((0, 0), 1, 1, fill=False, ls="--", ec=snr3cont.get_edgecolor()[0]))
|
||||||
# labels.append(r"$SNR_P \geq$ 4 contour")
|
# labels.append(r"$SNR_P \geq$ 4 contour")
|
||||||
# handles.append(Rectangle((0, 0), 1, 1, fill=False, ec=snr4cont.get_edgecolor()[0]))
|
# handles.append(Rectangle((0, 0), 1, 1, fill=False, ec=snr4cont.get_edgecolor()[0]))
|
||||||
ax.legend(
|
ax.legend(handles=handles, labels=labels, bbox_to_anchor=(-0.05, -0.02, 1.10, 0.01), loc="upper left", mode="expand", borderaxespad=0.0)
|
||||||
handles=handles,
|
|
||||||
labels=labels,
|
|
||||||
bbox_to_anchor=(-0.05, -0.02, 1.10, 0.01),
|
|
||||||
loc="upper left",
|
|
||||||
mode="expand",
|
|
||||||
borderaxespad=0.0,
|
|
||||||
)
|
|
||||||
|
|
||||||
if output_dir is not None:
|
if output_dir is not None:
|
||||||
filename = pathjoin(output_dir, "%s_center.pdf" % target)
|
filename = pathjoin(output_dir, "%s_center.pdf" % target)
|
||||||
@@ -103,57 +76,11 @@ if __name__ == "__main__":
|
|||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="Look for the center of emission for a given reduced observation")
|
parser = argparse.ArgumentParser(description="Look for the center of emission for a given reduced observation")
|
||||||
parser.add_argument(
|
parser.add_argument("-t", "--target", metavar="targetname", required=False, help="the name of the target", type=str, default=None)
|
||||||
"-t",
|
parser.add_argument("-f", "--file", metavar="path", required=False, help="The full or relative path to the data product", type=str, default=None)
|
||||||
"--target",
|
parser.add_argument("-c", "--pcut", metavar="pcut", required=False, help="The polarization cut for the data mask", type=float, default=0.99)
|
||||||
metavar="targetname",
|
parser.add_argument("-d", "--display", metavar="display", required=False, help="The map on which to display info", type=str, default="pf")
|
||||||
required=False,
|
parser.add_argument("-o", "--output_dir", metavar="directory_path", required=False, help="output directory path for the plots", type=str, default="./data")
|
||||||
help="the name of the target",
|
|
||||||
type=str,
|
|
||||||
default=None,
|
|
||||||
)
|
|
||||||
parser.add_argument(
|
|
||||||
"-f",
|
|
||||||
"--file",
|
|
||||||
metavar="path",
|
|
||||||
required=False,
|
|
||||||
help="The full or relative path to the data product",
|
|
||||||
type=str,
|
|
||||||
default=None,
|
|
||||||
)
|
|
||||||
parser.add_argument(
|
|
||||||
"-c",
|
|
||||||
"--pcut",
|
|
||||||
metavar="pcut",
|
|
||||||
required=False,
|
|
||||||
help="The polarization cut for the data mask",
|
|
||||||
type=float,
|
|
||||||
default=0.99,
|
|
||||||
)
|
|
||||||
parser.add_argument(
|
|
||||||
"-d",
|
|
||||||
"--display",
|
|
||||||
metavar="display",
|
|
||||||
required=False,
|
|
||||||
help="The map on which to display info",
|
|
||||||
type=str,
|
|
||||||
default="pf",
|
|
||||||
)
|
|
||||||
parser.add_argument(
|
|
||||||
"-o",
|
|
||||||
"--output_dir",
|
|
||||||
metavar="directory_path",
|
|
||||||
required=False,
|
|
||||||
help="output directory path for the plots",
|
|
||||||
type=str,
|
|
||||||
default="./data",
|
|
||||||
)
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
exitcode = main(
|
exitcode = main(infile=args.file, P_cut=args.pcut, target=args.target, display=args.display, output_dir=args.output_dir)
|
||||||
infile=args.file,
|
|
||||||
P_cut=args.pcut,
|
|
||||||
target=args.target,
|
|
||||||
display=args.display,
|
|
||||||
output_dir=args.output_dir,
|
|
||||||
)
|
|
||||||
print("Written to: ", exitcode)
|
print("Written to: ", exitcode)
|
||||||
|
|||||||
@@ -15,17 +15,7 @@ Radio = fits.open("./data/NGC1068/MERLIN-VLA/Combined_crop.fits")
|
|||||||
|
|
||||||
levels = np.logspace(-0.5, 1.99, 7) / 100.0 * Stokes_UV[0].data.max() * Stokes_UV[0].header["photflam"]
|
levels = np.logspace(-0.5, 1.99, 7) / 100.0 * Stokes_UV[0].data.max() * Stokes_UV[0].header["photflam"]
|
||||||
A = overplot_pol(Stokes_UV, Radio, norm=LogNorm())
|
A = overplot_pol(Stokes_UV, Radio, norm=LogNorm())
|
||||||
A.plot(
|
A.plot(levels=levels, P_cut=0.99, SNRi_cut=1.0, scale_vec=3, step_vec=1, norm=LogNorm(5e-5, 1e-1), cmap="inferno_r", width=0.8, linewidth=1.2)
|
||||||
levels=levels,
|
|
||||||
P_cut=0.99,
|
|
||||||
SNRi_cut=1.0,
|
|
||||||
scale_vec=3,
|
|
||||||
step_vec=1,
|
|
||||||
norm=LogNorm(5e-5, 1e-1),
|
|
||||||
cmap="inferno_r",
|
|
||||||
width=0.8,
|
|
||||||
linewidth=1.2,
|
|
||||||
)
|
|
||||||
A.add_vector(
|
A.add_vector(
|
||||||
A.other_wcs.celestial.wcs.crpix - (1.0, 1.0),
|
A.other_wcs.celestial.wcs.crpix - (1.0, 1.0),
|
||||||
pol_deg=0.124,
|
pol_deg=0.124,
|
||||||
|
|||||||
@@ -271,18 +271,9 @@ class specpol(object):
|
|||||||
"""
|
"""
|
||||||
data_dump = np.loadtxt(join_path(data_dir, filename), skiprows=1).T
|
data_dump = np.loadtxt(join_path(data_dir, filename), skiprows=1).T
|
||||||
self.zero(data_dump.shape[1])
|
self.zero(data_dump.shape[1])
|
||||||
(
|
(self.wav, self.wav_err[:, 0], self.I, self.IQUV_cov[0, 0], self.Q, self.IQUV_cov[1, 1], self.U, self.IQUV_cov[2, 2], self.V, self.IQUV_cov[3, 3]) = (
|
||||||
self.wav,
|
data_dump[:10]
|
||||||
self.wav_err[:, 0],
|
)
|
||||||
self.I,
|
|
||||||
self.IQUV_cov[0, 0],
|
|
||||||
self.Q,
|
|
||||||
self.IQUV_cov[1, 1],
|
|
||||||
self.U,
|
|
||||||
self.IQUV_cov[2, 2],
|
|
||||||
self.V,
|
|
||||||
self.IQUV_cov[3, 3],
|
|
||||||
) = data_dump[:10]
|
|
||||||
self.wav_err[:, 1] = deepcopy(self.wav_err[:, 0])
|
self.wav_err[:, 1] = deepcopy(self.wav_err[:, 0])
|
||||||
self.bin_edges[:-1], self.bin_edges[-1] = deepcopy(self.wav - self.wav_err[:, 0]), deepcopy(self.wav[-1] + self.wav_err[-1, 1])
|
self.bin_edges[:-1], self.bin_edges[-1] = deepcopy(self.wav - self.wav_err[:, 0]), deepcopy(self.wav[-1] + self.wav_err[-1, 1])
|
||||||
for i in range(4):
|
for i in range(4):
|
||||||
@@ -314,11 +305,7 @@ class specpol(object):
|
|||||||
self.PA_err,
|
self.PA_err,
|
||||||
]
|
]
|
||||||
).T
|
).T
|
||||||
np.savetxt(
|
np.savetxt(join_path(output_dir, filename + ".txt"), data_dump, header=header)
|
||||||
join_path(output_dir, filename + ".txt"),
|
|
||||||
data_dump,
|
|
||||||
header=header,
|
|
||||||
)
|
|
||||||
return join_path(output_dir, filename)
|
return join_path(output_dir, filename)
|
||||||
|
|
||||||
def plot(self, fig=None, ax=None, savename=None, plots_folder=""):
|
def plot(self, fig=None, ax=None, savename=None, plots_folder=""):
|
||||||
|
|||||||
Reference in New Issue
Block a user