config_auth_cds.ipynb
This commit is contained in:
parent
7f01181a86
commit
a87eac6903
|
@ -0,0 +1,390 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### d4science_copernicus_cds Library Setup and Example\n",
|
||||
"\n",
|
||||
"This Jupyter notebook will guide you through setting up all dependencies and configuring the environment to use the `d4science_copernicus_cds` library. It also provides a comprehensive example of the library's features and capabilities, helping you to manage Climate Data Store (CDS) API authentication and make programmatic requests from the CDS.\n",
|
||||
"\n",
|
||||
"The `d4science_copernicus_cds` library simplifies the authentication process. It prompts for credentials the first time, securely saves them in the workspace, and automatically retrieves them in future sessions—allowing seamless access to CDS data.\n",
|
||||
"\n",
|
||||
"### Obtain Your API Credentials\n",
|
||||
"\n",
|
||||
"To begin, you’ll need your CDS API credentials. Follow these steps to obtain them:\n",
|
||||
"\n",
|
||||
"1. Register or log in to the CDS at [https://cds-beta.climate.copernicus.eu](https://cds-beta.climate.copernicus.eu).\n",
|
||||
"2. Visit [https://cds-beta.climate.copernicus.eu/how-to-api](https://cds-beta.climate.copernicus.eu/how-to-api) and copy the API key provided.\n",
|
||||
"\n",
|
||||
"The library will prompt you to enter:\n",
|
||||
"- **URL**: The URL field is prefilled; simply press Enter to accept the default.\n",
|
||||
"- **KEY**: Insert the obtained API key when prompted, then confirm saving your credentials by pressing \"y.\"\n",
|
||||
"\n",
|
||||
"Once saved, the credentials will be automatically loaded in subsequent sessions, so there is no need to re-enter them.\n",
|
||||
"\n",
|
||||
"---\n",
|
||||
"\n",
|
||||
"With this setup, you’ll be ready to explore the full functionality of `d4science_copernicus_cds` in a BlueCloud JupyterLab environment, where you can seamlessly authenticate and interact with the CDS API across multiple notebooks.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Install Required Dependencies\n",
|
||||
"\n",
|
||||
"Before we begin using the `d4science_copernicus_cds` library to access the Climate Data Store (CDS), we need to install a few dependencies to ensure compatibility and functionality.\n",
|
||||
"\n",
|
||||
"Run the following commands to install the necessary packages:\n",
|
||||
"\n",
|
||||
"- **`cdsapi`**: The official API client for the Climate Data Store, allowing programmatic data access.\n",
|
||||
"- **`attrs` and `typing_extensions`**: Required packages to support the latest functionality of `cdsapi`."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install -U cdsapi\n",
|
||||
"!pip install -U attrs\n",
|
||||
"!pip install -U typing_extensions"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Install the d4science_copernicus_cds Library\n",
|
||||
"\n",
|
||||
"Next, install the `d4science_copernicus_cds` library from the D4Science Git repository. This library will handle authentication for the Climate Data Store (CDS) API in the JupyterLab environment, allowing you to request data seamlessly across multiple notebooks.\n",
|
||||
"\n",
|
||||
"Once installed, the library will be ready for use, and you can proceed with authenticating and configuring your environment."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install -U git+https://code-repo.d4science.org/D4Science/d4science_copernicus_cds.git"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Import d4science_copernicus_cds Functions\n",
|
||||
"\n",
|
||||
"With the `d4science_copernicus_cds` library installed, we can now import the main functions for managing CDS API authentication and configuration. These functions provide a range of capabilities for handling credentials and data directories.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from d4science_copernicus_cds import (\n",
|
||||
" cds_authenticate,\n",
|
||||
" cds_get_credentials,\n",
|
||||
" cds_show_conf,\n",
|
||||
" cds_save_conf,\n",
|
||||
" cds_remove_conf,\n",
|
||||
" cds_remove_env,\n",
|
||||
" cds_datadir\n",
|
||||
")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Authenticate with the CDS API\n",
|
||||
"\n",
|
||||
"To begin accessing data from the Climate Data Store (CDS), start by running the `cds_authenticate()` function to initialize authentication:\n",
|
||||
"\n",
|
||||
"#### First-Time Setup\n",
|
||||
"The first time you run this function, it will prompt you to enter your CDS API credentials:\n",
|
||||
"\n",
|
||||
"1. **URL**: The URL field is prefilled with the default CDS API endpoint. Simply press Enter to accept the default.\n",
|
||||
"2. **KEY**: You will need to enter your personal API key. To obtain it:\n",
|
||||
" - Register or log in to the CDS at [https://cds-beta.climate.copernicus.eu](https://cds-beta.climate.copernicus.eu).\n",
|
||||
" - Visit [https://cds-beta.climate.copernicus.eu/how-to-api](https://cds-beta.climate.copernicus.eu/how-to-api) and copy the API key provided.\n",
|
||||
"3. **Saving the Credentials**: After entering the key, the function will ask if you want to save the credentials in a hidden configuration file in your workspace. Press \"y\" to confirm saving, which will allow future sessions to load the credentials automatically.\n",
|
||||
"\n",
|
||||
"#### Subsequent Sessions\n",
|
||||
"Once saved, `cds_authenticate()` will detect and load the credentials from the environment or configuration file automatically, without requiring further interaction. This setup enables seamless, secure access to the CDS API across sessions.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"client = cds_authenticate()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### View Current Configuration\n",
|
||||
"\n",
|
||||
"The `cds_show_conf()` function displays the current configuration settings, including the credentials and any other parameters related to your Climate Data Store (CDS) API setup.\n",
|
||||
"\n",
|
||||
"This function will output:\n",
|
||||
"\n",
|
||||
"- **Environment-Based Credentials**: If credentials are stored in environment variables, they will be displayed here.\n",
|
||||
"- **Saved Configuration File**: If a configuration file exists in your workspace, the function will show the credentials and settings retrieved from it.\n",
|
||||
"\n",
|
||||
"This display helps verify that your credentials are correctly set up and allows you to check whether they are being loaded from the environment or from a saved configuration file."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"cds_show_conf()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Retrieve CDS API Credentials\n",
|
||||
"\n",
|
||||
"The `cds_get_credentials()` function retrieves your CDS API credentials, returning both the **URL** and **KEY** used for authentication\n",
|
||||
"\n",
|
||||
"If the credentials are already set in the environment or saved in a configuration file, `cds_get_credentials()` will load them directly. \n",
|
||||
"\n",
|
||||
"#### Automatic Authentication Check\n",
|
||||
"If no credentials are found, `cds_get_credentials()` will automatically invoke `cds_authenticate()` to prompt you for your credentials. This ensures that you don't need to call `cds_authenticate()` separately beforehand, as `cds_get_credentials()` will handle it if necessary.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"URL, KEY = cds_get_credentials()\n",
|
||||
"print(\"URL\", URL)\n",
|
||||
"print (\"KEY\", KEY)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Save CDS API Credentials\n",
|
||||
"\n",
|
||||
"The `cds_save_conf()` function saves your CDS API credentials to a hidden configuration file in your workspace. This setup allows future sessions to load the credentials automatically, so you won’t need to re-enter them.\n",
|
||||
"When executed, this function:\n",
|
||||
"\n",
|
||||
"- Retrieves your current credentials (if already set in the environment).\n",
|
||||
"- Prompts you to confirm saving them in a hidden file in your workspace.\n",
|
||||
"\n",
|
||||
"Once saved, the credentials will be securely stored and automatically loaded in future sessions, ensuring seamless authentication with the CDS API without requiring additional input.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"cds_save_conf()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Remove Saved Configuration from Workspace\n",
|
||||
"\n",
|
||||
"The `cds_remove_conf()` function removes the saved configuration file from your workspace. This is useful if you want to clear your stored credentials, so future sessions will require re-authentication.\n",
|
||||
"\n",
|
||||
"To avoid unintentional execution, this line is **commented** out by default. **Remove the comment symbol (`#`) to execute**\n",
|
||||
"\n",
|
||||
"When executed, this function permanently deletes the saved configuration file from your workspace, so the credentials will no longer be automatically loaded. You will be prompted to re-enter them next time you authenticate.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# cds_remove_conf()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Remove Credentials from Environment Variables\n",
|
||||
"\n",
|
||||
"The `cds_remove_env()` function removes the CDS API credentials from the environment variables. This is helpful if you want to clear the credentials from the current session without affecting any saved configuration files.\n",
|
||||
"\n",
|
||||
"To prevent accidental execution, this line is **commented** out by default. **Remove the comment symbol (`#`) to execute**\n",
|
||||
"\n",
|
||||
"When executed, this function clears the credentials stored in environment variables. This action will require you to re-authenticate in the current session or any future sessions if there is no saved configuration file.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# cds_remove_env()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Verify Removal of Credentials with `cds_show_conf()`\n",
|
||||
"\n",
|
||||
"After using `cds_remove_env()` and `cds_remove_conf()` to clear your credentials from both the environment and workspace, you can run `cds_show_conf()` to confirm that all credentials have been removed.\n",
|
||||
"\n",
|
||||
"This function will display any remaining credentials in the environment or configuration file. If both `cds_remove_env()` and `cds_remove_conf()` have been successfully executed, `cds_show_conf()` should indicate that no credentials are currently set, confirming that your workspace and environment have been cleared.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"cds_show_conf()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Set or Get the Data Directory with `cds_datadir()`\n",
|
||||
"\n",
|
||||
"The `cds_datadir()` function sets or retrieves a data directory for saving CDS downloads. Instead of directly using the specified folder name, it appends the provided label to a timestamp-based directory structure, making each directory unique.\n",
|
||||
"\n",
|
||||
"For example, to create a timestamped data directory with the label `\"example\"`, use:\n",
|
||||
"\n",
|
||||
"!!!python\n",
|
||||
"datadir = cds_datadir(\"example\")\n",
|
||||
"!!!\n",
|
||||
"\n",
|
||||
"This will create a directory with a timestamped format, such as:\n",
|
||||
"`/home/jovyan/cds_dataDir/out_2024_11_04_13_58_38_example/`\n",
|
||||
"\n",
|
||||
"- **Timestamped Directory**: The function appends a timestamp to the base directory, followed by the label `\"example\"`. This ensures that each call to `cds_datadir()` creates a unique directory, ideal for organizing data downloads by session or task.\n",
|
||||
"- **Custom Labels**: Use labels like `\"example\"` to organize or categorize downloads. Each call to `cds_datadir()` with a different label or at a different time will create a new directory, keeping data isolated and organized.\n",
|
||||
"\n",
|
||||
"This approach simplifies managing multiple data download sessions and ensures your data files are organized with minimal manual intervention.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 14,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"datadir: %s /home/jovyan/cds_dataDir/out_2024_11_04_13_58_38_example/\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"datadir = cds_datadir(\"example\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"datadir_current = cds_datadir(\"current_example\", basepath=\"./out\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Set or Get the Data Directory with a Custom Base Path\n",
|
||||
"\n",
|
||||
"The `cds_datadir()` function also allows specifying a custom base path for saving CDS data downloads. This function appends a timestamp and a label to the provided base path, creating a unique, organized directory structure.\n",
|
||||
"\n",
|
||||
"For example, to set a custom base path `\"./out\"` with the label `\"current_example\"`, use:\n",
|
||||
"\n",
|
||||
"```python\n",
|
||||
"datadir_current = cds_datadir(\"current_example\", basepath=\"./out\")\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"This will create a directory structure with a timestamped format, such as\n",
|
||||
"\n",
|
||||
"`./out/out_2024_11_04_13_58_38_current_example/`\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"- **Timestamped Directory**: The function automatically adds a timestamp and the provided label to create a unique directory. This is useful for organizing data by session or task.\n",
|
||||
"- **Custom Base Path**: By specifying `basepath=\"./out\"`, the data directory will be created within the specified location rather than the default path.\n",
|
||||
"\n",
|
||||
"This setup provides flexibility, allowing you to easily organize data downloads across multiple directories and ensuring a clear, timestamped folder structure for each session.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 15,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"datadir: %s ./out/out_2024_11_04_14_02_53_current_example/\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"datadir_current = cds_datadir(\"current_example\", basepath=\"./out\")\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.5"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 4
|
||||
}
|
|
@ -1,304 +0,0 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"#### Enter your CDS API key\n",
|
||||
"\n",
|
||||
"We will request data from the Climate Data Store (CDS) programmatically with the help of the CDS API. Let us make use of the option to manually set the CDS API credentials. First, you have to define two variables: `URL` and `KEY` which build together your CDS API key. The string of characters that make up your KEY include your personal User ID and CDS API key. To obtain these, first register or login to the CDS (https://cds-beta.climate.copernicus.eu), then visit https://cds-beta.climate.copernicus.eu/how-to-api and copy the string of characters listed after \"key:\". Replace the `#########` below with this string."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"zsh:1: /Users/Alfredo/works/copernicus/d4science_copernicus_cds/venv/bin/pip: bad interpreter: /Users/Alfredo/works/copernicus/d4science_auth_cds/venv/bin/python3.13: no such file or directory\n",
|
||||
"\n",
|
||||
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m24.2\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.3.1\u001b[0m\n",
|
||||
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpython3.12 -m pip install --upgrade pip\u001b[0m\n",
|
||||
"\u001b[1;31merror\u001b[0m: \u001b[1mexternally-managed-environment\u001b[0m\n",
|
||||
"\n",
|
||||
"\u001b[31m×\u001b[0m This environment is externally managed\n",
|
||||
"\u001b[31m╰─>\u001b[0m To install Python packages system-wide, try brew install\n",
|
||||
"\u001b[31m \u001b[0m xyz, where xyz is the package you are trying to\n",
|
||||
"\u001b[31m \u001b[0m install.\n",
|
||||
"\u001b[31m \u001b[0m \n",
|
||||
"\u001b[31m \u001b[0m If you wish to install a Python library that isn't in Homebrew,\n",
|
||||
"\u001b[31m \u001b[0m use a virtual environment:\n",
|
||||
"\u001b[31m \u001b[0m \n",
|
||||
"\u001b[31m \u001b[0m python3 -m venv path/to/venv\n",
|
||||
"\u001b[31m \u001b[0m source path/to/venv/bin/activate\n",
|
||||
"\u001b[31m \u001b[0m python3 -m pip install xyz\n",
|
||||
"\u001b[31m \u001b[0m \n",
|
||||
"\u001b[31m \u001b[0m If you wish to install a Python application that isn't in Homebrew,\n",
|
||||
"\u001b[31m \u001b[0m it may be easiest to use 'pipx install xyz', which will manage a\n",
|
||||
"\u001b[31m \u001b[0m virtual environment for you. You can install pipx with\n",
|
||||
"\u001b[31m \u001b[0m \n",
|
||||
"\u001b[31m \u001b[0m brew install pipx\n",
|
||||
"\u001b[31m \u001b[0m \n",
|
||||
"\u001b[31m \u001b[0m You may restore the old behavior of pip by passing\n",
|
||||
"\u001b[31m \u001b[0m the '--break-system-packages' flag to pip, or by adding\n",
|
||||
"\u001b[31m \u001b[0m 'break-system-packages = true' to your pip.conf file. The latter\n",
|
||||
"\u001b[31m \u001b[0m will permanently disable this error.\n",
|
||||
"\u001b[31m \u001b[0m \n",
|
||||
"\u001b[31m \u001b[0m If you disable this error, we STRONGLY recommend that you additionally\n",
|
||||
"\u001b[31m \u001b[0m pass the '--user' flag to pip, or set 'user = true' in your pip.conf\n",
|
||||
"\u001b[31m \u001b[0m file. Failure to do this can result in a broken Homebrew installation.\n",
|
||||
"\u001b[31m \u001b[0m \n",
|
||||
"\u001b[31m \u001b[0m Read more about this behavior here: <https://peps.python.org/pep-0668/>\n",
|
||||
"\n",
|
||||
"\u001b[1;35mnote\u001b[0m: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.\n",
|
||||
"\u001b[1;36mhint\u001b[0m: See PEP 668 for the detailed specification.\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"!pip install 'cdsapi>=0.7.2'"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"zsh:1: /Users/Alfredo/works/copernicus/d4science_copernicus_cds/venv/bin/pip: bad interpreter: /Users/Alfredo/works/copernicus/d4science_auth_cds/venv/bin/python3.13: no such file or directory\n",
|
||||
"\n",
|
||||
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m24.2\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.3.1\u001b[0m\n",
|
||||
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpython3.12 -m pip install --upgrade pip\u001b[0m\n",
|
||||
"\u001b[1;31merror\u001b[0m: \u001b[1mexternally-managed-environment\u001b[0m\n",
|
||||
"\n",
|
||||
"\u001b[31m×\u001b[0m This environment is externally managed\n",
|
||||
"\u001b[31m╰─>\u001b[0m To install Python packages system-wide, try brew install\n",
|
||||
"\u001b[31m \u001b[0m xyz, where xyz is the package you are trying to\n",
|
||||
"\u001b[31m \u001b[0m install.\n",
|
||||
"\u001b[31m \u001b[0m \n",
|
||||
"\u001b[31m \u001b[0m If you wish to install a Python library that isn't in Homebrew,\n",
|
||||
"\u001b[31m \u001b[0m use a virtual environment:\n",
|
||||
"\u001b[31m \u001b[0m \n",
|
||||
"\u001b[31m \u001b[0m python3 -m venv path/to/venv\n",
|
||||
"\u001b[31m \u001b[0m source path/to/venv/bin/activate\n",
|
||||
"\u001b[31m \u001b[0m python3 -m pip install xyz\n",
|
||||
"\u001b[31m \u001b[0m \n",
|
||||
"\u001b[31m \u001b[0m If you wish to install a Python application that isn't in Homebrew,\n",
|
||||
"\u001b[31m \u001b[0m it may be easiest to use 'pipx install xyz', which will manage a\n",
|
||||
"\u001b[31m \u001b[0m virtual environment for you. You can install pipx with\n",
|
||||
"\u001b[31m \u001b[0m \n",
|
||||
"\u001b[31m \u001b[0m brew install pipx\n",
|
||||
"\u001b[31m \u001b[0m \n",
|
||||
"\u001b[31m \u001b[0m You may restore the old behavior of pip by passing\n",
|
||||
"\u001b[31m \u001b[0m the '--break-system-packages' flag to pip, or by adding\n",
|
||||
"\u001b[31m \u001b[0m 'break-system-packages = true' to your pip.conf file. The latter\n",
|
||||
"\u001b[31m \u001b[0m will permanently disable this error.\n",
|
||||
"\u001b[31m \u001b[0m \n",
|
||||
"\u001b[31m \u001b[0m If you disable this error, we STRONGLY recommend that you additionally\n",
|
||||
"\u001b[31m \u001b[0m pass the '--user' flag to pip, or set 'user = true' in your pip.conf\n",
|
||||
"\u001b[31m \u001b[0m file. Failure to do this can result in a broken Homebrew installation.\n",
|
||||
"\u001b[31m \u001b[0m \n",
|
||||
"\u001b[31m \u001b[0m Read more about this behavior here: <https://peps.python.org/pep-0668/>\n",
|
||||
"\n",
|
||||
"\u001b[1;35mnote\u001b[0m: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.\n",
|
||||
"\u001b[1;36mhint\u001b[0m: See PEP 668 for the detailed specification.\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"!pip install -U cdsapi\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"zsh:1: /Users/Alfredo/works/copernicus/d4science_copernicus_cds/venv/bin/pip: bad interpreter: /Users/Alfredo/works/copernicus/d4science_auth_cds/venv/bin/python3.13: no such file or directory\n",
|
||||
"\n",
|
||||
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m24.2\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.3.1\u001b[0m\n",
|
||||
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpython3.12 -m pip install --upgrade pip\u001b[0m\n",
|
||||
"\u001b[1;31merror\u001b[0m: \u001b[1mexternally-managed-environment\u001b[0m\n",
|
||||
"\n",
|
||||
"\u001b[31m×\u001b[0m This environment is externally managed\n",
|
||||
"\u001b[31m╰─>\u001b[0m To install Python packages system-wide, try brew install\n",
|
||||
"\u001b[31m \u001b[0m xyz, where xyz is the package you are trying to\n",
|
||||
"\u001b[31m \u001b[0m install.\n",
|
||||
"\u001b[31m \u001b[0m \n",
|
||||
"\u001b[31m \u001b[0m If you wish to install a Python library that isn't in Homebrew,\n",
|
||||
"\u001b[31m \u001b[0m use a virtual environment:\n",
|
||||
"\u001b[31m \u001b[0m \n",
|
||||
"\u001b[31m \u001b[0m python3 -m venv path/to/venv\n",
|
||||
"\u001b[31m \u001b[0m source path/to/venv/bin/activate\n",
|
||||
"\u001b[31m \u001b[0m python3 -m pip install xyz\n",
|
||||
"\u001b[31m \u001b[0m \n",
|
||||
"\u001b[31m \u001b[0m If you wish to install a Python application that isn't in Homebrew,\n",
|
||||
"\u001b[31m \u001b[0m it may be easiest to use 'pipx install xyz', which will manage a\n",
|
||||
"\u001b[31m \u001b[0m virtual environment for you. You can install pipx with\n",
|
||||
"\u001b[31m \u001b[0m \n",
|
||||
"\u001b[31m \u001b[0m brew install pipx\n",
|
||||
"\u001b[31m \u001b[0m \n",
|
||||
"\u001b[31m \u001b[0m You may restore the old behavior of pip by passing\n",
|
||||
"\u001b[31m \u001b[0m the '--break-system-packages' flag to pip, or by adding\n",
|
||||
"\u001b[31m \u001b[0m 'break-system-packages = true' to your pip.conf file. The latter\n",
|
||||
"\u001b[31m \u001b[0m will permanently disable this error.\n",
|
||||
"\u001b[31m \u001b[0m \n",
|
||||
"\u001b[31m \u001b[0m If you disable this error, we STRONGLY recommend that you additionally\n",
|
||||
"\u001b[31m \u001b[0m pass the '--user' flag to pip, or set 'user = true' in your pip.conf\n",
|
||||
"\u001b[31m \u001b[0m file. Failure to do this can result in a broken Homebrew installation.\n",
|
||||
"\u001b[31m \u001b[0m \n",
|
||||
"\u001b[31m \u001b[0m Read more about this behavior here: <https://peps.python.org/pep-0668/>\n",
|
||||
"\n",
|
||||
"\u001b[1;35mnote\u001b[0m: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.\n",
|
||||
"\u001b[1;36mhint\u001b[0m: See PEP 668 for the detailed specification.\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"!pip install -U attrs"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!pip install -U typing_extensions"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import auth_cds"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"ENV - None None\n",
|
||||
"env is not configured\n",
|
||||
"Configuration from file /Users/Alfredo/.cdsapirc: {'url': 'https://cds-beta.climate.copernicus.eu/api', 'key': 'db1f2085-6b8b-42e6-b832-625dfaf831a4'}\n",
|
||||
"Configuration from environment: None\n",
|
||||
"Configuration from file: {'url': 'https://cds-beta.climate.copernicus.eu/api', 'key': 'db1f2085-6b8b-42e6-b832-625dfaf831a4'}\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"auth_cds.cds_show_conf()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"ENV - None None\n",
|
||||
"env is not configured\n",
|
||||
"Configuration from file /Users/Alfredo/.cdsapirc: {'url': 'https://cds-beta.climate.copernicus.eu/api', 'key': 'db1f2085-6b8b-42e6-b832-625dfaf831a4'}\n",
|
||||
"saving config to env\n",
|
||||
"Set environment variables CDSAPI_URL, CDSAPI_KEY\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"{'url': 'https://cds-beta.climate.copernicus.eu/api',\n",
|
||||
" 'key': 'db1f2085-6b8b-42e6-b832-625dfaf831a4'}"
|
||||
]
|
||||
},
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"auth_cds.cds_authenticate()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 11,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"2024-11-03 10:02:43,960 INFO [2024-09-28T00:00:00] **Welcome to the New Climate Data Store (CDS)!** This new system is in its early days of full operations and still undergoing enhancements and fine tuning. Some disruptions are to be expected. Your \n",
|
||||
"[feedback](https://jira.ecmwf.int/plugins/servlet/desk/portal/1/create/202) is key to improve the user experience on the new CDS for the benefit of everyone. Thank you.\n",
|
||||
"2024-11-03 10:02:43,961 WARNING [2024-09-26T00:00:00] Should you have not yet migrated from the old CDS system to the new CDS, please check our [informative page](https://confluence.ecmwf.int/x/uINmFw) for guidance.\n",
|
||||
"2024-11-03 10:02:43,962 INFO [2024-09-26T00:00:00] Watch our [Forum](https://forum.ecmwf.int/) for Announcements, news and other discussed topics.\n",
|
||||
"2024-11-03 10:02:43,962 INFO [2024-09-16T00:00:00] Remember that you need to have an ECMWF account to use the new CDS. **Your old CDS credentials will not work in new CDS!**\n",
|
||||
"2024-11-03 10:02:43,962 WARNING [2024-06-16T00:00:00] CDS API syntax is changed and some keys or parameter names may have also changed. To avoid requests failing, please use the \"Show API request code\" tool on the dataset Download Form to check you are using the correct syntax for your API request.\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import cdsapi\n",
|
||||
"client = cdsapi.Client()\n",
|
||||
" "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# auth_cds.removeCredentials()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "venv",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.13.0"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 4
|
||||
}
|
Loading…
Reference in New Issue