Commit 795abc48 authored by Friedemann Reum's avatar Friedemann Reum
Browse files

Speed up wrfchem_icbc.fetch

By switching from xarray to netCDF4 for reading 'Times' in the boundary conditions file
parent 8e4a7698
Pipeline #154 failed with stages
in 0 seconds
import os
# import numpy as np
import numpy as np
# import pandas as pd
import datetime as dtm
import xarray as xr
import netCDF4 as nc
from pycif.utils import path
# Copied from chimere_icbc, adapted to WRF
......@@ -29,10 +29,11 @@ def fetch(
filei = datei.strftime("{}/{}".format(ref_dir, ref_file))
list_files = {datei: [filei]}
# Get time intervals from file as datetime.datetime
ds = xr.open_dataset(filei)
times_bytestr = ds["Times"].data
times = [dtm.datetime.strptime(t.decode("utf-8"), "%Y-%m-%d_%H:%M:%S") for t in times_bytestr]
ncf = nc.Dataset(filei)
times_char = ncf["Times"][:].astype(str)
times_str = np.apply_along_axis(lambda x:"".join(x), 1, times_char)
times = [dtm.datetime.strptime(t, "%Y-%m-%d_%H:%M:%S") for t in times_str]
# Add one more timestep to cover the period of the last input
# time. In the flux plugin, I added flux_freq to the config to
# do this, but here, it's all in the same file and comes from
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment