Open saeed-moghimi-noaa opened 2 years ago
Hi @saeed-moghimi-noaa . The issue is that your dataset has nan values (see for instance data.q
variable) that need to be converted to float
for writing.
The easiest way is to convert them on the fly with
data.fillna(0).to_netcdf(var + '.nc').
You can choose any value instead of zero.
BTW, you can run the same code with searvey just by replacing
from stormevents.coops import coops_product_within_region
with
from searvey.coops import coops_product_within_region
You can install searvey
with
conda install -c conda-forge searvey
Thanks for the prompt reply @brey.
Worked fine. I will close the ticket. Thanks to @bery.
from shapely.geometry import box
from datetime import datetime,timedelta
from searvey.coops import coops_product_within_region
from os.path import exists
import geopandas
from matplotlib import pyplot as plt
vars = ['water_level','water_temperature','wind','salinity','conductivity','currents']
#bnd = -99.0,5,-52.8,46.3 #US mainland
#bnd = -98.5 ,-84.5,24.,31.5 #GulfM
bnd = -74.5 , -71.0 , 40.1 , 41.55 #newyork
now_ = datetime.now()
past_ = now_ - timedelta(0.25)
print (' > Read US medium shoreline ... ')
if not exists('us_medium_shoreline.shp'):
countries = geopandas.read_file('https://coast.noaa.gov/htdata/Shoreline/us_medium_shoreline.zip')
countries.to_file('us_medium_shoreline.shp')
else:
countries = geopandas.read_file('us_medium_shoreline.shp')
for var in vars:
print (' > get data ...', var)
if True:
# See here https://api.tidesandcurrents.noaa.gov/api/prod/
data = coops_product_within_region(
product = var,
start_date = past_.isoformat(),
end_date = now_.isoformat(),
region = box(*bnd),
datum = 'NAVD'
)
print (' > plot figure for ' , var)
plt.figure()
figure, axis = plt.subplots(1, 1)
figure.set_size_inches(12, 12 / 1.61803398875)
countries.plot(color='lightgrey', ax=axis, zorder=-1)
plt.scatter(x=data.x,y=data.y,c=data.v.mean(axis=1))
plt.colorbar()
plt.xlim(*bnd[:2])
plt.ylim(*bnd[2:])
axis.set_title(var)
plt.savefig(var + '.png')
plt.close('all')
if True:
print(' > save netcdf file')
data.fillna(-99).to_netcdf(var + '.nc')
There is work to be done on the parameters besides water level to:
Main remaining issue:
I did not consider multi-scalar outputs for plotting, that would be a good feature for searvey
to support.
@zacharyburnett Do them get included in the final netcdf file?
It seems that there is some normalization taking place with variable name change. I see from the API e.g wind has different and more scalar names which are lost.
{"metadata":{"id":"8452660","name":"Newport","lat":"41.5050","lon":"-71.3267"}, "data": [{"t":"2021-08-08 15:00", "s":"8.16", "d":"7.00", "dr":"N", "g":"9.72", "f":"0,0"},{"t":"2021-08-08 15:06", "s":"7.39", "d":"8.00", "dr":"N", "g":"10.89", "f":"0,0"}]}
This is an API issue that we need to tackle. @zacharyburnett I guess this is what you mean above.
For IOC we kept all their names to avoid errors but that means it is up to the user to differentiate.
@zacharyburnett @pmav99 @brey
Thanks for the great tool. I just want to report that the download process for water temperature went through nicely:
However it generated error on netcdf file output:
Here is my code:
Please look into this.