Ejemplo n.º 1
0
def mod_primary(composite, mod_id, algorithm):
    # paths
    template = composite.templates.get(name="source")  # SOURCE TEMPLATE

    # channel
    channel, channel_created = composite.channels.get_or_create(name="-primary")

    # iterate
    for t in range(composite.series.ts):
        print(t)

        # get markers
        markers = composite.experiment.markers.filter(t=t)
        primary = np.zeros(composite.series.shape(d=2))

        for marker in markers:
            primary[marker.r - 3 : marker.r + 2, marker.c - 3 : marker.c + 2] = 255

        # make blank image and print dots
        gon = composite.gons.create(
            experiment=composite.experiment, series=composite.series, channel=channel, template=template
        )
        gon.id_token = generate_id_token("img", "Gon")
        gon.set_origin(0, 0, 0, t)
        gon.set_extent(composite.series.rs, composite.series.cs, 1)

        gon.array = primary.copy()

        gon.save_array(composite.experiment.composite_path, template)
        gon.save()
Ejemplo n.º 2
0
  def compose(self):

    # composite
    composite, composite_created = self.composites.get_or_create(experiment=self.experiment, id_token=generate_id_token('img', 'Composite'))

    # templates
    for template in self.experiment.templates.all():
      composite_template, composite_template_created = composite.templates.get_or_create(name=template.name)
      if composite_template_created:
        composite_template.rx = template.rx
        composite_template.rv = template.rv
        composite_template.save()

    # iterate over paths
    for channel in self.experiment.channels.all():
      composite_channel, composite_channel_created = composite.channels.get_or_create(name=channel.name)

      for t in range(self.ts):

        # path set
        path_set = self.paths.filter(channel=channel, t=t)

        # if the total number of paths is less than a great gon, do not make one. Save only individual gons.
        if path_set.count()==self.zs:

          # gon
          gon, gon_created = self.gons.get_or_create(experiment=self.experiment, composite=composite, channel=composite_channel, t=t)
          if gon_created:
            gon.set_origin(0,0,0,t)
            gon.set_extent(self.rs, self.cs, self.zs)

          for z in range(self.zs):

            # path
            path = path_set.get(channel=channel, t=t, z=z)
            template = composite.templates.get(name=path.template.name)
            gon.template = template
            gon.paths.get_or_create(composite=composite, channel=composite_channel, template=template, url=path.url, file_name=path.file_name, t=t, z=z)

            # sub gon
            sub_gon, sub_gon_created = self.gons.get_or_create(experiment=self.experiment, gon=gon, channel=composite_channel, template=template, t=t, z=z)
            E = z==self.zs-1 and t==self.ts-1
            if sub_gon_created:
              # print('step01 | composing {} series {}... channel {} t{} z{}... created.{}'.format(self.experiment.name, self.name, channel.name, t, z, spacer), end='\n' if E else '\r')
              sub_gon.set_origin(0,0,z,t)
              sub_gon.set_extent(self.rs, self.cs, 1)
              sub_gon.paths.create(composite=composite, channel=composite_channel, template=template, url=path.url, file_name=path.file_name, t=t, z=z)

            else:
              pass
              # print('step01 | composing {} series {}... channel {} t{} z{}... already exists.{}'.format(self.experiment.name, self.name, channel.name, t, z, spacer), end='\n' if E else '\r')

            sub_gon.save()

          gon.save()


        else: # disfuse gon structure (reduced, regions)
          L = len(path_set) - 1
          for i, path in enumerate(path_set):
            E = i==L and t==self.ts-1
            # print('step01 | composing {} series {}... channel {} t{} z{}... created diffuse.{}'.format(self.experiment.name, self.name, channel.name, t, path.z, spacer), end='\n' if E else '\r')

            template = composite.templates.get(name=path.template.name)
            gon, gon_created = self.gons.get_or_create(experiment=self.experiment, composite=composite, channel=composite_channel, template=template, t=t, z=path.z)
            if gon_created:
              gon.set_origin(0,0,path.z,t)
              gon.set_extent(self.rs, self.cs, 1)

              gon.paths.create(composite=composite, channel=composite_channel, template=template, url=path.url, file_name=path.file_name, t=t, z=path.z)

            gon.save()

    composite.save()