|
31 | 31 | }, |
32 | 32 | { |
33 | 33 | "cell_type": "code", |
34 | | - "execution_count": null, |
| 34 | + "execution_count": 2, |
35 | 35 | "metadata": {}, |
36 | 36 | "outputs": [], |
37 | 37 | "source": [ |
|
46 | 46 | }, |
47 | 47 | { |
48 | 48 | "cell_type": "code", |
49 | | - "execution_count": null, |
| 49 | + "execution_count": 3, |
50 | 50 | "metadata": {}, |
51 | 51 | "outputs": [], |
52 | 52 | "source": [ |
|
72 | 72 | "outputs": [], |
73 | 73 | "source": [ |
74 | 74 | "#| export\n", |
75 | | - "def describe():\n", |
76 | | - " print(\"This package fetches ERA5 data.\")" |
| 75 | + "@hydra.main(version_base=None, config_path=\"../conf\", config_name=\"config\")\n", |
| 76 | + "def describe(\n", |
| 77 | + " cfg: DictConfig=None, # Configuration file\n", |
| 78 | + " )-> None:\n", |
| 79 | + " \"Describe the configuration file used by Hydra for the pipeline\"\n", |
| 80 | + " \n", |
| 81 | + " if cfg is None:\n", |
| 82 | + " cfg = OmegaConf.create()\n", |
| 83 | + " \n", |
| 84 | + " print(\"This package fetches ERA5 data. The following is the config file used by Hydra for the pipeline:\\n\")\n", |
| 85 | + " print(OmegaConf.to_yaml(cfg))" |
77 | 86 | ] |
78 | 87 | }, |
79 | 88 | { |
80 | 89 | "cell_type": "code", |
81 | | - "execution_count": null, |
| 90 | + "execution_count": 21, |
82 | 91 | "metadata": {}, |
83 | 92 | "outputs": [], |
84 | 93 | "source": [ |
85 | 94 | "#| export\n", |
86 | | - "#@hydra.main(version_base=None, config_path=here() / \"conf\", config_name=\"config\")\n", |
| 95 | + "@hydra.main(version_base=None, config_path=\"../conf\", config_name=\"config\")\n", |
87 | 96 | "def testAPI(\n", |
| 97 | + " cfg: DictConfig=None,\n", |
88 | 98 | " output_path:str=None,\n", |
89 | 99 | " dataset:str=\"reanalysis-era5-pressure-levels\",\n", |
90 | | - " remove:bool=False,\n", |
91 | | - " cfg: DictConfig = None\n", |
| 100 | + " remove:bool=True\n", |
92 | 101 | " )-> bool: \n", |
93 | 102 | " \n", |
94 | | - " #print(OmegaConf.to_yaml(cfg))\n", |
| 103 | + " print(OmegaConf.to_yaml(cfg))\n", |
95 | 104 | "\n", |
96 | 105 | " try:\n", |
97 | 106 | " client = cdsapi.Client()\n", |
|
131 | 140 | "\n", |
132 | 141 | " except Exception as e:\n", |
133 | 142 | " print(\"API connection test failed.\")\n", |
134 | | - " print(\"Did you set up your API key with CDS? If not, please visit https://cds.climate.copernicus.eu/api-how-to\")\n", |
| 143 | + " print(\"Did you set up your API key with CDS? If not, please visit https://cds.climate.copernicus.eu/how-to-api#install-the-cds-api-client\")\n", |
135 | 144 | " print(\"Error: {}\".format(e))\n", |
136 | 145 | " return False" |
137 | 146 | ] |
138 | 147 | }, |
| 148 | + { |
| 149 | + "cell_type": "markdown", |
| 150 | + "metadata": {}, |
| 151 | + "source": [ |
| 152 | + "We can see that this API tester tool works with Hydra configuration:" |
| 153 | + ] |
| 154 | + }, |
| 155 | + { |
| 156 | + "cell_type": "code", |
| 157 | + "execution_count": 33, |
| 158 | + "metadata": {}, |
| 159 | + "outputs": [ |
| 160 | + { |
| 161 | + "name": "stdout", |
| 162 | + "output_type": "stream", |
| 163 | + "text": [ |
| 164 | + "This package fetches ERA5 data. The following is the config file used by Hydra for the pipeline:\n", |
| 165 | + "\n", |
| 166 | + "db:\n", |
| 167 | + " driver: mysql\n", |
| 168 | + " user: omry\n", |
| 169 | + " password: secret\n", |
| 170 | + "\n" |
| 171 | + ] |
| 172 | + } |
| 173 | + ], |
| 174 | + "source": [ |
| 175 | + "from hydra import initialize, compose\n", |
| 176 | + "from omegaconf import OmegaConf\n", |
| 177 | + "\n", |
| 178 | + "# unfortunately, we have to use the initialize function to load the config file\n", |
| 179 | + "# this is because the @hydra decorator does not work with Notebooks very well\n", |
| 180 | + "# this is a known issue with Hydra: https://gist.github.com/bdsaglam/586704a98336a0cf0a65a6e7c247d248\n", |
| 181 | + "# \n", |
| 182 | + "# just use the relative path from the notebook to the config dir\n", |
| 183 | + "with initialize(version_base=None, config_path=\"../conf\"):\n", |
| 184 | + " cfg = compose(config_name='config.yaml')\n", |
| 185 | + "\n", |
| 186 | + "describe(cfg)" |
| 187 | + ] |
| 188 | + }, |
139 | 189 | { |
140 | 190 | "cell_type": "code", |
141 | 191 | "execution_count": null, |
|
144 | 194 | "source": [ |
145 | 195 | "#export\n", |
146 | 196 | "if __name__ == \"__main__\":\n", |
147 | | - " describe()\n", |
148 | | - " testAPI()\n", |
149 | | - "else:\n", |
150 | | - " pass" |
| 197 | + " # for testing\n", |
| 198 | + " describe()" |
151 | 199 | ] |
152 | 200 | }, |
153 | 201 | { |
|
168 | 216 | "name": "python3" |
169 | 217 | }, |
170 | 218 | "language_info": { |
| 219 | + "codemirror_mode": { |
| 220 | + "name": "ipython", |
| 221 | + "version": 3 |
| 222 | + }, |
| 223 | + "file_extension": ".py", |
| 224 | + "mimetype": "text/x-python", |
171 | 225 | "name": "python", |
| 226 | + "nbconvert_exporter": "python", |
| 227 | + "pygments_lexer": "ipython3", |
172 | 228 | "version": "3.13.2" |
173 | 229 | } |
174 | 230 | }, |
|
0 commit comments