-
Notifications
You must be signed in to change notification settings - Fork 10
Read pyuvdata-formatted beamfits beam models #301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rlbyrne
wants to merge
16
commits into
master
Choose a base branch
from
uvbeam_support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+226
−21
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
d068afe
non whitespace changes
rlbyrne ce58b77
update dictionary
rlbyrne f460406
remove obsolete code
rlbyrne d9daba7
add comments and remove unnecessary code
rlbyrne d7b575a
modify comments
rlbyrne 993eb46
coordsys commenting
rlbyrne f4c7229
remove more unneeded code
rlbyrne 9f86097
param transfer defaults
nicholebarry cc717f8
remove extra keywords
rlbyrne 5a9d452
get keyword from extra structure
rlbyrne 8a94394
Reduce mem by only using selected pix
nicholebarry 87c9db9
undo reduce mem changes
rlbyrne 89fa16d
transpose Jones matrix
rlbyrne ae2c5b5
flip Jones elements
rlbyrne 6afaef3
add mem reduction, fix further pix selection bug
nicholebarry 07bc4f8
update skyh5 heading to pyradiosky standard
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| FUNCTION import_az_el_beam, obs, antenna, file_path_J_matrix,$ | ||
rlbyrne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| za_arr=za_arr,az_arr=az_arr,psf_image_dim=psf_image_dim | ||
| ; Read in an e-field antenna beam stored in evenly-spaced azimuth-elevation (and frequency) | ||
|
|
||
| n_ant_pol=Max(antenna.n_pol) | ||
| nfreq_bin=Max(antenna.nfreq_bin) | ||
| n_tile=obs.n_tile | ||
| xvals_instrument=za_arr*Sin(az_arr*!DtoR) | ||
| yvals_instrument=za_arr*Cos(az_arr*!DtoR) | ||
| freq_center=antenna[0].freq ;all need to be identical, so just use the first | ||
| icomp=Complex(0,1) | ||
|
|
||
| fits_info,file_path_J_matrix,/silent,n_ext=n_ext | ||
| ;Cols of J matrix: theta phi real(Jxt(t,p)) imag(Jxt(t,p)) real(Jxp(t,p)) imag(Jxp(t,p)) real(Jyt(t,p)) imag(Jyt(t,p)) real(Jyp(t,p)) imag(Jyp(t,p))) | ||
| ;Where theta is the zenith angle, phi is angle measured clockwise from +east direction looking down | ||
| ; Jxt is the Jones mapping unit vec in theta (t) direction to the x (east-west) dipole etc | ||
| n_ext+=1 ;n_ext starts counting AFTER the 0th extension, which it considers to be the main data unit, but we use that one too | ||
| freq_arr_Jmat=Fltarr(n_ext) | ||
|
|
||
| ; Read beam data from fits file | ||
| ; Format is set by pyuvdata conventions, see https://github.com/RadioAstronomySoftwareGroup/pyuvdata for details | ||
| Jmat0=mrdfits(file_path_J_matrix,0,header,status=status,/silent) | ||
| n_za_ang = sxpar(header,'naxis2') | ||
| n_az_ang = sxpar(header,'naxis1') | ||
| n_freq = sxpar(header, 'naxis3') | ||
| n_feed = sxpar(header, 'naxis4') | ||
| n_basis = sxpar(header, 'naxis6') | ||
| n_ang = n_za_ang*n_az_ang | ||
|
|
||
| theta_arr0 = findgen(n_za_ang)*sxpar(header,'cdelt2') + sxpar(header, 'crval2') ;in degrees | ||
| phi_arr0 = findgen(n_az_ang)*sxpar(header,'cdelt1') + sxpar(header, 'crval1') ;in degrees | ||
| freq_arr_Jmat = findgen(sxpar(header,'naxis3'))*sxpar(header,'cdelt3') + sxpar(header, 'crval3') ; in Hz | ||
|
|
||
| az_ind_arr = Reform(Fix(meshgrid(n_za_ang, n_az_ang, 2)), n_ang) | ||
| za_ind_arr = Reform(Fix(meshgrid(n_za_ang, n_az_ang, 1)), n_ang) | ||
| theta_arr = theta_arr0[za_ind_arr] | ||
| phi_arr = phi_arr0[az_ind_arr] | ||
|
|
||
| Jmat_arr=Dcomplexarr(n_freq,n_basis,n_feed,n_ang) | ||
| FOR freq_i=0,n_freq-1 DO BEGIN | ||
| FOR f_i=0,n_feed-1 DO BEGIN | ||
| FOR b_i=0,n_basis-1 DO BEGIN | ||
| Jmat1 = Reform(Jmat0[*, *, freq_i, f_i, 0, b_i, 0] + icomp*Jmat0[*, *, freq_i, f_i, 0, b_i, 1]) | ||
| Jmat1 = Transpose(Jmat1) | ||
| Jmat_arr[freq_i,b_i,f_i,*] = Reform(Jmat1, n_ang) | ||
| if b_i eq 1 then Jmat_arr[freq_i,b_i,f_i,*] *= -1 ;flip to align with MWA beam conventions | ||
| ENDFOR | ||
| ENDFOR | ||
| ENDFOR | ||
|
|
||
| phi_arr=270.-phi_arr ;change azimuth convention | ||
|
|
||
| ; Interpolate in frequency | ||
| Jmat_interp=Ptrarr(n_ant_pol,n_ant_pol,nfreq_bin) | ||
| FOR p_i=0,n_ant_pol-1 DO FOR p_j=0,n_ant_pol-1 DO FOR freq_i=0L,nfreq_bin-1 DO Jmat_interp[p_i,p_j,freq_i]=Ptr_new(Dcomplexarr(n_ang)) | ||
| FOR p_i=0,n_ant_pol-1 DO FOR p_j=0,n_ant_pol-1 DO FOR a_i=0L,n_ang-1 DO BEGIN | ||
| Jmat_single_ang=Interpol(Jmat_arr[*,p_i,p_j,a_i],freq_arr_Jmat,freq_center);*norm_factor | ||
| FOR freq_i=0L,nfreq_bin-1 DO (*Jmat_interp[p_i,p_j,freq_i])[a_i]=Jmat_single_ang[freq_i] | ||
| ENDFOR | ||
|
|
||
| zenith_i=where(theta_arr EQ 0,n_zenith) | ||
|
|
||
| horizon_test=where(abs(za_arr) GE 90.,n_horizon_test,complement=pix_use,ncomplement=n_pix) | ||
| Jones_matrix=Ptrarr(n_ant_pol,n_ant_pol,nfreq_bin) | ||
| FOR p_i=0,n_ant_pol-1 DO FOR p_j=0,n_ant_pol-1 DO FOR freq_i=0L,nfreq_bin-1 DO $ | ||
| Jones_matrix[p_i,p_j,freq_i]=Ptr_new(Dcomplexarr(n_pix)) | ||
|
|
||
| interp_res=obs.degpix | ||
| angle_slice_i0=Uniq(phi_arr) | ||
| n_ang_slice=N_Elements(angle_slice_i0) | ||
| n_zen_slice=angle_slice_i0[0]+1 | ||
| az_ang_in=phi_arr[angle_slice_i0] | ||
| ;zen_ang_in=theta_arr[0:angle_slice_i0[0]] | ||
| zen_ang_out=Findgen(Ceil(90./interp_res)+1)*interp_res | ||
| az_ang_out=Findgen(Ceil(360./interp_res)+1)*interp_res+Round(Min(az_ang_in)) | ||
| n_zen_ang=N_Elements(zen_ang_out) | ||
| n_az_ang=N_Elements(az_ang_out) | ||
|
|
||
| ; Convert from x, y to azimuth, zenith angle coordinates | ||
| zen_ang_inst=Sqrt(xvals_instrument[pix_use]^2+yvals_instrument[pix_use]^2) | ||
| az_ang_inst=Atan(yvals_instrument[pix_use],xvals_instrument[pix_use])*!Radeg+180. | ||
|
|
||
| ; Interpolate in azimulth and zenith angle | ||
| FOR p_i=0,n_ant_pol-1 DO FOR p_j=0,n_ant_pol-1 DO FOR freq_i=0L,nfreq_bin-1 DO BEGIN | ||
| Jmat_use=Reform(*Jmat_interp[p_i,p_j,freq_i],n_zen_slice,n_ang_slice) | ||
| Expand,Jmat_use,n_zen_ang,n_az_ang,Jmat_single | ||
| (*Jones_matrix[p_i,p_j,freq_i])=Interpolate(Jmat_single,zen_ang_inst/interp_res,az_ang_inst/interp_res,cubic=-0.5) | ||
| ENDFOR | ||
|
|
||
| RETURN, Jones_matrix | ||
| END | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| FUNCTION pyuvdata_beam_import, obs, antenna_str, pyuvdata_filepath,$ | ||
| za_arr=za_arr, az_arr=az_arr, psf_image_dim=psf_image_dim, pix_use=pix_use | ||
|
|
||
| lun = fxposit(pyuvdata_filepath, 0,/readonly) | ||
| MRD_HREAD, lun, primary_header, /silent | ||
|
|
||
| coordsys = strtrim(sxpar(primary_header,'coordsys'),2) | ||
| CASE coordsys OF | ||
rlbyrne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "az_za": BEGIN ; Beam is in azimuth/zenith angle coordinates | ||
| Jones_matrix = import_az_el_beam(obs, antenna_str, pyuvdata_filepath,$ | ||
| za_arr=za_arr, az_arr=az_arr, psf_image_dim=psf_image_dim) | ||
| END | ||
| "orthoslant_zenith": BEGIN ; Beam is in orthoslant coordinates | ||
| message,"COORDSYS type 'orthoslant_zenith' not yet supported!"" | ||
| END | ||
| "healpix": BEGIN ; Beam is in Healpix coordinates | ||
| message,"COORDSYS type 'healpix' not yet supported!" | ||
| END | ||
| ELSE: message,"Unsupported COORDSYS found in pyuvdata file!" | ||
| ENDCASE | ||
|
|
||
| RETURN, Jones_matrix | ||
| END | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| FUNCTION general_beam_setup_gain,obs,antenna,file_path_fhd=file_path_fhd,$ | ||
| za_arr=za_arr,az_arr=az_arr,psf_image_dim=psf_image_dim,Jdate_use=Jdate_use,$ | ||
| import_pyuvdata_beam_filepath=import_pyuvdata_beam_filepath,_Extra=extra | ||
|
|
||
| if ~keyword_set(import_pyuvdata_beam_filepath) then import_pyuvdata_beam_filepath=extra.import_pyuvdata_beam_filepath | ||
|
|
||
| n_ant_pol=Max(antenna.n_pol) | ||
| nfreq_bin=Max(antenna.nfreq_bin) | ||
| pix_use = *antenna[0].pix_use | ||
| IF N_Elements(file_path_fhd) EQ 0 THEN file_path_fhd='' | ||
| n_tile=obs.n_tile | ||
| beam_model_version=Max(antenna.model_version) | ||
| xvals_interp=za_arr*Sin(az_arr*!DtoR)/obs.degpix+obs.dimension/2. | ||
| yvals_interp=za_arr*Cos(az_arr*!DtoR)/obs.degpix+obs.elements/2. | ||
| freq_center=antenna[0].freq ;all need to be identical, so just use the first | ||
| pyuvdata_filepath=import_pyuvdata_beam_filepath | ||
|
|
||
| ;calculate group identifications (used to set pointers to identical models) | ||
| FOR pol_i=0,n_ant_pol-1 DO BEGIN | ||
| gi=0 | ||
| n_ungrouped=n_tile | ||
| ungrouped_i=where(antenna.group_id[pol_i] EQ -1,n_ungrouped) | ||
| WHILE n_ungrouped GT 0 DO BEGIN | ||
| ref_i=ungrouped_i[0] | ||
| antenna[ref_i].group_id[pol_i]=gi | ||
| FOR ug_i=1L,n_ungrouped-1 DO IF Total(*antenna[ungrouped_i[ug_i]].gain[pol_i] - *antenna[ref_i].gain[pol_i]) EQ 0 THEN antenna[ungrouped_i[ug_i]].group_id[pol_i]=gi | ||
| ungrouped_i=where(antenna.group_id[pol_i] EQ -1,n_ungrouped) | ||
| gi+=1 | ||
| ENDWHILE | ||
| ENDFOR | ||
|
|
||
| ;get the instrumental pol Jones matrix | ||
| print,"Reading in: " + pyuvdata_filepath | ||
| Jones_matrix = pyuvdata_beam_import(obs, antenna, pyuvdata_filepath,$ | ||
| za_arr=za_arr, az_arr=az_arr, psf_image_dim=psf_image_dim, pix_use=pix_use) | ||
|
|
||
| antenna.jones=Jones_matrix | ||
|
|
||
| RETURN,antenna | ||
| END |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| FUNCTION general_beam_setup_init,obs,antenna_str,_Extra=extra | ||
|
|
||
| ;copied from hera_beam_setup_init | ||
| ; | ||
| ; | ||
| ;polarization 0: x, 1: y | ||
|
|
||
| n_ant_pol=antenna_str.n_pol | ||
| n_tiles=obs.n_tile | ||
| n_dipoles=1 | ||
| nfreq_bin=antenna_str.nfreq_bin | ||
|
|
||
| IF N_Elements(antenna_size) EQ 0 THEN antenna_size=10 ;meters A GUESS | ||
| antenna_height=1.5 ;meters A GUESS | ||
| velocity_factor=0.673 ;use MWA number (ignored anyway) | ||
|
|
||
| xc_arr=Fltarr(n_dipoles) | ||
| yc_arr=Fltarr(n_dipoles) | ||
| zc_arr=Fltarr(n_dipoles) | ||
|
|
||
| antenna_coords=Ptrarr(3) | ||
| antenna_coords[0]=Ptr_new(xc_arr) | ||
| antenna_coords[1]=Ptr_new(yc_arr) | ||
| antenna_coords[2]=Ptr_new(zc_arr) | ||
|
|
||
| delay_settings=Ptr_new(Fltarr(n_dipoles)) | ||
|
|
||
| freq_center=antenna_str.freq | ||
| FOR i=0L,N_Elements(antenna_str.coupling)-1 DO antenna_str.coupling[i]=Ptr_new(Complex(Identity(n_dipoles))) | ||
|
|
||
| base_gain=fltarr(n_dipoles)+1. | ||
| gain_arr=Ptrarr(n_ant_pol) | ||
| FOR pol_i=0,n_ant_pol-1 DO gain_arr[pol_i]=Ptr_new(Rebin(reform(base_gain,1,n_dipoles),nfreq_bin,n_dipoles,/sample)) | ||
|
|
||
| antenna_str.n_ant_elements=n_dipoles | ||
| antenna_str.size_meters=antenna_size | ||
| antenna_str.coords=antenna_coords | ||
| antenna_str.height=antenna_height | ||
| antenna_str.delays=delay_settings | ||
| antenna=replicate(antenna_str,n_tiles) | ||
| FOR t_i=0L,n_tiles-1 DO antenna[t_i].gain=Pointer_copy(gain_arr) | ||
|
|
||
| RETURN, antenna | ||
| END |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.