Skip to content

Commit

Permalink
Merge branch 'gh3'
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverSchmitz committed Mar 6, 2024
2 parents 8f5d4d2 + 467cfa0 commit 879f7d3
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 25 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.18)

project(campo
VERSION 0.3.10
VERSION 0.3.11
DESCRIPTION "Modelling framework for fields and agents"
HOMEPAGE_URL "https://campo.computationalgeography.org/"
LANGUAGES NONE
Expand All @@ -15,7 +15,7 @@ set(CMAKE_MODULE_PATH

set(DEV_CURRENT_YEAR "2024")

set(${PROJECT_NAME}_ORGANISATION_NAME "Computational Geography group, Dept of Physical Geography, Utrecht University")
set(${PROJECT_NAME}_ORGANISATION_NAME "Computational Geography group, Dept. of Physical Geography, Utrecht University")
set(${PROJECT_NAME}_COPYRIGHT
"2020 - ${DEV_CURRENT_YEAR}, ${${PROJECT_NAME}_ORGANISATION_NAME}")

Expand Down
7 changes: 4 additions & 3 deletions source/campo/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,10 @@ def write(self, timestep=None):
if not p in dataset_phenomena:
self._generate_lue_phenomenon(self._phenomena[p])

for pset in self._phenomena[p].property_sets.values():
for prop in pset.properties.values():
self._lue_write_property(p, pset, prop, timestep)
for phen in self._phenomena:
for pset in self._phenomena[phen].property_sets.values():
for prop in pset.properties.values():
self._lue_write_property(phen, pset, prop, timestep)

def set_time(self, start, unit, stepsize, nrTimeSteps):
""" """
Expand Down
92 changes: 72 additions & 20 deletions source/test/test_dynamic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,40 @@ def tearDownClass(self):
def setUpClass(self):

# Some dummy spatial domain
with open('locations.csv', 'w') as content:
content.write('1,2\n3,4\n5,6\n7,8')
with open("locations.csv", "w") as content:
content.write("1,2\n3,4\n5,6\n7,8")

with open('extent.csv', 'w') as content:
with open("extent.csv", "w") as content:
content.write("0,0,30,20,2,3\n")
content.write("0,0,30,20,2,3\n")
content.write("0,0,30,20,2,3\n")
content.write("0,0,30,20,2,3\n")

self.ds = campo.Campo(seed=13)

self.phen = self.ds.add_phenomenon('phen')
self.phen.add_property_set('point', 'locations.csv')
self.phen.add_property_set('field', 'extent.csv')

self.phen = self.ds.add_phenomenon("phen")
self.phen.add_property_set("point", "locations.csv")
self.phen.add_property_set("field", "extent.csv")

# dummy time
date = datetime.date(2000, 1, 1)
time = datetime.time(0, 0)
self.start = datetime.datetime.combine(date, time)
self.unit = campo.TimeUnit.month
self.stepsize = 1
self.timesteps = 5

def test_1(self):
""" Dynamic model, stationary points and fields """
""" Stationary points and fields """

# initial section
self.phen.point.pdata = 500
self.phen.field.fdata = 300

# dummy time
date = datetime.date(2000, 1, 1)
time = datetime.time(0, 0)
start = datetime.datetime.combine(date, time)
unit = campo.TimeUnit.month
stepsize = 1
timesteps = 5

# create the output lue data set
self.ds.create_dataset("TestDynamicModel_test_1.lue")
self.ds.set_time(start, unit, stepsize, timesteps)

filename = "TestDynamicModel_test_1.lue"
self.ds.create_dataset(filename)
self.ds.set_time(self.start, self.unit, self.stepsize, self.timesteps)

self.phen.point.pdata.is_dynamic = True
self.phen.field.fdata.is_dynamic = True
Expand All @@ -62,8 +60,62 @@ def test_1(self):
self.ds.write()

# dynamic section
for timestep in range(1, timesteps + 1):
for timestep in range(1, self.timesteps + 1):
self.phen.point.pdata += 200
self.phen.field.fdata += 100

self.ds.write(timestep)

# ldm.assert_is_valid(filename)

def test_2(self):
""" Points and fields different phenomena """

# initial section
ds = campo.Campo(seed=13)

phen1 = ds.add_phenomenon("phen1")
phen2 = ds.add_phenomenon("phen2")

phen1.add_property_set("point", "locations.csv")
phen2.add_property_set("field", "extent.csv")

phen1.point.pdata = 500
phen2.field.fdata = 300

# create the output lue data set
filename = "TestDynamicModel_test_2.lue"
ds.create_dataset(filename)
ds.set_time(self.start, self.unit, self.stepsize, self.timesteps)

phen1.point.pdata.is_dynamic = True
phen2.field.fdata.is_dynamic = True

# write after modifying coordinates
ds.write()

# dynamic section
for timestep in range(1, self.timesteps + 1):
phen1.point.pdata += 200
phen2.field.fdata += 100
ds.write(timestep)

dataset = ldm.open_dataset(filename, "r")
pset_points = dataset.phenomena["phen1"].property_sets["point"]
pset_fields = dataset.phenomena["phen2"].property_sets["field"]

nr_pagents = len(dataset.phenomena["phen1"].object_id[:])
nr_fagents = len(dataset.phenomena["phen2"].object_id[:])
self.assertTrue(nr_pagents == 4)
self.assertTrue(nr_fagents == 4)

pvalues = pset_points.pdata.value[:]
fvalues = pset_fields.fdata.value[0][:]

pvalid = np.repeat([700, 900, 1100, 1300, 1500], nr_pagents).reshape(self.timesteps, nr_pagents).T
rows = 2
cols = 3
fvalid = np.repeat([400, 500, 600, 700, 800], rows * cols).reshape(self.timesteps, rows, cols)

self.assertTrue(np.array_equal(fvalues, fvalid))
self.assertTrue(np.array_equal(pvalues, pvalid))

0 comments on commit 879f7d3

Please sign in to comment.