Exemplo n.º 1
0
  public void parseGroup(Group g) throws Hdf5Exception, EndOfSequenceException {
    startGroup(g);

    java.util.List members = g.getMemberList();

    // NOTE: parsing contents twice to ensure subgroups are handled before datasets
    // This is mainly because synapse_props groups will need to be parsed before dataset of
    // connections

    for (int j = 0; j < members.size(); j++) {
      HObject obj = (HObject) members.get(j);

      if (obj instanceof Group) {
        Group subGroup = (Group) obj;

        logger.logComment("---------    Found a sub group: " + subGroup.getName());

        parseGroup(subGroup);
      }
    }

    for (int j = 0; j < members.size(); j++) {
      HObject obj = (HObject) members.get(j);

      if (obj instanceof Dataset) {
        Dataset ds = (Dataset) obj;

        logger.logComment("Found a dataset: " + ds.getName());

        dataSet(ds);
      }
    }

    endGroup(g);
  }
Exemplo n.º 2
0
  public void endGroup(Group g) throws Hdf5Exception {
    logger.logComment("-----   Going out of a group: " + g.getFullName());

    if (g.getName().equals(NetworkMLConstants.POPULATIONS_ELEMENT)) {
      inPopulations = false;
    } else if (g.getName().equals(NetworkMLConstants.PROJECTIONS_ELEMENT)) {
      inProjections = false;
    } else if (g.getName().equals(NetworkMLConstants.INPUTS_ELEMENT)) {
      inInputs = false;
    } else if (g.getName().equals(NetworkMLConstants.INPUT_ELEMENT) && inInputs) {
      currentInput = null;
    } else if (g.getName().startsWith(NetworkMLConstants.POPULATION_ELEMENT) && inPopulations) {
      currentCellGroup = null;
    } else if (g.getName().startsWith(NetworkMLConstants.PROJECTION_ELEMENT) && inProjections) {
      currentNetConn = null;
      globConnProps = new ArrayList<ConnSpecificProps>();
    } else if (g.getName().startsWith(NetworkMLConstants.CONNECTION_ELEMENT)) {
      localConnProps = new ArrayList<ConnSpecificProps>();
      localAPDelay = 0;
    }
  }
