@@ -127,7 +127,8 @@ def _init_as_fits(self, fits_filename, telescope_name, istokes=0, ichan=0):
127127 """
128128 self .filename = fits_filename
129129 self .telescope_name = telescope_name
130- self .rootname = "." .join (fits_filename .split ("." )[:- 1 ]) + "."
130+ fits_real_filename = fits_filename .split ("/" )[- 1 ]
131+ self .rootname = "." .join (fits_real_filename .split ("." )[:- 1 ]) + "."
131132 self .header , self .data = read_fits (self .filename , header_as_dict = True )
132133 stokes_iaxis = get_stokes_axis_iaxis (self .header )
133134
@@ -152,12 +153,16 @@ def _init_as_fits(self, fits_filename, telescope_name, istokes=0, ichan=0):
152153 self .y_axis , _ , self .y_unit = get_axis_from_fits_header (
153154 self .header , 2 , pixel_offset = False
154155 )
156+ offset_scale = 1.5
157+ x_offset = offset_scale * np .unique (np .diff (self .x_axis ))[0 ]
158+ y_offset = offset_scale * np .unique (np .diff (self .y_axis ))[0 ]
159+ self .x_axis = np .flip (self .x_axis + x_offset )
160+ self .y_axis = np .flip (self .y_axis + y_offset )
155161 self .x_unit = "m"
156162 self .y_unit = "m"
157163 elif "Astrohack" in self .header ["ORIGIN" ]:
158164 self .x_axis , _ , self .x_unit = get_axis_from_fits_header (self .header , 1 )
159165 self .y_axis , _ , self .y_unit = get_axis_from_fits_header (self .header , 2 )
160- self .data = np .fliplr (self .data )
161166 else :
162167 raise NotImplementedError (f'Unrecognized origin:\n { self .header ["origin" ]} ' )
163168 self ._create_base_mask ()
@@ -208,11 +213,13 @@ def resample(self, ref_image):
208213 x_mesh_dest , y_mesh_dest = np .meshgrid (
209214 ref_image .x_axis , ref_image .y_axis , indexing = "ij"
210215 )
216+ raveled_data = self .data .ravel ()
217+ valid_data = np .isfinite (raveled_data )
211218 resamp = griddata (
212- (x_mesh_orig .ravel (), y_mesh_orig .ravel ()),
213- self . data . ravel () ,
219+ (x_mesh_orig .ravel ()[ valid_data ] , y_mesh_orig .ravel ()[ valid_data ] ),
220+ raveled_data [ valid_data ] ,
214221 (x_mesh_dest .ravel (), y_mesh_dest .ravel ()),
215- method = "linear " ,
222+ method = "nearest " ,
216223 )
217224 size = ref_image .x_axis .shape [0 ], ref_image .y_axis .shape [0 ]
218225 self .x_axis = ref_image .x_axis
@@ -592,14 +599,24 @@ def export_to_fits(self, destination):
592599 reorder_axis = False ,
593600 )
594601
595- def scatter_plot (self , destination , ref_image , dpi = 300 , display = False ):
602+ def scatter_plot (
603+ self ,
604+ destination ,
605+ ref_image ,
606+ dpi = 300 ,
607+ display = False ,
608+ max_radius = None ,
609+ min_radius = None ,
610+ ):
596611 """
597612 Produce a scatter plot of self.data agains ref_image.data
598613 Args:
599614 destination: Location to store scatter plot
600615 ref_image: Reference FITSImage object
601616 dpi: png resolution on disk
602617 display: Show interactive view of plot
618+ max_radius: Maximum radius for scatter plot comparison as the outer panels can be crappy.
619+ min_radius: Minimum radius for scatter plot comparison as the innermost panels can be crappy.
603620
604621 Returns:
605622 None
@@ -610,10 +627,23 @@ def scatter_plot(self, destination, ref_image, dpi=300, display=False):
610627
611628 fig , ax = plt .subplots (1 , 1 , figsize = [10 , 8 ])
612629
630+ x_mesh_orig , y_mesh_orig = np .meshgrid (self .x_axis , self .y_axis , indexing = "ij" )
631+ radius = np .sqrt (x_mesh_orig ** 2 + y_mesh_orig ** 2 )
632+
633+ telescope = get_proper_telescope (self .telescope_name )
634+ if min_radius is None :
635+ min_radius = telescope .inner_radial_limit
636+ if max_radius is None :
637+ max_radius = telescope .outer_radial_limit - 1.0
613638 scatter_mask = np .isfinite (ref_image .data )
614639 scatter_mask = np .where (np .isfinite (self .data ), scatter_mask , False )
640+ scatter_mask = np .where (radius < max_radius , scatter_mask , False )
641+ scatter_mask = np .where (radius > min_radius , scatter_mask , False )
642+
615643 ydata = self .data [scatter_mask ]
616644 xdata = ref_image .data [scatter_mask ]
645+ pl_max = np .max ((np .max (xdata ), np .max (ydata )))
646+ pl_min = np .min ((np .min (xdata ), np .min (ydata )))
617647
618648 scatter_plot (
619649 ax ,
@@ -622,6 +652,12 @@ def scatter_plot(self, destination, ref_image, dpi=300, display=False):
622652 ydata ,
623653 f"{ self .filename } [{ self .unit } ]" ,
624654 add_regression = True ,
655+ regression_method = "siegelslopes" ,
656+ add_regression_reference = True ,
657+ regression_reference_label = "Perfect agreement" ,
658+ xlim = (pl_min , pl_max ),
659+ ylim = [pl_min , pl_max ],
660+ force_equal_aspect = True ,
625661 )
626662 close_figure (
627663 fig ,
@@ -641,7 +677,6 @@ def image_comparison_chunk(compare_params):
641677 Returns:
642678 A DataTree containing the Image and its reference Image.
643679 """
644-
645680 image = FITSImage .from_fits_file (
646681 compare_params ["this_image" ], compare_params ["telescope_name" ]
647682 )
@@ -698,8 +733,8 @@ def image_comparison_chunk(compare_params):
698733 if compare_params ["plot_scatter" ]:
699734 image .scatter_plot (destination , ref_image , dpi = dpi , display = display )
700735
701- img_node = xr .DataTree (name = image .filename , dataset = image .export_as_xds ())
702- ref_node = xr .DataTree (name = ref_image .filename , dataset = ref_image .export_as_xds ())
736+ img_node = xr .DataTree (name = image .rootname , dataset = image .export_as_xds ())
737+ ref_node = xr .DataTree (name = ref_image .rootname , dataset = ref_image .export_as_xds ())
703738 tree_node = xr .DataTree (
704739 name = image .rootname [:- 1 ], children = {"Reference" : ref_node , "Image" : img_node }
705740 )
0 commit comments