diff --git a/aosstower/level_b1/calc.py b/aosstower/level_b1/calc.py index 1eba391e1a88e57c6b96e36ce81014d914662441..4db8699e69db64927dac576539baf02b47a985b6 100644 --- a/aosstower/level_b1/calc.py +++ b/aosstower/level_b1/calc.py @@ -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): diff --git a/aosstower/level_b1/nc.py b/aosstower/level_b1/nc.py index 7c593ceadf57563e54f374732d0ec6659f887c73..0f696a4e36817546e6450326e4850c4c1194f541 100644 --- a/aosstower/level_b1/nc.py +++ b/aosstower/level_b1/nc.py @@ -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()