code: def download_hrrr_for_gssha(main_directory,
                              forecast_start_date_string,
                              forecast_start_hour_string,
                              leftlon=-180, rightlon=180,
                              toplat=90,bottomlat=-90):
      out_directory = path.join(main_directory, forecast_start_date_string)
      try:
          mkdir(out_directory)
      except OSError:
          pass
      forecast_timestep_hour_string_array = ['00', '01', '02', '03', '04',
                                             '05', '06', '07', '08', '09',
                                             '10', '11', '12', '13', '14',
                                             '15', '16', '17', '18']
      downloaded_file_list = []
      for forecast_timestep_hour_string in forecast_timestep_hour_string_array:
          file_name = 'hrrr.t{0}z.wrfsfcf{1}.grib2'.format(forecast_start_hour_string, forecast_timestep_hour_string)
          payload = {
                     'file': file_name,
                     'lev_10_m_above_ground': 'on',
                     'lev_2_m_above_ground': 'on',
                     'lev_entire_atmosphere': 'on',
                     'lev_surface': 'on',
                     'var_DSWRF': 'on',
                     'var_PRATE': 'on',
                     'var_PRES': 'on',
                     'var_RH': 'on',
                     'var_TMP': 'on',
                     'var_UGRD': 'on',
                     'var_VGRD': 'on',
                     'var_TCDC': 'on',
                     'subregion': '',
                     'leftlon': str(leftlon),
                     'rightlon': str(rightlon),
                     'toplat': str(toplat),
                     'bottomlat': str(bottomlat),
                     'dir': '/hrrr.{0}'.format(forecast_start_date_string),
                     }
          r = requests.get('http://nomads.ncep.noaa.gov/cgi-bin/filter_hrrr_2d.pl', params=payload, stream=True)
          if r.status_code == requests.codes.ok:
              out_file = path.join(out_directory, file_name)
              downloaded_file_list.append(out_file)
              with open(out_file, 'wb') as fd:
                  for chunk in r.iter_content(chunk_size=1024):
                      fd.write(chunk)
          else:
              log.error("Problem downloading {0}".format(file_name))
              for filename in downloaded_file_list:
                  try:
                      remove(filename)
                  except OSError:
                      pass
              downloaded_file_list = []
              break
      return downloaded_file_list