Return the file path for the specified object. This is used to return the file path for a netcdf object. If the particular object does not have the appropriate file path information, then one is created based on the timestep in the file. Args: obj: An object. Returns:
(obj)
| 3045 | |
| 3046 | |
| 3047 | def get_filepath(obj): |
| 3048 | """Return the file path for the specified object. |
| 3049 | |
| 3050 | This is used to return the file path for a netcdf object. If the |
| 3051 | particular object does not have the appropriate file path information, |
| 3052 | then one is created based on the timestep in the file. |
| 3053 | |
| 3054 | Args: |
| 3055 | |
| 3056 | obj: An object. |
| 3057 | |
| 3058 | Returns: |
| 3059 | |
| 3060 | :obj:`str`: A string for a file path. |
| 3061 | |
| 3062 | """ |
| 3063 | try: |
| 3064 | path = obj.filepath() |
| 3065 | except AttributeError: |
| 3066 | try: |
| 3067 | path = obj.file.path |
| 3068 | except AttributeError: |
| 3069 | # Let's make up a filename from the first file time |
| 3070 | found = False |
| 3071 | times = extract_times(obj, None, meta=False, do_xtime=False) |
| 3072 | for t in times: |
| 3073 | path = "wrfout_{}".format(str(t)) |
| 3074 | found = True |
| 3075 | break |
| 3076 | |
| 3077 | if not found: |
| 3078 | raise ValueError("file contains no path information") |
| 3079 | |
| 3080 | return path |
| 3081 | |
| 3082 | |
| 3083 | def get_id(obj, prefix=''): |
no test coverage detected