diff --git a/aosstower/level_b1/nc.py b/aosstower/level_b1/nc.py index fe5d6232ae7a2f17c9578dd4059e5d7cf68eb5af..ebf7a3d67b8fe76167f1f74c5e639b0d2fad20de 100644 --- a/aosstower/level_b1/nc.py +++ b/aosstower/level_b1/nc.py @@ -75,7 +75,7 @@ def write_dimensions(nc_file): def create_variables(nc_file, first_stamp, database, chunk_sizes=None, zlib=False): # base_time long name - btln = 'base time as unix timestamp' + btln = 'Base time in Epoch' # base time units btu = 'seconds since 1970-01-01 00:00:00' @@ -83,21 +83,25 @@ def create_variables(nc_file, first_stamp, database, chunk_sizes=None, zlib=Fals # base time string bts = first_stamp.strftime('%Y-%m-%d 00:00:00Z') - # time long name - tln = 'Time offset from base_time' + # time offset long name + to_ln = 'Time offset from base_time' - # time units - tu = 'seconds since ' + first_stamp.strftime('%Y-%m-%d 00:00:00Z') + # time offset units + to_u = 'seconds since ' + first_stamp.strftime('%Y-%m-%d 00:00:00Z') + # 'time' units + t_u = 'hours since ' + first_stamp.strftime('%Y-%m-%d 00:00:00Z') coordinates = { # fields: type, dimension, fill, valid_min, std_name, longname, units, valid_max, cf_role, axis - 'time': [np.float64, ('time',), -999., None, None, "Time offset from epoch", - "seconds since 1970-01-01 00:00:00Z", None, None, None], + 'time': [np.float64, ('time',), -999., None, None, "Hour offset from midnight", + t_u, None, None, None], 'lon': [np.float32, tuple(), -999., -180., 'longitude', None, 'degrees_east', 180., None], 'lat': [np.float32, tuple(), -999., -90., 'latitude', None, 'degrees_north', 90., None], 'alt': [np.float32, tuple(), -999., None, 'height', 'vertical distance', 'm', None, None], + # int64 for base_time would be best, but NetCDF4 Classic does not support it + # NetCDF4 Classic mode was chosen so users can use MFDatasets (multi-file datasets) 'base_time': [np.int32, tuple(), -999., None, 'time', btln, btu, None, None], - 'time_offset': [np.float64, ('time',), -999., None, 'time', tln, tu, None, None], + 'time_offset': [np.float64, ('time',), -999., None, 'time', to_ln, to_u, None, None], 'station_name': ['c', ('max_len_station_name',), '\0', None, None, 'station name', None, None, 'timeseries_id'], } @@ -184,12 +188,8 @@ def calculate_wind_gust(wind_speed_5s, wind_speed_2m): http://www.nws.noaa.gov/asos/pdfs/aum-toc.pdf - Criteria Summary - ---------------- - - Wind Gust: - - 1. 2 minute average + Note: This operates on wind data in meters per second even though the + ASOS User's Guide operates on knots. Arguments: wind_speed_5s (Series): 5-second average of instantaneous wind speed magnitudes in m/s @@ -289,15 +289,17 @@ def write_vars(nc_file, frame, database): base_epoch = frame.index[0].replace(hour=0, minute=0, second=0, microsecond=0).value // 10**9 fileVar = nc_file.variables + # base_time is midnight of the current day fileVar['base_time'].assignValue(base_epoch) fileVar['time_offset'][:] = time_epoch - base_epoch - fileVar['time'][:] = time_epoch + # hours since midnight + fileVar['time'][:] = (time_epoch - base_epoch) / (60 * 60) # write coordinate var values to file # alt might not be right, need to verify fileVar['lon'].assignValue(station.LONGITUDE) fileVar['lat'].assignValue(station.LATITUDE) - fileVar['alt'].assignValue(328) + fileVar['alt'].assignValue(station.ELEVATION) # write station name to file fileVar['station_name'][:len(STATION_NAME)] = STATION_NAME @@ -370,6 +372,8 @@ def create_giant_netcdf(input_files, output_fn, zlib, chunk_size, chunk_sizes = [frame.shape[0]] first_stamp = dt.strptime(str(frame.index[0]), '%Y-%m-%d %H:%M:%S') + # NETCDF4_CLASSIC was chosen so that MFDataset reading would work. See: + # http://unidata.github.io/netcdf4-python/#netCDF4.MFDataset nc_file = Dataset(output_fn, 'w', format='NETCDF4_CLASSIC') write_dimensions(nc_file) create_variables(nc_file, first_stamp, database, chunk_sizes, zlib) diff --git a/aosstower/station.py b/aosstower/station.py index 681ca79fb5357977ffed52d781cee4c044420e77..88b301fe9926d94acea51680220c595ea4ecb1b2 100644 --- a/aosstower/station.py +++ b/aosstower/station.py @@ -5,8 +5,9 @@ from datetime import timedelta # Time between data samples in seconds DATA_INTERVAL = timedelta(seconds=5) -# station elevation in meters above the surface in feet -ELEVATION = 325 +# these heights are for the top of the penthouse roof +ELEVATION = 329.522 # meters above mean sea level +HEIGHT = 294.8338 # height in meters above ground level # Id of station from v1 records ID = 1