mantidproject / mantid

Main repository for Mantid code
https://www.mantidproject.org
GNU General Public License v3.0
210 stars 121 forks source link

Add algorithm to extract time dependency of analyser polarised efficiency algorithm #36142

Open rbauststfc opened 10 months ago

rbauststfc commented 10 months ago

Add a new algorithm to find the polarised efficiency of the 3He analyser for a given time based on the fit results. This will make it possible to find the specific polarised efficiency at the time of any run during the experiment. This is more accurate than using a value that isn't time-dependent because the polarised efficiency of the analyser reduces over time.

With the extracted polarisation of the 3He gas (wavelength-independent quantity) interpolate the time dependence. The data analysis will also work assuming constant polarisation between periods.

Dirk has provided this information about what is required, in addition to a further comment below:

The code finds the time stamp of the measurement relative to a starting time. The transmission and polarisation of the 3He gas is then calculated for that time stamp based on the parameters established earlier in the calibration for the 3He cell (opacity, polarisation, transmission through cell,start time, decay constant).

This is a nice to have for the Polarised SANS reduction at ISIS.

Requirements still need to be gathered, but Dirk has provided the below script that they use for extracting the time from a workspace group. He explained that the timing becomes relevant to fit the time dependency of the analyser efficiency and then also to get the efficiency at a given moment in time to perform the correction for the scattering measurements (that happen in between the calibration):

#Extract start and end time of run from log
def transform_time(Logged_Time):
    format = "%Y-%m-%d"+"T"+"%H:%M:%S"
    date_value=datetime.datetime.strptime(Logged_Time, format)  
    date_value=datetime.datetime(date_value.year, date_value.month, date_value.day,date_value.hour, date_value.minute,date_value.second)
    return date_value

#read time for every period and not midtime for totalrun
def get_time(wsGroup):
    try:
        no_period= len(range(wsGroup.getNumberOfEntries()))
        time_start=wsGroup.getItem(0).getRun().getLogData('start_time').value
        time_end=wsGroup.getItem(no_period-1).getRun().getLogData('end_time').value
    except:
        try:
            time_start=wsGroup.getRun().getLogData('run_start').value
            time_end=wsGroup.getRun().getLogData('run_end').value
        except:
            time_start=wsGroup.getRun().getLogData('start_time').value
            time_end=wsGroup.getRun().getLogData('end_time').value

    time_start=transform_time(time_start)
    time_end=transform_time(time_end)    
    mid_time=time_start+(time_start-time_end)/2
    duration=time_end-time_start
    return mid_time, duration

#Calculate Difference between time and reference    
def diff_time(wsGroup_later,wsGroup_ref):
    later_time, later_duration=get_time(wsGroup_later)
    time_ref, ref_duration=get_time(wsGroup_ref)
    time_diff=later_time-time_ref 
    time_uncertainty=later_duration+ref_duration
    time_diff=time_diff.total_seconds()/3600 #time in h
    time_uncertainty=time_uncertainty.total_seconds()/3600

    return  [time_diff, time_uncertainty]

#Write parameters in sample history/log    
def set_time(wsGroup,midtime=None,set_duration=None):
    no_period= range(wsGroup.getNumberOfEntries())
    for i in no_period:
        wsLoop = wsGroup.getItem(i)
        AddSampleLog(Workspace=wsGroup.getItem(i), LogName='set_midtime', LogText=str(midtime), LogType='String')
        AddSampleLog(Workspace=wsGroup.getItem(i), LogName='set_duration', LogText=str(set_duration), LogType='String')
dehoni commented 8 months ago

For each calibration measurement calculate the polarisation of the He3 gas. FItting the decay 3He polarisation with time determines the gas lifetime.

github-actions[bot] commented 1 month ago

This issue has been automatically marked as stale because it has not had activity in 6 months. It will be closed in 7 days if no further activity occurs. Allowing issues to close as stale helps us filter out issues which can wait for future development time. All issues closed by stale bot act like normal issues; they can be searched for, commented on or reopened at any point. If you'd like a closed stale issue to be considered, feel free to either re-open the issue directly or contact a developer. To extend the lifetime of an issue please comment below, it helps us see that this is still affecting you and you want it fixed in the near-future. Extending the lifetime of an issue may cause the development team to prioritise it over other issues, which may be closed as stale instead.