问题
I have some data files which I need to read. I know I should use Dataset, but is there a way how to download these files without downloading them manually but by its URL? How would it look like in my case. I am working with conda-python and netCDF4. Whatever I do I cannot read these files. Sorry for my English. The source is http://meop40.troja.mff.cuni.cz:11180/gw.projekt/data.stratopauza/netcdf.profily/
My first try:
from netCDF4 import Dataset
import numpy as np
my_example_nc_file = '/Users/Leif/Downloads/my_example_nc_data.nc'
fh = Dataset(my_example_nc_file, mode='r')
Another Try:
from mpl_toolkits.basemap import Basemap, shiftgrid, cm
import numpy as np
import matplotlib.pyplot as plt
from netCDF4 import Dataset
url = 'http://meop40.troja.mff.cuni.cz:11180/gw.projekt/data.stratopauza/netcdf.profily/atmPrf_C001.2010.227.00.03.G04_2013.3520_nc '
etopodata = Dataset(url) **Error**
回答1:
Maybe save the contents to a temporary file?
import urllib.request
response = urllib.request.urlopen(url)
with open("./tempfile", "w") as f:
f.write(response.read())
Now the file ./tempfile
can be used normally
来源:https://stackoverflow.com/questions/44622315/working-with-python-files