{
  "id": 349837,
  "title": "How to read dicom file on the GCS? ",
  "url": "/competitions/rsna-2022-cervical-spine-fracture-detection/discussion/349837",
  "author_name": "",
  "post_date": "2022-09-03T01:37:57.996688Z",
  "votes": 1,
  "comment_count": 6,
  "views": 0,
  "content": "<p>If you try to read a file using pydicom on the GCS, for example:<br>\ndcom = pydicom.dcmread(f'{GCS_PATH}/train_images/1.2.826.0.1.3680043.10001/1.dcm')<br>\nyou get an error \"FileNotFoundError: [Errno 2] No such file or directory\".</p>\n<p>But if you use Pandas to read the \"train.csv\" under the same GCS_PATH, it works with no problem:<br>\ntrain_df = pd.read_csv(f\"{GCS_PATH}/train.csv\")</p>\n<p>So it appears pydicom refuses to work with files on GCS. Does anyone have a way to read dicom directly from GCS?</p>",
  "messages": [
    {
      "id": "1924345",
      "postDate": "09/03/2022 01:37:57",
      "content": "<p>If you try to read a file using pydicom on the GCS, for example:<br>\ndcom = pydicom.dcmread(f'{GCS_PATH}/train_images/1.2.826.0.1.3680043.10001/1.dcm')<br>\nyou get an error \"FileNotFoundError: [Errno 2] No such file or directory\".</p>\n<p>But if you use Pandas to read the \"train.csv\" under the same GCS_PATH, it works with no problem:<br>\ntrain_df = pd.read_csv(f\"{GCS_PATH}/train.csv\")</p>\n<p>So it appears pydicom refuses to work with files on GCS. Does anyone have a way to read dicom directly from GCS?</p>",
      "rawMarkdown": "If you try to read a file using pydicom on the GCS, for example:\ndcom = pydicom.dcmread(f'{GCS_PATH}/train_images/1.2.826.0.1.3680043.10001/1.dcm')\nyou get an error \"FileNotFoundError: [Errno 2] No such file or directory\".\n\nBut if you use Pandas to read the \"train.csv\" under the same GCS_PATH, it works with no problem:\ntrain_df = pd.read_csv(f\"{GCS_PATH}/train.csv\")\n\nSo it appears pydicom refuses to work with files on GCS. Does anyone have a way to read dicom directly from GCS?",
      "votes": null
    },
    {
      "id": "1924562",
      "postDate": "09/03/2022 07:00:31",
      "content": "<p>What is your output if you print the \"GCS_PATH\"?</p>",
      "rawMarkdown": "What is your output if you print the \"GCS_PATH\"?",
      "votes": null
    },
    {
      "id": "1924833",
      "postDate": "09/03/2022 13:04:19",
      "content": "<p>gs://kds-ea6df003e64042a4465e34d7079d9b27214085a21968a59e22b53788</p>",
      "rawMarkdown": "gs://kds-ea6df003e64042a4465e34d7079d9b27214085a21968a59e22b53788",
      "votes": null
    },
    {
      "id": "1925042",
      "postDate": "09/03/2022 15:42:21",
      "content": "<p>Seems like a strange bug. I ran the following code to check whether the file and folder exist and I can see the file. But when running the dcmread command, I get the same error as you. I will have to do more research on it. </p>\n<pre><code>from kaggle_datasets import KaggleDatasets\nGCS_PATH = KaggleDatasets().get_gcs_path()\nGCS_PATH = GCS_PATH + \"/train_images/1.2.826.0.1.3680043.10001\"\n!gsutil ls $GCS_PATH \n</code></pre>",
      "rawMarkdown": "Seems like a strange bug. I ran the following code to check whether the file and folder exist and I can see the file. But when running the dcmread command, I get the same error as you. I will have to do more research on it. \n\n```\nfrom kaggle_datasets import KaggleDatasets\nGCS_PATH = KaggleDatasets().get_gcs_path()\nGCS_PATH = GCS_PATH + \"/train_images/1.2.826.0.1.3680043.10001\"\n!gsutil ls $GCS_PATH \n```",
      "votes": null
    },
    {
      "id": "1925181",
      "postDate": "09/03/2022 17:36:19",
      "content": "<p>I think the issue is that dcmread uses the python built-in function \"open()\" that can't handle the filepath like this. I think it's the same issue as talked about here:</p>\n<p><a href=\"https://stackoverflow.com/questions/56700236/how-to-load-the-file-use-the-gcs-path-without-ioerror\" target=\"_blank\">https://stackoverflow.com/questions/56700236/how-to-load-the-file-use-the-gcs-path-without-ioerror</a></p>",
      "rawMarkdown": "I think the issue is that dcmread uses the python built-in function \"open()\" that can't handle the filepath like this. I think it's the same issue as talked about here:\n\n[https://stackoverflow.com/questions/56700236/how-to-load-the-file-use-the-gcs-path-without-ioerror](https://stackoverflow.com/questions/56700236/how-to-load-the-file-use-the-gcs-path-without-ioerror)",
      "votes": null
    },
    {
      "id": "1925205",
      "postDate": "09/03/2022 17:50:33",
      "content": "<p>That seems to be the problem. Is there other way around this? Any other Python library that can read dicom on the GCS? Pandas can read csv for no problem. </p>",
      "rawMarkdown": "That seems to be the problem. Is there other way around this? Any other Python library that can read dicom on the GCS? Pandas can read csv for no problem.",
      "votes": null
    },
    {
      "id": "1925215",
      "postDate": "09/03/2022 18:05:26",
      "content": "<p>I think the data needs to be imported to work:</p>\n<p><a href=\"https://cloud.google.com/healthcare-api/docs/how-tos/dicom-import-export\" target=\"_blank\">https://cloud.google.com/healthcare-api/docs/how-tos/dicom-import-export</a></p>\n<p>I don't know of any other library. Sorry :(</p>\n<p>Alternatively, use the provided files within the storage.</p>\n<p><code>example_path = \"../input/rsna-2022-cervical-spine-fracture-detection/train_images/1.2.826.0.1.3680043.10443/1.dcm\"</code></p>\n<p>Maybe someone else has another idea or knows of any other library.</p>",
      "rawMarkdown": "I think the data needs to be imported to work:\n\n[https://cloud.google.com/healthcare-api/docs/how-tos/dicom-import-export](https://cloud.google.com/healthcare-api/docs/how-tos/dicom-import-export)\n\nI don't know of any other library. Sorry :(\n\nAlternatively, use the provided files within the storage.\n\n`example_path = \"../input/rsna-2022-cervical-spine-fracture-detection/train_images/1.2.826.0.1.3680043.10443/1.dcm\"`\n\nMaybe someone else has another idea or knows of any other library.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1924562,
      "author_name": "andir16",
      "author_url": "",
      "post_date": "09/03/2022 07:00:31",
      "content": "<p>What is your output if you print the \"GCS_PATH\"?</p>",
      "votes": null,
      "replies": [
        {
          "id": 1924833,
          "author_name": "azureblue83",
          "author_url": "",
          "post_date": "09/03/2022 13:04:19",
          "content": "<p>gs://kds-ea6df003e64042a4465e34d7079d9b27214085a21968a59e22b53788</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1925042,
          "author_name": "andir16",
          "author_url": "",
          "post_date": "09/03/2022 15:42:21",
          "content": "<p>Seems like a strange bug. I ran the following code to check whether the file and folder exist and I can see the file. But when running the dcmread command, I get the same error as you. I will have to do more research on it. </p>\n<pre><code>from kaggle_datasets import KaggleDatasets\nGCS_PATH = KaggleDatasets().get_gcs_path()\nGCS_PATH = GCS_PATH + \"/train_images/1.2.826.0.1.3680043.10001\"\n!gsutil ls $GCS_PATH \n</code></pre>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1925181,
          "author_name": "andir16",
          "author_url": "",
          "post_date": "09/03/2022 17:36:19",
          "content": "<p>I think the issue is that dcmread uses the python built-in function \"open()\" that can't handle the filepath like this. I think it's the same issue as talked about here:</p>\n<p><a href=\"https://stackoverflow.com/questions/56700236/how-to-load-the-file-use-the-gcs-path-without-ioerror\" target=\"_blank\">https://stackoverflow.com/questions/56700236/how-to-load-the-file-use-the-gcs-path-without-ioerror</a></p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1925205,
          "author_name": "azureblue83",
          "author_url": "",
          "post_date": "09/03/2022 17:50:33",
          "content": "<p>That seems to be the problem. Is there other way around this? Any other Python library that can read dicom on the GCS? Pandas can read csv for no problem. </p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1925215,
          "author_name": "andir16",
          "author_url": "",
          "post_date": "09/03/2022 18:05:26",
          "content": "<p>I think the data needs to be imported to work:</p>\n<p><a href=\"https://cloud.google.com/healthcare-api/docs/how-tos/dicom-import-export\" target=\"_blank\">https://cloud.google.com/healthcare-api/docs/how-tos/dicom-import-export</a></p>\n<p>I don't know of any other library. Sorry :(</p>\n<p>Alternatively, use the provided files within the storage.</p>\n<p><code>example_path = \"../input/rsna-2022-cervical-spine-fracture-detection/train_images/1.2.826.0.1.3680043.10443/1.dcm\"</code></p>\n<p>Maybe someone else has another idea or knows of any other library.</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "1924345": "If you try to read a file using pydicom on the GCS, for example:\ndcom = pydicom.dcmread(f'{GCS_PATH}/train_images/1.2.826.0.1.3680043.10001/1.dcm')\nyou get an error \"FileNotFoundError: [Errno 2] No such file or directory\".\n\nBut if you use Pandas to read the \"train.csv\" under the same GCS_PATH, it works with no problem:\ntrain_df = pd.read_csv(f\"{GCS_PATH}/train.csv\")\n\nSo it appears pydicom refuses to work with files on GCS. Does anyone have a way to read dicom directly from GCS?",
    "1924562": "What is your output if you print the \"GCS_PATH\"?",
    "1924833": "gs://kds-ea6df003e64042a4465e34d7079d9b27214085a21968a59e22b53788",
    "1925042": "Seems like a strange bug. I ran the following code to check whether the file and folder exist and I can see the file. But when running the dcmread command, I get the same error as you. I will have to do more research on it. \n\n```\nfrom kaggle_datasets import KaggleDatasets\nGCS_PATH = KaggleDatasets().get_gcs_path()\nGCS_PATH = GCS_PATH + \"/train_images/1.2.826.0.1.3680043.10001\"\n!gsutil ls $GCS_PATH \n```",
    "1925181": "I think the issue is that dcmread uses the python built-in function \"open()\" that can't handle the filepath like this. I think it's the same issue as talked about here:\n\n[https://stackoverflow.com/questions/56700236/how-to-load-the-file-use-the-gcs-path-without-ioerror](https://stackoverflow.com/questions/56700236/how-to-load-the-file-use-the-gcs-path-without-ioerror)",
    "1925205": "That seems to be the problem. Is there other way around this? Any other Python library that can read dicom on the GCS? Pandas can read csv for no problem.",
    "1925215": "I think the data needs to be imported to work:\n\n[https://cloud.google.com/healthcare-api/docs/how-tos/dicom-import-export](https://cloud.google.com/healthcare-api/docs/how-tos/dicom-import-export)\n\nI don't know of any other library. Sorry :(\n\nAlternatively, use the provided files within the storage.\n\n`example_path = \"../input/rsna-2022-cervical-spine-fracture-detection/train_images/1.2.826.0.1.3680043.10443/1.dcm\"`\n\nMaybe someone else has another idea or knows of any other library."
  },
  "source": "meta"
}