PathedObject¶
- class snappl.pathedobject.PathedObject(filepath=None, base_path=None, base_dir=None, full_filepath=None, no_base_path=False)[source]¶
Bases:
objectAn object that might be stored in the database but that also has files on disk.
Subclasses include Image, SegmentatonMap, Lightcurve, and Spectrum1d, and will include more in the future.
Here so we can have a semi-unified interface.
Standard properties of a PathedObject are:
- filepathpathlib.Pathpath of the object relative to the base
path for this kind of object. This is what gets stored in the database (usually in a column named “filepath”, though the user will not need to know that).
- full_filepathpathlib.Paththe absolute path to the file on disk.
(But see “complications” below.) This attribute is usually derived from base_path and filepath.
- base_pathpathlib.Pathbase path for this kind of object.
Normally this is from the config, and is the base path for this kind of object. (For instance, for L2 images, base_path is the directory pointed to by config value “system.paths.images”). However, for backwards compatibility, we want to be able to support objects that aren’t in the database, so you can set a custom base_path, if you need to, every time you create an object.
filename : string : the name part of filepath (so if filepath is Path(“/foo/bar”), filename is “bar”).
Complications:
This class is designed implicitly assuming that one row in the database corresponds to one PathedObject object, and to one file on disk. Sometimes that may not be true, e.g. an image might not have the image, noise, and flags arrays all packed into one file, but in three different files. In that case, the subclass must know how to deal with this, and “filepath” may not be the path to an actual file, but to a path to the name of which you must append additional standard stuff to find the file. (The one extant example of this is the image.FITSImage class with std_imagenames set to True.)
For subclass developers:
Any subclass of this class must define one of two things. Either, it must define a class variable _base_path_config_item that is thing to look up with Config.get().value(…) to figure out the default base path for objects of that class; or, it must define a function _set_base_path that sets both self._no_base_path and self._base_path. (Practically speaking: they all define _base_path_config_item, except for Image, which has to do other gyrations for backwards compatibility.)
Set up object paths.
- Parameters:
filepath (str or Path, default None) – Path of the file relative to base_path. If no_base_path is True (which should never be the case for an object that is associated with the database), then this is the full path.
base_path (str or Path, default None) – Only use one of these; they set the same thing. (Both parameters are defined for backwards compatibility.) Most of the time you do not want to specify this, but leave it at the default. If no_base_path is True, you must leave these at None. This is the base path for objects of the subclass of PathedObject that is being constructed. By default (which is usually what you want), it will use a path that is configured for the type of object that the subclass tracks.
base_dir (str or Path, default None) – Only use one of these; they set the same thing. (Both parameters are defined for backwards compatibility.) Most of the time you do not want to specify this, but leave it at the default. If no_base_path is True, you must leave these at None. This is the base path for objects of the subclass of PathedObject that is being constructed. By default (which is usually what you want), it will use a path that is configured for the type of object that the subclass tracks.
full_filepath (str or Path, default None) – Usually you don’t want to specify this, but there are cases where you can.
no_base_path (bool, default False) – You may want to set this to True if you are dealing with files that aren’t tracked by the database. In that case, you can’t specify base_path (or base_dir), and filepath and full_filepath mean the same thing (and must be the same if for some reasdon you give both).
Attributes Summary
Methods Summary
Classes that have default filepaths should override this function to set self._filepath.
Attributes Documentation
- base_dir¶
- base_path¶
- filename¶
- filepath¶
- full_filepath¶
Methods Documentation