function hsi_annsec2xy,annsecimage, modpat_obj,  xgrid, ygrid, $
    this_harmonic=this_harmonic, this_det_index=this_det_index, $
    max_value=max_value, min_value=min_value, quintic=quintic,$
    limits=limits, modpat_ptr=modpat_ptr, gs=gs, missing=missing



if size(modpat_ptr,/tname) ne 'POINTER' then $
    modpat_ptr = modpat_obj-> getdata(class_name='hsi_modul_pattern' )
this_modpat_ptr = modpat_ptr

checkvar, this_harmonic, 0

case  1 of
 size(/tname, modpat_obj) eq 'OBJREF' : begin
    valid= where(modpat_obj->get(/det_index_mask))
    this_modpat_ptr = (modpat_obj->getdata(class_name='hsi_modul_pattern'))[valid[0]]
    end
 else: begin
    valid = 0
    while size(/tname,*this_modpat_ptr[valid]) ne 'STRUCT' do valid = valid+1
    this_modpat_ptr = this_modpat_ptr[valid]
    end
endcase

if exist(this_det_index) and n_elements(this_modpat_ptr) gt 1 then $
    this_modpat_ptr = this_modpat_ptr[ this_det_index, this_harmonic ]

hsi_annsec_coord, dummy, x, y, rmap, thetamap, modpat_ptr = this_modpat_ptr
if n_elements(limits) ne 4  then limits = hsi_fovbox( modpat_obj, modpat_ptr = this_modpat_ptr)

if not keyword_set(gs) then $
    gs = (*this_modpat_ptr).pixel_size * (*this_modpat_ptr).pixel_scale 
gs = gs + fltarr(2)
if not keyword_set(missing) then missing = avg( annsecimage)
triangulate, x, y, tr

return, trigrid( x, y, annsecimage,  tr, gs, limits[*], missing=missing,$
    xgrid = xgrid, ygrid=ygrid, quintic=quintic, $
    max_value=max_value, min_value=min_value)


end