VERITAS-Observatory / V2DL3

VERITAS (VEGAS and Eventdisplay) to DL3 Converter
BSD 3-Clause "New" or "Revised" License
8 stars 1 forks source link

Incorrect telescope pointing #213

Closed steob92 closed 4 weeks ago

steob92 commented 1 month ago

This is related to #60 and #66.

Looks like the RA_PNT isn't getting correctly set. I'm using v0.5.2-preprocessing-v490.7. Here's what the datastore.obs_table reports for both point like and full enclosure IRFs:

image

https://github.com/VERITAS-Observatory/V2DL3/blob/ee2a5fc6a06cfe1a826db9073fb09536357033b9/pyV2DL3/eventdisplay/fillEVENTS.py#L194-L209

Replacing the arctan2 function with scipy.stats.circmean seems to give a consistent answer:

def __get_average_pointing(file, runNumber):
    """
    Return circular mean RA and average DEC of telescope pointing

    """
    pointingDataReduced = file[
        f"run_{runNumber}/stereo/pointingDataReduced"].arrays(library="np")
    avRA = np.rad2deg(
        np.arctan2(
            np.sum(np.sin(pointingDataReduced["TelRAJ2000"])),
            np.sum(np.cos(pointingDataReduced["TelRAJ2000"])),
        )
    )
    avDec = np.mean(np.rad2deg(pointingDataReduced["TelDecJ2000"]))

    return avRA, avDec

def __get_average_pointing2(file, runNumber):
    """
    Return circular mean RA and average DEC of telescope pointing

    """
    pointingDataReduced = file[
        f"run_{runNumber}/stereo/pointingDataReduced"].arrays(library="np")

    n = len(pointingDataReduced["TelRAJ2000"])
    avRA = np.rad2deg(
        circmean(pointingDataReduced["TelRAJ2000"])
    )
    avDec = np.mean(np.rad2deg(pointingDataReduced["TelDecJ2000"]))

    return avRA, avDec
__get_average_pointing(file,run)
> (-107.18294548529406, 39.75928023998721)
__get_average_pointing2(file,run)
> (252.81705451470597, 39.75928023998721)

I didn't look too much into it but it looks like circmean applies a phase correction. See: https://github.com/scipy/scipy/blob/44e4ebaac992fde33f04638b99629d23973cb9b2/scipy/stats/_morestats.py#L4338-L4417

steob92 commented 1 month ago

04617c5 seems to be working: image