prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  tanh instead of tan bug
  Hi,
  please change tanh (hyperbolic tan) to tan 
  
  https://github.com/nerfstudio-project/nerfstudio/blob/1a24f3e58c544bc0211563e770d425426284256c/nerfstudio/data/dataparsers/instant_ngp_dataparser.py#L133
  
  thanks
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `nerfstudio/data/dataparsers/instant_ngp_dataparser.py`
  Content:
  ```
  1 # Copyright 2022 The Nerfstudio Team. All rights reserved.
  2 #
  3 # Licensed under the Apache License, Version 2.0 (the "License");
  4 # you may not use this file except in compliance with the License.
  5 # You may obtain a copy of the License at
  6 #
  7 #     http://www.apache.org/licenses/LICENSE-2.0
  8 #
  9 # Unless required by applicable law or agreed to in writing, software
  10 # distributed under the License is distributed on an "AS IS" BASIS,
  11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12 # See the License for the specific language governing permissions and
  13 # limitations under the License.
  14 
  15 """Data parser for instant ngp data"""
  16 
  17 from __future__ import annotations
  18 
  19 from dataclasses import dataclass, field
  20 from pathlib import Path
  21 from typing import Dict, Tuple, Type
  22 
  23 import numpy as np
  24 import torch
  25 from rich.console import Console
  26 
  27 from nerfstudio.cameras import camera_utils
  28 from nerfstudio.cameras.cameras import Cameras, CameraType
  29 from nerfstudio.data.dataparsers.base_dataparser import (
  30     DataParser,
  31     DataParserConfig,
  32     DataparserOutputs,
  33 )
  34 from nerfstudio.data.scene_box import SceneBox
  35 from nerfstudio.utils.io import load_from_json
  36 
  37 CONSOLE = Console(width=120)
  38 
  39 
  40 @dataclass
  41 class InstantNGPDataParserConfig(DataParserConfig):
  42     """Instant-NGP dataset parser config"""
  43 
  44     _target: Type = field(default_factory=lambda: InstantNGP)
  45     """target class to instantiate"""
  46     data: Path = Path("data/ours/posterv2")
  47     """Directory specifying location of data."""
  48     scale_factor: float = 1.0
  49     """How much to scale the camera origins by."""
  50     scene_scale: float = 0.33
  51     """How much to scale the scene."""
  52 
  53 
  54 @dataclass
  55 class InstantNGP(DataParser):
  56     """Instant NGP Dataset"""
  57 
  58     config: InstantNGPDataParserConfig
  59 
  60     def _generate_dataparser_outputs(self, split="train"):
  61 
  62         meta = load_from_json(self.config.data / "transforms.json")
  63         image_filenames = []
  64         poses = []
  65         num_skipped_image_filenames = 0
  66         for frame in meta["frames"]:
  67             fname = self.config.data / Path(frame["file_path"])
  68             if not fname:
  69                 num_skipped_image_filenames += 1
  70             else:
  71                 image_filenames.append(fname)
  72                 poses.append(np.array(frame["transform_matrix"]))
  73         if num_skipped_image_filenames >= 0:
  74             CONSOLE.print(f"Skipping {num_skipped_image_filenames} files in dataset split {split}.")
  75         assert (
  76             len(image_filenames) != 0
  77         ), """
  78         No image files found. 
  79         You should check the file_paths in the transforms.json file to make sure they are correct.
  80         """
  81         poses = np.array(poses).astype(np.float32)
  82         poses[:, :3, 3] *= self.config.scene_scale
  83 
  84         camera_to_world = torch.from_numpy(poses[:, :3])  # camera to world transform
  85 
  86         distortion_params = camera_utils.get_distortion_params(
  87             k1=float(meta["k1"]), k2=float(meta["k2"]), p1=float(meta["p1"]), p2=float(meta["p2"])
  88         )
  89 
  90         # in x,y,z order
  91         # assumes that the scene is centered at the origin
  92         aabb_scale = meta["aabb_scale"]
  93         scene_box = SceneBox(
  94             aabb=torch.tensor(
  95                 [[-aabb_scale, -aabb_scale, -aabb_scale], [aabb_scale, aabb_scale, aabb_scale]], dtype=torch.float32
  96             )
  97         )
  98 
  99         fl_x, fl_y = InstantNGP.get_focal_lengths(meta)
  100 
  101         cameras = Cameras(
  102             fx=float(fl_x),
  103             fy=float(fl_y),
  104             cx=float(meta["cx"]),
  105             cy=float(meta["cy"]),
  106             distortion_params=distortion_params,
  107             height=int(meta["h"]),
  108             width=int(meta["w"]),
  109             camera_to_worlds=camera_to_world,
  110             camera_type=CameraType.PERSPECTIVE,
  111         )
  112 
  113         # TODO(ethan): add alpha background color
  114         dataparser_outputs = DataparserOutputs(
  115             image_filenames=image_filenames,
  116             cameras=cameras,
  117             scene_box=scene_box,
  118         )
  119 
  120         return dataparser_outputs
  121 
  122     @classmethod
  123     def get_focal_lengths(cls, meta: Dict) -> Tuple[float, float]:
  124         """Reads or computes the focal length from transforms dict.
  125         Args:
  126             meta: metadata from transforms.json file.
  127         Returns:
  128             Focal lengths in the x and y directions. Error is raised if these cannot be calculated.
  129         """
  130         fl_x, fl_y = 0, 0
  131 
  132         def fov_to_focal_length(rad, res):
  133             return 0.5 * res / np.tanh(0.5 * rad)
  134 
  135         if "fl_x" in meta:
  136             fl_x = meta["fl_x"]
  137         elif "x_fov" in meta:
  138             fl_x = fov_to_focal_length(np.deg2rad(meta["x_fov"]), meta["w"])
  139         elif "camera_angle_x" in meta:
  140             fl_x = fov_to_focal_length(meta["camera_angle_x"], meta["w"])
  141 
  142         if "fl_y" in meta:
  143             fl_y = meta["fl_y"]
  144         elif "y_fov" in meta:
  145             fl_y = fov_to_focal_length(np.deg2rad(meta["y_fov"]), meta["h"])
  146         elif "camera_angle_y" in meta:
  147             fl_y = fov_to_focal_length(meta["camera_angle_y"], meta["h"])
  148 
  149         if fl_x == 0 or fl_y == 0:
  150             raise AttributeError("Focal length cannot be calculated from transforms.json (missing fields).")
  151 
  152         return (fl_x, fl_y)
  153
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/nerfstudio/data/dataparsers/instant_ngp_dataparser.py b/nerfstudio/data/dataparsers/instant_ngp_dataparser.py
  --- a/nerfstudio/data/dataparsers/instant_ngp_dataparser.py
  +++ b/nerfstudio/data/dataparsers/instant_ngp_dataparser.py
  @@ -130,7 +130,7 @@
           fl_x, fl_y = 0, 0
   
           def fov_to_focal_length(rad, res):
  -            return 0.5 * res / np.tanh(0.5 * rad)
  +            return 0.5 * res / np.tan(0.5 * rad)
   
           if "fl_x" in meta:
               fl_x = meta["fl_x"]
  
verification_info: {"golden_diff": "diff --git a/nerfstudio/data/dataparsers/instant_ngp_dataparser.py b/nerfstudio/data/dataparsers/instant_ngp_dataparser.py\n--- a/nerfstudio/data/dataparsers/instant_ngp_dataparser.py\n+++ b/nerfstudio/data/dataparsers/instant_ngp_dataparser.py\n@@ -130,7 +130,7 @@\n         fl_x, fl_y = 0, 0\n \n         def fov_to_focal_length(rad, res):\n-            return 0.5 * res / np.tanh(0.5 * rad)\n+            return 0.5 * res / np.tan(0.5 * rad)\n \n         if \"fl_x\" in meta:\n             fl_x = meta[\"fl_x\"]\n", "issue": "tanh instead of tan bug\nHi,\r\nplease change tanh (hyperbolic tan) to tan \r\n\r\nhttps://github.com/nerfstudio-project/nerfstudio/blob/1a24f3e58c544bc0211563e770d425426284256c/nerfstudio/data/dataparsers/instant_ngp_dataparser.py#L133\r\n\r\nthanks\n", "before_files": [{"content": "# Copyright 2022 The Nerfstudio Team. All rights reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\"\"\"Data parser for instant ngp data\"\"\"\n\nfrom __future__ import annotations\n\nfrom dataclasses import dataclass, field\nfrom pathlib import Path\nfrom typing import Dict, Tuple, Type\n\nimport numpy as np\nimport torch\nfrom rich.console import Console\n\nfrom nerfstudio.cameras import camera_utils\nfrom nerfstudio.cameras.cameras import Cameras, CameraType\nfrom nerfstudio.data.dataparsers.base_dataparser import (\n    DataParser,\n    DataParserConfig,\n    DataparserOutputs,\n)\nfrom nerfstudio.data.scene_box import SceneBox\nfrom nerfstudio.utils.io import load_from_json\n\nCONSOLE = Console(width=120)\n\n\n@dataclass\nclass InstantNGPDataParserConfig(DataParserConfig):\n    \"\"\"Instant-NGP dataset parser config\"\"\"\n\n    _target: Type = field(default_factory=lambda: InstantNGP)\n    \"\"\"target class to instantiate\"\"\"\n    data: Path = Path(\"data/ours/posterv2\")\n    \"\"\"Directory specifying location of data.\"\"\"\n    scale_factor: float = 1.0\n    \"\"\"How much to scale the camera origins by.\"\"\"\n    scene_scale: float = 0.33\n    \"\"\"How much to scale the scene.\"\"\"\n\n\n@dataclass\nclass InstantNGP(DataParser):\n    \"\"\"Instant NGP Dataset\"\"\"\n\n    config: InstantNGPDataParserConfig\n\n    def _generate_dataparser_outputs(self, split=\"train\"):\n\n        meta = load_from_json(self.config.data / \"transforms.json\")\n        image_filenames = []\n        poses = []\n        num_skipped_image_filenames = 0\n        for frame in meta[\"frames\"]:\n            fname = self.config.data / Path(frame[\"file_path\"])\n            if not fname:\n                num_skipped_image_filenames += 1\n            else:\n                image_filenames.append(fname)\n                poses.append(np.array(frame[\"transform_matrix\"]))\n        if num_skipped_image_filenames >= 0:\n            CONSOLE.print(f\"Skipping {num_skipped_image_filenames} files in dataset split {split}.\")\n        assert (\n            len(image_filenames) != 0\n        ), \"\"\"\n        No image files found. \n        You should check the file_paths in the transforms.json file to make sure they are correct.\n        \"\"\"\n        poses = np.array(poses).astype(np.float32)\n        poses[:, :3, 3] *= self.config.scene_scale\n\n        camera_to_world = torch.from_numpy(poses[:, :3])  # camera to world transform\n\n        distortion_params = camera_utils.get_distortion_params(\n            k1=float(meta[\"k1\"]), k2=float(meta[\"k2\"]), p1=float(meta[\"p1\"]), p2=float(meta[\"p2\"])\n        )\n\n        # in x,y,z order\n        # assumes that the scene is centered at the origin\n        aabb_scale = meta[\"aabb_scale\"]\n        scene_box = SceneBox(\n            aabb=torch.tensor(\n                [[-aabb_scale, -aabb_scale, -aabb_scale], [aabb_scale, aabb_scale, aabb_scale]], dtype=torch.float32\n            )\n        )\n\n        fl_x, fl_y = InstantNGP.get_focal_lengths(meta)\n\n        cameras = Cameras(\n            fx=float(fl_x),\n            fy=float(fl_y),\n            cx=float(meta[\"cx\"]),\n            cy=float(meta[\"cy\"]),\n            distortion_params=distortion_params,\n            height=int(meta[\"h\"]),\n            width=int(meta[\"w\"]),\n            camera_to_worlds=camera_to_world,\n            camera_type=CameraType.PERSPECTIVE,\n        )\n\n        # TODO(ethan): add alpha background color\n        dataparser_outputs = DataparserOutputs(\n            image_filenames=image_filenames,\n            cameras=cameras,\n            scene_box=scene_box,\n        )\n\n        return dataparser_outputs\n\n    @classmethod\n    def get_focal_lengths(cls, meta: Dict) -> Tuple[float, float]:\n        \"\"\"Reads or computes the focal length from transforms dict.\n        Args:\n            meta: metadata from transforms.json file.\n        Returns:\n            Focal lengths in the x and y directions. Error is raised if these cannot be calculated.\n        \"\"\"\n        fl_x, fl_y = 0, 0\n\n        def fov_to_focal_length(rad, res):\n            return 0.5 * res / np.tanh(0.5 * rad)\n\n        if \"fl_x\" in meta:\n            fl_x = meta[\"fl_x\"]\n        elif \"x_fov\" in meta:\n            fl_x = fov_to_focal_length(np.deg2rad(meta[\"x_fov\"]), meta[\"w\"])\n        elif \"camera_angle_x\" in meta:\n            fl_x = fov_to_focal_length(meta[\"camera_angle_x\"], meta[\"w\"])\n\n        if \"fl_y\" in meta:\n            fl_y = meta[\"fl_y\"]\n        elif \"y_fov\" in meta:\n            fl_y = fov_to_focal_length(np.deg2rad(meta[\"y_fov\"]), meta[\"h\"])\n        elif \"camera_angle_y\" in meta:\n            fl_y = fov_to_focal_length(meta[\"camera_angle_y\"], meta[\"h\"])\n\n        if fl_x == 0 or fl_y == 0:\n            raise AttributeError(\"Focal length cannot be calculated from transforms.json (missing fields).\")\n\n        return (fl_x, fl_y)\n", "path": "nerfstudio/data/dataparsers/instant_ngp_dataparser.py"}], "after_files": [{"content": "# Copyright 2022 The Nerfstudio Team. All rights reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\"\"\"Data parser for instant ngp data\"\"\"\n\nfrom __future__ import annotations\n\nfrom dataclasses import dataclass, field\nfrom pathlib import Path\nfrom typing import Dict, Tuple, Type\n\nimport numpy as np\nimport torch\nfrom rich.console import Console\n\nfrom nerfstudio.cameras import camera_utils\nfrom nerfstudio.cameras.cameras import Cameras, CameraType\nfrom nerfstudio.data.dataparsers.base_dataparser import (\n    DataParser,\n    DataParserConfig,\n    DataparserOutputs,\n)\nfrom nerfstudio.data.scene_box import SceneBox\nfrom nerfstudio.utils.io import load_from_json\n\nCONSOLE = Console(width=120)\n\n\n@dataclass\nclass InstantNGPDataParserConfig(DataParserConfig):\n    \"\"\"Instant-NGP dataset parser config\"\"\"\n\n    _target: Type = field(default_factory=lambda: InstantNGP)\n    \"\"\"target class to instantiate\"\"\"\n    data: Path = Path(\"data/ours/posterv2\")\n    \"\"\"Directory specifying location of data.\"\"\"\n    scale_factor: float = 1.0\n    \"\"\"How much to scale the camera origins by.\"\"\"\n    scene_scale: float = 0.33\n    \"\"\"How much to scale the scene.\"\"\"\n\n\n@dataclass\nclass InstantNGP(DataParser):\n    \"\"\"Instant NGP Dataset\"\"\"\n\n    config: InstantNGPDataParserConfig\n\n    def _generate_dataparser_outputs(self, split=\"train\"):\n\n        meta = load_from_json(self.config.data / \"transforms.json\")\n        image_filenames = []\n        poses = []\n        num_skipped_image_filenames = 0\n        for frame in meta[\"frames\"]:\n            fname = self.config.data / Path(frame[\"file_path\"])\n            if not fname:\n                num_skipped_image_filenames += 1\n            else:\n                image_filenames.append(fname)\n                poses.append(np.array(frame[\"transform_matrix\"]))\n        if num_skipped_image_filenames >= 0:\n            CONSOLE.print(f\"Skipping {num_skipped_image_filenames} files in dataset split {split}.\")\n        assert (\n            len(image_filenames) != 0\n        ), \"\"\"\n        No image files found. \n        You should check the file_paths in the transforms.json file to make sure they are correct.\n        \"\"\"\n        poses = np.array(poses).astype(np.float32)\n        poses[:, :3, 3] *= self.config.scene_scale\n\n        camera_to_world = torch.from_numpy(poses[:, :3])  # camera to world transform\n\n        distortion_params = camera_utils.get_distortion_params(\n            k1=float(meta[\"k1\"]), k2=float(meta[\"k2\"]), p1=float(meta[\"p1\"]), p2=float(meta[\"p2\"])\n        )\n\n        # in x,y,z order\n        # assumes that the scene is centered at the origin\n        aabb_scale = meta[\"aabb_scale\"]\n        scene_box = SceneBox(\n            aabb=torch.tensor(\n                [[-aabb_scale, -aabb_scale, -aabb_scale], [aabb_scale, aabb_scale, aabb_scale]], dtype=torch.float32\n            )\n        )\n\n        fl_x, fl_y = InstantNGP.get_focal_lengths(meta)\n\n        cameras = Cameras(\n            fx=float(fl_x),\n            fy=float(fl_y),\n            cx=float(meta[\"cx\"]),\n            cy=float(meta[\"cy\"]),\n            distortion_params=distortion_params,\n            height=int(meta[\"h\"]),\n            width=int(meta[\"w\"]),\n            camera_to_worlds=camera_to_world,\n            camera_type=CameraType.PERSPECTIVE,\n        )\n\n        # TODO(ethan): add alpha background color\n        dataparser_outputs = DataparserOutputs(\n            image_filenames=image_filenames,\n            cameras=cameras,\n            scene_box=scene_box,\n        )\n\n        return dataparser_outputs\n\n    @classmethod\n    def get_focal_lengths(cls, meta: Dict) -> Tuple[float, float]:\n        \"\"\"Reads or computes the focal length from transforms dict.\n        Args:\n            meta: metadata from transforms.json file.\n        Returns:\n            Focal lengths in the x and y directions. Error is raised if these cannot be calculated.\n        \"\"\"\n        fl_x, fl_y = 0, 0\n\n        def fov_to_focal_length(rad, res):\n            return 0.5 * res / np.tan(0.5 * rad)\n\n        if \"fl_x\" in meta:\n            fl_x = meta[\"fl_x\"]\n        elif \"x_fov\" in meta:\n            fl_x = fov_to_focal_length(np.deg2rad(meta[\"x_fov\"]), meta[\"w\"])\n        elif \"camera_angle_x\" in meta:\n            fl_x = fov_to_focal_length(meta[\"camera_angle_x\"], meta[\"w\"])\n\n        if \"fl_y\" in meta:\n            fl_y = meta[\"fl_y\"]\n        elif \"y_fov\" in meta:\n            fl_y = fov_to_focal_length(np.deg2rad(meta[\"y_fov\"]), meta[\"h\"])\n        elif \"camera_angle_y\" in meta:\n            fl_y = fov_to_focal_length(meta[\"camera_angle_y\"], meta[\"h\"])\n\n        if fl_x == 0 or fl_y == 0:\n            raise AttributeError(\"Focal length cannot be calculated from transforms.json (missing fields).\")\n\n        return (fl_x, fl_y)\n", "path": "nerfstudio/data/dataparsers/instant_ngp_dataparser.py"}]}