meteortools.ukmondb.getDetections

 1# Copyright (C) 2018-2023 Mark McIntyre
 2
 3# use the API to retrieve single-station data
 4
 5import datetime 
 6import requests
 7import pandas as pd
 8
 9
10def getDetections(dtstr, interval='m'):
11    """ 
12    Returns a list of detections within one interval of the specified time  
13
14    Arguments:  
15        dtstr:      [string] Date to search for in the format YYYYMMDD_HHMMSS  
16        interval:   [string] window to search around the specified time. Currently only 'm' supported  
17
18    Returns:  
19        pandas dataframe containing [ID, Dtstamp, Filename] of any matching detections  
20
21    Note:  
22        dtstr must be at least YYYYMMDD_HHMM. If seconds are omitted, the window wil be centred on 
23        hh:mm:30.  
24
25    """
26    srchapi = 'https://api.ukmeteors.co.uk/detections?'
27    if len(dtstr) < 13:
28        print('date range too wide. Must contain minutes')
29        return False
30    if len(dtstr) == 13:
31        dtstr = dtstr + '30'
32    if len(dtstr) == 14:
33        dtstr = dtstr + '0'
34    dt = datetime.datetime.strptime(dtstr[:15], '%Y%m%d_%H%M%S')
35    if interval == 'm':
36        dt1 = (dt + datetime.timedelta(seconds=-30)).strftime('%Y-%m-%dT%H:%M:%S.000Z')
37        dt2 = (dt + datetime.timedelta(seconds=30)).strftime('%Y-%m-%dT%H:%M:%S.000Z')
38    apiurl = f'{srchapi}d1={dt1}&d2={dt2}&opts=t:S'
39
40    res = requests.get(apiurl)
41    ids = []
42    filenames = []
43    dtstamps = []
44    if res.status_code == 200:
45        rawdata=res.text.strip()
46        rawdata = rawdata[8:-2]
47        spls = rawdata.split('"')
48        for spl in spls:
49            if len(spl) > 10:
50                thisrow = spl.split(',')
51                ids.append(thisrow[4])
52                fname = thisrow[5].split('/')[-1].strip()
53                filenames.append(fname)
54                dtstamps.append(fname[10:25])
55        df = pd.DataFrame({'ID':ids, 'Dtstamp':dtstamps, 'Filename':filenames})
56        return df
57    else:
58        return False
def getDetections(dtstr, interval='m'):
11def getDetections(dtstr, interval='m'):
12    """ 
13    Returns a list of detections within one interval of the specified time  
14
15    Arguments:  
16        dtstr:      [string] Date to search for in the format YYYYMMDD_HHMMSS  
17        interval:   [string] window to search around the specified time. Currently only 'm' supported  
18
19    Returns:  
20        pandas dataframe containing [ID, Dtstamp, Filename] of any matching detections  
21
22    Note:  
23        dtstr must be at least YYYYMMDD_HHMM. If seconds are omitted, the window wil be centred on 
24        hh:mm:30.  
25
26    """
27    srchapi = 'https://api.ukmeteors.co.uk/detections?'
28    if len(dtstr) < 13:
29        print('date range too wide. Must contain minutes')
30        return False
31    if len(dtstr) == 13:
32        dtstr = dtstr + '30'
33    if len(dtstr) == 14:
34        dtstr = dtstr + '0'
35    dt = datetime.datetime.strptime(dtstr[:15], '%Y%m%d_%H%M%S')
36    if interval == 'm':
37        dt1 = (dt + datetime.timedelta(seconds=-30)).strftime('%Y-%m-%dT%H:%M:%S.000Z')
38        dt2 = (dt + datetime.timedelta(seconds=30)).strftime('%Y-%m-%dT%H:%M:%S.000Z')
39    apiurl = f'{srchapi}d1={dt1}&d2={dt2}&opts=t:S'
40
41    res = requests.get(apiurl)
42    ids = []
43    filenames = []
44    dtstamps = []
45    if res.status_code == 200:
46        rawdata=res.text.strip()
47        rawdata = rawdata[8:-2]
48        spls = rawdata.split('"')
49        for spl in spls:
50            if len(spl) > 10:
51                thisrow = spl.split(',')
52                ids.append(thisrow[4])
53                fname = thisrow[5].split('/')[-1].strip()
54                filenames.append(fname)
55                dtstamps.append(fname[10:25])
56        df = pd.DataFrame({'ID':ids, 'Dtstamp':dtstamps, 'Filename':filenames})
57        return df
58    else:
59        return False

Returns a list of detections within one interval of the specified time

Arguments:
dtstr: [string] Date to search for in the format YYYYMMDD_HHMMSS
interval: [string] window to search around the specified time. Currently only 'm' supported

Returns:
pandas dataframe containing [ID, Dtstamp, Filename] of any matching detections

Note:
dtstr must be at least YYYYMMDD_HHMM. If seconds are omitted, the window wil be centred on hh:mm:30.