johnpaton / airbase Goto Github PK
View Code? Open in Web Editor NEW㪠An easy downloader for the AirBase air quality data.
Home Page: https://airbase.readthedocs.io
License: MIT License
π¬ An easy downloader for the AirBase air quality data.
Home Page: https://airbase.readthedocs.io
License: MIT License
Right now we only support CSV, which is what the portal provides. We could convert to other file formats (parquet, avro) on the fly for easier processing later.
Hi John,
Have you considered to use an asynchronous request library?
Replacing requests
by aiohttp
would give you concurrent downloads,
like in the 3rd implementation shown on this article.
Would you accept a PR?
I have no experience with async python, but I'm willing to give it a try.
Cheers,
Γlvaro.
when attempting to download CO
data, no data is found
$ airbase pollutant CO --year 2023
Generating CSV download links...
100%|βββββββββββββββββββββββββββββββββββββββββββββββββββββββ| 40/40 [00:52<00:00, 1.32s/it]
Generated 0 CSV links ready for downloading
Downloading CSVs to data...
0it [00:00, ?it/s]
After some debut, I found out that this is a problem in typer (tiangolo/typer#570).
The CO
CLI option is interpreted as Co
, which has no data...
Hi,
I very much like this tool to extract information from the Airbase database. Thanks for this.
As a test, I was trying to select data from Belgium, for eg. O3 since 2018.
I tried both the download_to_file (my preference) and download_to_directory extensions.
Yet both fail at the point of 23/70. With the following error:
File "/home/demuzmp4/.local/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 3291, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 1, in
r.download_to_file(ofile)
File "/home/demuzmp4/.local/lib/python3.6/site-packages/airbase/airbase.py", line 453, in download_to_file
r = requests.get(url)
File "/home/demuzmp4/.local/lib/python3.6/site-packages/requests/api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "/home/demuzmp4/.local/lib/python3.6/site-packages/requests/api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
File "/home/demuzmp4/.local/lib/python3.6/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/home/demuzmp4/.local/lib/python3.6/site-packages/requests/sessions.py", line 640, in send
adapter = self.get_adapter(url=request.url)
File "/home/demuzmp4/.local/lib/python3.6/site-packages/requests/sessions.py", line 731, in get_adapter
raise InvalidSchema("No connection adapters were found for '%s'" % url)
requests.exceptions.InvalidSchema: No connection adapters were found for 'https://ereporting.blob.core.windows.net/downloadservice/BE_6001_42519_2018_timeseries.csv'
They do fail at the same URL, while this file can be downloaded via a browser.
To me it is not clear why this fails. I also tried with raise_for_status=False, but the problem persists.
Would it make sense that the download functions include a try error statement, allowing them to continue even though it fails to retrieve a file?
Or perhaps there is another way on how to address this?
Cheers,
Matthias
Looks like it disappeared after merging #24
Since merging #12, the ReadTheDocs build is failing (e.g. https://readthedocs.org/projects/airbase/builds/16034892). That PR included some updates to the RTD config. @avaldebe any ideas on this?
Dear John,
I am trying to download Airbase data for 2019 and 2020.
import airbase
client = airbase.AirbaseClient()
client.all_countries
client.all_pollutants
for i in range(len(client.all_countries)):
print (i)
r = client.request(country=client.all_countries[i], pl=["O3","NO","NO2"],year_from=2019,update_date="2019-01-01 00:00:00")
r.download_to_file("/path/raw_o3_no_no2_"f"{client.all_countries[i]}"".csv")
But I get this error
raceback (most recent call last):
File "<stdin>", line 4, in <module>
File "/home/srvx11/lehre/users/a1276905/.conda/envs/py36/lib/python3.6/site-packages/airbase/airbase.py", line 456, in download_to_file
r.raise_for_status()??????????????????????????| 3/3 [00:11<00:00, 3.52s/it]
File "/home/srvx11/lehre/users/a1276905/.conda/envs/py36/lib/python3.6/site-packages/requests/models.py", line 940, in raise_for_status
raise HTTPError(http_error_msg, response=self)2/671 [05:08<43:40, 4.38s/it]
requests.exceptions.HTTPError: 404 Client Error: The specified blob does not exist. for url: https://ereporting.blob.core.windows.net/downloadservice/AT_7_48957_2020_timeseries.cs
Could you please let me know how to fix it?
Best regards,
Omid.
Like requests
, create a new api that basically bypasses the client (by handling it internally) so that users can jump directly to download_*
ing the data.
This terminology is only really used internally by the portal for generating URLs, it doesn't need to be exposed to the user.
The CSVs themselves use AirPollutant
for the name (now: pl
), AirPollutantCode
for the URL containing the id (now: shortpl
), and the portal refers to the "pollutant id" in the text.
The data dictionary calls them "pollutant notation" and "pollutant id"
This can basically be a 1-1 map from #29 to a command line interface, to avoid needing to write any code to start downloading.
The url for the metadata file is now http://discomap.eea.europa.eu/map/fme/metadata/PanEuropean_metadata.csv, this should be updated
From the readme:
>>> import airbase
>>> client = airbase.AirbaseClient()
>>> client.all_countries
['GR', 'ES', 'IS', 'CY', 'NL', 'AT', 'LV', 'BE', 'CH', 'EE', 'FR', 'DE', ...
>>> client.all_pollutants
{'k': 412, 'CO': 10, 'NO': 38, 'O3': 7, 'As': 2018, 'Cd': 2014, ...
>>> client.pollutants_per_country
{'AD': [{'pl': 'CO', 'shortpl': 10}, {'pl': 'NO', 'shortpl': 38}, ...
>>> client.search_pollutant("O3")
[{'pl': 'O3', 'shortpl': 7}, {'pl': 'NO3', 'shortpl': 46}, ...
It would be more intuitive if all of these had the same format (either the list of pl/shortpl dicts, or the big pl:shortpl dict). The current mix is confusing.
This will be a breaking change though so should be handled with care.
setuptools_scm
for the package versioning__version__.py
(or similar) inside the package for easily checking the version from PythonA declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.