position = source.center model = source.subtracted.fit_model(position, "Gaussian") rel_center = center - Extent(source.x_min, source.y_min) rel_model = fitting.shifted_model(model, -source.cutout.x_min, -source.cutout.y_min) plotting.plot_peak_model(source.cutout, rel_center.x, rel_center.y, rel_model) model_fwhm_pix = fitting.fwhm(model) * Unit("pix") model_fwhm = (model_fwhm_pix * frame.average_pixelscale).to("arcsec") print("Model FWHM: ", model_fwhm) evaluated_model = source.cutout.evaluate_model(model) all_residual = Frame(np.copy(model_residual)) all_residual[source.y_slice, source.x_slice] -= evaluated_model all_residual.save(fs.join(residuals_path, "all_residual.fits")) model = Gaussian2D(amplitude=0.0087509425805, x_mean=center.x, y_mean=center.y, x_stddev=sigma, y_stddev=sigma) rel_model = fitting.shifted_model(model, -source.cutout.x_min, -source.cutout.y_min) plotting.plot_peak_model(source.cutout, rel_center.x, rel_center.y, rel_model) evaluated_model = source.cutout.evaluate_model(model) all_residual2 = Frame(np.copy(model_residual)) all_residual2[source.y_slice, source.x_slice] -= evaluated_model all_residual2.save(fs.join(residuals_path, "all_residual2.fits")) # -----------------------------------------------------------------
# Create a mask of the pixels that are NaNs nans = Mask.is_nan(frame) # Set the NaN pixels to zero in the frame frame[nans] = 0.0 # Interpolate the frame in the masked pixels if arguments.method == "biharmonic": data = interpolation.inpaint_biharmonic(frame, mask) elif arguments.method == "local_mean": data = interpolation.in_paint(frame, mask, method="localmean") else: raise ValueError("Invalid interpolation method (should be 'biharmonic' or 'local_mean')") new_frame = Frame(data) # Set the original NaN pixels back to NaN new_frame[nans] = float("nan") # Inform the user log.info("Saving the result ...") # Save the result path = fs.join(output_path, arguments.image) new_frame.save(path, header=header) # Write the mask if arguments.mask: path = fs.join(output_path, "mask.fits") new_frame[mask] = float('nan') new_frame.save(path, header=header) # -----------------------------------------------------------------
# Interpolate the frame in the masked pixels if arguments.method == "biharmonic": data = interpolation.inpaint_biharmonic(frame, mask) elif arguments.method == "local_mean": data = interpolation.in_paint(frame, mask, method="localmean") else: raise ValueError( "Invalid interpolation method (should be 'biharmonic' or 'local_mean')" ) new_frame = Frame(data) # Set the original NaN pixels back to NaN new_frame[nans] = float("nan") # Inform the user log.info("Saving the result ...") # Save the result path = fs.join(output_path, arguments.image) new_frame.save(path, header=header) # Write the mask if arguments.mask: path = fs.join(output_path, "mask.fits") new_frame[mask] = float('nan') new_frame.save(path, header=header) # -----------------------------------------------------------------
# ----------------------------------------------------------------- # Load the image frame = Frame.from_file(arguments.image) # Load the region region_name = os.path.splitext(os.path.basename(arguments.region))[0] region = Region.from_file(arguments.region) # Create the mask mask = Mask(region.get_mask(shape=frame.shape)) # Calculate the inverse, if requested if arguments.invert: mask = mask.inverse() # ----------------------------------------------------------------- if arguments.data: new_frame = frame frame[mask] = arguments.value # Create a frame for the total mask else: new_frame = Frame(mask.astype(int)) # Write out the new frame new_frame.save(region_name + ".fits") # -----------------------------------------------------------------
frame *= conversion_factor # Plot the difference #plotting.plot_difference(frame, simulated[filter_name]) sum_simulated = np.sum(frame) sum_observed = np.sum(observed[filter_name]) ratio = sum_simulated / sum_observed wavelength = simulated[filter_name].filter.pivotwavelength() x.append(wavelength) y.append(ratio) frame_path = fs.join(new_path, filter_name + ".fits") frame.save(frame_path) exit() plt.plot(x, y) plt.xscale('log') plt.yscale('log') plt.show() # -----------------------------------------------------------------