Skip to content

Commit

Permalink
make uvf cube outputs be 3D arrays rather than pointer arrays (#317)
Browse files Browse the repository at this point in the history
* make uvf cube outputs be 3D arrays rather than pointer arrays

separate pols into different files
save uvf cubes in the `grid_data` subfolder

* use precision set in obs structure
  • Loading branch information
bhazelton authored Jan 19, 2025
1 parent c15a605 commit 92f170f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 29 deletions.
61 changes: 39 additions & 22 deletions fhd_core/gridding/vis_model_freq_split.pro
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@ FUNCTION vis_model_freq_split,obs,status_str,psf,params,vis_weights,model_uv_arr
file_path_fhd=file_path_fhd,rephase_weights=rephase_weights,silent=silent,$
vis_n_arr=vis_n_arr,x_range=x_range,y_range=y_range,preserve_visibilities=preserve_visibilities,$
obs_out=obs_out,psf_out=psf_out,save_uvf=save_uvf, uvf_name=uvf_name,bi_use=bi_use,_Extra=extra
ext='.UVFITS'

t0=Systime(1)

IF N_Elements(silent) EQ 0 THEN silent=0
pol_names=obs.pol_names
vis_filepath=file_path_fhd+'_vis_'

if keyword_set(save_uvf) then begin
if n_elements(uvf_name) ne 0 then uvf_filepath = file_path_fhd+'_'+uvf_name+'_gridded_uvf.sav' $
else uvf_filepath = file_path_fhd+'_gridded_uvf.sav'
folder_use = file_dirname(file_path_fhd)
folder_use += path_sep() + "grid_data" + path_sep()
basename = file_basename(file_path_fhd)
if n_elements(uvf_name) ne 0 then begin
uvf_filepath = folder_use + basename + '_' + uvf_name + '_gridded_uvf_' + pol_names + '.sav'
endif else begin
uvf_filepath = folder_use + basename + '_gridded_uvf_' + pol_names + '.sav'
endelse
endif

n_freq=obs.n_freq
n_pol=obs.n_pol
dimension=obs.dimension
Expand Down Expand Up @@ -71,13 +76,6 @@ FUNCTION vis_model_freq_split,obs,status_str,psf,params,vis_weights,model_uv_arr
ENDIF ELSE obs_out=obs
IF N_Elements(psf_out) EQ 0 THEN psf_out=psf

if keyword_set(save_uvf) then begin
dirty_uv_arr=Ptrarr(n_pol,nf,/allocate)
weights_uv_arr=Ptrarr(n_pol,nf,/allocate)
variance_uv_arr=Ptrarr(n_pol,nf,/allocate)
IF Keyword_Set(model_flag) THEN model_uv_arr=Ptrarr(n_pol,nf,/allocate)
endif

dirty_arr=Ptrarr(n_pol,nf,/allocate)
weights_arr=Ptrarr(n_pol,nf,/allocate)
variance_arr=Ptrarr(n_pol,nf,/allocate)
Expand All @@ -97,6 +95,21 @@ FUNCTION vis_model_freq_split,obs,status_str,psf,params,vis_weights,model_uv_arr
model_ptr=vis_model_arr[pol_i]
freq_use=(*obs_out.baseline_info).freq_use
n_vis_use=0.

if keyword_set(save_uvf) then begin
if obs.double_precision then begin
dirty_uv_arr=dcomplexarr(dimension, dimension, nf)
weights_uv_arr=dcomplexarr(dimension, dimension, nf)
variance_uv_arr=dcomplexarr(dimension, dimension, nf)
IF Keyword_Set(model_flag) THEN model_uv_arr=dcomplexarr(dimension, dimension, nf)
endif else begin
dirty_uv_arr=complexarr(dimension, dimension, nf)
weights_uv_arr=complexarr(dimension, dimension, nf)
variance_uv_arr=complexarr(dimension, dimension, nf)
IF Keyword_Set(model_flag) THEN model_uv_arr=complexarr(dimension, dimension, nf)
endelse
endif

FOR fi=0L,nf-1 DO BEGIN
fi_use=where((freq_bin_i2 EQ fi) AND (freq_use GT 0),nf_use)
variance_holo=1 ;initialize
Expand All @@ -116,12 +129,12 @@ FUNCTION vis_model_freq_split,obs,status_str,psf,params,vis_weights,model_uv_arr
vis_n_arr[pol_i,fi]=n_vis

if keyword_set(save_uvf) then begin
*dirty_uv_arr[pol_i,fi]=dirty_uv*n_vis
*weights_uv_arr[pol_i,fi]=weights_holo*rephase_use*n_vis
*variance_uv_arr[pol_i,fi]=variance_holo*rephase_use*n_vis
IF Keyword_Set(model_flag) THEN *model_uv_arr[pol_i,fi]=model_return*n_vis
dirty_uv_arr[*, *, fi]=dirty_uv*n_vis
weights_uv_arr[*, *, fi]=weights_holo*rephase_use*n_vis
variance_uv_arr[*, *, fi]=variance_holo*rephase_use*n_vis
IF Keyword_Set(model_flag) THEN model_uv_arr[*, *, fi]=model_return*n_vis
endif

IF Keyword_Set(fft) THEN BEGIN
IF N_Elements(x_range)<N_Elements(y_range) GT 0 THEN BEGIN
*dirty_arr[pol_i,fi]=extract_subarray(dirty_image_generate(dirty_uv,degpix=degpix)*n_vis,x_range,y_range)
Expand All @@ -147,12 +160,16 @@ FUNCTION vis_model_freq_split,obs,status_str,psf,params,vis_weights,model_uv_arr
IF Keyword_Set(t_grid0) THEN t_grid+=t_grid0
ENDFOR
IF ~Keyword_Set(preserve_visibilities) THEN ptr_free,vis_ptr,model_ptr
ENDFOR
obs_out.n_vis=n_vis_use
IF ~Arg_present(obs_out) THEN obs.n_vis=n_vis_use

if keyword_set(save_uvf) then save, filename = uvf_filepath, dirty_uv_arr, weights_uv_arr, variance_uv_arr, model_uv_arr, obs_out, /compress

obs_out.n_vis=n_vis_use
IF ~Arg_present(obs_out) THEN obs.n_vis=n_vis_use

IF keyword_set(save_uvf) THEN BEGIN
save, filename = uvf_filepath[pol_i], dirty_uv_arr, weights_uv_arr, variance_uv_arr, model_uv_arr, obs_out, /compress
ENDIF

ENDFOR

IF ~Keyword_Set(silent) THEN print,"Gridding timing: ",strn(t_grid)
timing=Systime(1)-t0
RETURN,dirty_arr
Expand Down
11 changes: 4 additions & 7 deletions outputs.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,12 @@ Text file of generated bandpass solutions. The first column is the frequency cha

* **vis_count**: an image of dimensions N<sub>dimension</sub> by N<sub>elements</sub> (where dimension and elements are FHD keywords). Each pixel value is how many visibilities contributed to that pixel, which is the same as our in-house uniform weighting. (!Q right?)

### \<obsids\>\_\<even/odd\>\_gridded_uvf_\<pol\>.sav <br />
Gridded uvf cubes, alternative input to eppsilon. Saved only if keyword `save_uvf` is set.

## HEALPix<br />

### \<obsids\>\_even_cube\<pol\>.sav / \<obsids\>_even_cube\<pol\>.sav <br />
### \<obsids\>\_\<even/odd\>_cube\<pol\>.sav

* **variance_cube/weights_cube**: an array of HEALPix pixels organized by hpx_inds for each output frequency. This is an image cube of 1's gridded with the beam for all visibilities (weights) or 1's gridded with the beam squared for all visibilities (variances).

Expand Down Expand Up @@ -371,12 +374,6 @@ Residual image with the subtracted sources over-plotted. Each source is plotted

### \<obsids\>\_\<filter\>\_UV_weights_\<pol\>.png <br />

## UVF Cubes<br />
Saved only if keyword `save_uvf` is set.

### \<obsids\>\_even_gridded_uvf.sav <br />

### \<obsids\>\_odd_gridded_uvf.sav <br />

## Vis Data<br />

Expand Down

0 comments on commit 92f170f

Please sign in to comment.