earthkit.data.targets.file_pattern

Attributes

Classes

FilePatternTarget

File target with a pattern for the output file names.

Module Contents

class earthkit.data.targets.file_pattern.FilePatternTarget(path, *, append=False, **kwargs)

Bases: earthkit.data.targets.SimpleTarget

File target with a pattern for the output file names.

Parameters:
  • path (str) – The file path to write to. The output file name defines a pattern containing metadata keys in the format of {key}. Each data item (e.g. a field) will be written into a file with a name created by substituting the relevant metadata values in the filename pattern.

  • append (bool) – If True, the files are opened in append mode. Only used if file is a path.

  • **kwargs – Additional keyword arguments passed to the parent class

append = False
close()

Close the target and closing all the files.

The target will not be able to write anymore.

Raises:

ValueError

property closed

True if the target is closed, False otherwise.

ext = None
filename
flush()

Flush all the files.

split_output
write(data=None, **kwargs)

Write data to the target using the given encoder.

Parameters:
  • data (obj, None) – The data object to write. If None, the encoder will use all the other arguments to generate the data to write.

  • encoder (str, Encoder, None) – The encoder to use to encode the data. When a string is passed, the encoder is looked up in the available encoders. When None, the encoder the Target was created with will be used if available. Otherwise, the encoder will be determined from the data to write (if possible) or from the Target properties.

  • template (obj, None) – The template to use to encode the data. When None, the template the Target was created with will be used if available.

  • metadata (dict, None) – Metadata to pass to the encoder.

  • **kwargs (dict) – Other keyword arguments passed to the encoder.

Raises:

ValueError

earthkit.data.targets.file_pattern.target