Source code for pycif.plugins.models.wrfchem.ini_periods
import numpy as np
import pandas as pd
[docs]
def ini_periods(self, **kwargs):
"""Initialize variables related to model run periods
Variables set (not all implemented):
According to documentation:
self.subsimu_dates
self.tstep_all
self.tstep_dates
Additional variables in lmdz plugin:
self.input_dates
self.meteo_dates
self.iniobs
self.reset_obs
self.chain
DOCUMENTATION
https://satinv.pages.in2p3.fr/cif/html/devtutos/newmodel/
obsvect.html?highlight=ini_periods
VERSION HISTORY
2021-08-18 freum Adapted for wrfchem
- Similar to models/TM5/ini_periods.py (branch TM5)
- Added comments
- Some questions remain
2021-08-18 Original code in models/lmdz/ini_periods.py
"""
datei = self.datei
datef = self.datef
# List of sub-simulation windows
# self.subsimu_dates = date_range(datei, datef, period=self.periods)
# freum:
# - Not using subsimulations for now
# - Explanation in online documentation: "List of the starting dates
# of all the model sub-simulations chained to form the simulation
# window; it should include the end date of the chain simulation
# as well; for instance, LMDZ simulations are split into monthly
# simulations; subsimu_dates would then include the list of the
# first day of every months in the simulation window; if your
# model is not split into sub-simulations, subsimu_dates is a list
# with a single element, the starting date of the overall
# simulation window."
if hasattr(self, "periods"):
self.subsimu_dates = pd.date_range(datei, datef, freq=self.periods)
else:
self.subsimu_dates = np.array([datei, datef])
# Time steps of output are defined by namelist
# For now, this can only handle time steps
# identical in each domain.
# Actually it can only handle one domain at
# this point, but prepare.
wrfout_freqs_min = \
self.namelist["time_control"]["history_interval"]
if len(np.unique(wrfout_freqs_min)) > 1:
msg = \
"Can only handle identical " + \
"history_interval across all domains"
raise NotImplementedError(msg)
else:
wrfout_freq_min = wrfout_freqs_min[0]
# Time interval of flux input is defined
# in namelist (change this?)
wrfchemi_freqs_min = \
self.namelist["time_control"]["auxinput5_interval_m"]
if len(np.unique(wrfchemi_freqs_min)) > 1:
msg = \
"Can only handle identical " + \
"auxinput5_interval_m across all " + \
"domains"
raise NotImplementedError(msg)
else:
wrfchemi_freq_min = wrfout_freqs_min[0]
# Input frequency of meteo data (=that of lbc) is
# defined by namelist
meteo_freq_sec = \
self.namelist["time_control"]["interval_seconds"]
self.tstep_dates = {}
self.meteo_dates = {}
self.flux_dates = {}
for dd0, dd1 in zip(self.subsimu_dates[:-1], self.subsimu_dates[1:]):
self.tstep_dates[dd0] = pd.date_range(
dd0, dd1,
freq=str(wrfout_freq_min) + "min"
).to_pydatetime()
self.meteo_dates[dd0] = pd.date_range(
dd0, dd1,
freq=str(meteo_freq_sec) + "S"
).to_pydatetime()
self.flux_dates[dd0] = pd.date_range(
dd0, dd1,
freq=str(wrfchemi_freq_min) + "min"
).to_pydatetime()
# All time steps unpacked
# This is a nested list comprehension:
# list(self.tstep_dates.values()) is a list with one list of values
# per key. The nested list comprehension picks all elements from
# the sublists one-by-one, so it un-nests this 2-level list.
self.tstep_all = \
np.sort(np.unique(
np.array([x
for l in list(self.tstep_dates.values())
for x in l])))
# Initializes dictionary to keep in memory whether observations were
# already dumped for a given period
#self.iniobs = {ddi: False for ddi in self.subsimu_dates}
self.reset_obs = {ddi: True for ddi in self.subsimu_dates}