diff --git a/coolest/template/classes/likelihood.py b/coolest/template/classes/likelihood.py index ce74d0a..90530b9 100644 --- a/coolest/template/classes/likelihood.py +++ b/coolest/template/classes/likelihood.py @@ -72,9 +72,9 @@ def check_consistency_with_observation(self, observation): width = abs(self.mask.field_of_view_x[1] - self.mask.field_of_view_x[0]) height = abs(self.mask.field_of_view_y[1] - self.mask.field_of_view_y[0]) num_pix_ra = round(width / observation.pixels.pixel_size) - error_message_ra = f"Field-of-view along RA is inconsistent (data: {num_pix_ra}, likelihood mask: {self.mask.num_pix_x})." + error_message_ra = f"Number of pixels along x is inconsistent (data: {num_pix_ra}, likelihood mask: {self.mask.num_pix_x})." assert self.mask.num_pix_x == num_pix_ra, error_message_ra num_pix_dec = round(height / observation.pixels.pixel_size) - error_message_dec = f"Field-of-view along Dec is inconsistent (data: {num_pix_dec}, likelihood mask: {self.mask.num_pix_y})." + error_message_dec = f"Number of pixels along y is inconsistent (data: {num_pix_dec}, likelihood mask: {self.mask.num_pix_y})." assert self.mask.num_pix_y == num_pix_dec, error_message_dec # TODO: check pixel size value? diff --git a/coolest/template/classes/observation.py b/coolest/template/classes/observation.py index cd47bd5..ff5abef 100644 --- a/coolest/template/classes/observation.py +++ b/coolest/template/classes/observation.py @@ -54,10 +54,10 @@ def check_consistency_with_instrument(self, instrument): width = abs(self.pixels.field_of_view_x[1] - self.pixels.field_of_view_x[0]) height = abs(self.pixels.field_of_view_y[1] - self.pixels.field_of_view_y[0]) num_pix_ra = round(width / instrument.pixel_size) - error_message_ra = f"Field-of-view along RA is inconsistent (data: {self.pixels.num_pix_x}, instrument: {num_pix_ra})." + error_message_ra = f"Number of pixels along x is inconsistent (data: {self.pixels.num_pix_x}, instrument: {num_pix_ra})." assert self.pixels.num_pix_x == num_pix_ra, error_message_ra num_pix_dec = round(height / instrument.pixel_size) - error_message_dec = f"Field-of-view along Dec is inconsistent (data: {self.pixels.num_pix_y}, instrument: {num_pix_dec})." + error_message_dec = f"Number of pixels along y is inconsistent (data: {self.pixels.num_pix_y}, instrument: {num_pix_dec})." assert self.pixels.num_pix_y == num_pix_dec, error_message_dec # TODO: check pixel size value? diff --git a/coolest/template/json.py b/coolest/template/json.py index 558f028..d671012 100644 --- a/coolest/template/json.py +++ b/coolest/template/json.py @@ -88,7 +88,7 @@ def dump_jsonpickle(self): with open(json_path, 'w') as f: f.write(result) - def load(self, skip_jsonpickle=False, verbose=True): + def load(self, skip_jsonpickle=False, validate=True, verbose=True): """Read the JSON template file and build up the corresponding COOLEST object. It will first try to load the '_pyAPI' template if it exists using `jsonpickle`, otherwise it will fall back to reading the pure json template. @@ -114,11 +114,11 @@ def load(self, skip_jsonpickle=False, verbose=True): else: if verbose: print(f"Template file '{jsonpickle_path}' not found, now trying to read '{json_path}'.") - instance = self.load_simple(json_path, as_object=True) + instance = self.load_simple(json_path, as_object=True, validate=validate) assert isinstance(instance, COOLEST) return instance - def load_simple(self, json_path, as_object=True): + def load_simple(self, json_path, as_object=True, validate=True): """Read the JSON template file and build up the corresponding COOLEST object. Parameters @@ -137,7 +137,7 @@ def load_simple(self, json_path, as_object=True): content = json.loads(f.read()) if not as_object: return content # dictionary - return self._json_to_coolest(content) # COOLEST object + return self._json_to_coolest(content, validate) # COOLEST object def load_jsonpickle(self, jsonpickle_path): """Read the JSON template file and build up the corresponding COOLEST object @@ -157,7 +157,7 @@ def load_jsonpickle(self, jsonpickle_path): content = jsonpickle.decode(f.read()) return content # COOLEST object - def _json_to_coolest(self, json_content): + def _json_to_coolest(self, json_content, validate): """Creates from scratch a COOLEST instance based on the content of a JSON file, given as a nested dictionnary. @@ -208,7 +208,8 @@ def _json_to_coolest(self, json_content): metadata=metadata) # check consistency across the whole coolest object - self._validate_global(coolest) + if validate: + self._validate_global(coolest) return coolest @staticmethod diff --git a/test/template/json_test.py b/test/template/json_test.py index 1a3ed5f..d593ecb 100644 --- a/test/template/json_test.py +++ b/test/template/json_test.py @@ -119,7 +119,7 @@ def test_dump_and_read(self): # and btw we also instantiate another JSONSerializer as a test serializer_2 = JSONSerializer(template_path, obj=None, check_external_files=self.check_files) - coolest_3 = serializer_2.load(skip_jsonpickle=True) + coolest_3 = serializer_2.load(skip_jsonpickle=True, validate=False) # no validation as it is a dummy json file assert isinstance(coolest_3, COOLEST) # test that the content of the new json file is *exactly* the same as the original one