Skip to content

Commit

Permalink
resolve ec-jrc#117
Browse files Browse the repository at this point in the history
  • Loading branch information
brey authored and pmav99 committed Jan 13, 2023
1 parent 01c13a8 commit 1f397a0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 27 deletions.
8 changes: 4 additions & 4 deletions pyposeidon/d3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def __init__(self, **kwargs):
`pd.to_datetime()`.
time_frame str: The duration of the analysis. It should be a string parseable by
`pd.to_datetime()`.
date str: Reference date of the run.
rdate str: Reference date of the run.
meteo_source str: Path or url to meteo data.
dem_source str: Path or url to bathymetric data.
argfile str: Path to `_hydro.xml` file.
Expand Down Expand Up @@ -129,8 +129,8 @@ def __init__(self, **kwargs):
self.end_date = pd.to_datetime(end_date)
self.time_frame = self.end_date - self.start_date

if not hasattr(self, "date"):
self.date = self.start_date
if not hasattr(self, "rdate"):
self.rdate = self.start_date

if not hasattr(self, "end_date"):
# ---------------------------------------------------------------------
Expand Down Expand Up @@ -192,7 +192,7 @@ def config(self, **kwargs):
self.mdf.loc[self.mdf.index.str.contains("MNKmax")] = "{} {} {}".format(ni + 1, nj + 1, 1) # add one like ddb

# adjust iteration date
self.mdf.loc[self.mdf.index.str.contains("Itdate")] = "#{}#".format(self.date.strftime(format="%Y-%m-%d"))
self.mdf.loc[self.mdf.index.str.contains("Itdate")] = "#{}#".format(self.rdate.strftime(format="%Y-%m-%d"))

# set time unit
self.mdf.loc[self.mdf.index.str.contains("Tunit")] = "#M#"
Expand Down
13 changes: 6 additions & 7 deletions pyposeidon/schism.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ def __init__(self, **kwargs):
`pd.to_datetime()`.
time_frame str: The duration of the analysis. It should be a string parseable by
`pd.to_datetime()`.
date str: Reference date of the run.
rdate str: Reference date of the run.
rpath str: Path for output of the model. Defaults to `./schism/`.
m_index int: Define the index of the meteo Dataset. Defaults to `1`.
filename str: Path to output the meteo Dataset. Defaults to `sflux/`.
dstamp str: Reference date for station data. Defaults to date.
dstamp str: Reference date for station data. Defaults to rdate.
parameters dict: Overwrite default Schism's parameter values.
meteo_source str: Path or url to meteo data.
dem_source str: Path or url to bathymetric data.
Expand Down Expand Up @@ -165,8 +165,8 @@ def __init__(self, **kwargs):
self.end_date = pd.to_datetime(end_date)
self.time_frame = self.end_date - self.start_date

if not hasattr(self, "date"):
self.date = get_value(self, kwargs, "date", self.start_date)
if not hasattr(self, "rdate"):
self.rdate = get_value(self, kwargs, "rdate", self.start_date)

if not hasattr(self, "end_date"):
# ---------------------------------------------------------------------
Expand Down Expand Up @@ -521,7 +521,6 @@ def output(self, **kwargs):
f.write("{} {}\n".format(1, -1.0)) # first S-level (sigma-coordinate must be -1)
f.write("{} {}\n".format(2, 0.0)) # levels index, sigma-coordinate, last sigma-coordinate must be 0


# save hgrid.gr3
try:

Expand Down Expand Up @@ -627,7 +626,7 @@ def output(self, **kwargs):
mpaths = ["sflux/sflux_air_{}.{:04d}.nc".format(m_index, t + 1) for t in np.arange(len(times))]
for das, mpath in list(zip(datasets, mpaths)):
self.to_force(
das, vars=["msl", "u10", "v10"], rpath=path, filename=mpath, date=self.date, **kwargs
das, vars=["msl", "u10", "v10"], rpath=path, filename=mpath, date=self.rdate, **kwargs
)
else:
self.to_force(self.meteo.Dataset, vars=["msl", "u10", "v10"], rpath=path, **kwargs)
Expand Down Expand Up @@ -1863,7 +1862,7 @@ def get_station_sim_data(self, **kwargs):
logger.error("No station.in file present")
return

dstamp = kwargs.get("dstamp", self.date)
dstamp = kwargs.get("dstamp", self.rdate)

