Skip to content

Commit

Permalink
Changed output file names and paths as requested. refs: #42
Browse files Browse the repository at this point in the history
  • Loading branch information
spanezz committed Dec 6, 2021
1 parent ee09132 commit 40099bf
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 13 deletions.
4 changes: 3 additions & 1 deletion arkimapslib/flavours.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ def make_orders(self,
if inputs_for_all_instants:
input_files.update(inputs_for_all_instants)

logger = logging.getLogger(f"arkimaps.render.{self.name}.{recipe.name}{output_instant.pantry_suffix()}")
logger = logging.getLogger(
f"arkimaps.render.{self.name}.{recipe.name}{output_instant.product_suffix()}")

# Instantiate order steps from recipe steps
order_steps: List[Step] = []
Expand All @@ -190,6 +191,7 @@ def make_orders(self,
res.append(orders.Order(
mixer=recipe.mixer,
input_files=input_files,
flavour_name=self.name,
recipe_name=recipe.name,
instant=output_instant,
order_steps=order_steps,
Expand Down
4 changes: 3 additions & 1 deletion arkimapslib/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def __init__(
self,
mixer: str,
input_files: Dict[str, inputs.InputFile],
flavour_name: str,
recipe_name: str,
instant: "inputs.Instant",
order_steps: List[steps.Step],
Expand All @@ -24,8 +25,9 @@ def __init__(
self.mixer = mixer
# Dict mapping source names to pathnames of GRIB files
self.input_files = input_files
self.relpath = f"{instant.reftime:%Y-%m-%dT%H:%M:%S}/{recipe_name}_{flavour_name}"
# Destination file name (without path or .png extension)
self.basename = f"{recipe_name}{instant.product_suffix()}"
self.basename = f"{recipe_name}+{instant.step:03d}"
# Recipe name
self.recipe_name = recipe_name
# Product instant
Expand Down
5 changes: 4 additions & 1 deletion arkimapslib/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ def prepare_order(self, order: 'Order') -> Optional['Order']:
try:
from .worktops import Worktop

output_pathname = os.path.join(self.workdir, order.basename)
path = os.path.join(self.workdir, order.relpath)
os.makedirs(path, exist_ok=True)

output_pathname = os.path.join(path, order.basename)

# Write the python code, so that if we trigger a bug in Magics, we
# have a Python reproducer available
Expand Down
8 changes: 4 additions & 4 deletions arkimapslib/unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,12 @@ def fill_pantry(
for fn in expected:
self.assertIn(fn, os.listdir(os.path.join(self.kitchen.pantry.data_root)))

def assertRenders(self, order, reftime=datetime.datetime(2021, 1, 10), output_name=None):
def assertRenders(self, order, reftime=datetime.datetime(2021, 1, 10)):
"""
Render an order, collecting a debug_trace of all steps invoked
"""
if output_name is None:
output_name = f"{self.recipe_name}_{reftime:%Y-%m-%dT%H:%M:%S}+012.png"
self.assertEqual(order.relpath, f"{reftime:%Y-%m-%dT%H:%M:%S}/{self.recipe_name}_{self.flavour_name}")
self.assertEqual(order.basename, f"{self.recipe_name}+012")
renderer = Renderer(self.kitchen.workdir)

# Stop testing at this point, if we know Magics would segfault or abort
Expand All @@ -210,7 +210,7 @@ def assertRenders(self, order, reftime=datetime.datetime(2021, 1, 10), output_na
rendered = renderer.render_one(order)
self.assertIsNotNone(rendered)
self.assertIsNotNone(rendered.output)
self.assertEqual(os.path.basename(rendered.output), output_name)
self.assertEqual(os.path.basename(rendered.output), f"{self.recipe_name}+012.png")

def order_to_python(self, order) -> str:
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cp3h.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_dispatch(self):

orders = self.make_orders()
self.assertGreaterEqual(len(orders), 4)
orders = [o for o in orders if o.basename == "cp3h_2021-01-10T00:00:00+012"]
orders = [o for o in orders if o.basename == "cp3h+012"]
self.assertEqual(len(orders), 1)

self.assertRenders(orders[0])
Expand Down
4 changes: 2 additions & 2 deletions tests/test_flavour.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ def test_recipe_filter(self):
orders = kitchen.make_orders(flavour=kitchen.flavours.get("default"))
self.assertCountEqual(
[o.basename for o in orders],
["t2m_2021-01-10T00:00:00+012", "tcc_2021-01-10T00:00:00+012"])
["t2m+012", "tcc+012"])

orders = kitchen.make_orders(flavour=kitchen.flavours.get("test"))
self.assertCountEqual(
[o.basename for o in orders],
["t2m_2021-01-10T00:00:00+012"])
["t2m+012"])
1 change: 0 additions & 1 deletion tests/test_lcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ def test_dispatch(self):

orders = self.make_orders()
self.assertEqual(len(orders), 1)
self.assertEqual(orders[0].basename, "lcc_2021-01-10T00:00:00+012")

self.assertRenders(orders[0])

Expand Down
2 changes: 1 addition & 1 deletion tests/test_tp1h.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_dispatch(self):
return
else:
self.assertGreaterEqual(len(orders), 12)
orders = [o for o in orders if o.basename == "tp1h_2021-01-10T00:00:00+012"]
orders = [o for o in orders if o.basename == "tp1h+012"]
self.assertEqual(len(orders), 1)

self.assertRenders(orders[0])
Expand Down
1 change: 0 additions & 1 deletion tests/test_wflags.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ def test_dispatch(self):

orders = self.make_orders()
self.assertEqual(len(orders), 1)
self.assertEqual(orders[0].basename, "wflags10m_2021-01-10T00:00:00+012")

self.assertRenders(orders[0])

Expand Down

0 comments on commit 40099bf

Please sign in to comment.