Exemplo n.º 3
0
  public void startGroup(Group g) throws Hdf5Exception {
    logger.logComment("-----   Going into a group: " + g.getFullName());

    ArrayList<Attribute> attrs = Hdf5Utils.parseGroupForAttributes(g);

    for (Attribute attribute : attrs) {
      // attribute.
      logger.logComment(
          "Group: "
              + g.getName()
              + " has attribute: "
              + attribute.getName()
              + " = "
              + Hdf5Utils.getFirstStringValAttr(attrs, attribute.getName()));
    }

    if (g.getName().equals(NetworkMLConstants.ROOT_ELEMENT)) {
      logger.logComment("Found the main group");

      String simConfigName =
          Hdf5Utils.getFirstStringValAttr(attrs, NetworkMLConstants.NC_SIM_CONFIG);

      if (simConfigName != null) this.foundSimConfig = simConfigName;

      String randomSeed =
          Hdf5Utils.getFirstStringValAttr(attrs, NetworkMLConstants.NC_NETWORK_GEN_RAND_SEED);

      if (randomSeed != null) this.foundRandomSeed = Long.parseLong(randomSeed);

    } else if (g.getName().equals(NetworkMLConstants.POPULATIONS_ELEMENT)) {
      logger.logComment("Found the pops group");
      inPopulations = true;

    } else if (g.getName().startsWith(NetworkMLConstants.POPULATION_ELEMENT) && inPopulations) {
      String name = Hdf5Utils.getFirstStringValAttr(attrs, NetworkMLConstants.POP_NAME_ATTR);

      logger.logComment("Found a population: " + name);
      currentCellGroup = name;
    } else if (g.getName().equals(NetworkMLConstants.PROJECTIONS_ELEMENT)) {
      logger.logComment("Found the projections group");
      inProjections = true;

      String units = Hdf5Utils.getFirstStringValAttr(attrs, NetworkMLConstants.UNITS_ATTR);

      projUnitSystem = UnitConverter.getUnitSystemIndex(units);

    } else if (g.getName().startsWith(NetworkMLConstants.PROJECTION_ELEMENT) && inProjections) {
      String name = Hdf5Utils.getFirstStringValAttr(attrs, NetworkMLConstants.PROJ_NAME_ATTR);
      String source = Hdf5Utils.getFirstStringValAttr(attrs, NetworkMLConstants.SOURCE_ATTR);
      String target = Hdf5Utils.getFirstStringValAttr(attrs, NetworkMLConstants.TARGET_ATTR);

      logger.logComment("Found a projection: " + name + " from " + source + " to " + target);

      if (!project.morphNetworkConnectionsInfo.isValidSimpleNetConn(name)
          && !project.volBasedConnsInfo.isValidVolBasedConn(name)) {
        throw new Hdf5Exception(
            "Error: there is a network connection with name: "
                + name
                + " specified in "
                + "that file, but no such NetConn exists in the project. Add one to allow import of this file");
      }

      /* TODO: Add checks on source & target!!
       */

      if (project.morphNetworkConnectionsInfo.isValidSimpleNetConn(name)) {
        // if (project.morphNetworkConnectionsInfo)
      }

      currentNetConn = name;
    } else if (g.getName().startsWith(NetworkMLConstants.SYN_PROPS_ELEMENT + "_")
        && inProjections) {
      String name = Hdf5Utils.getFirstStringValAttr(attrs, NetworkMLConstants.SYN_TYPE_ATTR);

      ConnSpecificProps cp = new ConnSpecificProps(name);

      String internalDelay =
          Hdf5Utils.getFirstStringValAttr(attrs, NetworkMLConstants.INTERNAL_DELAY_ATTR);
      if (internalDelay != null)
        cp.internalDelay =
            (float)
                UnitConverter.getTime(
                    Float.parseFloat(internalDelay),
                    projUnitSystem,
                    UnitConverter.NEUROCONSTRUCT_UNITS);

      // Lump them in to the internal delay...
      String preDelay = Hdf5Utils.getFirstStringValAttr(attrs, NetworkMLConstants.PRE_DELAY_ATTR);
      if (preDelay != null)
        cp.internalDelay =
            cp.internalDelay
                + (float)
                    UnitConverter.getTime(
                        Float.parseFloat(preDelay),
                        projUnitSystem,
                        UnitConverter.NEUROCONSTRUCT_UNITS);

      String postDelay = Hdf5Utils.getFirstStringValAttr(attrs, NetworkMLConstants.POST_DELAY_ATTR);
      if (postDelay != null)
        cp.internalDelay =
            cp.internalDelay
                + (float)
                    UnitConverter.getTime(
                        Float.parseFloat(postDelay),
                        projUnitSystem,
                        UnitConverter.NEUROCONSTRUCT_UNITS);

      cp.weight =
          Float.parseFloat(Hdf5Utils.getFirstStringValAttr(attrs, NetworkMLConstants.WEIGHT_ATTR));

      String propDelay = Hdf5Utils.getFirstStringValAttr(attrs, NetworkMLConstants.PROP_DELAY_ATTR);
      if (propDelay != null)
        globAPDelay =
            (float)
                UnitConverter.getTime(
                    Float.parseFloat(propDelay),
                    projUnitSystem,
                    UnitConverter.NEUROCONSTRUCT_UNITS);

      logger.logComment("Found: " + cp);

      globConnProps.add(cp);
    } else if (g.getName().equals(NetworkMLConstants.INPUTS_ELEMENT)) {
      logger.logComment("Found the Inputs group");
      inInputs = true;

      String units = Hdf5Utils.getFirstStringValAttr(attrs, NetworkMLConstants.UNITS_ATTR);

      inputUnitSystem = UnitConverter.getUnitSystemIndex(units);
    } else if (g.getName().startsWith(NetworkMLConstants.INPUT_ELEMENT) && inInputs) {
      // The table of input sites is within the input group so get sites from here

      String inputName = g.getName().substring(6);

      // String inputName = Hdf5Utils.getFirstStringValAttr(attrs,
      // NetworkMLConstants.INPUT_ELEMENT);

      logger.logComment("Found an Input: " + inputName);
      // inInput = true;

      if (project.elecInputInfo.getStim(inputName) == null) {
        throw new Hdf5Exception(
            "Error: there is an electrical input with name: "
                + inputName
                + " specified in "
                + "that file, but no such electrical input exists in the project. Add one to allow import of this file");
      }
      // Get the atributes of the Input and compare them with the attributes within the project
      // Test to find out what type of input this is

    } else if (g.getName().startsWith("IClamp") && inInputs) {
      String inputName = g.getParent().getName().substring(6);
      // Get the input sites from the table

      String cellGroup =
          Hdf5Utils.getFirstStringValAttr(attrs, NetworkMLConstants.INPUT_TARGET_POPULATION_ATTR);
      if (cellGroup == null) {
        cellGroup =
            Hdf5Utils.getFirstStringValAttr(
                attrs, NetworkMLConstants.INPUT_TARGET_CELLGROUP_OLD_ATTR); // check old name
      }

      float readDelay =
          (float)
              UnitConverter.getTime(
                  Float.parseFloat(
                      Hdf5Utils.getFirstStringValAttr(attrs, NetworkMLConstants.INPUT_DELAY_ATTR)),
                  inputUnitSystem,
                  UnitConverter.NEUROCONSTRUCT_UNITS);
      float readDuration =
          (float)
              UnitConverter.getTime(
                  Float.parseFloat(
                      Hdf5Utils.getFirstStringValAttr(attrs, NetworkMLConstants.INPUT_DUR_ATTR)),
                  inputUnitSystem,
                  UnitConverter.NEUROCONSTRUCT_UNITS);
      float readAmp =
          (float)
              UnitConverter.getCurrent(
                  Float.parseFloat(
                      Hdf5Utils.getFirstStringValAttr(attrs, NetworkMLConstants.INPUT_AMP_ATTR)),
                  inputUnitSystem,
                  UnitConverter.NEUROCONSTRUCT_UNITS);

      StimulationSettings nextStim = project.elecInputInfo.getStim(inputName);
      ElectricalInput myElectricalInput = nextStim.getElectricalInput();
      IClamp ic = (IClamp) myElectricalInput;

      logger.logComment("Found an IClamp Input");

      float currDelay = -1, currDur = -1, currAmp = -1;

      /*
      try
      {
          ic.getDelay().reset();
          currDelay = ic.getDelay().getNumber();
          ic.getDuration().reset();
          currDur = ic.getDuration().getNumber();
          ic.getAmplitude().reset();
          currAmp = ic.getAmplitude().getNumber();
      }
      catch (Exception ex)
      {
          logger.logError("Legacy error getting iclamp params!!");
      }*/

      currDelay = ic.getDel().getNominalNumber();
      currDur = ic.getDur().getNominalNumber();
      currAmp = ic.getAmp().getNominalNumber();

      if ((!project.elecInputInfo.getStim(inputName).getCellGroup().equals(cellGroup))
          || (readDelay != currDelay)
          || (readDuration != currDur)
          || (readAmp != currAmp)) {
        throw new Hdf5Exception(
            "Error: the input properties of the file do not match those in the project for input "
                + inputName
                + ""
                + "\nreadDelay: "
                + readDelay
                + ", currDelay: "
                + currDelay
                + "\nreadDuration: "
                + readDuration
                + ", currDur: "
                + currDur
                + "\nreadAmp: "
                + readAmp
                + ", currAmp: "
                + currAmp
                + ", str: "
                + Hdf5Utils.getFirstStringValAttr(attrs, NetworkMLConstants.INPUT_AMP_ATTR));
      }
      currentInput = inputName;
    } else if (g.getName().startsWith("RandomSpikeTrain") && inInputs) {
      String inputName = g.getParent().getName().substring(6);
      // Get the input sites from the table
      String cellGroup =
          Hdf5Utils.getFirstStringValAttr(attrs, NetworkMLConstants.INPUT_TARGET_POPULATION_ATTR);
      if (cellGroup == null) {
        cellGroup =
            Hdf5Utils.getFirstStringValAttr(
                attrs, NetworkMLConstants.INPUT_TARGET_CELLGROUP_OLD_ATTR); // check old name
      }

      float frequency =
          (float)
              UnitConverter.getRate(
                  Float.parseFloat(
                      Hdf5Utils.getFirstStringValAttr(
                          attrs, NetworkMLConstants.RND_STIM_FREQ_ATTR)),
                  inputUnitSystem,
                  UnitConverter.NEUROCONSTRUCT_UNITS);
      String mechanism =
          Hdf5Utils.getFirstStringValAttr(attrs, NetworkMLConstants.RND_STIM_MECH_ATTR);

      StimulationSettings nextStim = project.elecInputInfo.getStim(inputName);
      ElectricalInput myElectricalInput = nextStim.getElectricalInput();
      RandomSpikeTrain rs = (RandomSpikeTrain) myElectricalInput;

      logger.logComment("Found an Random Spike Train Input");

      if ((!project.elecInputInfo.getStim(inputName).getCellGroup().equals(cellGroup))
          || frequency != rs.getRate().getFixedNum()
          || !rs.getSynapseType().equals(mechanism)) {
        throw new Hdf5Exception(
            "Error: the input properties of the file do not match those in the project for input "
                + inputName);
      }
      currentInput = inputName;
    }
  }