docs: def get_scenario_from_nrml(oqparam, fname):
      """
      :param oqparam:
          an :class:`openquake.commonlib.oqvalidation.OqParam` instance
      :param fname:
          the NRML files containing the GMFs
      :returns:
          a pair (eids, gmf array)
      """
      if not oqparam.imtls:
          oqparam.set_risk_imtls(get_risk_models(oqparam))
      imts = sorted(oqparam.imtls)
      num_imts = len(imts)
      imt_dt = numpy.dtype([(imt, F32) for imt in imts])
      gmfset = nrml.read(fname).gmfCollection.gmfSet
      eids, sitecounts = _extract_eids_sitecounts(gmfset)
      coords = sorted(sitecounts)
      oqparam.sites = [(lon, lat, 0) for lon, lat in coords]
      site_idx = {lonlat: i for i, lonlat in enumerate(coords)}
      oqparam.number_of_ground_motion_fields = num_events = len(eids)
      num_sites = len(oqparam.sites)
      gmf_by_imt = numpy.zeros((num_events, num_sites), imt_dt)
      counts = collections.Counter()
      for i, gmf in enumerate(gmfset):
          if len(gmf) != num_sites:  # there must be one node per site
              raise InvalidFile('Expected %d sites, got %d nodes in %s, line %d'
                                % (num_sites, len(gmf), fname, gmf.lineno))
          counts[gmf['ruptureId']] += 1
          imt = gmf['IMT']
          if imt == 'SA':
              imt = 'SA(%s)' % gmf['saPeriod']
          for node in gmf:
              sid = site_idx[node['lon'], node['lat']]
              gmf_by_imt[imt][i % num_events, sid] = node['gmv']
  
      for rupid, count in sorted(counts.items()):
          if count < num_imts:
              raise InvalidFile("Found a missing ruptureId %d in %s" %
                                (rupid, fname))
          elif count > num_imts:
              raise InvalidFile("Found a duplicated ruptureId '%s' in %s" %
                                (rupid, fname))
      expected_gmvs_per_site = num_imts * len(eids)
      for lonlat, counts in sitecounts.items():
          if counts != expected_gmvs_per_site:
              raise InvalidFile(
                  '%s: expected %d gmvs at location %s, found %d' %
                  (fname, expected_gmvs_per_site, lonlat, counts))
      return eids, gmf_by_imt.T