Skip to content
Snippets Groups Projects
Unverified Commit 445bf446 authored by David Hoese's avatar David Hoese
Browse files

Fix netcdf creation of dewpoint when it isn't in the input files

parent 069ff562
No related branches found
No related tags found
No related merge requests found
......@@ -3,9 +3,11 @@ import math
import numpy as np
try:
import pandas as pd
from pandas import Series
except ImportError:
# expected to use for isinstance
pd = None
Series = np.ndarray
NaN = float('nan')
......@@ -33,7 +35,9 @@ def dewpoint(tempC, relhum):
dp = 1.0 / (1.0 / (273.15 + tempC) - gasconst * np.log((0.0 + relhum) / 100) /
(latheat - tempC * 2397.5))
return min(dp - 273.15, tempC)
if pd is not None and isinstance(dp, pd.Series):
return pd.concat([dp - 273.15, tempC], axis=1).min(axis=1)
return np.min(dp - 273.15, tempC)
def relhum(airTempK, dewpointTempK):
......
......@@ -402,6 +402,11 @@ def create_giant_netcdf(input_files, output_fn, zlib, chunk_size,
# Add wind direction components so we can average wind direction properly
frame['wind_east'], frame['wind_north'], _ = calc.wind_vector_components(frame['wind_speed'], frame['wind_dir'])
if 'air_temp' in frame and 'rh' in frame and 'dewpoint' in database:
LOG.info("'dewpoint' is missing from the input file, will calculate it from air temp and relative humidity")
frame['dewpoint'] = calc.dewpoint(frame['air_temp'], frame['rh'])
# round up each 1 minute group so data at time T is the average of data
# from T - 1 (exclusive) to T (inclusive).
new_frame = frame.resample('5S', closed='right', loffset='5S').mean()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment