Source code for pycif.plugins.datastreams.fluxes.wrfchem.utils

import datetime
import glob
import os
import calendar 
import numpy as np


[docs] def find_valid_file(ref_dir, file_format, dd): """Not used VERSION HISTORY 2021-08-20 freum Original from flux_template_plugin, raising NotImplementedError at beginning """ raise NotImplementedError("Not used") # Get all files and dates matching the file and format print('Here, basic listing of all available files') list_files_orig = os.listdir(ref_dir) list_files_avail = [] for f in list_files_orig: try: check = datetime.datetime.strptime(f, file_format) list_files_avail.append(f) except: continue print('All availables files',list_files_avail) print('Modifiy to suit your case e.g. list less files, list also files for antoher year or month.') print('See examples in other plugins or in the documentation/tutorials.') list_files = [] list_dates = [] print('Here, list provided dates and matching files') print('The list of dates is probably sparse e.g. every 3 hours or every month.') list_files = np.array(list_files) list_dates = np.array(list_dates) # Sorting along dates isort = np.argsort(list_dates) list_dates = list_dates[isort] list_files = list_files[isort] if list_files == []: raise Exception("Did not find any valid flux files in {} " "with format {}. Please check your yml file" .format(ref_dir, file_format)) print('Here, among list_dates, find the two dates between which dd is and') print('return those dates and the matching files.') print('If dd is among the provided date, return it twice (same for the matching file.') return [file_ref1, file_ref2], [date_ref1, date_ref2]