Skip to content
Snippets Groups Projects
Unverified Commit f3888048 authored by Gigg, Martyn Anthony's avatar Gigg, Martyn Anthony Committed by GitHub
Browse files

Merge pull request #30997 from mantidproject/PD195_filename_update

Update filenames to match new convention - master
parents c9efd39b 3ce25838
No related branches found
No related tags found
No related merge requests found
......@@ -14,6 +14,7 @@ from mantid import logger
import numpy as np
import datetime
import os
import os.path
import re
import warnings
......@@ -229,7 +230,7 @@ class HB2AReduce(PythonAlgorithm):
# Get either vcorr file or vanadium data
vanadium_count, vanadium_monitor, vcorr = self.get_vanadium(detector_mask, data['m1'][0],
data['colltrans'][0], exp,
indir)
indir, metadata)
def_x = self.getProperty("DefX").value
if not def_x:
......@@ -318,7 +319,7 @@ class HB2AReduce(PythonAlgorithm):
detector_mask[exclude_detectors - 1] = False
return detector_mask
def get_vanadium(self, detector_mask, m1, colltrans, exp, indir):
def get_vanadium(self, detector_mask, m1, colltrans, exp, indir, metadata):
"""
This function returns either (vanadium_count, vanadium_monitor, None) or
(None, None, vcorr) depending what type of file is provided by getProperty("Vanadium")
......@@ -341,11 +342,21 @@ class HB2AReduce(PythonAlgorithm):
# m1 = 0 -> Ge 115, 1.54A
# m1 = 9.45 -> Ge 113, 2.41A
# colltrans is the collimator position, whether in or out of the beam
# colltrans = 0 -> IN
# colltrans = +/-80 -> OUT
vcorr_filename = 'HB2A_{}__Ge_{}_{}_vcorr.txt'.format(
exp, 115 if np.isclose(m1, 0, atol=0.1) else 113,
"IN" if np.isclose(colltrans, 0, atol=0.1) else "OUT")
new_convention = np.datetime64(datetime.datetime(2021, 2, 23))
date_created = self.get_date(metadata)
if date_created >= new_convention:
# colltrans = 0 -> OUT
# colltrans = +/-80 -> IN
vcorr_filename = 'HB2A_{}__Ge_{}_{}_vcorr.txt'.format(
exp, 115 if np.isclose(m1, 0, atol=0.1) else 113,
"OUT" if np.isclose(colltrans, 0, atol=0.1) else "IN")
elif date_created < new_convention:
# colltrans = +/-80 -> OUT
# colltrans = 0 -> IN
vcorr_filename = 'HB2A_{}__Ge_{}_{}_vcorr.txt'.format(
exp, 115 if np.isclose(m1, 0, atol=0.1) else 113,
"IN" if np.isclose(colltrans, 0, atol=0.1) else "OUT")
vcorr_filename = os.path.join(indir, vcorr_filename)
logger.notice("Using vcorr file: {}".format(vcorr_filename))
if not os.path.isfile(vcorr_filename):
......@@ -353,6 +364,13 @@ class HB2AReduce(PythonAlgorithm):
return None, None, np.genfromtxt(vcorr_filename)[detector_mask]
def get_date(self, metadata):
# Get correct start time
date_created = np.datetime64(
datetime.datetime.strptime(metadata['time'] + ' ' + metadata['date'],
'%I:%M:%S %p %m/%d/%Y'))
return date_created
def process(self,
counts,
scale,
......
......@@ -113,6 +113,12 @@ class HB2AReduceTest(unittest.TestCase):
os.path.exists(os.path.join(self._default_save_directory, f"{HB2AReduce_ws}.gss")))
HB2AReduce_ws.delete()
def test_new_convention(self):
HB2AReduce_ws = HB2AReduce('HB2A_exp0666_scan0024.dat',
IndividualDetectors=True,
SaveData=False)
HB2AReduce_ws.delete()
if __name__ == '__main__':
unittest.main()
7fbf5aa9d9eba9b582ed028775cfad10
73dc7cf1b20ab8dad34c3fe1483be454
73dc7cf1b20ab8dad34c3fe1483be454
6112caadec2cfdaf5f8b979b612dcb07
6112caadec2cfdaf5f8b979b612dcb07
61dd268cd2f083178530f30549ad974a
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment