Last active
June 6, 2017 22:49
-
-
Save thehesiod/b0f2b80ade8fb4a08b5c2be82f3a7e0f to your computer and use it in GitHub Desktop.
Comparison of new and old AHPS file formats
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import netCDF4 | |
def reversed_list_enumerate(value: list): | |
for i in range(-1, -len(value) - 1, -1): | |
yield i, value[i] | |
def find_first(dataset, var_name, reverse: bool, ahps_to_inches: bool=False): | |
if reverse: | |
iterator = reversed_list_enumerate(dataset.variables[var_name]) | |
else: | |
iterator = enumerate(dataset.variables[var_name]) | |
num_prints = 0 | |
for i, row in iterator: | |
row = np.ma.array(row, mask=row<=0) | |
if ahps_to_inches: | |
row = row.astype(float) * 0.0003937008 | |
row = row.astype(object) | |
row[row.mask] = None | |
if not set(row).issubset({None}): | |
print(i, [round(c, 3) for c in row if c is not None]) | |
num_prints += 1 | |
if num_prints == 10: | |
return | |
np.set_printoptions(threshold=2000, linewidth=200) | |
ds_old = netCDF4.Dataset('/Users/amohr/Downloads/nws_precip_conus_20170404.nc') | |
ds = netCDF4.Dataset('/Users/amohr/Downloads/nws_precip_1day_20170404_conus.nc') | |
print("Old") | |
find_first(ds_old, 'amountofprecip', False, True) | |
find_first(ds_old, 'amountofprecip', True, True) | |
print("New") | |
find_first(ds, 'observation', False) | |
find_first(ds, 'observation', True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment