Skip to content

source filename tracking when using open_mfdataset() #8972

Closed Answered by dcherian
Marston asked this question in General
Discussion options

You must be logged in to vote

You'll have to add the file name using a preprocess function.

def preprocess(ds):
    # something like this with the right dimension name instead of "time"
    # The file name *should* be in `.encoding["source"]`
    ds.coords["filename"] = ("time", ds.encoding["source"])
	return ds

xr.open_mfdataset(..., preprocess=preprocess)

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by Marston
Comment options

You must be logged in to vote
1 reply
@Marston
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-metadata Relating to the handling of metadata (i.e. attrs and encoding)
3 participants