Code Monkey home page Code Monkey logo

airbase's People

Contributors

avaldebe avatar johnpaton avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

airbase's Issues

Support additional output types

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.

use async request library

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.

cli request confuses "CO" with "Co"

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...

No connection adapters were found

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

The specified blob does not exist. for url ....

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.

Implement functional API for dowloading

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.

Drop "pl"/"shortpl" terminology in favor of something more readable

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"

Add cli for downloading

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.

Make search_pollutant and pollutants_per_country output consistent with all_pollutants

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.

Switch to setuptools_scm for versioning

  • Switch to using setuptools_scm for the package versioning
  • CI should release to PyPI on any new tag (#13)
  • Should start writing a __version__.py (or similar) inside the package for easily checking the version from Python

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.