dfs = []
for idx in vals.index:
Expand Down
32 changes: 16 additions & 16 deletions pyposeidon/utils/cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def run(self, **kwargs):
files_sym = [self.tag + ".grd", self.tag + ".dep"]

self.origin = self.model.rpath
self.date0 = self.model.date
self.rdate = self.model.rdate

if not os.path.exists(self.origin):
sys.stdout.write("Initial folder not present {}\n".format(self.origin))
Expand Down Expand Up @@ -104,8 +104,8 @@ def run(self, **kwargs):
pass

# update the properties
info["date"] = self.date
info["start_date"] = self.date
info["rdate"] = self.rdate
info["start_date"] = self.start_date
info["time_frame"] = self.time_frame
info["meteo_source"] = self.meteo
info["rpath"] = rpath
Expand Down Expand Up @@ -151,9 +151,9 @@ def run(self, **kwargs):

# copy restart file

inresfile = "tri-rst." + m.tag + "." + datetime.datetime.strftime(self.date, "%Y%m%d.%H%M%M")
inresfile = "tri-rst." + m.tag + "." + datetime.datetime.strftime(self.rdate, "%Y%m%d.%H%M%M")

outresfile = "restart." + datetime.datetime.strftime(self.date, "%Y%m%d.%H%M%M")
outresfile = "restart." + datetime.datetime.strftime(self.rdate, "%Y%m%d.%H%M%M")

# copy2(ppath+inresfile,rpath+'tri-rst.'+outresfile)
try:
Expand Down Expand Up @@ -208,7 +208,7 @@ def run(self, **kwargs):
# cleanup
os.remove(rpath + "tri-rst." + outresfile)

logger.info("done for date :" + datetime.datetime.strftime(self.date, "%Y%m%d.%H"))
logger.info("done for date :" + datetime.datetime.strftime(self.rdate, "%Y%m%d.%H"))

os.chdir(pwd)

Expand Down Expand Up @@ -261,7 +261,7 @@ def run(self, **kwargs):
]

self.origin = self.model.rpath
self.date0 = self.model.date
self.rdate = self.model.rdate

if not os.path.exists(self.origin):
sys.stdout.write("Initial folder not present {}\n".format(self.origin))
Expand Down Expand Up @@ -294,7 +294,7 @@ def run(self, **kwargs):

# update the properties

info["date"] = self.date0
info["rdate"] = self.rdate
info["start_date"] = self.sdate
info["time_frame"] = self.time_frame
info["end_date"] = self.sdate + pd.to_timedelta(self.time_frame)
Expand Down Expand Up @@ -371,7 +371,7 @@ def run(self, **kwargs):
logger.debug("create restart file")

# check for combine hotstart
hotout = int((self.sdate - self.date0).total_seconds() / info["params"]["core"]["dt"])
hotout = int((self.sdate - self.rdate).total_seconds() / info["params"]["core"]["dt"])
logger.debug("hotout_it = {}".format(hotout))

resfile = glob.glob(ppath + "/outputs/hotstart_it={}.nc".format(hotout))
Expand Down Expand Up @@ -424,32 +424,32 @@ def run(self, **kwargs):
vars=["msl", "u10", "v10"],
rpath=rpath,
filename=mpath,
date=self.date0,
date=self.rdate,
)
else:
m.to_force(
m.meteo.Dataset,
vars=["msl", "u10", "v10"],
rpath=rpath,
date=self.date0,
date=self.rdate,
)

else:
logger.warning("meteo files present\n")

# modify param file
rnday_new = (self.sdate - self.date0).total_seconds() / (3600 * 24.0) + pd.to_timedelta(
rnday_new = (self.sdate - self.rdate).total_seconds() / (3600 * 24.0) + pd.to_timedelta(
self.time_frame
).total_seconds() / (3600 * 24.0)
hotout_write = int(rnday_new * 24 * 3600 / info["params"]["core"]["dt"])
info["parameters"].update(
{
"ihot": 2,
"rnday": rnday_new,
"start_hour": self.date0.hour,
"start_day": self.date0.day,
"start_month": self.date0.month,
"start_year": self.date0.year,
"start_hour": self.rdate.hour,
"start_day": self.rdate.day,
"start_month": self.rdate.month,
"start_year": self.rdate.year,
}
)

Expand Down

0 comments on commit 1f397a0

Please sign in to comment.