Python-IrradPy icon indicating copy to clipboard operation
Python-IrradPy copied to clipboard

Key Error

Open sek89244 opened this issue 2 years ago • 3 comments

I am hoping to use this package to download data. I have changed some of the variables to download the data in the regions and collections I need. However, whenever I run the example download script I get a Key Error. I am a Windows user and below is my code.

class dummy_downloader():
def setUp(self):
    # SIMPLE USE CONFIGURATION
    ## The user should define the input parameters in this script for the easiest use case of the package
    # specify your user authentication
    self.username = input("Please Enter Your USERNAME:")
    self.password = getpass("Please Enter Your PASSWORD: ")

    # specify the date range
    self.initial_year = 2018
    self.initial_month = 1
    self.initial_day = 1

    # specify the end date
    self.final_year = 2018
    self.final_month = 1
    self.final_day = 3

    # specify the bottom left corner of the rectangular region
    self.lat_1 = 30.36
    self.lon_1 = -85.03

    # specify the top right corner of the rectangular region
    self.lat_2 = 35.2
    self.lon_2 = -81.25

    # specify the number of threads, this is the number of instances that will run at the same time
    # theoretically, this can be as many as you think your machine can handle, though GESDISC may
    # impose a limit
    self.thread_num = 5

    # specify the output destination of the data, depending on operating system changes the file separator
    # default location is where you run the script, specify here if you want to change it using os.join.
    self.output_dir = os.path.join(os.getcwd(),"MERRA2_data")

    # specify the merge timelapse of the data
    # select from 'none', 'daily', 'monthly', 'yearly'
    self.merge_timelapse = 'monthly'

    # Here you can change what actually gets downloaded
    # full list of variables can be founnd here https://gmao.gsfc.nasa.gov/pubs/docs/Bosilovich785.pdf
    self.merra2_var_dicts = {
            "lnd": {
                "esdt_dir": "(M2T1NXLND.5.12.4",
                "collection": "tavg1_2d_lnd_Nx",
                "var_name": ["PRECTOTLAND", "PRECSNOLAND", "GWETTOP", "TSURF"],
                "standard_name": "surface_diag",
                "least_significant_digit": 3,

                },
            "slv": {
                "esdt_dir": "M2T1NXSLV.5.12.4",
                "collection": "tavg1_2d_slv_Nx",
                "var_name": ["V2M", "TS", "PS","U2M"],
                "standard_name": "single_lvl_surface",
                "least_significant_digit": 3,

                },
            "lsf": {
                "esdt_dir": "M2T1NXAER.5.12.4",
                "collection": "inst1_2d_lfo_Nx",
                "var_name": ["HLML", "PS", "QLML","SPEEDLML","TLML"],
                "standard_name": "Surface_forcings",
                "least_significant_digit": 3,

                },
    }

def download(self):
    irradpy.downloader.run(
        auth={"uid": self.username, "password": self.password},
        initial_year=self.initial_year,
        final_year=self.final_year,
        initial_month=self.initial_month,
        final_month=self.final_month,
        initial_day=self.initial_day,
        final_day=self.final_day,
        lat_1=self.lat_1,
        lat_2=self.lat_2,
        lon_1=self.lon_1,
        lon_2=self.lon_2,
        thread_num=self.thread_num,
        merra2_var_dicts=self.merra2_var_dicts,
        output_dir=self.output_dir,
        merge_timelapse=self.merge_timelapse
    )

freeze_support() d = dummy_downloader() d.setUp() d.download()

And below is the error I am receiving.

Please Enter Your USERNAME:sek89244 Please Enter Your PASSWORD: ········ INFO:root:Downloading data from 2018-1-1 to 2018-1-3...

KeyError Traceback (most recent call last) Input In [6], in <cell line: 5>() 3 d = dummy_downloader() 4 d.setUp() ----> 5 d.download()

Input In [5], in dummy_downloader.download(self) 70 def download(self): ---> 71 irradpy.downloader.run( 72 auth={"uid": self.username, "password": self.password}, 73 initial_year=self.initial_year, 74 final_year=self.final_year, 75 initial_month=self.initial_month, 76 final_month=self.final_month, 77 initial_day=self.initial_day, 78 final_day=self.final_day, 79 lat_1=self.lat_1, 80 lat_2=self.lat_2, 81 lon_1=self.lon_1, 82 lon_2=self.lon_2, 83 thread_num=self.thread_num, 84 merra2_var_dicts=self.merra2_var_dicts, 85 output_dir=self.output_dir, 86 merge_timelapse=self.merge_timelapse 87 )

File ~\anaconda3\envs\IrradPyEnv\lib\site-packages\irradpy-1.5.0-py3.9.egg\irradpy\downloader\socket.py:122, in run(collection_names, initial_year, final_year, initial_month, final_month, initial_day, final_day, lat_1, lon_1, lat_2, lon_2, merra2_var_dicts, output_dir, auth, merge_timelapse, thread_num) 120 # Call the main function 121 socket = SocketManager() --> 122 socket.daily_download_and_convert( 123 collection_names, merra2_var_dicts=merra2_var_dicts, 124 initial_year=initial_year, initial_month=initial_month, initial_day=initial_day, 125 final_year=final_year, final_month=final_month, final_day=final_day, 126 output_dir=output_dir, 127 auth=auth, 128 merge_timelapse=merge_timelapse, 129 lat_1=lat_1, lon_1=lon_1, 130 lat_2=lat_2, lon_2=lon_2, 131 thread_num=thread_num, 132 )

File ~\anaconda3\envs\IrradPyEnv\lib\site-packages\irradpy-1.5.0-py3.9.egg\irradpy\downloader\download.py:645, in SocketManager.daily_download_and_convert(self, collection_names, initial_year, final_year, initial_month, final_month, initial_day, final_day, lat_1, lon_1, lat_2, lon_2, merra2_var_dicts, output_dir, auth, merge_timelapse, merge, thread_num) 643 merra2_var_dict = var_list[collection_name] 644 else: --> 645 merra2_var_dict = merra2_var_dicts[i] 646 # Download subdaily files 647 # Translate the coordinates that define your area to grid coordinates. 648 lat_coord_1 = self.translate_lat_to_geos5_native(lat_1)

KeyError: 0

Any help would be greatly appreciated!

sek89244 avatar Aug 24 '22 18:08 sek89244

I don’t know exactly what is happening here but I think you made a typo in merra2 var dicts.

"lnd": { "esdt_dir": "(M2T1NXLND.5.12.4",

included an extra ( symbol.

let me know if it still doesn’t work after fixing it.

BXYMartin avatar Aug 24 '22 18:08 BXYMartin

It did not work, it is downloading the folder, but the folder is empty.

sek89244 avatar Aug 26 '22 16:08 sek89244

I have recently encountered the same issue, did you solve it?

wenqi18 avatar Jun 04 '23 07:06 wenqi18