Skip to content

add option for prefix_chars in silcam and holo load classes#385

Merged
emlynjdavies merged 13 commits into
mainfrom
384-dynamic-prefix-in-filenames
Jun 16, 2026
Merged

add option for prefix_chars in silcam and holo load classes#385
emlynjdavies merged 13 commits into
mainfrom
384-dynamic-prefix-in-filenames

Conversation

@emlynjdavies

@emlynjdavies emlynjdavies commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

add option for prefix_chars in silcam and holo load classes. This allows load functions to have an optional number of characters to exclude in filename prefixes.

Example toml pipeline step with optional prefix_chars defined:

[steps.load]
pipeline_class = 'pyopia.instrument.silcam.Load'
prefix_chars = 5

prefix_chars defaults to 1 if not defined (to match the standard 'D' at the start of "normal" silcam and LISST-Holo filenames.

@emlynjdavies emlynjdavies linked an issue Jun 9, 2026 that may be closed by this pull request
@emlynjdavies emlynjdavies self-assigned this Jun 9, 2026
@emlynjdavies emlynjdavies added the patch / enhancement improved functionality or patch indented for changes that require bumping only the PATCH number label Jun 9, 2026
@nordam

nordam commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

How about reviving my elegant and robust suggested regex from yonder, which will match the standard date and time format, irrespective of the number of characters in the prefix?

#291

@emlynjdavies

emlynjdavies commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator Author

How about reviving my elegant and robust suggested regex from yonder, which will match the standard date and time format, irrespective of the number of characters in the prefix?

#291

so, instead of parsing a single integer in the config settings, you suggest parsing a regex that describes the filename format?

maybe like this:

def timestamp_from_filename(filename, datetime_format='D%Y%m%dT%H%M%S.%f'):
    '''get a pandas timestamp from a silcam filename

    Parameters
    ----------
    filename : string
        silcam filename (.silc)

    datetime_format : string, optional
        Format string for parsing the timestamp from the filename,
        by default 'D%Y%m%dT%H%M%S.%f'

    Returns
    -------
    timestamp : pandas.Timestamp
        timestamp from pandas.to_datetime()
    '''

    # get the timestamp of the image (in this case from the filename)
    timestamp = pd.to_datetime(os.path.splitext(os.path.basename(filename))[0],
                               format=datetime_format)
    return timestamp

@emlynjdavies

emlynjdavies commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator Author

Since the to_datetime function cannot accept wildcards, this means that any prefix must have known and constant characters if we were to use the format string as the only input. The approach of using the prefix_chars integer allows for any content of those prefix characters (so they could be something changing within one dataset as long as their length is constant).

We can perhaps do both of these, by having optional inputs for prefix_chars and a datetime_format, where datetime format defaults to 'None' (which should keep the current default automatic parsing)

@emlynjdavies emlynjdavies linked an issue Jun 12, 2026 that may be closed by this pull request
@emlynjdavies emlynjdavies marked this pull request as ready for review June 12, 2026 13:21
@emlynjdavies emlynjdavies requested review from nepstad and nordam June 12, 2026 13:21
Comment thread pyopia/instrument/holo.py Outdated
Comment thread pyopia/instrument/holo.py Outdated
@emlynjdavies emlynjdavies merged commit 69ea05d into main Jun 16, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

patch / enhancement improved functionality or patch indented for changes that require bumping only the PATCH number

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dynamic prefix in filenames Move to more flexible image containers for SilCam

3 participants